mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-22 07:06:14 +00:00
added isBanned check in addrbook
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user