Merge lp:~stefanor/ibid/timeout-344882 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera on 2009-04-19
Status: Merged
Approved by: Stefano Rivera on 2009-04-20
Approved revision: 598
Merged at revision: 602
Proposed branch: lp:~stefanor/ibid/timeout-344882
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp:~stefanor/ibid/timeout-344882
Reviewer Review Type Date Requested Status
Michael Gorven Approve on 2009-04-20
Jonathan Hitchcock 2009-04-19 Approve on 2009-04-20
Review via email: mp+5698@code.launchpad.net
To post a comment you must log in.
Stefano Rivera (stefanor) wrote :

This only fixes the problem for IRC, but I filed a new bug for the other protocols (they are harder to fix). Seems good in artificial testing, but I've got ibid using it for some real-world tests - If UCT keeps up their unreliable network, we should get some good test coverage.

Jonathan Hitchcock (vhata) :
review: Approve
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/source/irc.py'
2--- ibid/source/irc.py 2009-03-16 18:52:53 +0000
3+++ ibid/source/irc.py 2009-04-18 21:57:47 +0000
4@@ -10,7 +10,7 @@
5 from pkg_resources import resource_exists, resource_string
6
7 import ibid
8-from ibid.config import Option, IntOption, BoolOption
9+from ibid.config import Option, IntOption, BoolOption, FloatOption
10 from ibid.models import Credential
11 from ibid.source import IbidSourceFactory
12 from ibid.event import Event
13@@ -18,6 +18,8 @@
14 class Ircbot(irc.IRCClient):
15
16 versionNum = resource_exists(__name__, '../.version') and resource_string(__name__, '../.version') or ''
17+ _ping_deferred = None
18+ _reconnect_deferred = None
19
20 def connectionMade(self):
21 self.nickname = self.factory.nick.encode('utf-8')
22@@ -26,12 +28,40 @@
23 self.factory.send = self.send
24 self.factory.proto = self
25 self.auth_callbacks = {}
26+ self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)
27 self.factory.log.info(u"Connected")
28
29 def connectionLost(self, reason):
30 self.factory.log.info(u"Disconnected (%s)", reason)
31 irc.IRCClient.connectionLost(self, reason)
32
33+ def _idle_ping(self):
34+ self.factory.log.log(logging.DEBUG - 5, u'Sending idle PING')
35+ self._ping_deferred = None
36+ self._reconnect_deferred = reactor.callLater(self.factory.pong_timeout, self._timeout_reconnect)
37+ self.sendLine('PING foo')
38+
39+ def _timeout_reconnect(self):
40+ self.factory.log.info(u'Ping-Pong timeout. Reconnecting')
41+ self.factory.clientConnectionLost(self.factory, 'pingpong timeout')
42+
43+ def irc_PONG(self, prefix, params):
44+ if params[-1] == 'foo' and self._reconnect_deferred is not None:
45+ self.factory.log.log(logging.DEBUG - 5, u'Received PONG')
46+ self._reconnect_deferred.cancel()
47+ self._reconnect_deferred = None
48+ self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)
49+
50+ def dataReceived(self, data):
51+ irc.IRCClient.dataReceived(self, data)
52+ if self._ping_deferred is not None:
53+ self._ping_deferred.reset(self.factory.ping_interval)
54+
55+ def sendLine(self, line):
56+ irc.IRCClient.sendLine(self, line)
57+ if self._ping_deferred is not None:
58+ self._ping_deferred.reset(self.factory.ping_interval)
59+
60 def signedOn(self):
61 if self.factory.modes:
62 self.mode(self.nickname, True, self.factory.modes.encode('utf-8'))
63@@ -155,6 +185,8 @@
64 nick = Option('nick', 'IRC nick', ibid.config['botname'])
65 modes = Option('modes', 'User modes to set')
66 channels = Option('channels', 'Channels to autojoin', [])
67+ ping_interval = FloatOption('ping_interval', 'Seconds of idle before sending a PING', 60)
68+ pong_timeout = FloatOption('pong_timeout', 'Seconds to wait for PONG', 300)
69
70 def __init__(self, name):
71 IbidSourceFactory.__init__(self, name)

Subscribers

People subscribed via source and target branches