Checks for stanzas handled by server
This commit is contained in:
parent
5b1edd03b8
commit
9c8b63afc4
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
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…
Reference in New Issue