feat(botfilter): add clientCache.cleanupLocked
This commit is contained in:
1 parent
f9bc58409a
commit
6269efeeab
1 file changed
+14
@@ -177,3 +177,17 @@ func (c *clientCache) pruneEventsLocked(state *clientState, now time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *clientCache) cleanupLocked(now time.Time) {
|
||||
// Full cleanup every 256 requests amortises the map scan while retaining
|
||||
// recently scored clients for the entire score window.
|
||||
if c.operations%256 != 0 {
|
||||
return
|
||||
}
|
||||
cutoff := now.Add(-c.scoreWindow)
|
||||
for ip, state := range c.entries {
|
||||
if !state.banUntil.After(now) && !state.lastSeen.After(cutoff) {
|
||||
delete(c.entries, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user