feat(botfilter): cache.go part 3/5

This commit is contained in:
hoelee committed 2026-02-11 09:58:00 +08:00
1 parent 618122a6fb
commit 54a0655e4c
1 file changed
+18
+18
View File
@@ -97,3 +97,21 @@ func (c *clientCache) observeRequest(ip string, observation requestObservation)
c.entries[ip] = state
}
c.pruneEventsLocked(state, observation.at)
points := observation.points + c.behaviorScoreLocked(state, observation.paths)
state.requests++
state.lastSeen = observation.at
if points > 0 {
state.events = append(state.events, scoreEvent{at: observation.at, points: points})
if len(state.events) > c.maxEvents {
state.events = append([]scoreEvent(nil), state.events[len(state.events)-c.maxEvents:]...)
}
}
score := sumScore(state.events)
if observation.forceBan || score >= c.threshold {
state.banUntil = observation.at.Add(c.banDuration)
return cacheResult{banned: true, banUntil: state.banUntil, score: score}
}
return cacheResult{score: score}
}