cmd/strelaypoolsrv: Simplify LRU usage (#6507)
This commit is contained in:
@@ -589,19 +589,15 @@ func limit(addr string, cache *lru.Cache, lock sync.Mutex, intv time.Duration, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
bkt, ok := cache.Get(addr)
|
v, _ := cache.Get(addr)
|
||||||
if ok {
|
bkt, ok := v.(*rate.Limiter)
|
||||||
lock.Unlock()
|
if !ok {
|
||||||
bkt := bkt.(*rate.Limiter)
|
bkt = rate.NewLimiter(rate.Every(intv), burst)
|
||||||
if !bkt.Allow() {
|
cache.Add(addr, bkt)
|
||||||
// Rate limit
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cache.Add(addr, rate.NewLimiter(rate.Every(intv), burst))
|
|
||||||
lock.Unlock()
|
|
||||||
}
|
}
|
||||||
return false
|
lock.Unlock()
|
||||||
|
|
||||||
|
return !bkt.Allow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadRelays(file string) []*relay {
|
func loadRelays(file string) []*relay {
|
||||||
|
|||||||
Reference in New Issue
Block a user