52 lines
915 B
Go
52 lines
915 B
Go
package botfilter
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type scoreEvent struct {
|
|
at time.Time
|
|
points int
|
|
}
|
|
|
|
type clientState struct {
|
|
banUntil time.Time
|
|
lastSeen time.Time
|
|
requests int
|
|
sawHome bool
|
|
sawStatic bool
|
|
sawFavicon bool
|
|
events []scoreEvent
|
|
}
|
|
|
|
type requestObservation struct {
|
|
at time.Time
|
|
paths []string
|
|
points int
|
|
forceBan bool
|
|
}
|
|
|
|
type cacheResult struct {
|
|
banned bool
|
|
banUntil time.Time
|
|
score int
|
|
}
|
|
|
|
// clientCache deliberately has no background goroutine. A middleware
|
|
// instance can be discarded on a Traefik reload without needing goroutine
|
|
// cleanup, and opportunistic cleanup keeps its memory use bounded.
|
|
type clientCache struct {
|
|
mu sync.Mutex
|
|
entries map[string]*clientState
|
|
maxEntries int
|
|
maxEvents int
|
|
scoreWindow time.Duration
|
|
banDuration time.Duration
|
|
threshold int
|
|
randomPaths []string
|
|
randomScore int
|
|
operations uint64
|
|
}
|
|
|