xep_0384: loop again until encryption errors are fixed or until we're stuck
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
112bdddf11
commit
c355b14f79
1 changed files with 12 additions and 4 deletions
16
plugin.py
16
plugin.py
|
@ -8,7 +8,7 @@
|
|||
|
||||
import logging
|
||||
|
||||
from typing import Any, Dict, List, Set, Union
|
||||
from typing import Any, Dict, List, Set, Tuple, Union
|
||||
|
||||
import os
|
||||
import json
|
||||
|
@ -76,6 +76,9 @@ class MissingOwnKey(XEP0384): pass
|
|||
class NoEligibleDevices(XEP0384): pass
|
||||
|
||||
|
||||
class EncryptionPrepareException(XEP0384): pass
|
||||
|
||||
|
||||
class XEP_0384(BasePlugin):
|
||||
|
||||
"""
|
||||
|
@ -298,7 +301,10 @@ class XEP_0384(BasePlugin):
|
|||
recipients = [jid.bare for jid in recipients]
|
||||
bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]]
|
||||
|
||||
old_errors = None # type: Union[None, List[Tuple[Exception, Any, Any]]]
|
||||
while True:
|
||||
# Try to encrypt and resolve errors until there is no error at all
|
||||
# or if we hit the same set of errors.
|
||||
errors = []
|
||||
|
||||
self._omemo.encryptMessage(
|
||||
|
@ -313,9 +319,13 @@ class XEP_0384(BasePlugin):
|
|||
if not errors:
|
||||
break
|
||||
|
||||
if errors == old_errors:
|
||||
raise EncryptionPrepareException
|
||||
|
||||
old_errors = errors
|
||||
|
||||
no_eligible_devices = set() # type: Set[str]
|
||||
for (exn, key, val) in errors:
|
||||
|
||||
if isinstance(exn, MissingBundleException):
|
||||
bundle = await self._fetch_bundle(key, val)
|
||||
if bundle is not None:
|
||||
|
@ -341,8 +351,6 @@ class XEP_0384(BasePlugin):
|
|||
if no_eligible_devices:
|
||||
raise NoEligibleDevices(no_eligible_devices)
|
||||
|
||||
break
|
||||
|
||||
# Attempt encryption
|
||||
payload = Encrypted()
|
||||
payload['omemo_encrypted'] = self._omemo.encryptMessage(
|
||||
|
|
Loading…
Reference in a new issue