From 1e37a1f3e489eb97d132d6d92277e5f341e1ba24 Mon Sep 17 00:00:00 2001 From: Callum Michael Waters Date: Wed, 11 Mar 2020 16:43:32 +0100 Subject: [PATCH] added isBanned check in addrbook --- p2p/pex/addrbook.go | 9 +++++++++ p2p/pex/addrbook_test.go | 1 + 2 files changed, 10 insertions(+) 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