diff options
author | Felix Lange <fjl@twurst.com> | 2015-01-06 19:14:29 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-01-06 19:23:38 +0800 |
commit | b0ff946b55c23f0fffc50a700bcb255f95855afc (patch) | |
tree | 4b9ad93f4b7385146978eaaea5af974ec75b5ed2 /p2p | |
parent | eb0e7b1b8120852a1d56aa0ebd3a98e652965635 (diff) | |
download | dexon-b0ff946b55c23f0fffc50a700bcb255f95855afc.tar.gz dexon-b0ff946b55c23f0fffc50a700bcb255f95855afc.tar.zst dexon-b0ff946b55c23f0fffc50a700bcb255f95855afc.zip |
p2p: move peerList back into baseProtocol
It had been moved to Peer, probably for debugging.
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/peer.go | 22 | ||||
-rw-r--r-- | p2p/protocol.go | 24 |
2 files changed, 23 insertions, 23 deletions
diff --git a/p2p/peer.go b/p2p/peer.go index 0d7eec9f4..2380a3285 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -460,25 +460,3 @@ func (r *eofSignal) Read(buf []byte) (int, error) { } return n, err } - -func (peer *Peer) PeerList() []interface{} { - peers := peer.otherPeers() - ds := make([]interface{}, 0, len(peers)) - for _, p := range peers { - p.infolock.Lock() - addr := p.listenAddr - p.infolock.Unlock() - // filter out this peer and peers that are not listening or - // have not completed the handshake. - // TODO: track previously sent peers and exclude them as well. - if p == peer || addr == nil { - continue - } - ds = append(ds, addr) - } - ourAddr := peer.ourListenAddr - if ourAddr != nil && !ourAddr.IP.IsLoopback() && !ourAddr.IP.IsUnspecified() { - ds = append(ds, ourAddr) - } - return ds -} diff --git a/p2p/protocol.go b/p2p/protocol.go index 969937076..1d121a885 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -169,7 +169,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error { case pongMsg: case getPeersMsg: - peers := bp.peer.PeerList() + peers := bp.peerList() // this is dangerous. the spec says that we should _delay_ // sending the response if no new information is available. // this means that would need to send a response later when @@ -264,3 +264,25 @@ func (bp *baseProtocol) handshakeMsg() Msg { bp.peer.ourID.Pubkey()[1:], ) } + +func (bp *baseProtocol) peerList() []interface{} { + peers := bp.peer.otherPeers() + ds := make([]interface{}, 0, len(peers)) + for _, p := range peers { + p.infolock.Lock() + addr := p.listenAddr + p.infolock.Unlock() + // filter out this peer and peers that are not listening or + // have not completed the handshake. + // TODO: track previously sent peers and exclude them as well. + if p == bp.peer || addr == nil { + continue + } + ds = append(ds, addr) + } + ourAddr := bp.peer.ourListenAddr + if ourAddr != nil && !ourAddr.IP.IsLoopback() && !ourAddr.IP.IsUnspecified() { + ds = append(ds, ourAddr) + } + return ds +} |