|
@@ -103,7 +103,6 @@ type Server struct {
|
103
|
103
|
name string
|
104
|
104
|
nameCasefolded string
|
105
|
105
|
networkName string
|
106
|
|
- newConns chan clientConn
|
107
|
106
|
operators map[string]Oper
|
108
|
107
|
operclasses map[string]OperClass
|
109
|
108
|
password []byte
|
|
@@ -152,7 +151,6 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
152
|
151
|
listeners: make(map[string]*ListenerWrapper),
|
153
|
152
|
logger: logger,
|
154
|
153
|
monitorManager: NewMonitorManager(),
|
155
|
|
- newConns: make(chan clientConn),
|
156
|
154
|
rehashSignal: make(chan os.Signal, 1),
|
157
|
155
|
signals: make(chan os.Signal, len(ServerExitSignals)),
|
158
|
156
|
snomasks: NewSnoManager(),
|
|
@@ -249,46 +247,45 @@ func (server *Server) Run() {
|
249
|
247
|
// defer closing db/store
|
250
|
248
|
defer server.store.Close()
|
251
|
249
|
|
252
|
|
- done := false
|
253
|
|
- for !done {
|
|
250
|
+ for {
|
254
|
251
|
select {
|
255
|
252
|
case <-server.signals:
|
256
|
253
|
server.Shutdown()
|
257
|
|
- done = true
|
|
254
|
+ return
|
258
|
255
|
|
259
|
256
|
case <-server.rehashSignal:
|
260
|
|
- server.logger.Info("rehash", "Rehashing due to SIGHUP")
|
261
|
257
|
go func() {
|
|
258
|
+ server.logger.Info("rehash", "Rehashing due to SIGHUP")
|
262
|
259
|
err := server.rehash()
|
263
|
260
|
if err != nil {
|
264
|
261
|
server.logger.Error("rehash", fmt.Sprintln("Failed to rehash:", err.Error()))
|
265
|
262
|
}
|
266
|
263
|
}()
|
|
264
|
+ }
|
|
265
|
+ }
|
|
266
|
+}
|
267
|
267
|
|
268
|
|
- case conn := <-server.newConns:
|
269
|
|
- // check IP address
|
270
|
|
- ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
|
271
|
|
- if ipaddr == nil {
|
272
|
|
- conn.Conn.Write([]byte(couldNotParseIPMsg))
|
273
|
|
- conn.Conn.Close()
|
274
|
|
- continue
|
275
|
|
- }
|
|
268
|
+func (server *Server) acceptClient(conn clientConn) {
|
|
269
|
+ // check IP address
|
|
270
|
+ ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
|
|
271
|
+ if ipaddr == nil {
|
|
272
|
+ conn.Conn.Write([]byte(couldNotParseIPMsg))
|
|
273
|
+ conn.Conn.Close()
|
|
274
|
+ return
|
|
275
|
+ }
|
276
|
276
|
|
277
|
|
- isBanned, banMsg := server.checkBans(ipaddr)
|
278
|
|
- if isBanned {
|
279
|
|
- // this might not show up properly on some clients, but our objective here is just to close the connection out before it has a load impact on us
|
280
|
|
- conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
281
|
|
- conn.Conn.Close()
|
282
|
|
- continue
|
283
|
|
- }
|
|
277
|
+ isBanned, banMsg := server.checkBans(ipaddr)
|
|
278
|
+ if isBanned {
|
|
279
|
+ // this might not show up properly on some clients, but our objective here is just to close the connection out before it has a load impact on us
|
|
280
|
+ conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
|
281
|
+ conn.Conn.Close()
|
|
282
|
+ return
|
|
283
|
+ }
|
284
|
284
|
|
285
|
|
- server.logger.Debug("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
|
286
|
|
- // prolly don't need to alert snomasks on this, only on connection reg
|
|
285
|
+ server.logger.Debug("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
|
|
286
|
+ // prolly don't need to alert snomasks on this, only on connection reg
|
287
|
287
|
|
288
|
|
- go NewClient(server, conn.Conn, conn.IsTLS)
|
289
|
|
- continue
|
290
|
|
- }
|
291
|
|
- }
|
|
288
|
+ NewClient(server, conn.Conn, conn.IsTLS)
|
292
|
289
|
}
|
293
|
290
|
|
294
|
291
|
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
|
@@ -375,7 +372,7 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config) *Listen
|
375
|
372
|
IsTLS: tlsConfig != nil,
|
376
|
373
|
}
|
377
|
374
|
// hand off the connection
|
378
|
|
- server.newConns <- newConn
|
|
375
|
+ go server.acceptClient(newConn)
|
379
|
376
|
}
|
380
|
377
|
|
381
|
378
|
if shouldStop {
|