added isBanned check in addrbook

This commit is contained in:
Callum Michael Waters
2020-03-11 16:43:32 +01:00
parent 2f2d62efed
commit 1e37a1f3e4
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -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()
+1
View File
@@ -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