Keep track of known bundles on the instance

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 Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent 869b11d3
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment