Browse Source

ban function requires a ban duration as an argument

pull/4548/head
Callum Michael Waters 5 years ago
parent
commit
08ccbdcb43
2 changed files with 6 additions and 6 deletions
  1. +2
    -2
      p2p/pex/addrbook.go
  2. +4
    -4
      p2p/pex/known_address.go

+ 2
- 2
p2p/pex/addrbook.go View File

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


+ 4
- 4
p2p/pex/known_address.go View File

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


Loading…
Cancel
Save