From 2a346ac48d1cdb27063e54ca966f4f063369e3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 24 Aug 2019 00:44:46 +0200 Subject: [PATCH] Keep track of known bundles on the instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we're raising exceptions often to yield to the client, we need to keep track of bundles on the object and not just in the method itself. Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index fd0586c..2e74900 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -179,6 +179,9 @@ class XEP_0384(BasePlugin): backend_loaded = HAS_OMEMO + # OMEMO Bundles used for encryption + bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] + def plugin_init(self) -> None: if not self.backend_loaded: log.info("xep_0384 cannot be loaded as the backend omemo library " @@ -441,7 +444,6 @@ class XEP_0384(BasePlugin): """ recipients = [jid.bare for jid in recipients] - bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] old_errors = None # type: Optional[List[Tuple[Exception, Any, Any]]] while True: @@ -456,7 +458,7 @@ class XEP_0384(BasePlugin): encrypted = self._omemo.encryptMessage( recipients, plaintext.encode('utf-8'), - bundles, + self.bundles, expect_problems=expect_problems, ) return _generate_encrypted_payload(encrypted) @@ -474,7 +476,7 @@ class XEP_0384(BasePlugin): elif isinstance(exn, omemo.exceptions.MissingBundleException): bundle = await self._fetch_bundle(exn.bare_jid, exn.device) if bundle is not None: - devices = bundles.setdefault(exn.bare_jid, {}) + devices = self.bundles.setdefault(exn.bare_jid, {}) devices[exn.device] = bundle elif isinstance(exn, omemo.exceptions.TrustException): # On TrustException, there are two possibilities.