mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
made ratelimit configurable
This commit is contained in:
parent
88b01e3c83
commit
c6730945dc
4 changed files with 22 additions and 11 deletions
14
bird/bird.go
14
bird/bird.go
|
@ -9,9 +9,7 @@ import (
|
|||
|
||||
var ClientConf BirdConfig
|
||||
var StatusConf StatusConfig
|
||||
|
||||
var rateLimit = 0
|
||||
var MAX_RATE = 5
|
||||
var rateLimitConf RateLimitConfig
|
||||
|
||||
var Cache = struct {
|
||||
sync.RWMutex
|
||||
|
@ -43,17 +41,21 @@ func InstallRateLimitReset() {
|
|||
c := time.Tick(time.Second)
|
||||
|
||||
for _ = range c {
|
||||
rateLimit = 0
|
||||
rateLimitConf.Reqs = 0
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func checkRateLimit() bool {
|
||||
if rateLimit > MAX_RATE {
|
||||
if !rateLimitConf.Enabled {
|
||||
return true
|
||||
}
|
||||
|
||||
if rateLimitConf.Reqs > rateLimitConf.Max {
|
||||
return false
|
||||
}
|
||||
|
||||
rateLimit += 1
|
||||
rateLimitConf.Reqs += 1
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -14,3 +14,9 @@ type BirdConfig struct {
|
|||
ConfigFilename string `toml:"config"`
|
||||
BirdCmd string `toml:"birdc"`
|
||||
}
|
||||
|
||||
type RateLimitConfig struct {
|
||||
Reqs int `toml:"requests_per_minute"`
|
||||
Max int `toml:"requests_per_minute"`
|
||||
Enabled bool
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@ import (
|
|||
type Config struct {
|
||||
Server endpoints.ServerConfig
|
||||
|
||||
Status bird.StatusConfig
|
||||
Bird bird.BirdConfig
|
||||
Bird6 bird.BirdConfig
|
||||
Ratelimit bird.RateLimitConfig
|
||||
Status bird.StatusConfig
|
||||
Bird bird.BirdConfig
|
||||
Bird6 bird.BirdConfig
|
||||
}
|
||||
|
||||
// Try to load configfiles as specified in the files
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
#
|
||||
# Birdwatcher Configuration
|
||||
#
|
||||
|
@ -36,6 +34,10 @@ reconfig_timestamp_match = "# Created: (.*)"
|
|||
# Remove fields e.g. last_reboot
|
||||
filter_fields = []
|
||||
|
||||
[ratelimit]
|
||||
enabled = true
|
||||
requests_per_minute = 10
|
||||
|
||||
|
||||
[bird]
|
||||
listen = "0.0.0.0:29188"
|
||||
|
|
Loading…
Add table
Reference in a new issue