rename private_peers to private_peer_ids to distinguish from peers

This commit is contained in:
Anton Kaliaev
2018-03-15 11:55:30 +04:00
parent 8bef3eb1f4
commit a39aec0bae
7 changed files with 67 additions and 20 deletions
+21 -2
View File
@@ -74,6 +74,10 @@ type PEXReactorConfig struct {
// Seeds is a list of addresses reactor may use
// if it can't connect to peers in the addrbook.
Seeds []string
// PrivatePeerIDs is a list of peer IDs, which must not be gossiped to other
// peers.
PrivatePeerIDs []string
}
type _attemptsToDial struct {
@@ -152,7 +156,9 @@ func (r *PEXReactor) AddPeer(p Peer) {
// Let the ensurePeersRoutine handle asking for more
// peers when we need - we don't trust inbound peers as much.
addr := p.NodeInfo().NetAddress()
r.book.AddAddress(addr, addr)
if !isAddrPrivate(addr, r.config.PrivatePeerIDs) {
r.book.AddAddress(addr, addr)
}
}
}
@@ -251,7 +257,10 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
srcAddr := src.NodeInfo().NetAddress()
for _, netAddr := range addrs {
if netAddr != nil {
if netAddr == nil {
continue
}
if !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) {
r.book.AddAddress(netAddr, srcAddr)
}
}
@@ -579,6 +588,16 @@ func (r *PEXReactor) attemptDisconnects() {
}
}
// isAddrPrivate returns true if addr is private.
func isAddrPrivate(addr *p2p.NetAddress, privatePeerIDs []string) bool {
for _, id := range privatePeerIDs {
if string(addr.ID) == id {
return true
}
}
return false
}
//-----------------------------------------------------------------------------
// Messages