Browse Source

cannot decrease ban time

pull/4548/head
Callum Michael Waters 4 years ago
parent
commit
7e6b1a87da
3 changed files with 14 additions and 11 deletions
  1. +10
    -9
      p2p/pex/addrbook.go
  2. +1
    -1
      p2p/pex/errors.go
  3. +3
    -1
      p2p/pex/known_address.go

+ 10
- 9
p2p/pex/addrbook.go View File

@ -769,16 +769,17 @@ func (a *addrBook) addBadPeer(addr *p2p.NetAddress, banTime time.Duration) bool
// check it exists in addrbook
ka := a.addrLookup[addr.ID]
// check address is not already there
if ka != nil {
if _, alreadyBadPeer := a.badPeers[addr.ID]; !alreadyBadPeer {
// add to bad peer list
ka.ban(banTime)
a.badPeers[addr.ID] = ka
a.Logger.Info("Add address to blacklist", "addr", addr)
}
return true
if ka == nil {
return false
}
if _, alreadyBadPeer := a.badPeers[addr.ID]; !alreadyBadPeer {
// add to bad peer list
ka.ban(banTime)
a.badPeers[addr.ID] = ka
a.Logger.Info("Add address to blacklist", "addr", addr)
}
return false
return true
}
//---------------------------------------------------------------------


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

@ -64,7 +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
// ErrAddressBanned is thrown when the address has been banned and therefore cannot be used
type ErrAddressBanned struct {
Addr *p2p.NetAddress
}


+ 3
- 1
p2p/pex/known_address.go View File

@ -56,7 +56,9 @@ func (ka *knownAddress) markGood() {
}
func (ka *knownAddress) ban(banTime time.Duration) {
ka.LastBanTime = time.Now().Add(banTime)
if ka.LastBanTime.Before(time.Now().Add(banTime)) {
ka.LastBanTime = time.Now().Add(banTime)
}
}
func (ka *knownAddress) isBanned() bool {


Loading…
Cancel
Save