diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 4913373ae..1637129c4 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -64,6 +64,7 @@ type AddrBook interface { ReinstateBadPeers() IsGood(*p2p.NetAddress) bool + IsBanned(*p2p.NetAddress) bool // Send a selection of addresses to peers GetSelection() []*p2p.NetAddress @@ -221,6 +222,14 @@ func (a *addrBook) IsGood(addr *p2p.NetAddress) bool { return a.addrLookup[addr.ID].isOld() } +func (a *addrBook) IsBanned(addr *p2p.NetAddress) bool { + a.mtx.Lock() + defer a.mtx.Unlock() + + _, ok := a.badPeers[addr.ID] + return ok +} + // HasAddress returns true if the address is in the book. func (a *addrBook) HasAddress(addr *p2p.NetAddress) bool { a.mtx.Lock() diff --git a/p2p/pex/addrbook_test.go b/p2p/pex/addrbook_test.go index 454b0070f..51e968693 100644 --- a/p2p/pex/addrbook_test.go +++ b/p2p/pex/addrbook_test.go @@ -408,6 +408,7 @@ func TestBanBadPeers(t *testing.T) { book.MarkBad(addr, 1*time.Second) // addr should not reachable assert.False(t, book.HasAddress(addr)) + assert.True(t, book.IsBanned(addr)) err := book.AddAddress(addr, addr) // book should not add address from the blacklist