forked from External/ergo
remove more indirections
This commit is contained in:
parent
353aeb0389
commit
80a594802f
6 changed files with 25 additions and 48 deletions
|
|
@ -150,17 +150,6 @@ func (ct *Throttler) BanMessage() string {
|
|||
return ct.banMessage
|
||||
}
|
||||
|
||||
// NewThrottler returns a new client connection throttler.
|
||||
// The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.
|
||||
func NewThrottler() *Throttler {
|
||||
var ct Throttler
|
||||
|
||||
// initialize empty population; all other state is configurable
|
||||
ct.population = make(map[string]ThrottleDetails)
|
||||
|
||||
return &ct
|
||||
}
|
||||
|
||||
// ApplyConfig atomically applies a config update to a throttler
|
||||
func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
|
||||
// assemble exempted nets
|
||||
|
|
@ -172,6 +161,10 @@ func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
|
|||
ct.Lock()
|
||||
defer ct.Unlock()
|
||||
|
||||
if ct.population == nil {
|
||||
ct.population = make(map[string]ThrottleDetails)
|
||||
}
|
||||
|
||||
ct.enabled = config.Enabled
|
||||
ct.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
|
||||
ct.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue