Преглед изворни кода

consolidate acceptClient into RunNewClient

tags/v1.1.0-rc1
Shivaram Lingamneni пре 5 година
родитељ
комит
0b55fed7c5
2 измењених фајлова са 26 додато и 31 уклоњено
  1. 25
    5
      irc/client.go
  2. 1
    26
      irc/server.go

+ 25
- 5
irc/client.go Прегледај датотеку

@@ -163,8 +163,29 @@ type ClientDetails struct {
163 163
 	accountName        string
164 164
 }
165 165
 
166
-// NewClient sets up a new client and runs its goroutine.
167
-func RunNewClient(server *Server, conn clientConn) {
166
+// RunClient sets up a new client and runs its goroutine.
167
+func (server *Server) RunClient(conn clientConn) {
168
+	var isBanned bool
169
+	var banMsg string
170
+	var realIP net.IP
171
+	if conn.IsTor {
172
+		realIP = utils.IPv4LoopbackAddress
173
+		isBanned, banMsg = server.checkTorLimits()
174
+	} else {
175
+		realIP = utils.AddrToIP(conn.Conn.RemoteAddr())
176
+		isBanned, banMsg = server.checkBans(realIP)
177
+	}
178
+
179
+	if isBanned {
180
+		// this might not show up properly on some clients,
181
+		// but our objective here is just to close the connection out before it has a load impact on us
182
+		conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
183
+		conn.Conn.Close()
184
+		return
185
+	}
186
+
187
+	server.logger.Info("localconnect-ip", fmt.Sprintf("Client connecting from %v", realIP))
188
+
168 189
 	now := time.Now().UTC()
169 190
 	config := server.Config()
170 191
 	fullLineLenLimit := ircmsg.MaxlenTagsFromClient + config.Limits.LineLen.Rest
@@ -194,6 +215,7 @@ func RunNewClient(server *Server, conn clientConn) {
194 215
 		capState:   caps.NoneState,
195 216
 		ctime:      now,
196 217
 		atime:      now,
218
+		realIP:     realIP,
197 219
 	}
198 220
 	session.SetMaxlenRest()
199 221
 	client.sessions = []*Session{session}
@@ -204,19 +226,17 @@ func RunNewClient(server *Server, conn clientConn) {
204 226
 		client.certfp, _ = socket.CertFP()
205 227
 	}
206 228
 
207
-	remoteAddr := conn.Conn.RemoteAddr()
208 229
 	if conn.IsTor {
209 230
 		client.SetMode(modes.TLS, true)
210
-		session.realIP = utils.AddrToIP(remoteAddr)
211 231
 		// cover up details of the tor proxying infrastructure (not a user privacy concern,
212 232
 		// but a hardening measure):
213 233
 		session.proxiedIP = utils.IPv4LoopbackAddress
214 234
 		session.rawHostname = config.Server.TorListeners.Vhost
215 235
 	} else {
216
-		session.realIP = utils.AddrToIP(remoteAddr)
217 236
 		// set the hostname for this client (may be overridden later by PROXY or WEBIRC)
218 237
 		session.rawHostname = utils.LookupHostname(session.realIP.String())
219 238
 		client.cloakedHostname = config.Server.Cloaks.ComputeCloak(session.realIP)
239
+		remoteAddr := conn.Conn.RemoteAddr()
220 240
 		if utils.AddrIsLocal(remoteAddr) {
221 241
 			// treat local connections as secure (may be overridden later by WEBIRC)
222 242
 			client.SetMode(modes.TLS, true)

+ 1
- 26
irc/server.go Прегледај датотеку

@@ -27,7 +27,6 @@ import (
27 27
 	"github.com/oragono/oragono/irc/logger"
28 28
 	"github.com/oragono/oragono/irc/modes"
29 29
 	"github.com/oragono/oragono/irc/sno"
30
-	"github.com/oragono/oragono/irc/utils"
31 30
 	"github.com/tidwall/buntdb"
32 31
 )
33 32
 
@@ -207,30 +206,6 @@ func (server *Server) Run() {
207 206
 	}
208 207
 }
209 208
 
210
-func (server *Server) acceptClient(conn clientConn) {
211
-	var isBanned bool
212
-	var banMsg string
213
-	var ipaddr net.IP
214
-	if conn.IsTor {
215
-		ipaddr = utils.IPv4LoopbackAddress
216
-		isBanned, banMsg = server.checkTorLimits()
217
-	} else {
218
-		ipaddr = utils.AddrToIP(conn.Conn.RemoteAddr())
219
-		isBanned, banMsg = server.checkBans(ipaddr)
220
-	}
221
-
222
-	if isBanned {
223
-		// 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
224
-		conn.Conn.Write([]byte(fmt.Sprintf(errorMsg, banMsg)))
225
-		conn.Conn.Close()
226
-		return
227
-	}
228
-
229
-	server.logger.Info("localconnect-ip", fmt.Sprintf("Client connecting from %v", ipaddr))
230
-
231
-	go RunNewClient(server, conn)
232
-}
233
-
234 209
 func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
235 210
 	// check DLINEs
236 211
 	isBanned, info := server.dlines.CheckIP(ipaddr)
@@ -338,7 +313,7 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config, isTor b
338 313
 					IsTor: isTor,
339 314
 				}
340 315
 				// hand off the connection
341
-				go server.acceptClient(newConn)
316
+				go server.RunClient(newConn)
342 317
 			}
343 318
 
344 319
 			if shouldStop {

Loading…
Откажи
Сачувај