mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-08 19:22:53 +01:00
remove newConns channel
This commit is contained in:
parent
728863a17c
commit
7edd9032d3
@ -103,7 +103,6 @@ type Server struct {
|
|||||||
name string
|
name string
|
||||||
nameCasefolded string
|
nameCasefolded string
|
||||||
networkName string
|
networkName string
|
||||||
newConns chan clientConn
|
|
||||||
operators map[string]Oper
|
operators map[string]Oper
|
||||||
operclasses map[string]OperClass
|
operclasses map[string]OperClass
|
||||||
password []byte
|
password []byte
|
||||||
@ -152,7 +151,6 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
listeners: make(map[string]*ListenerWrapper),
|
listeners: make(map[string]*ListenerWrapper),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
monitorManager: NewMonitorManager(),
|
monitorManager: NewMonitorManager(),
|
||||||
newConns: make(chan clientConn),
|
|
||||||
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(),
|
||||||
@ -249,29 +247,31 @@ func (server *Server) Run() {
|
|||||||
// defer closing db/store
|
// defer closing db/store
|
||||||
defer server.store.Close()
|
defer server.store.Close()
|
||||||
|
|
||||||
done := false
|
for {
|
||||||
for !done {
|
|
||||||
select {
|
select {
|
||||||
case <-server.signals:
|
case <-server.signals:
|
||||||
server.Shutdown()
|
server.Shutdown()
|
||||||
done = true
|
return
|
||||||
|
|
||||||
case <-server.rehashSignal:
|
case <-server.rehashSignal:
|
||||||
server.logger.Info("rehash", "Rehashing due to SIGHUP")
|
|
||||||
go func() {
|
go func() {
|
||||||
|
server.logger.Info("rehash", "Rehashing due to SIGHUP")
|
||||||
err := server.rehash()
|
err := server.rehash()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
server.logger.Error("rehash", fmt.Sprintln("Failed to rehash:", err.Error()))
|
server.logger.Error("rehash", fmt.Sprintln("Failed to rehash:", err.Error()))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case conn := <-server.newConns:
|
func (server *Server) acceptClient(conn clientConn) {
|
||||||
// check IP address
|
// check IP address
|
||||||
ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
|
ipaddr := net.ParseIP(utils.IPString(conn.Conn.RemoteAddr()))
|
||||||
if ipaddr == nil {
|
if ipaddr == nil {
|
||||||
conn.Conn.Write([]byte(couldNotParseIPMsg))
|
conn.Conn.Write([]byte(couldNotParseIPMsg))
|
||||||
conn.Conn.Close()
|
conn.Conn.Close()
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isBanned, banMsg := server.checkBans(ipaddr)
|
isBanned, banMsg := server.checkBans(ipaddr)
|
||||||
@ -279,16 +279,13 @@ func (server *Server) Run() {
|
|||||||
// 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
|
// 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
|
||||||
conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
|
||||||
conn.Conn.Close()
|
conn.Conn.Close()
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
server.logger.Debug("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
|
server.logger.Debug("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
|
||||||
// prolly don't need to alert snomasks on this, only on connection reg
|
// prolly don't need to alert snomasks on this, only on connection reg
|
||||||
|
|
||||||
go NewClient(server, conn.Conn, conn.IsTLS)
|
NewClient(server, conn.Conn, conn.IsTLS)
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
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
|
|||||||
IsTLS: tlsConfig != nil,
|
IsTLS: tlsConfig != nil,
|
||||||
}
|
}
|
||||||
// hand off the connection
|
// hand off the connection
|
||||||
server.newConns <- newConn
|
go server.acceptClient(newConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldStop {
|
if shouldStop {
|
||||||
|
Loading…
Reference in New Issue
Block a user