Browse Source

made suggested changes

pull/4548/head
Callum Michael Waters 5 years ago
parent
commit
c8bb1cc8b7
3 changed files with 5 additions and 7 deletions
  1. +4
    -3
      p2p/pex/addrbook.go
  2. +1
    -0
      p2p/pex/errors.go
  3. +0
    -4
      p2p/pex/pex_reactor.go

+ 4
- 3
p2p/pex/addrbook.go View File

@ -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)
}
}
}


+ 1
- 0
p2p/pex/errors.go View File

@ -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
}


+ 0
- 4
p2p/pex/pex_reactor.go View File

@ -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{}
}


Loading…
Cancel
Save