1
0
Fork 0
forked from External/ergo

initial UBAN implementation

This commit is contained in:
Shivaram Lingamneni 2021-01-19 08:49:45 -05:00
parent 64bc363cf1
commit bb5276553d
14 changed files with 598 additions and 44 deletions

View file

@ -209,6 +209,38 @@ func (cl *Limiter) RemoveClient(addr flatip.IP) {
cl.limiter[addrString] = count
}
type LimiterStatus struct {
Exempt bool
Count int
MaxCount int
Throttle int
MaxPerWindow int
ThrottleDuration time.Duration
}
func (cl *Limiter) Status(addr flatip.IP) (status LimiterStatus) {
cl.Lock()
defer cl.Unlock()
if flatip.IPInNets(addr, cl.config.exemptedNets) {
status.Exempt = true
return
}
status.ThrottleDuration = cl.config.Window
addrString, maxConcurrent, maxPerWindow := cl.addrToKey(addr)
status.MaxCount = maxConcurrent
status.MaxPerWindow = maxPerWindow
status.Count = cl.limiter[addrString]
status.Throttle = cl.throttler[addrString].Count
return
}
// ResetThrottle resets the throttle count for an IP
func (cl *Limiter) ResetThrottle(addr flatip.IP) {
cl.Lock()