self._owner.Dispatcher.send(i,False)#use this send so that our stanzas actually increment out_h
self.old_uqueue=[]
defresume_request(self):
ifnotself.session_id:
self.resuming=False
log.error('Attempted to resume without a valid session id ')
return
self.old_uqueue=self.uqueue#save old messages in an extra "queue" to avoid race conditions
#save old messages in an extra "queue" to avoid race conditions and to make it possible to replay stanzas even when resuming fails
#add messages here (instead of overwriting) so that repeated connection errors don't delete unacked stanzas (uqueue should be empty in this case anyways)
self.old_uqueue+=self.uqueue
self.uqueue=[]
resume=Acks()
resume.buildResume(self.in_h,self.session_id)
...
...
@@ -124,6 +140,7 @@ class Smacks(object):
number of stanzas received by the server. Resends stanzas not received
by the server in the last session.
"""
log.info("Session resumption succeeded")
h=stanza.getAttr('h')
ifnoth:
log.error('Server did not send h attribute')
...
...
@@ -137,7 +154,7 @@ class Smacks(object):
eliflen(self.old_uqueue)<diff:
log.error('Server and client number of stanzas handled mismatch on session resumption (our h: %d, server h: %d)'%(self.out_h,h))
else:
log.info('Removing %d already received stanzas from old outgoing queue (our h: %d, server h: %d, remaining in queue: %d)'%(len(self.old_uqueue)-diff,self.out_h,h,diff))
log.info('Removing %d already acked stanzas from old outgoing queue (our h: %d, server h: %d, remaining in queue: %d)'%(len(self.old_uqueue)-diff,self.out_h,h,diff))
while(len(self.old_uqueue)>diff):
self.old_uqueue.pop(0)
...
...
@@ -160,14 +177,33 @@ class Smacks(object):
self._owner.NonBlockingBind.resuming=False
self._owner._on_auth_bind(None)
self.failed_resume=True
h=stanza.getTag('item-not-found').getAttr('h')
log.info('Session resumption failed (item-not-found), server h: %s'%str(h))
ifnoth:
return
#prepare old_queue to contain only unacked stanzas for later resend (which is happening after our session is established properly)
h=int(h)
diff=self.out_h-h
ifdiff<0:
log.error('Server and client number of stanzas handled mismatch on session resumption (our h: %d, server h: %d)'%(self.out_h,h))
self.old_uqueue=[]#that's weird, but we don't resend this stanzas if the server says we don't need to
eliflen(self.old_uqueue)<diff:
log.error('Server and client number of stanzas handled mismatch on session resumption (our h: %d, server h: %d)'%(self.out_h,h))
else:
log.info('Removing %d already acked stanzas from old outgoing queue (our h: %d, server h: %d, remaining in queue: %d)'%(len(self.old_uqueue)-diff,self.out_h,h,diff))