From 4de8953246a5bfc61a0183b96509a42775bae1a6 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 10 Aug 2013 15:38:52 +0100 Subject: [PATCH] Listening on the raw socket in TLS IRC connections --- server/irc/connection.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/server/irc/connection.js b/server/irc/connection.js index 5cb8dc8..d61d064 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -207,6 +207,9 @@ IrcConnection.prototype.connect = function () { localAddress: outgoing }); + // We need the raw socket connect event + that.socket.socket.on('connect', function() { rawSocketConnect.call(that, this); }); + socket_connect_event_name = 'secureConnect'; } else { @@ -221,19 +224,16 @@ IrcConnection.prototype.connect = function () { // Apply the socket listeners that.socket.on(socket_connect_event_name, function socketConnectCb() { - // SSL connections have the actual socket as a property - var socket = (typeof this.socket !== 'undefined') ? - this.socket : - this; + // TLS connections have the actual socket as a property + var is_tls = (typeof this.socket !== 'undefined') ? + true : + false; - that.connected = true; + // TLS sockets have already called this + if (!is_tls) + rawSocketConnect.call(that, this); - // Make note of the port numbers for any identd lookups - // Nodejs < 0.9.6 has no socket.localPort so check this first - if (socket.localPort) { - that.identd_port_pair = socket.localPort.toString() + '_' + socket.remotePort.toString(); - global.clients.port_pairs[that.identd_port_pair] = that; - } + that.connected = true; socketConnectHandler.call(that); }); @@ -525,6 +525,19 @@ function onUserKick(event){ +/** + * When a socket connects to an IRCd + * May be called before any socket handshake are complete (eg. TLS) + */ +var rawSocketConnect = function(socket) { + // Make note of the port numbers for any identd lookups + // Nodejs < 0.9.6 has no socket.localPort so check this first + if (typeof socket.localPort != 'undefined') { + this.identd_port_pair = socket.localPort.toString() + '_' + socket.remotePort.toString(); + global.clients.port_pairs[this.identd_port_pair] = this; + } +}; + /** * Handle the socket connect event, starting the IRCd registration -- 2.25.1