Checks for stanzas handled by server
This commit is contained in:
parent
5b1edd03b8
commit
9c8b63afc4
2 changed files with 30 additions and 3 deletions
|
@ -533,6 +533,13 @@ class XMPPDispatcher(PlugIn):
|
||||||
ID = stanza.getID()
|
ID = stanza.getID()
|
||||||
if self._owner._registered_name and not stanza.getAttr('from'):
|
if self._owner._registered_name and not stanza.getAttr('from'):
|
||||||
stanza.setAttr('from', self._owner._registered_name)
|
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)
|
self._owner.Connection.send(stanza, now)
|
||||||
return ID
|
return ID
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from protocol import Acks
|
from protocol import Acks
|
||||||
from protocol import NS_STREAM_MGMT
|
from protocol import NS_STREAM_MGMT
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger('gajim.c.x.smacks')
|
||||||
|
|
||||||
class Smacks():
|
class Smacks():
|
||||||
'''
|
'''
|
||||||
|
@ -16,13 +18,16 @@ class Smacks():
|
||||||
self.out_h = 0 # Outgoing stanzas handled
|
self.out_h = 0 # Outgoing stanzas handled
|
||||||
self.in_h = 0 # Incoming stanzas handled
|
self.in_h = 0 # Incoming stanzas handled
|
||||||
self.uqueue = [] # Unhandled stanzas queue
|
self.uqueue = [] # Unhandled stanzas queue
|
||||||
|
# Max number of stanzas in queue before making a request
|
||||||
|
self.max_queue = 5
|
||||||
# Register handlers
|
# Register handlers
|
||||||
owner.Dispatcher.RegisterNamespace(NS_STREAM_MGMT)
|
owner.Dispatcher.RegisterNamespace(NS_STREAM_MGMT)
|
||||||
owner.Dispatcher.RegisterHandler('enabled', self._neg_response
|
owner.Dispatcher.RegisterHandler('enabled', self._neg_response
|
||||||
,xmlns=NS_STREAM_MGMT)
|
,xmlns=NS_STREAM_MGMT)
|
||||||
owner.Dispatcher.RegisterHandler('r', self.send_ack
|
owner.Dispatcher.RegisterHandler('r', self.send_ack
|
||||||
,xmlns=NS_STREAM_MGMT)
|
,xmlns=NS_STREAM_MGMT)
|
||||||
|
owner.Dispatcher.RegisterHandler('a', self.check_ack
|
||||||
|
,xmlns=NS_STREAM_MGMT)
|
||||||
|
|
||||||
|
|
||||||
def negociate(self):
|
def negociate(self):
|
||||||
|
@ -42,3 +47,18 @@ class Smacks():
|
||||||
r = Acks()
|
r = Acks()
|
||||||
r.buildRequest()
|
r.buildRequest()
|
||||||
self._owner.Connection.send(r, False)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue