mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Changed IrcMsgQueue a bit to make it even more smarter; Added reconnection on ERROR disconnect; Added reconnect on returned PINGs.
This commit is contained in:
parent
d6087e2906
commit
a30ee6cd0b
@ -92,34 +92,34 @@ class IrcCallback(object):
|
|||||||
class IrcMsgQueue(object):
|
class IrcMsgQueue(object):
|
||||||
"""Class for a queue of IrcMsgs. Eventually, it should be smart.
|
"""Class for a queue of IrcMsgs. Eventually, it should be smart.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('msgs', 'modes', 'kicks', 'lowpriority')
|
__slots__ = ('msgs', 'highpriority', 'normal', 'lowpriority')
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.modes = queue()
|
self.highpriority = queue()
|
||||||
self.kicks = queue()
|
self.normal = queue()
|
||||||
self.lowpriority = queue()
|
self.lowpriority = queue()
|
||||||
self.msgs = set()
|
self.msgs = set()
|
||||||
|
|
||||||
def enqueueMsg(self, msg):
|
def enqueue(self, msg):
|
||||||
if msg in self.msgs:
|
if msg in self.msgs:
|
||||||
if not world.startup:
|
if not world.startup:
|
||||||
debug.debugMsg('Not adding msg %s to queue' % msg, 'normal')
|
debug.debugMsg('Not adding msg %s to queue' % msg, 'normal')
|
||||||
else:
|
else:
|
||||||
self.msgs.add(msg)
|
self.msgs.add(msg)
|
||||||
if msg.command == 'MODE':
|
if msg.command in ('MODE', 'KICK', 'PONG'):
|
||||||
self.modes.enqueue(msg)
|
self.highpriority.enqueue(msg)
|
||||||
elif msg.command == 'KICK':
|
elif msg.command in ('PING',):
|
||||||
self.kicks.enqueue(msg)
|
|
||||||
else:
|
|
||||||
self.lowpriority.enqueue(msg)
|
self.lowpriority.enqueue(msg)
|
||||||
|
else:
|
||||||
|
self.normal.enqueue(msg)
|
||||||
|
|
||||||
def dequeueMsg(self):
|
def dequeue(self):
|
||||||
if self.modes:
|
if self.highpriority:
|
||||||
msg = self.modes.dequeue()
|
msg = self.highpriority.dequeue()
|
||||||
elif self.kicks:
|
elif self.normal:
|
||||||
msg = self.kicks.dequeue()
|
msg = self.normal.dequeue()
|
||||||
elif self.lowpriority:
|
elif self.lowpriority:
|
||||||
msg = self.lowpriority.dequeue()
|
msg = self.lowpriority.dequeue()
|
||||||
else:
|
else:
|
||||||
@ -128,8 +128,8 @@ class IrcMsgQueue(object):
|
|||||||
self.msgs.remove(msg)
|
self.msgs.remove(msg)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def empty(self):
|
def __nonzero__(self):
|
||||||
return not (self.modes or self.kicks or self.lowpriority)
|
return (self.highpriority or self.normal or self.lowpriority)
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
@ -282,18 +282,19 @@ class Irc(object):
|
|||||||
self.queue = IrcMsgQueue()
|
self.queue = IrcMsgQueue()
|
||||||
self.fastqueue = queue()
|
self.fastqueue = queue()
|
||||||
self.lastping = time.time()
|
self.lastping = time.time()
|
||||||
|
self.lastpong = time.time()+60
|
||||||
self.lastTake = 0
|
self.lastTake = 0
|
||||||
self.driver = None # The driver should set this later.
|
self.driver = None # The driver should set this later.
|
||||||
self.queue.enqueueMsg(ircmsgs.user(self.user, self.ident))
|
self.queue.enqueue(ircmsgs.user(self.user, self.ident))
|
||||||
self.queue.enqueueMsg(ircmsgs.nick(self.nick))
|
self.queue.enqueue(ircmsgs.nick(self.nick))
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._nickmods = copy.copy(conf.nickmods)
|
self._nickmods = copy.copy(conf.nickmods)
|
||||||
self.state.reset()
|
self.state.reset()
|
||||||
self.queue.reset()
|
self.queue.reset()
|
||||||
self.fastqueue = queue()
|
self.fastqueue = queue()
|
||||||
self.queue.enqueueMsg(ircmsgs.user(self.user, self.ident))
|
self.queue.enqueue(ircmsgs.user(self.user, self.ident))
|
||||||
self.queue.enqueueMsg(ircmsgs.nick(self.nick))
|
self.queue.enqueue(ircmsgs.nick(self.nick))
|
||||||
for callback in self.callbacks:
|
for callback in self.callbacks:
|
||||||
callback.reset()
|
callback.reset()
|
||||||
|
|
||||||
@ -313,7 +314,7 @@ class Irc(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def queueMsg(self, msg):
|
def queueMsg(self, msg):
|
||||||
self.queue.enqueueMsg(msg)
|
self.queue.enqueue(msg)
|
||||||
|
|
||||||
def sendMsg(self, msg):
|
def sendMsg(self, msg):
|
||||||
self.fastqueue.enqueue(msg)
|
self.fastqueue.enqueue(msg)
|
||||||
@ -323,12 +324,17 @@ class Irc(object):
|
|||||||
msg = None
|
msg = None
|
||||||
if self.fastqueue:
|
if self.fastqueue:
|
||||||
msg = self.fastqueue.dequeue()
|
msg = self.fastqueue.dequeue()
|
||||||
elif not self.queue.empty():
|
elif self.queue:
|
||||||
if now - self.lastTake <= conf.throttleTime:
|
if now - self.lastTake <= conf.throttleTime:
|
||||||
debug.debugMsg('Irc.takeMsg throttling.', 'verbose')
|
debug.debugMsg('Irc.takeMsg throttling.', 'verbose')
|
||||||
else:
|
else:
|
||||||
self.lastTake = now
|
self.lastTake = now
|
||||||
msg = self.queue.dequeueMsg()
|
msg = self.queue.dequeue()
|
||||||
|
elif self.lastping - self.lastpong > 180:
|
||||||
|
# Our ping hasn't be responded to.
|
||||||
|
if hasattr(self.driver, 'scheduleReconnect'):
|
||||||
|
self.driver.scheduleReconnect()
|
||||||
|
self.driver.die()
|
||||||
elif now > (self.lastping + conf.pingInterval):
|
elif now > (self.lastping + conf.pingInterval):
|
||||||
if now - self.lastTake <= conf.throttleTime:
|
if now - self.lastTake <= conf.throttleTime:
|
||||||
debug.debugMsg('Irc.takeMsg throttling.', 'verbose')
|
debug.debugMsg('Irc.takeMsg throttling.', 'verbose')
|
||||||
@ -393,10 +399,14 @@ class Irc(object):
|
|||||||
hostmasks=[msg.prefix])
|
hostmasks=[msg.prefix])
|
||||||
ircdb.users.setUser(self.nick, u)
|
ircdb.users.setUser(self.nick, u)
|
||||||
atexit.register(lambda: catch(ircdb.users.delUser(self.nick)))
|
atexit.register(lambda: catch(ircdb.users.delUser(self.nick)))
|
||||||
|
elif msg.command == 'PONG':
|
||||||
# elif msg.command == 'ERROR':
|
self.lastpong = time.time()
|
||||||
# if msg.args[0].startswith('Closing Link'):
|
elif msg.command == 'ERROR':
|
||||||
# self.driver.die()
|
if msg.args[0].startswith('Closing Link'):
|
||||||
|
if hasattr(self.driver, 'scheduleReconnect'):
|
||||||
|
self.driver.scheduleReconnect()
|
||||||
|
if self.driver:
|
||||||
|
self.driver.die()
|
||||||
# Now update the IrcState object.
|
# Now update the IrcState object.
|
||||||
try:
|
try:
|
||||||
self.state.addMsg(self, msg)
|
self.state.addMsg(self, msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user