Przeglądaj źródła

remove newConns channel

tags/v0.11.0-alpha
Shivaram Lingamneni 6 lat temu
rodzic
commit
7edd9032d3
1 zmienionych plików z 25 dodań i 28 usunięć
  1. 25
    28
      irc/server.go

+ 25
- 28
irc/server.go Wyświetl plik

103
 	name                         string
103
 	name                         string
104
 	nameCasefolded               string
104
 	nameCasefolded               string
105
 	networkName                  string
105
 	networkName                  string
106
-	newConns                     chan clientConn
107
 	operators                    map[string]Oper
106
 	operators                    map[string]Oper
108
 	operclasses                  map[string]OperClass
107
 	operclasses                  map[string]OperClass
109
 	password                     []byte
108
 	password                     []byte
152
 		listeners:           make(map[string]*ListenerWrapper),
151
 		listeners:           make(map[string]*ListenerWrapper),
153
 		logger:              logger,
152
 		logger:              logger,
154
 		monitorManager:      NewMonitorManager(),
153
 		monitorManager:      NewMonitorManager(),
155
-		newConns:            make(chan clientConn),
156
 		rehashSignal:        make(chan os.Signal, 1),
154
 		rehashSignal:        make(chan os.Signal, 1),
157
 		signals:             make(chan os.Signal, len(ServerExitSignals)),
155
 		signals:             make(chan os.Signal, len(ServerExitSignals)),
158
 		snomasks:            NewSnoManager(),
156
 		snomasks:            NewSnoManager(),
249
 	// defer closing db/store
247
 	// defer closing db/store
250
 	defer server.store.Close()
248
 	defer server.store.Close()
251
 
249
 
252
-	done := false
253
-	for !done {
250
+	for {
254
 		select {
251
 		select {
255
 		case <-server.signals:
252
 		case <-server.signals:
256
 			server.Shutdown()
253
 			server.Shutdown()
257
-			done = true
254
+			return
258
 
255
 
259
 		case <-server.rehashSignal:
256
 		case <-server.rehashSignal:
260
-			server.logger.Info("rehash", "Rehashing due to SIGHUP")
261
 			go func() {
257
 			go func() {
258
+				server.logger.Info("rehash", "Rehashing due to SIGHUP")
262
 				err := server.rehash()
259
 				err := server.rehash()
263
 				if err != nil {
260
 				if err != nil {
264
 					server.logger.Error("rehash", fmt.Sprintln("Failed to rehash:", err.Error()))
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
 func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
291
 func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
375
 					IsTLS: tlsConfig != nil,
372
 					IsTLS: tlsConfig != nil,
376
 				}
373
 				}
377
 				// hand off the connection
374
 				// hand off the connection
378
-				server.newConns <- newConn
375
+				go server.acceptClient(newConn)
379
 			}
376
 			}
380
 
377
 
381
 			if shouldStop {
378
 			if shouldStop {

Ładowanie…
Anuluj
Zapisz