3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

review fix: rename various packages and objects

This commit is contained in:
Shivaram Lingamneni 2017-10-09 17:37:13 -04:00
parent 0e5eec3037
commit d66470f1c4
5 changed files with 70 additions and 70 deletions

View File

@ -542,7 +542,7 @@ func (client *Client) destroy() {
ipaddr := client.IP() ipaddr := client.IP()
// this check shouldn't be required but eh // this check shouldn't be required but eh
if ipaddr != nil { if ipaddr != nil {
client.server.connectionLimits.RemoveClient(ipaddr) client.server.connectionLimiter.RemoveClient(ipaddr)
} }
// alert monitors // alert monitors

View File

@ -15,7 +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/connection_limits"
"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"
@ -151,19 +151,19 @@ type Config struct {
Server struct { Server struct {
PassConfig PassConfig
Password string Password string
Name string Name string
Listen []string Listen []string
TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"` TLSListeners map[string]*TLSListenConfig `yaml:"tls-listeners"`
STS STSConfig STS STSConfig
CheckIdent bool `yaml:"check-ident"` CheckIdent bool `yaml:"check-ident"`
MOTD string MOTD string
MOTDFormatting bool `yaml:"motd-formatting"` MOTDFormatting bool `yaml:"motd-formatting"`
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 connection_limiting.ConnectionLimitsConfig `yaml:"connection-limits"` ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
ConnectionThrottle connection_limiting.ConnectionThrottleConfig `yaml:"connection-throttling"` ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
} }
Datastore struct { Datastore struct {
@ -383,12 +383,12 @@ func LoadConfig(filename string) (config *Config, err error) {
return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port) return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port)
} }
} }
if config.Server.ConnectionThrottle.Enabled { if config.Server.ConnectionThrottler.Enabled {
config.Server.ConnectionThrottle.Duration, err = time.ParseDuration(config.Server.ConnectionThrottle.DurationString) config.Server.ConnectionThrottler.Duration, err = time.ParseDuration(config.Server.ConnectionThrottler.DurationString)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not parse connection-throttle duration: %s", err.Error()) return nil, fmt.Errorf("Could not parse connection-throttle duration: %s", err.Error())
} }
config.Server.ConnectionThrottle.BanDuration, err = time.ParseDuration(config.Server.ConnectionThrottle.BanDurationString) config.Server.ConnectionThrottler.BanDuration, err = time.ParseDuration(config.Server.ConnectionThrottler.BanDurationString)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error()) return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
} }

View File

