server: Don't make multiple key claim and group share requests for a room.
This commit is contained in:
parent
583926560a
commit
69db90dd4d
1 changed files with 14 additions and 3 deletions
|
@ -241,6 +241,9 @@ class MatrixServer(object):
|
||||||
self.unhandled_users = dict() # type: Dict[str, List[str]]
|
self.unhandled_users = dict() # type: Dict[str, List[str]]
|
||||||
self.lazy_load_hook = None # type: Optional[str]
|
self.lazy_load_hook = None # type: Optional[str]
|
||||||
|
|
||||||
|
self.keys_claimed = defaultdict(bool)
|
||||||
|
self.group_session_shared = defaultdict(bool)
|
||||||
|
|
||||||
self.config = ServerConfig(self.name, config_ptr)
|
self.config = ServerConfig(self.name, config_ptr)
|
||||||
self._create_session_dir()
|
self._create_session_dir()
|
||||||
# yapf: enable
|
# yapf: enable
|
||||||
|
@ -649,13 +652,19 @@ class MatrixServer(object):
|
||||||
room.room_id, "m.room.message", body
|
room.room_id, "m.room.message", body
|
||||||
)
|
)
|
||||||
except GroupEncryptionError:
|
except GroupEncryptionError:
|
||||||
|
request = None
|
||||||
try:
|
try:
|
||||||
|
if not self.group_session_shared[room.room_id]:
|
||||||
_, request = self.client.share_group_session(room.room_id)
|
_, request = self.client.share_group_session(room.room_id)
|
||||||
|
self.group_session_shared[room.room_id] = True
|
||||||
except EncryptionError:
|
except EncryptionError:
|
||||||
|
if not self.keys_claimed[room.room_id]:
|
||||||
_, request = self.client.keys_claim(room.room_id)
|
_, request = self.client.keys_claim(room.room_id)
|
||||||
|
self.keys_claimed[room.room_id] = True
|
||||||
|
|
||||||
message = EncrytpionQueueItem(msgtype, formatted)
|
message = EncrytpionQueueItem(msgtype, formatted)
|
||||||
self.encryption_queue[room.room_id].append(message)
|
self.encryption_queue[room.room_id].append(message)
|
||||||
|
if request:
|
||||||
self.send_or_queue(request)
|
self.send_or_queue(request)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -878,6 +887,7 @@ class MatrixServer(object):
|
||||||
self.handle_backlog_response(response)
|
self.handle_backlog_response(response)
|
||||||
|
|
||||||
elif isinstance(response, KeysClaimResponse):
|
elif isinstance(response, KeysClaimResponse):
|
||||||
|
self.keys_claimed[response.room_id] = False
|
||||||
try:
|
try:
|
||||||
_, request = self.client.share_group_session(
|
_, request = self.client.share_group_session(
|
||||||
response.room_id,
|
response.room_id,
|
||||||
|
@ -892,6 +902,7 @@ class MatrixServer(object):
|
||||||
|
|
||||||
elif isinstance(response, ShareGroupSessionResponse):
|
elif isinstance(response, ShareGroupSessionResponse):
|
||||||
room_id = response.room_id
|
room_id = response.room_id
|
||||||
|
self.group_session_shared[response.room_id] = False
|
||||||
room_buffer = self.room_buffers[room_id]
|
room_buffer = self.room_buffers[room_id]
|
||||||
|
|
||||||
while self.encryption_queue[room_id]:
|
while self.encryption_queue[room_id]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue