Added host rules + minor refactoring

This commit is contained in:
simon
2019-06-04 22:02:50 -04:00
parent 2b77188ef4
commit 7b0e9a0c13
7 changed files with 513 additions and 81 deletions

18
gc.go
View File

@@ -42,32 +42,20 @@ func cleanExpiredLimits(proxy *Proxy) {
const ttl = time.Hour
limits := make(map[string]*ExpiringLimiter, 0)
var limits []*ExpiringLimiter
now := time.Now()
for host, limiter := range proxy.Limiters {
if now.Sub(limiter.LastRead) > ttl && shouldPruneLimiter(host) {
if now.Sub(limiter.LastRead) > ttl && limiter.CanDelete {
logrus.WithFields(logrus.Fields{
"proxy": proxy.Name,
"limiter": host,
"last_read": now.Sub(limiter.LastRead),
}).Trace("Pruning limiter")
} else {
limits[host] = limiter
limits = append(limits, limiter)
}
}
proxy.Limiters = limits
}
func shouldPruneLimiter(host string) bool {
// Don't remove hosts that are coming from the config
for _, conf := range config.Hosts {
if conf.Host == host {
return false
}
}
return true
}