github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/mobile/p2p.go (about) 1 // Contains wrappers for the p2p package. 2 3 package geth 4 5 import ( 6 "errors" 7 8 "github.com/quickchainproject/quickchain/p2p" 9 ) 10 11 // NodeInfo represents pi short summary of the information known about the host. 12 type NodeInfo struct { 13 info *p2p.NodeInfo 14 } 15 16 func (ni *NodeInfo) GetID() string { return ni.info.ID } 17 func (ni *NodeInfo) GetName() string { return ni.info.Name } 18 func (ni *NodeInfo) GetEnode() string { return ni.info.Enode } 19 func (ni *NodeInfo) GetIP() string { return ni.info.IP } 20 func (ni *NodeInfo) GetDiscoveryPort() int { return ni.info.Ports.Discovery } 21 func (ni *NodeInfo) GetListenerPort() int { return ni.info.Ports.Listener } 22 func (ni *NodeInfo) GetListenerAddress() string { return ni.info.ListenAddr } 23 func (ni *NodeInfo) GetProtocols() *Strings { 24 protos := []string{} 25 for proto := range ni.info.Protocols { 26 protos = append(protos, proto) 27 } 28 return &Strings{protos} 29 } 30 31 // PeerInfo represents pi short summary of the information known about pi connected peer. 32 type PeerInfo struct { 33 info *p2p.PeerInfo 34 } 35 36 func (pi *PeerInfo) GetID() string { return pi.info.ID } 37 func (pi *PeerInfo) GetName() string { return pi.info.Name } 38 func (pi *PeerInfo) GetCaps() *Strings { return &Strings{pi.info.Caps} } 39 func (pi *PeerInfo) GetLocalAddress() string { return pi.info.Network.LocalAddress } 40 func (pi *PeerInfo) GetRemoteAddress() string { return pi.info.Network.RemoteAddress } 41 42 // PeerInfos represents a slice of infos about remote peers. 43 type PeerInfos struct { 44 infos []*p2p.PeerInfo 45 } 46 47 // Size returns the number of peer info entries in the slice. 48 func (pi *PeerInfos) Size() int { 49 return len(pi.infos) 50 } 51 52 // Get returns the peer info at the given index from the slice. 53 func (pi *PeerInfos) Get(index int) (info *PeerInfo, _ error) { 54 if index < 0 || index >= len(pi.infos) { 55 return nil, errors.New("index out of bounds") 56 } 57 return &PeerInfo{pi.infos[index]}, nil 58 }