@ -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 connection_limiting package connection_limits
import ( import (
"errors" "errors"
@ -10,8 +10,8 @@ import (
"sync" "sync"
) )
// ConnectionLimitsConfig controls the automated connection limits. // LimiterConfig controls the automated connection limits.
type ConnectionLimitsConfig struct { type LimiterConfig struct {
Enabled bool Enabled bool
CidrLenIPv4 int `yaml:"cidr-len-ipv4"` CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
CidrLenIPv6 int `yaml:"cidr-len-ipv6"` CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
@ -23,8 +23,8 @@ var (
errTooManyClients = errors.New("Too many clients in subnet") errTooManyClients = errors.New("Too many clients in subnet")
) )
// ConnectionLimits manages the automated client connection limits. // Limiter manages the automated client connection limits.
type ConnectionLimits struct { type Limiter struct {
sync.Mutex sync.Mutex
enabled bool enabled bool
@ -42,7 +42,7 @@ type ConnectionLimits struct {
} }
// maskAddr masks the given IPv4/6 address with our cidr limit masks. // maskAddr masks the given IPv4/6 address with our cidr limit masks.
func (cl *ConnectionLimits) maskAddr(addr net.IP) net.IP { func (cl *Limiter) maskAddr(addr net.IP) net.IP {
if addr.To4() == nil { if addr.To4() == nil {
// IPv6 addr // IPv6 addr
addr = addr.Mask(cl.ipv6Mask) addr = addr.Mask(cl.ipv6Mask)
@ -56,7 +56,7 @@ func (cl *ConnectionLimits) maskAddr(addr net.IP) net.IP {
// AddClient adds a client to our population if possible. If we can't, throws an error instead. // AddClient adds a client to our population if possible. If we can't, throws an error instead.
// 'force' is used to add already-existing clients (i.e. ones that are already on the network). // 'force' is used to add already-existing clients (i.e. ones that are already on the network).
func (cl *ConnectionLimits) AddClient(addr net.IP, force bool) error { func (cl *Limiter) AddClient(addr net.IP, force bool) error {
cl.Lock() cl.Lock()
defer cl.Unlock() defer cl.Unlock()
@ -89,7 +89,7 @@ func (cl *ConnectionLimits) AddClient(addr net.IP, force bool) error {
} }
// RemoveClient removes the given address from our population // RemoveClient removes the given address from our population
func (cl *ConnectionLimits) RemoveClient(addr net.IP) { func (cl *Limiter) RemoveClient(addr net.IP) {
cl.Lock() cl.Lock()
defer cl.Unlock() defer cl.Unlock()
@ -106,10 +106,10 @@ func (cl *ConnectionLimits) RemoveClient(addr net.IP) {
} }
} }
// NewConnectionLimits returns a new connection limit handler. // NewLimiter returns a new connection limit handler.
// The handler is functional, but disabled; it can be enabled via `ApplyConfig`. // The handler is functional, but disabled; it can be enabled via `ApplyConfig`.
func NewConnectionLimits() *ConnectionLimits { func NewLimiter() *Limiter {
var cl ConnectionLimits var cl Limiter
// initialize empty population; all other state is configurable // initialize empty population; all other state is configurable
cl.population = make(map[string]int) cl.population = make(map[string]int)
@ -118,7 +118,7 @@ func NewConnectionLimits() *ConnectionLimits {
} }
// ApplyConfig atomically applies a config update to a connection limit handler // ApplyConfig atomically applies a config update to a connection limit handler
func (cl *ConnectionLimits) ApplyConfig(config ConnectionLimitsConfig) error { func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
// assemble exempted nets // assemble exempted nets
exemptedIPs := make(map[string]bool) exemptedIPs := make(map[string]bool)
var exemptedNets []net.IPNet var exemptedNets []net.IPNet

View File

@ -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 connection_limiting package connection_limits
import ( import (
"fmt" "fmt"
@ -10,8 +10,8 @@ import (
"time" "time"
) )
// ConnectionThrottleConfig controls the automated connection throttling. // ThrottlerConfig controls the automated connection throttling.
type ConnectionThrottleConfig struct { type ThrottlerConfig struct {
Enabled bool Enabled bool
CidrLenIPv4 int `yaml:"cidr-len-ipv4"` CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
CidrLenIPv6 int `yaml:"cidr-len-ipv6"` CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
@ -30,8 +30,8 @@ type ThrottleDetails struct {
ClientCount int ClientCount int
} }
// ConnectionThrottle manages automated client connection throttling. // Throttler manages automated client connection throttling.
type ConnectionThrottle struct { type Throttler struct {
sync.RWMutex sync.RWMutex
enabled bool enabled bool
@ -52,7 +52,7 @@ type ConnectionThrottle struct {
} }
// maskAddr masks the given IPv4/6 address with our cidr limit masks. // maskAddr masks the given IPv4/6 address with our cidr limit masks.
func (ct *ConnectionThrottle) maskAddr(addr net.IP) net.IP { func (ct *Throttler) maskAddr(addr net.IP) net.IP {
if addr.To4() == nil { if addr.To4() == nil {
// IPv6 addr // IPv6 addr
addr = addr.Mask(ct.ipv6Mask) addr = addr.Mask(ct.ipv6Mask)
@ -65,7 +65,7 @@ func (ct *ConnectionThrottle) maskAddr(addr net.IP) net.IP {
} }
// ResetFor removes any existing count for the given address. // ResetFor removes any existing count for the given address.
func (ct *ConnectionThrottle) ResetFor(addr net.IP) { func (ct *Throttler) ResetFor(addr net.IP) {
ct.Lock() ct.Lock()
defer ct.Unlock() defer ct.Unlock()
@ -80,7 +80,7 @@ func (ct *ConnectionThrottle) ResetFor(addr net.IP) {
} }
// AddClient introduces a new client connection if possible. If we can't, throws an error instead. // AddClient introduces a new client connection if possible. If we can't, throws an error instead.
func (ct *ConnectionThrottle) AddClient(addr net.IP) error { func (ct *Throttler) AddClient(addr net.IP) error {
ct.Lock() ct.Lock()
defer ct.Unlock() defer ct.Unlock()
@ -119,24 +119,24 @@ func (ct *ConnectionThrottle) AddClient(addr net.IP) error {
return nil return nil
} }
func (ct *ConnectionThrottle) BanDuration() time.Duration { func (ct *Throttler) BanDuration() time.Duration {
ct.RLock() ct.RLock()
defer ct.RUnlock() defer ct.RUnlock()
return ct.banDuration return ct.banDuration
} }
func (ct *ConnectionThrottle) BanMessage() string { func (ct *Throttler) BanMessage() string {
ct.RLock() ct.RLock()
defer ct.RUnlock() defer ct.RUnlock()
return ct.banMessage return ct.banMessage
} }
// NewConnectionThrottle returns a new client connection throttler. // NewThrottler returns a new client connection throttler.
// The throttler is functional, but disabled; it can be enabled via `ApplyConfig`. // The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.
func NewConnectionThrottle() *ConnectionThrottle { func NewThrottler() *Throttler {
var ct ConnectionThrottle var ct Throttler
// initialize empty population; all other state is configurable // initialize empty population; all other state is configurable
ct.population = make(map[string]ThrottleDetails) ct.population = make(map[string]ThrottleDetails)
@ -145,7 +145,7 @@ func NewConnectionThrottle() *ConnectionThrottle {
} }
// ApplyConfig atomically applies a config update to a throttler // ApplyConfig atomically applies a config update to a throttler
func (ct *ConnectionThrottle) ApplyConfig(config ConnectionThrottleConfig) error { func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
// assemble exempted nets // assemble exempted nets
exemptedIPs := make(map[string]bool) exemptedIPs := make(map[string]bool)
var exemptedNets []net.IPNet var exemptedNets []net.IPNet

View File

@ -24,7 +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/connection_limits"
"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"
@ -87,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 *connection_limiting.ConnectionLimits connectionLimiter *connection_limits.Limiter
connectionThrottle *connection_limiting.ConnectionThrottle connectionThrottler *connection_limits.Throttler
ctime time.Time ctime time.Time
defaultChannelModes Modes defaultChannelModes Modes
dlines *DLineManager dlines *DLineManager
@ -144,21 +144,21 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
// initialize data structures // initialize data structures
server := &Server{ server := &Server{
accounts: make(map[string]*ClientAccount), accounts: make(map[string]*ClientAccount),
channels: *NewChannelNameMap(), channels: *NewChannelNameMap(),
clients: NewClientLookupSet(), clients: NewClientLookupSet(),
commands: make(chan Command), commands: make(chan Command),
connectionLimits: connection_limiting.NewConnectionLimits(), connectionLimiter: connection_limits.NewLimiter(),
connectionThrottle: connection_limiting.NewConnectionThrottle(), connectionThrottler: connection_limits.NewThrottler(),
listeners: make(map[string]*ListenerWrapper), listeners: make(map[string]*ListenerWrapper),
logger: logger, logger: logger,
monitorManager: NewMonitorManager(), monitorManager: NewMonitorManager(),
newConns: make(chan clientConn), newConns: make(chan clientConn),
registeredChannels: make(map[string]*RegisteredChannel), registeredChannels: make(map[string]*RegisteredChannel),
rehashSignal: make(chan os.Signal, 1), rehashSignal: make(chan os.Signal, 1),
signals: make(chan os.Signal, len(ServerExitSignals)), signals: make(chan os.Signal, len(ServerExitSignals)),
snomasks: NewSnoManager(), snomasks: NewSnoManager(),
whoWas: NewWhoWasList(config.Limits.WhowasEntries), whoWas: NewWhoWasList(config.Limits.WhowasEntries),
} }
if err := server.applyConfig(config, true); err != nil { if err := server.applyConfig(config, true); err != nil {
@ -303,7 +303,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
} }
// check connection limits // check connection limits
err := server.connectionLimits.AddClient(ipaddr, false) err := server.connectionLimiter.AddClient(ipaddr, false)
if err != nil { if err != nil {
// too many connections from one client, tell the client and close the connection // too many connections from one client, tell the client and close the connection
server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr)) server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
@ -311,25 +311,25 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
} }
// check connection throttle // check connection throttle
err = server.connectionThrottle.AddClient(ipaddr) err = server.connectionThrottler.AddClient(ipaddr)
if err != nil { if err != nil {
// too many connections too quickly from client, tell them and close the connection // too many connections too quickly from client, tell them and close the connection
duration := server.connectionThrottle.BanDuration() duration := server.connectionThrottler.BanDuration()
length := &IPRestrictTime{ length := &IPRestrictTime{
Duration: duration, Duration: duration,
Expires: time.Now().Add(duration), Expires: time.Now().Add(duration),
} }
server.dlines.AddIP(ipaddr, length, server.connectionThrottle.BanMessage(), "Exceeded automated connection throttle") server.dlines.AddIP(ipaddr, length, server.connectionThrottler.BanMessage(), "Exceeded automated connection throttle")
// they're DLINE'd for 15 minutes or whatever, so we can reset the connection throttle now, // they're DLINE'd for 15 minutes or whatever, so we can reset the connection throttle now,
// and once their temporary DLINE is finished they can fill up the throttler again // and once their temporary DLINE is finished they can fill up the throttler again
server.connectionThrottle.ResetFor(ipaddr) server.connectionThrottler.ResetFor(ipaddr)
// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us // this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
server.logger.Info( server.logger.Info(
"localconnect-ip", "localconnect-ip",
fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration)) fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration))
return true, server.connectionThrottle.BanMessage() return true, server.connectionThrottler.BanMessage()
} }
return false, "" return false, ""
@ -1263,12 +1263,12 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
// apply new PROXY command restrictions // apply new PROXY command restrictions
server.proxyAllowedFrom = config.Server.ProxyAllowedFrom server.proxyAllowedFrom = config.Server.ProxyAllowedFrom
err = server.connectionLimits.ApplyConfig(config.Server.ConnectionLimits) err = server.connectionLimiter.ApplyConfig(config.Server.ConnectionLimiter)
if err != nil { if err != nil {
return err return err
} }
err = server.connectionThrottle.ApplyConfig(config.Server.ConnectionThrottle) err = server.connectionThrottler.ApplyConfig(config.Server.ConnectionThrottler)
if err != nil { if err != nil {
return err return err
} }