mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-26 05:49:25 +01:00
consolidate acceptClient into RunNewClient
This commit is contained in:
parent
80a594802f
commit
0b55fed7c5
@ -163,8 +163,29 @@ type ClientDetails struct {
|
|||||||
accountName string
|
accountName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient sets up a new client and runs its goroutine.
|
// RunClient sets up a new client and runs its goroutine.
|
||||||
func RunNewClient(server *Server, conn clientConn) {
|
func (server *Server) RunClient(conn clientConn) {
|
||||||
|
var isBanned bool
|
||||||
|
var banMsg string
|
||||||
|
var realIP net.IP
|
||||||
|
if conn.IsTor {
|
||||||
|
realIP = utils.IPv4LoopbackAddress
|
||||||
|
isBanned, banMsg = server.checkTorLimits()
|
||||||
|
} else {
|
||||||
|
realIP = utils.AddrToIP(conn.Conn.RemoteAddr())
|
||||||
|
isBanned, banMsg = server.checkBans(realIP)
|
||||||
|
}
|
||||||
|
|
||||||
|
if isBanned {
|
||||||
|
// 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.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
server.logger.Info("localconnect-ip", fmt.Sprintf("Client connecting from %v", realIP))
|
||||||
|
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
config := server.Config()
|
config := server.Config()
|
||||||
fullLineLenLimit := ircmsg.MaxlenTagsFromClient + config.Limits.LineLen.Rest
|
fullLineLenLimit := ircmsg.MaxlenTagsFromClient + config.Limits.LineLen.Rest
|
||||||
@ -194,6 +215,7 @@ func RunNewClient(server *Server, conn clientConn) {
|
|||||||
capState: caps.NoneState,
|
capState: caps.NoneState,
|
||||||
ctime: now,
|
ctime: now,
|
||||||
atime: now,
|
atime: now,
|
||||||
|
realIP: realIP,
|
||||||
}
|
}
|
||||||
session.SetMaxlenRest()
|
session.SetMaxlenRest()
|
||||||
client.sessions = []*Session{session}
|
client.sessions = []*Session{session}
|
||||||
@ -204,19 +226,17 @@ func RunNewClient(server *Server, conn clientConn) {
|
|||||||
client.certfp, _ = socket.CertFP()
|
client.certfp, _ = socket.CertFP()
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteAddr := conn.Conn.RemoteAddr()
|
|
||||||
if conn.IsTor {
|
if conn.IsTor {
|
||||||
client.SetMode(modes.TLS, true)
|
client.SetMode(modes.TLS, true)
|
||||||
session.realIP = utils.AddrToIP(remoteAddr)
|
|
||||||
// cover up details of the tor proxying infrastructure (not a user privacy concern,
|
// cover up details of the tor proxying infrastructure (not a user privacy concern,
|
||||||
// but a hardening measure):
|
// but a hardening measure):
|
||||||
session.proxiedIP = utils.IPv4LoopbackAddress
|
session.proxiedIP = utils.IPv4LoopbackAddress
|
||||||
session.rawHostname = config.Server.TorListeners.Vhost
|
session.rawHostname = config.Server.TorListeners.Vhost
|
||||||
} else {
|
} else {
|
||||||
session.realIP = utils.AddrToIP(remoteAddr)
|
|
||||||
// set the hostname for this client (may be overridden later by PROXY or WEBIRC)
|
// set the hostname for this client (may be overridden later by PROXY or WEBIRC)
|
||||||
session.rawHostname = utils.LookupHostname(session.realIP.String())
|
session.rawHostname = utils.LookupHostname(session.realIP.String())
|
||||||
client.cloakedHostname = config.Server.Cloaks.ComputeCloak(session.realIP)
|
client.cloakedHostname = config.Server.Cloaks.ComputeCloak(session.realIP)
|
||||||
|
remoteAddr := conn.Conn.RemoteAddr()
|
||||||
if utils.AddrIsLocal(remoteAddr) {
|
if utils.AddrIsLocal(remoteAddr) {
|
||||||
// treat local connections as secure (may be overridden later by WEBIRC)
|
// treat local connections as secure (may be overridden later by WEBIRC)
|
||||||
client.SetMode(modes.TLS, true)
|
client.SetMode(modes.TLS, true)
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/oragono/oragono/irc/logger"
|
"github.com/oragono/oragono/irc/logger"
|
||||||
"github.com/oragono/oragono/irc/modes"
|
"github.com/oragono/oragono/irc/modes"
|
||||||
"github.com/oragono/oragono/irc/sno"
|
"github.com/oragono/oragono/irc/sno"
|
||||||
"github.com/oragono/oragono/irc/utils"
|
|
||||||
"github.com/tidwall/buntdb"
|
"github.com/tidwall/buntdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -207,30 +206,6 @@ func (server *Server) Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) acceptClient(conn clientConn) {
|
|
||||||
var isBanned bool
|
|
||||||
var banMsg string
|
|
||||||
var ipaddr net.IP
|
|
||||||
if conn.IsTor {
|
|
||||||
ipaddr = utils.IPv4LoopbackAddress
|
|
||||||
isBanned, banMsg = server.checkTorLimits()
|
|
||||||
} else {
|
|
||||||
ipaddr = utils.AddrToIP(conn.Conn.RemoteAddr())
|
|
||||||
isBanned, banMsg = server.checkBans(ipaddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
if isBanned {
|
|
||||||
// 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.Close()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
server.logger.Info("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
|
|
||||||
|
|
||||||
go RunNewClient(server, conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
|
||||||
// check DLINEs
|
// check DLINEs
|
||||||
isBanned, info := server.dlines.CheckIP(ipaddr)
|
isBanned, info := server.dlines.CheckIP(ipaddr)
|
||||||
@ -338,7 +313,7 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config, isTor b
|
|||||||
IsTor: isTor,
|
IsTor: isTor,
|
||||||
}
|
}
|
||||||
// hand off the connection
|
// hand off the connection
|
||||||
go server.acceptClient(newConn)
|
go server.RunClient(newConn)
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldStop {
|
if shouldStop {
|
||||||
|
Loading…
Reference in New Issue
Block a user