-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
25 lines (21 loc) · 1008 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package ratelimit
import (
"time"
"github.com/zeta-protocol/zeta/datanode/config/encoding"
)
type Config struct {
Enabled bool `long:"enabled" description:"Enable rate limit of API requests per IP address. Based on a 'token bucket' algorithm"`
Rate float64 `long:"rate" description:"Refill rate of token bucket; maximum average request rate"`
Burst int `long:"burst" description:"Size of token bucket; maximum number of requests in short time window"`
TTL encoding.Duration `long:"ttl" description:"Time after which inactive token buckets are reset"`
BanFor encoding.Duration `long:"banfor" description:"If IP continues to make requests after passing rate limit threshold, ban for this duration. Setting to 0 seconds disables banning."`
}
func NewDefaultConfig() Config {
return Config{
Enabled: true,
Rate: 20,
Burst: 100,
TTL: encoding.Duration{Duration: time.Hour},
BanFor: encoding.Duration{Duration: 10 * time.Minute},
}
}