mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 13:29:27 +01:00
create separate irc/connection_limiting package
This commit is contained in:
parent
a2ac4eeef9
commit
ac9ac5ef19
@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
"github.com/oragono/oragono/irc/connection_limiting"
|
||||
"github.com/oragono/oragono/irc/custime"
|
||||
"github.com/oragono/oragono/irc/logger"
|
||||
"github.com/oragono/oragono/irc/passwd"
|
||||
@ -108,29 +109,6 @@ func (conf *OperConfig) PasswordBytes() []byte {
|
||||
return bytes
|
||||
}
|
||||
|
||||
// ConnectionLimitsConfig controls the automated connection limits.
|
||||
type ConnectionLimitsConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
||||
IPsPerCidr int `yaml:"ips-per-subnet"`
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
// ConnectionThrottleConfig controls the automated connection throttling.
|
||||
type ConnectionThrottleConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
||||
ConnectionsPerCidr int `yaml:"max-connections"`
|
||||
DurationString string `yaml:"duration"`
|
||||
Duration time.Duration `yaml:"duration-time"`
|
||||
BanDurationString string `yaml:"ban-duration"`
|
||||
BanDuration time.Duration
|
||||
BanMessage string `yaml:"ban-message"`
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
// LineLenConfig controls line lengths.
|
||||
type LineLenConfig struct {
|
||||
Tags int
|
||||
@ -184,8 +162,8 @@ type Config struct {
|
||||
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
|
||||
MaxSendQString string `yaml:"max-sendq"`
|
||||
MaxSendQBytes uint64
|
||||
ConnectionLimits ConnectionLimitsConfig `yaml:"connection-limits"`
|
||||
ConnectionThrottle ConnectionThrottleConfig `yaml:"connection-throttling"`
|
||||
ConnectionLimits connection_limiting.ConnectionLimitsConfig `yaml:"connection-limits"`
|
||||
ConnectionThrottle connection_limiting.ConnectionThrottleConfig `yaml:"connection-throttling"`
|
||||
}
|
||||
|
||||
Datastore struct {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the MIT license
|
||||
|
||||
package irc
|
||||
package connection_limiting
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -10,6 +10,15 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ConnectionLimitsConfig controls the automated connection limits.
|
||||
type ConnectionLimitsConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
||||
IPsPerCidr int `yaml:"ips-per-subnet"`
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
var (
|
||||
errTooManyClients = errors.New("Too many clients in subnet")
|
||||
)
|
@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the MIT license
|
||||
|
||||
package irc
|
||||
package connection_limiting
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,6 +10,20 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ConnectionThrottleConfig controls the automated connection throttling.
|
||||
type ConnectionThrottleConfig struct {
|
||||
Enabled bool
|
||||
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
||||
CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
|
||||
ConnectionsPerCidr int `yaml:"max-connections"`
|
||||
DurationString string `yaml:"duration"`
|
||||
Duration time.Duration `yaml:"duration-time"`
|
||||
BanDurationString string `yaml:"ban-duration"`
|
||||
BanDuration time.Duration
|
||||
BanMessage string `yaml:"ban-message"`
|
||||
Exempted []string
|
||||
}
|
||||
|
||||
// ThrottleDetails holds the connection-throttling details for a subnet/IP.
|
||||
type ThrottleDetails struct {
|
||||
Start time.Time
|
@ -24,6 +24,7 @@ import (
|
||||
"github.com/goshuirc/irc-go/ircfmt"
|
||||
"github.com/goshuirc/irc-go/ircmsg"
|
||||
"github.com/oragono/oragono/irc/caps"
|
||||
"github.com/oragono/oragono/irc/connection_limiting"
|
||||
"github.com/oragono/oragono/irc/isupport"
|
||||
"github.com/oragono/oragono/irc/logger"
|
||||
"github.com/oragono/oragono/irc/passwd"
|
||||
@ -86,8 +87,8 @@ type Server struct {
|
||||
commands chan Command
|
||||
configFilename string
|
||||
configurableStateMutex sync.RWMutex // generic protection for server state modified by rehash()
|
||||
connectionLimits *ConnectionLimits
|
||||
connectionThrottle *ConnectionThrottle
|
||||
connectionLimits *connection_limiting.ConnectionLimits
|
||||
connectionThrottle *connection_limiting.ConnectionThrottle
|
||||
ctime time.Time
|
||||
defaultChannelModes Modes
|
||||
dlines *DLineManager
|
||||
|
Loading…
Reference in New Issue
Block a user