From e3cf822047f7fcc622f98914d438eb8a576d0f75 Mon Sep 17 00:00:00 2001 From: dub4u Date: Sat, 18 Oct 2014 09:33:20 +0800 Subject: [PATCH] patch for irc-0.3.7 https://github.com/martynsmith/node-irc/pull/214 --- misc/ping_timeout.patch | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 misc/ping_timeout.patch diff --git a/misc/ping_timeout.patch b/misc/ping_timeout.patch new file mode 100644 index 0000000..be880e8 --- /dev/null +++ b/misc/ping_timeout.patch @@ -0,0 +1,116 @@ +--- irc.js.0.3.7 2014-10-17 22:43:48.745380337 +0800 ++++ irc.js 2014-10-17 22:56:18.455379821 +0800 +@@ -51,7 +51,10 @@ + sasl: false, + stripColors: false, + channelPrefixes: "&#", +- messageSplit: 512 ++ messageSplit: 512, ++ hostIdTimeout: 90*1000, ++ pingTimeoutLength: 90*1000, ++ pingInterval: 30*1000 + }; + + // Features supported by the server +@@ -93,6 +96,24 @@ + self.connect(); + } + ++ function sendPing(sendNow) { ++ function doPing() { ++ self.send('PING', self.host); ++ self.pingTimeoutTimer = setTimeout(function(){ ++ if (self.opt.debug) { ++ util.log('Ping timeout'); ++ } ++ self.emit('timeout'); ++ }, self.opt.pingTimeoutLength); ++ } ++ if (sendNow) { ++ doPing(); ++ } ++ else { ++ self.pingTimer = setTimeout(doPing, self.opt.pingInterval); ++ } ++ } ++ + self.addListener("raw", function (message) { // {{{ + switch ( message.command ) { + case "rpl_welcome": +@@ -101,7 +122,20 @@ + // the server has shortened it + self.nick = message.args[0]; + self.emit('registered', message); ++ ++ self.hostIdTimer = setTimeout( function() { ++ if ( self.opt.debug ) ++ util.log('Server took too long to send 002'); ++ self.emit('timeout'); ++ }, self.opt.hostIdTimeout); ++ ++ break; ++ case "rpl_yourhost": ++ clearTimeout(self.hostIdTimer); ++ self.host = message.args[1].substring(13).split(',')[0]; ++ sendPing(true); + break; ++ case "rpl_created": + case "rpl_myinfo": + self.supported.usermodes = message.args[3]; + break; +@@ -176,8 +210,6 @@ + } + }); + break; +- case "rpl_yourhost": +- case "rpl_created": + case "rpl_luserclient": + case "rpl_luserop": + case "rpl_luserchannels": +@@ -194,6 +226,10 @@ + self.send("NICK", self.opt.nick + self.opt.nickMod); + self.nick = self.opt.nick + self.opt.nickMod; + break; ++ case "PONG": ++ clearTimeout(self.pingTimeoutTimer); ++ sendPing(false); ++ break; + case "PING": + self.send("PONG", message.args[0]); + self.emit('ping', message.args[0]); +@@ -569,6 +605,14 @@ + }); + }); + ++ self.addListener('timeout', function () { ++ self.conn.wantsReconnect = true; ++ if ( self.opt.debug ) { ++ util.log('timeout'); ++ } ++ self.disconnect('Client detected ping timeout'); ++ }); ++ + process.EventEmitter.call(this); + } + +@@ -644,6 +688,7 @@ + self.conn = net.createConnection(self.opt.port, self.opt.server); + } + self.conn.requestedDisconnect = false; ++ self.conn.wantsReconnect = false; + self.conn.setTimeout(0); + self.conn.setEncoding('utf8'); + self.conn.addListener("connect", function () { +@@ -679,9 +724,11 @@ + util.log('Connection got "end" event'); + }); + self.conn.addListener("close", function() { ++ clearTimeout(self.pingTimer); ++ clearTimeout(self.hostIdTimer); + if ( self.opt.debug ) + util.log('Connection got "close" event'); +- if ( self.conn.requestedDisconnect ) ++ if ( self.conn.requestedDisconnect && !self.conn.wantsReconnect ) + return; + if ( self.opt.debug ) + util.log('Disconnected: reconnecting');