Skip to content

Commit

Permalink
patch for irc-0.3.7 martynsmith/node-irc#214
Browse files Browse the repository at this point in the history
  • Loading branch information
dub4u committed Oct 18, 2014
1 parent a9c21ed commit e3cf822
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions misc/ping_timeout.patch
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit e3cf822

Please sign in to comment.