From 9c8b63afc420d80a933ebfe5f2caf4100e850706 Mon Sep 17 00:00:00 2001 From: Jefry Lagrange <jefry.reyes@gmail.com> Date: Tue, 31 May 2011 17:09:49 -0400 Subject: [PATCH] Checks for stanzas handled by server --- src/common/xmpp/dispatcher_nb.py | 7 +++++++ src/common/xmpp/smacks.py | 26 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py index 31fa86e3a3..f01f78a0a8 100644 --- a/src/common/xmpp/dispatcher_nb.py +++ b/src/common/xmpp/dispatcher_nb.py @@ -533,6 +533,13 @@ class XMPPDispatcher(PlugIn): ID = stanza.getID() if self._owner._registered_name and not stanza.getAttr('from'): stanza.setAttr('from', self._owner._registered_name) + + if self.supports_sm: + self.sm.uqueue.append(stanza) + self.sm.out_h = self.sm.out_h + 1 + if len(self.sm.uqueue) > self.sm.max_queue: + self.sm.request_ack() + self._owner.Connection.send(stanza, now) return ID diff --git a/src/common/xmpp/smacks.py b/src/common/xmpp/smacks.py index 7c99ab5b80..005f2e375b 100644 --- a/src/common/xmpp/smacks.py +++ b/src/common/xmpp/smacks.py @@ -1,5 +1,7 @@ from protocol import Acks from protocol import NS_STREAM_MGMT +import logging +log = logging.getLogger('gajim.c.x.smacks') class Smacks(): ''' @@ -16,13 +18,16 @@ class Smacks(): self.out_h = 0 # Outgoing stanzas handled self.in_h = 0 # Incoming stanzas handled self.uqueue = [] # Unhandled stanzas queue - - #Register handlers + # Max number of stanzas in queue before making a request + self.max_queue = 5 + # Register handlers owner.Dispatcher.RegisterNamespace(NS_STREAM_MGMT) owner.Dispatcher.RegisterHandler('enabled', self._neg_response ,xmlns=NS_STREAM_MGMT) owner.Dispatcher.RegisterHandler('r', self.send_ack ,xmlns=NS_STREAM_MGMT) + owner.Dispatcher.RegisterHandler('a', self.check_ack + ,xmlns=NS_STREAM_MGMT) def negociate(self): @@ -41,4 +46,19 @@ class Smacks(): def request_ack(self): r = Acks() r.buildRequest() - self._owner.Connection.send(r, False) \ No newline at end of file + self._owner.Connection.send(r, False) + + def check_ack(self, disp, stanza): + h = int(stanza.getAttr('h')) + diff = self.out_h - h + + + if len(self.uqueue) < diff or diff < 0: + log.error('Server and client number of stanzas handled mismatch ') + return + + while (len(self.uqueue) > diff): + self.uqueue.pop(0) + + + -- GitLab