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

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
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
Jonathan Hitchcock Approve
Review via email: mp+5698@code.launchpad.net
To post a comment you must log in.
Revision history for this message
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.

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
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
=== modified file 'ibid/source/irc.py'
--- ibid/source/irc.py 2009-03-16 18:52:53 +0000
+++ ibid/source/irc.py 2009-04-18 21:57:47 +0000
@@ -10,7 +10,7 @@
10from pkg_resources import resource_exists, resource_string10from pkg_resources import resource_exists, resource_string
1111
12import ibid12import ibid
13from ibid.config import Option, IntOption, BoolOption13from ibid.config import Option, IntOption, BoolOption, FloatOption
14from ibid.models import Credential14from ibid.models import Credential
15from ibid.source import IbidSourceFactory15from ibid.source import IbidSourceFactory
16from ibid.event import Event16from ibid.event import Event
@@ -18,6 +18,8 @@
18class Ircbot(irc.IRCClient):18class Ircbot(irc.IRCClient):
1919
20 versionNum = resource_exists(__name__, '../.version') and resource_string(__name__, '../.version') or ''20 versionNum = resource_exists(__name__, '../.version') and resource_string(__name__, '../.version') or ''
21 _ping_deferred = None
22 _reconnect_deferred = None
2123
22 def connectionMade(self):24 def connectionMade(self):
23 self.nickname = self.factory.nick.encode('utf-8')25 self.nickname = self.factory.nick.encode('utf-8')
@@ -26,12 +28,40 @@
26 self.factory.send = self.send28 self.factory.send = self.send
27 self.factory.proto = self29 self.factory.proto = self
28 self.auth_callbacks = {}30 self.auth_callbacks = {}
31 self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)
29 self.factory.log.info(u"Connected")32 self.factory.log.info(u"Connected")
3033
31 def connectionLost(self, reason):34 def connectionLost(self, reason):
32 self.factory.log.info(u"Disconnected (%s)", reason)35 self.factory.log.info(u"Disconnected (%s)", reason)
33 irc.IRCClient.connectionLost(self, reason)36 irc.IRCClient.connectionLost(self, reason)
3437
38 def _idle_ping(self):
39 self.factory.log.log(logging.DEBUG - 5, u'Sending idle PING')
40 self._ping_deferred = None
41 self._reconnect_deferred = reactor.callLater(self.factory.pong_timeout, self._timeout_reconnect)
42 self.sendLine('PING foo')
43
44 def _timeout_reconnect(self):
45 self.factory.log.info(u'Ping-Pong timeout. Reconnecting')
46 self.factory.clientConnectionLost(self.factory, 'pingpong timeout')
47
48 def irc_PONG(self, prefix, params):
49 if params[-1] == 'foo' and self._reconnect_deferred is not None:
50 self.factory.log.log(logging.DEBUG - 5, u'Received PONG')
51 self._reconnect_deferred.cancel()
52 self._reconnect_deferred = None
53 self._ping_deferred = reactor.callLater(self.factory.ping_interval, self._idle_ping)
54
55 def dataReceived(self, data):
56 irc.IRCClient.dataReceived(self, data)
57 if self._ping_deferred is not None:
58 self._ping_deferred.reset(self.factory.ping_interval)
59
60 def sendLine(self, line):
61 irc.IRCClient.sendLine(self, line)
62 if self._ping_deferred is not None:
63 self._ping_deferred.reset(self.factory.ping_interval)
64
35 def signedOn(self):65 def signedOn(self):
36 if self.factory.modes:66 if self.factory.modes:
37 self.mode(self.nickname, True, self.factory.modes.encode('utf-8'))67 self.mode(self.nickname, True, self.factory.modes.encode('utf-8'))
@@ -155,6 +185,8 @@
155 nick = Option('nick', 'IRC nick', ibid.config['botname'])185 nick = Option('nick', 'IRC nick', ibid.config['botname'])
156 modes = Option('modes', 'User modes to set')186 modes = Option('modes', 'User modes to set')
157 channels = Option('channels', 'Channels to autojoin', [])187 channels = Option('channels', 'Channels to autojoin', [])
188 ping_interval = FloatOption('ping_interval', 'Seconds of idle before sending a PING', 60)
189 pong_timeout = FloatOption('pong_timeout', 'Seconds to wait for PONG', 300)
158190
159 def __init__(self, name):191 def __init__(self, name):
160 IbidSourceFactory.__init__(self, name)192 IbidSourceFactory.__init__(self, name)

Subscribers

People subscribed via source and target branches