You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

  1. package core
  2. import (
  3. "fmt"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. )
  6. //-----------------------------------------------------------------------------
  7. func NetInfo() (*ctypes.ResultNetInfo, error) {
  8. listening := p2pSwitch.IsListening()
  9. listeners := []string{}
  10. for _, listener := range p2pSwitch.Listeners() {
  11. listeners = append(listeners, listener.String())
  12. }
  13. peers := []ctypes.Peer{}
  14. for _, peer := range p2pSwitch.Peers().List() {
  15. peers = append(peers, ctypes.Peer{
  16. NodeInfo: *peer.NodeInfo,
  17. IsOutbound: peer.IsOutbound(),
  18. ConnectionStatus: peer.Connection().Status(),
  19. })
  20. }
  21. return &ctypes.ResultNetInfo{
  22. Listening: listening,
  23. Listeners: listeners,
  24. Peers: peers,
  25. }, nil
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Dial given list of seeds if we have no outbound peers
  29. func DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
  30. outbound, _, _ := p2pSwitch.NumPeers()
  31. if outbound != 0 {
  32. return nil, fmt.Errorf("Already have some outbound peers")
  33. }
  34. // starts go routines to dial each seed after random delays
  35. p2pSwitch.DialSeeds(seeds)
  36. return &ctypes.ResultDialSeeds{}, nil
  37. }
  38. //-----------------------------------------------------------------------------
  39. func Genesis() (*ctypes.ResultGenesis, error) {
  40. return &ctypes.ResultGenesis{genDoc}, nil
  41. }