mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
cmd/strelaypoolsrv: Simplify LRU usage (#6507)
This commit is contained in:
parent
88cabb9e0a
commit
674a99e9ae
@ -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()
|
lock.Unlock()
|
||||||
}
|
|
||||||
return false
|
return !bkt.Allow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadRelays(file string) []*relay {
|
func loadRelays(file string) []*relay {
|
||||||
|
Loading…
Reference in New Issue
Block a user