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"
|
"time"
|
||||||
|
|
||||||
"code.cloudfoundry.org/bytefmt"
|
"code.cloudfoundry.org/bytefmt"
|
||||||
|
"github.com/oragono/oragono/irc/connection_limiting"
|
||||||
"github.com/oragono/oragono/irc/custime"
|
"github.com/oragono/oragono/irc/custime"
|
||||||
"github.com/oragono/oragono/irc/logger"
|
"github.com/oragono/oragono/irc/logger"
|
||||||
"github.com/oragono/oragono/irc/passwd"
|
"github.com/oragono/oragono/irc/passwd"
|
||||||
@ -108,29 +109,6 @@ func (conf *OperConfig) PasswordBytes() []byte {
|
|||||||
return bytes
|
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.
|
// LineLenConfig controls line lengths.
|
||||||
type LineLenConfig struct {
|
type LineLenConfig struct {
|
||||||
Tags int
|
Tags int
|
||||||
@ -184,8 +162,8 @@ type Config struct {
|
|||||||
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
|
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
|
||||||
MaxSendQString string `yaml:"max-sendq"`
|
MaxSendQString string `yaml:"max-sendq"`
|
||||||
MaxSendQBytes uint64
|
MaxSendQBytes uint64
|
||||||
ConnectionLimits ConnectionLimitsConfig `yaml:"connection-limits"`
|
ConnectionLimits connection_limiting.ConnectionLimitsConfig `yaml:"connection-limits"`
|
||||||
ConnectionThrottle ConnectionThrottleConfig `yaml:"connection-throttling"`
|
ConnectionThrottle connection_limiting.ConnectionThrottleConfig `yaml:"connection-throttling"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Datastore struct {
|
Datastore struct {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||||
// released under the MIT license
|
// released under the MIT license
|
||||||
|
|
||||||
package irc
|
package connection_limiting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -10,6 +10,15 @@ import (
|
|||||||
"sync"
|
"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 (
|
var (
|
||||||
errTooManyClients = errors.New("Too many clients in subnet")
|
errTooManyClients = errors.New("Too many clients in subnet")
|
||||||
)
|
)
|
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
|
||||||
// released under the MIT license
|
// released under the MIT license
|
||||||
|
|
||||||
package irc
|
package connection_limiting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -10,6 +10,20 @@ import (
|
|||||||
"time"
|
"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.
|
// ThrottleDetails holds the connection-throttling details for a subnet/IP.
|
||||||
type ThrottleDetails struct {
|
type ThrottleDetails struct {
|
||||||
Start time.Time
|
Start time.Time
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/goshuirc/irc-go/ircfmt"
|
"github.com/goshuirc/irc-go/ircfmt"
|
||||||
"github.com/goshuirc/irc-go/ircmsg"
|
"github.com/goshuirc/irc-go/ircmsg"
|
||||||
"github.com/oragono/oragono/irc/caps"
|
"github.com/oragono/oragono/irc/caps"
|
||||||
|
"github.com/oragono/oragono/irc/connection_limiting"
|
||||||
"github.com/oragono/oragono/irc/isupport"
|
"github.com/oragono/oragono/irc/isupport"
|
||||||
"github.com/oragono/oragono/irc/logger"
|
"github.com/oragono/oragono/irc/logger"
|
||||||
"github.com/oragono/oragono/irc/passwd"
|
"github.com/oragono/oragono/irc/passwd"
|
||||||
@ -86,8 +87,8 @@ type Server struct {
|
|||||||
commands chan Command
|
commands chan Command
|
||||||
configFilename string
|
configFilename string
|
||||||
configurableStateMutex sync.RWMutex // generic protection for server state modified by rehash()
|
configurableStateMutex sync.RWMutex // generic protection for server state modified by rehash()
|
||||||
connectionLimits *ConnectionLimits
|
connectionLimits *connection_limiting.ConnectionLimits
|
||||||
connectionThrottle *ConnectionThrottle
|
connectionThrottle *connection_limiting.ConnectionThrottle
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
defaultChannelModes Modes
|
defaultChannelModes Modes
|
||||||
dlines *DLineManager
|
dlines *DLineManager
|
||||||
|
Loading…
Reference in New Issue
Block a user