diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-04 18:59:31 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-04 18:59:31 +0800 |
commit | e165c2d23cf29fdec51c59f42f74735be2a8e1ff (patch) | |
tree | 375a6b3870c6b4f791c79128a4d7b29015b64851 /eth/backend.go | |
parent | dda3bf3ce7ef109541adb6f0020f8d2dd28e5e51 (diff) | |
parent | e46ab3bdcde7236c8fe54d6c83655e50bd19fe31 (diff) | |
download | dexon-e165c2d23cf29fdec51c59f42f74735be2a8e1ff.tar.gz dexon-e165c2d23cf29fdec51c59f42f74735be2a8e1ff.tar.zst dexon-e165c2d23cf29fdec51c59f42f74735be2a8e1ff.zip |
Merge pull request #1934 from karalabe/polish-protocol-infos
eth, p2p, rpc/api: polish protocol info gathering
Diffstat (limited to 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 60 |
1 files changed, 4 insertions, 56 deletions
diff --git a/eth/backend.go b/eth/backend.go index 0683705df..9eb211e31 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -467,62 +467,10 @@ func New(config *Config) (*Ethereum, error) { return eth, nil } -type NodeInfo struct { - Name string - NodeUrl string - NodeID string - IP string - DiscPort int // UDP listening port for discovery protocol - TCPPort int // TCP listening port for RLPx - Td string - ListenAddr string -} - -func (s *Ethereum) NodeInfo() *NodeInfo { - node := s.net.Self() - - return &NodeInfo{ - Name: s.Name(), - NodeUrl: node.String(), - NodeID: node.ID.String(), - IP: node.IP.String(), - DiscPort: int(node.UDP), - TCPPort: int(node.TCP), - ListenAddr: s.net.ListenAddr, - Td: s.BlockChain().GetTd(s.BlockChain().CurrentBlock().Hash()).String(), - } -} - -type PeerInfo struct { - ID string - Name string - Caps string - RemoteAddress string - LocalAddress string -} - -func newPeerInfo(peer *p2p.Peer) *PeerInfo { - var caps []string - for _, cap := range peer.Caps() { - caps = append(caps, cap.String()) - } - return &PeerInfo{ - ID: peer.ID().String(), - Name: peer.Name(), - Caps: strings.Join(caps, ", "), - RemoteAddress: peer.RemoteAddr().String(), - LocalAddress: peer.LocalAddr().String(), - } -} - -// PeersInfo returns an array of PeerInfo objects describing connected peers -func (s *Ethereum) PeersInfo() (peersinfo []*PeerInfo) { - for _, peer := range s.net.Peers() { - if peer != nil { - peersinfo = append(peersinfo, newPeerInfo(peer)) - } - } - return +// Network retrieves the underlying P2P network server. This should eventually +// be moved out into a protocol independent package, but for now use an accessor. +func (s *Ethereum) Network() *p2p.Server { + return s.net } func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) { |