diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index cb9e62bfd..5b53d3f43 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -257,10 +257,7 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error { srcAddr := src.NodeInfo().NetAddress() for _, netAddr := range addrs { - if netAddr == nil { - continue - } - if !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) { + if netAddr != nil && !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) { r.book.AddAddress(netAddr, srcAddr) } } diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index 41eb2e8dd..95cedfea5 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -269,21 +269,21 @@ func TestPEXReactorCrawlStatus(t *testing.T) { } func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) { + peer := p2p.CreateRandomPeer(false) + pexR, book := createReactor(&PEXReactorConfig{PrivatePeerIDs: []string{string(peer.NodeInfo().ID())}}) defer teardownReactor(book) - peer := p2p.CreateRandomPeer(false) - // we have to send a request to receive responses - r.RequestAddrs(peer) + pexR.RequestAddrs(peer) size := book.Size() addrs := []*p2p.NetAddress{peer.NodeInfo().NetAddress()} msg := wire.BinaryBytes(struct{ PexMessage }{&pexAddrsMessage{Addrs: addrs}}) - r.Receive(PexChannel, peer, msg) + pexR.Receive(PexChannel, peer, msg) assert.Equal(t, size, book.Size()) - r.AddPeer(peer) + pexR.AddPeer(peer) assert.Equal(t, size, book.Size()) } @@ -395,7 +395,7 @@ func createReactor(config *PEXReactorConfig) (r *PEXReactor, book *addrBook) { book = NewAddrBook(filepath.Join(dir, "addrbook.json"), true) book.SetLogger(log.TestingLogger()) - r = NewPEXReactor(book, &PEXReactorConfig{}) + r = NewPEXReactor(book, config) r.SetLogger(log.TestingLogger()) return }