Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0198.py @ 3008:c8c68a3b0a79
plugins XEP-0045, XEP-0198: rejoin MUC rooms while a hot reconnection is done:
when resuming is not possible with stream management, a hot reconnection is done
(reconnecting without restarting every plugin). This was causing trouble for joined MUC
rooms, which were not accessible anymore (because they were not re-joined).
This patch fixes it by clearing rooms first (to avoid considering the room joined and
broadcasting the initial presence to them), then re-joining them.
fix 322
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 16 Jul 2019 21:59:30 +0200 |
parents | 9213c6dff48d |
children | 93da7c6f8e0c |
comparison
equal
deleted
inserted
replaced
3007:420897488080 | 3008:c8c68a3b0a79 |
---|---|
33 import time | 33 import time |
34 | 34 |
35 log = getLogger(__name__) | 35 log = getLogger(__name__) |
36 | 36 |
37 PLUGIN_INFO = { | 37 PLUGIN_INFO = { |
38 C.PI_NAME: "Stream Management", | 38 C.PI_NAME: u"Stream Management", |
39 C.PI_IMPORT_NAME: "XEP-0198", | 39 C.PI_IMPORT_NAME: u"XEP-0198", |
40 C.PI_TYPE: "XEP", | 40 C.PI_TYPE: u"XEP", |
41 C.PI_MODES: C.PLUG_MODE_BOTH, | 41 C.PI_MODES: C.PLUG_MODE_BOTH, |
42 C.PI_PROTOCOLS: ["XEP-0198"], | 42 C.PI_PROTOCOLS: [u"XEP-0198"], |
43 C.PI_DEPENDENCIES: [], | 43 C.PI_DEPENDENCIES: [], |
44 C.PI_MAIN: "XEP_0198", | 44 C.PI_RECOMMENDATIONS: [u"XEP-0045"], |
45 C.PI_HANDLER: "yes", | 45 C.PI_MAIN: u"XEP_0198", |
46 C.PI_HANDLER: u"yes", | |
46 C.PI_DESCRIPTION: _(u"""Implementation of Stream Management"""), | 47 C.PI_DESCRIPTION: _(u"""Implementation of Stream Management"""), |
47 } | 48 } |
48 | 49 |
49 NS_SM = u"urn:xmpp:sm:3" | 50 NS_SM = u"urn:xmpp:sm:3" |
50 SM_ENABLED = '/enabled[@xmlns="' + NS_SM + '"]' | 51 SM_ENABLED = '/enabled[@xmlns="' + NS_SM + '"]' |
392 # and initial presence sending. | 393 # and initial presence sending. |
393 if client.conn_deferred.called: | 394 if client.conn_deferred.called: |
394 client.conn_deferred = defer.Deferred() | 395 client.conn_deferred = defer.Deferred() |
395 else: | 396 else: |
396 log.error(u"conn_deferred should be called at this point") | 397 log.error(u"conn_deferred should be called at this point") |
398 plg_0045 = self.host.plugins.get(u'XEP-0045') | |
399 if plg_0045 is not None: | |
400 # we have to remove joined rooms | |
401 muc_join_args = plg_0045.popRooms(client) | |
397 # we need to recreate roster | 402 # we need to recreate roster |
398 client.handlers.remove(client.roster) | 403 client.handlers.remove(client.roster) |
399 client.roster = client.roster.__class__(self.host) | 404 client.roster = client.roster.__class__(self.host) |
400 client.roster.setHandlerParent(client) | 405 client.roster.setHandlerParent(client) |
401 # bind init is not done when resuming is possible, so we have to do it now | 406 # bind init is not done when resuming is possible, so we have to do it now |
410 d.addCallback(lambda __: client.roster.requestRoster()) | 415 d.addCallback(lambda __: client.roster.requestRoster()) |
411 # we add got_roster to be sure to have roster before sending initial presence | 416 # we add got_roster to be sure to have roster before sending initial presence |
412 d.addCallback(lambda __: client.roster.got_roster) | 417 d.addCallback(lambda __: client.roster.got_roster) |
413 # initial presence must be sent manually | 418 # initial presence must be sent manually |
414 d.addCallback(lambda __: client.presence.available()) | 419 d.addCallback(lambda __: client.presence.available()) |
420 if plg_0045 is not None: | |
421 muc_d_list = defer.DeferredList( | |
422 [plg_0045.join(*args) for args in muc_join_args]) | |
423 d.addCallback(lambda __: muc_d_list) | |
415 | 424 |
416 def onReceive(self, element, client): | 425 def onReceive(self, element, client): |
417 if not client.is_component: | 426 if not client.is_component: |
418 session = client._xep_0198_session | 427 session = client._xep_0198_session |
419 if session.enabled and element.name.lower() in C.STANZA_NAMES: | 428 if session.enabled and element.name.lower() in C.STANZA_NAMES: |
435 def onAckAnswer(self, a_elt, client): | 444 def onAckAnswer(self, a_elt, client): |
436 session = client._xep_0198_session | 445 session = client._xep_0198_session |
437 session.ack_requested = False | 446 session.ack_requested = False |
438 if self._ack_timeout: | 447 if self._ack_timeout: |
439 if session.req_timer is None: | 448 if session.req_timer is None: |
440 log.error("reg_timer should be set") | 449 log.error("req_timer should be set") |
441 else: | 450 else: |
442 session.req_timer.cancel() | 451 session.req_timer.cancel() |
443 session.req_timer = None | 452 session.req_timer = None |
444 try: | 453 try: |
445 server_acked = int(a_elt['h']) | 454 server_acked = int(a_elt['h']) |