forked from cerc-io/plugeth
p2p: move peerList back into baseProtocol
It had been moved to Peer, probably for debugging.
This commit is contained in:
parent
eb0e7b1b81
commit
b0ff946b55
22
p2p/peer.go
22
p2p/peer.go
@ -460,25 +460,3 @@ func (r *eofSignal) Read(buf []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
return n, err
|
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
|
|
||||||
}
|
|
||||||
|
@ -169,7 +169,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error {
|
|||||||
case pongMsg:
|
case pongMsg:
|
||||||
|
|
||||||
case getPeersMsg:
|
case getPeersMsg:
|
||||||
peers := bp.peer.PeerList()
|
peers := bp.peerList()
|
||||||
// this is dangerous. the spec says that we should _delay_
|
// this is dangerous. the spec says that we should _delay_
|
||||||
// sending the response if no new information is available.
|
// sending the response if no new information is available.
|
||||||
// this means that would need to send a response later when
|
// 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:],
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user