From 08ccbdcb43c214f2f349d6b2f2d6f6c271985836 Mon Sep 17 00:00:00 2001 From: Callum Michael Waters Date: Wed, 11 Mar 2020 15:06:42 +0100 Subject: [PATCH] ban function requires a ban duration as an argument --- p2p/pex/addrbook.go | 4 ++-- p2p/pex/known_address.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index c99ea75e5..c3351a600 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -339,7 +339,7 @@ func (a *addrBook) ReinstateBadPeers() { a.mtx.Lock() defer a.mtx.Unlock() for _, ka := range a.badPeers { - if !ka.isBanned(defaultBanTime) { + if !ka.isBanned() { bucket := a.calcNewBucket(ka.Addr, ka.Src) a.addToNewBucket(ka, bucket) delete(a.badPeers, ka.ID()) @@ -761,7 +761,7 @@ func (a *addrBook) addBadPeer(addr *p2p.NetAddress) bool { if ka != nil { if _, alreadyBadPeer := a.badPeers[addr.ID]; !alreadyBadPeer { // add to bad peer list - ka.ban() + ka.ban(defaultBanTime) a.badPeers[addr.ID] = ka } return true diff --git a/p2p/pex/known_address.go b/p2p/pex/known_address.go index 9d4d060a5..fdd055a13 100644 --- a/p2p/pex/known_address.go +++ b/p2p/pex/known_address.go @@ -55,12 +55,12 @@ func (ka *knownAddress) markGood() { ka.LastSuccess = now } -func (ka *knownAddress) ban() { - ka.LastBanTime = time.Now() +func (ka *knownAddress) ban(banTime time.Duration) { + ka.LastBanTime = time.Now().Add(banTime) } -func (ka *knownAddress) isBanned(banTime time.Duration) bool { - return ka.LastBanTime.Add(banTime).Before(time.Now()) +func (ka *knownAddress) isBanned() bool { + return ka.LastBanTime.Before(time.Now()) } func (ka *knownAddress) addBucketRef(bucketIdx int) int {