diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 207b6a1c3..6e8397cd6 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -222,11 +222,12 @@ func (a *addrBook) IsGood(addr *p2p.NetAddress) bool { return a.addrLookup[addr.ID].isOld() } +// IsBanned returns true if the peer is currently banned func (a *addrBook) IsBanned(addr *p2p.NetAddress) bool { a.mtx.Lock() - defer a.mtx.Unlock() - _, ok := a.badPeers[addr.ID] + a.mtx.Unlock() + return ok } @@ -351,7 +352,7 @@ func (a *addrBook) ReinstateBadPeers() { bucket := a.calcNewBucket(ka.Addr, ka.Src) a.addToNewBucket(ka, bucket) delete(a.badPeers, ka.ID()) - a.Logger.Info("Reinstated Address", "addr", ka.Addr) + a.Logger.Info("Reinstated address", "addr", ka.Addr) } } } diff --git a/p2p/pex/errors.go b/p2p/pex/errors.go index 1ea5a3b3e..1892b5fff 100644 --- a/p2p/pex/errors.go +++ b/p2p/pex/errors.go @@ -64,6 +64,7 @@ func (err ErrAddrBookInvalidAddr) Error() string { return fmt.Sprintf("Cannot add invalid address %v: %v", err.Addr, err.AddrErr) } +// Err is thrown when the address is banned and therefore cannot be used type ErrAddressBanned struct { Addr *p2p.NetAddress } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index afe29e16e..b0a1c02bb 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -534,10 +534,6 @@ func (r *Reactor) dialAttemptsInfo(addr *p2p.NetAddress) (attempts int, lastDial func (r *Reactor) dialPeer(addr *p2p.NetAddress) error { attempts, lastDialed := r.dialAttemptsInfo(addr) if !r.Switch.IsPeerPersistent(addr) && attempts > maxAttemptsToDial { - // TODO(melekes): have a blacklist in the addrbook with peers whom we've - // failed to connect to. Then we can clean up attemptsToDial, which acts as - // a blacklist currently. - // https://github.com/tendermint/tendermint/issues/3572 r.book.MarkBad(addr, defaultBanTime) return errMaxAttemptsToDial{} }