mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
remove more indirections
This commit is contained in:
parent
353aeb0389
commit
80a594802f
6 changed files with 25 additions and 48 deletions
|
|
@ -98,17 +98,6 @@ func (cl *Limiter) RemoveClient(addr net.IP) {
|
|||
}
|
||||
}
|
||||
|
||||
// NewLimiter returns a new connection limit handler.
|
||||
// The handler is functional, but disabled; it can be enabled via `ApplyConfig`.
|
||||
func NewLimiter() *Limiter {
|
||||
var cl Limiter
|
||||
|
||||
// initialize empty population; all other state is configurable
|
||||
cl.population = make(map[string]int)
|
||||
|
||||
return &cl
|
||||
}
|
||||
|
||||
// ApplyConfig atomically applies a config update to a connection limit handler
|
||||
func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
|
||||
// assemble exempted nets
|
||||
|
|
@ -120,6 +109,10 @@ func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
|
|||
cl.Lock()
|
||||
defer cl.Unlock()
|
||||
|
||||
if cl.population == nil {
|
||||
cl.population = make(map[string]int)
|
||||
}
|
||||
|
||||
cl.enabled = config.Enabled
|
||||
cl.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
|
||||
cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue