|
@@ -24,7 +24,7 @@ import (
|
24
|
24
|
"github.com/goshuirc/irc-go/ircfmt"
|
25
|
25
|
"github.com/goshuirc/irc-go/ircmsg"
|
26
|
26
|
"github.com/oragono/oragono/irc/caps"
|
27
|
|
- "github.com/oragono/oragono/irc/connection_limiting"
|
|
27
|
+ "github.com/oragono/oragono/irc/connection_limits"
|
28
|
28
|
"github.com/oragono/oragono/irc/isupport"
|
29
|
29
|
"github.com/oragono/oragono/irc/logger"
|
30
|
30
|
"github.com/oragono/oragono/irc/passwd"
|
|
@@ -87,8 +87,8 @@ type Server struct {
|
87
|
87
|
commands chan Command
|
88
|
88
|
configFilename string
|
89
|
89
|
configurableStateMutex sync.RWMutex // generic protection for server state modified by rehash()
|
90
|
|
- connectionLimits *connection_limiting.ConnectionLimits
|
91
|
|
- connectionThrottle *connection_limiting.ConnectionThrottle
|
|
90
|
+ connectionLimiter *connection_limits.Limiter
|
|
91
|
+ connectionThrottler *connection_limits.Throttler
|
92
|
92
|
ctime time.Time
|
93
|
93
|
defaultChannelModes Modes
|
94
|
94
|
dlines *DLineManager
|
|
@@ -144,21 +144,21 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
144
|
144
|
|
145
|
145
|
// initialize data structures
|
146
|
146
|
server := &Server{
|
147
|
|
- accounts: make(map[string]*ClientAccount),
|
148
|
|
- channels: *NewChannelNameMap(),
|
149
|
|
- clients: NewClientLookupSet(),
|
150
|
|
- commands: make(chan Command),
|
151
|
|
- connectionLimits: connection_limiting.NewConnectionLimits(),
|
152
|
|
- connectionThrottle: connection_limiting.NewConnectionThrottle(),
|
153
|
|
- listeners: make(map[string]*ListenerWrapper),
|
154
|
|
- logger: logger,
|
155
|
|
- monitorManager: NewMonitorManager(),
|
156
|
|
- newConns: make(chan clientConn),
|
157
|
|
- registeredChannels: make(map[string]*RegisteredChannel),
|
158
|
|
- rehashSignal: make(chan os.Signal, 1),
|
159
|
|
- signals: make(chan os.Signal, len(ServerExitSignals)),
|
160
|
|
- snomasks: NewSnoManager(),
|
161
|
|
- whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
|
147
|
+ accounts: make(map[string]*ClientAccount),
|
|
148
|
+ channels: *NewChannelNameMap(),
|
|
149
|
+ clients: NewClientLookupSet(),
|
|
150
|
+ commands: make(chan Command),
|
|
151
|
+ connectionLimiter: connection_limits.NewLimiter(),
|
|
152
|
+ connectionThrottler: connection_limits.NewThrottler(),
|
|
153
|
+ listeners: make(map[string]*ListenerWrapper),
|
|
154
|
+ logger: logger,
|
|
155
|
+ monitorManager: NewMonitorManager(),
|
|
156
|
+ newConns: make(chan clientConn),
|
|
157
|
+ registeredChannels: make(map[string]*RegisteredChannel),
|
|
158
|
+ rehashSignal: make(chan os.Signal, 1),
|
|
159
|
+ signals: make(chan os.Signal, len(ServerExitSignals)),
|
|
160
|
+ snomasks: NewSnoManager(),
|
|
161
|
+ whoWas: NewWhoWasList(config.Limits.WhowasEntries),
|
162
|
162
|
}
|
163
|
163
|
|
164
|
164
|
if err := server.applyConfig(config, true); err != nil {
|
|
@@ -303,7 +303,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
303
|
303
|
}
|
304
|
304
|
|
305
|
305
|
// check connection limits
|
306
|
|
- err := server.connectionLimits.AddClient(ipaddr, false)
|
|
306
|
+ err := server.connectionLimiter.AddClient(ipaddr, false)
|
307
|
307
|
if err != nil {
|
308
|
308
|
// too many connections from one client, tell the client and close the connection
|
309
|
309
|
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) {
|
311
|
311
|
}
|
312
|
312
|
|
313
|
313
|
// check connection throttle
|
314
|
|
- err = server.connectionThrottle.AddClient(ipaddr)
|
|
314
|
+ err = server.connectionThrottler.AddClient(ipaddr)
|
315
|
315
|
if err != nil {
|
316
|
316
|
// too many connections too quickly from client, tell them and close the connection
|
317
|
|
- duration := server.connectionThrottle.BanDuration()
|
|
317
|
+ duration := server.connectionThrottler.BanDuration()
|
318
|
318
|
length := &IPRestrictTime{
|
319
|
319
|
Duration: duration,
|
320
|
320
|
Expires: time.Now().Add(duration),
|
321
|
321
|
}
|
322
|
|
- server.dlines.AddIP(ipaddr, length, server.connectionThrottle.BanMessage(), "Exceeded automated connection throttle")
|
|
322
|
+ server.dlines.AddIP(ipaddr, length, server.connectionThrottler.BanMessage(), "Exceeded automated connection throttle")
|
323
|
323
|
|
324
|
324
|
// they're DLINE'd for 15 minutes or whatever, so we can reset the connection throttle now,
|
325
|
325
|
// and once their temporary DLINE is finished they can fill up the throttler again
|
326
|
|
- server.connectionThrottle.ResetFor(ipaddr)
|
|
326
|
+ server.connectionThrottler.ResetFor(ipaddr)
|
327
|
327
|
|
328
|
328
|
// 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
|
329
|
329
|
server.logger.Info(
|
330
|
330
|
"localconnect-ip",
|
331
|
331
|
fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration))
|
332
|
|
- return true, server.connectionThrottle.BanMessage()
|
|
332
|
+ return true, server.connectionThrottler.BanMessage()
|
333
|
333
|
}
|
334
|
334
|
|
335
|
335
|
return false, ""
|
|
@@ -1263,12 +1263,12 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
1263
|
1263
|
// apply new PROXY command restrictions
|
1264
|
1264
|
server.proxyAllowedFrom = config.Server.ProxyAllowedFrom
|
1265
|
1265
|
|
1266
|
|
- err = server.connectionLimits.ApplyConfig(config.Server.ConnectionLimits)
|
|
1266
|
+ err = server.connectionLimiter.ApplyConfig(config.Server.ConnectionLimiter)
|
1267
|
1267
|
if err != nil {
|
1268
|
1268
|
return err
|
1269
|
1269
|
}
|
1270
|
1270
|
|
1271
|
|
- err = server.connectionThrottle.ApplyConfig(config.Server.ConnectionThrottle)
|
|
1271
|
+ err = server.connectionThrottler.ApplyConfig(config.Server.ConnectionThrottler)
|
1272
|
1272
|
if err != nil {
|
1273
|
1273
|
return err
|
1274
|
1274
|
}
|