Skip to content

Commit b0ff946

Browse files
committed
p2p: move peerList back into baseProtocol
It had been moved to Peer, probably for debugging.
1 parent eb0e7b1 commit b0ff946

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

‎p2p/peer.go‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -460,25 +460,3 @@ func (r *eofSignal) Read(buf []byte) (int, error) {
460460
}
461461
return n, err
462462
}
463-
464-
func (peer *Peer) PeerList() []interface{} {
465-
peers := peer.otherPeers()
466-
ds := make([]interface{}, 0, len(peers))
467-
for _, p := range peers {
468-
p.infolock.Lock()
469-
addr := p.listenAddr
470-
p.infolock.Unlock()
471-
// filter out this peer and peers that are not listening or
472-
// have not completed the handshake.
473-
// TODO: track previously sent peers and exclude them as well.
474-
if p == peer || addr == nil {
475-
continue
476-
}
477-
ds = append(ds, addr)
478-
}
479-
ourAddr := peer.ourListenAddr
480-
if ourAddr != nil && !ourAddr.IP.IsLoopback() && !ourAddr.IP.IsUnspecified() {
481-
ds = append(ds, ourAddr)
482-
}
483-
return ds
484-
}

‎p2p/protocol.go‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
169169
case pongMsg:
170170

171171
case getPeersMsg:
172-
peers := bp.peer.PeerList()
172+
peers := bp.peerList()
173173
// this is dangerous. the spec says that we should _delay_
174174
// sending the response if no new information is available.
175175
// this means that would need to send a response later when
@@ -264,3 +264,25 @@ func (bp *baseProtocol) handshakeMsg() Msg {
264264
bp.peer.ourID.Pubkey()[1:],
265265
)
266266
}
267+
268+
func (bp *baseProtocol) peerList() []interface{} {
269+
peers := bp.peer.otherPeers()
270+
ds := make([]interface{}, 0, len(peers))
271+
for _, p := range peers {
272+
p.infolock.Lock()
273+
addr := p.listenAddr
274+
p.infolock.Unlock()
275+
// filter out this peer and peers that are not listening or
276+
// have not completed the handshake.
277+
// TODO: track previously sent peers and exclude them as well.
278+
if p == bp.peer || addr == nil {
279+
continue
280+
}
281+
ds = append(ds, addr)
282+
}
283+
ourAddr := bp.peer.ourListenAddr
284+
if ourAddr != nil && !ourAddr.IP.IsLoopback() && !ourAddr.IP.IsUnspecified() {
285+
ds = append(ds, ourAddr)
286+
}
287+
return ds
288+
}

0 commit comments

Comments
 (0)