Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix error when claiming e2e keys from offline servers #3034

Merged
merged 2 commits into from
Mar 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -134,23 +135,8 @@ def do_remote_query(destination):
if user_id in destination_query:
results[user_id] = keys

except CodeMessageException as e:
failures[destination] = {
"status": e.code, "message": e.message
}
except NotRetryingDestination as e:
failures[destination] = {
"status": 503, "message": "Not ready for retry",
}
except FederationDeniedError as e:
failures[destination] = {
"status": 403, "message": "Federation Denied",
}
except Exception as e:
# include ConnectionRefused and other errors
failures[destination] = {
"status": 503, "message": e.message
}
failures[destination] = _exception_to_failure(e)

yield make_deferred_yieldable(defer.gatherResults([
preserve_fn(do_remote_query)(destination)
Expand Down Expand Up @@ -252,19 +238,8 @@ def claim_client_keys(destination):
for user_id, keys in remote_result["one_time_keys"].items():
if user_id in device_keys:
json_result[user_id] = keys
except CodeMessageException as e:
failures[destination] = {
"status": e.code, "message": e.message
}
except NotRetryingDestination as e:
failures[destination] = {
"status": 503, "message": "Not ready for retry",
}
except Exception as e:
# include ConnectionRefused and other errors
failures[destination] = {
"status": 503, "message": e.message
}
failures[destination] = _exception_to_failure(e)

yield make_deferred_yieldable(defer.gatherResults([
preserve_fn(claim_client_keys)(destination)
Expand Down Expand Up @@ -362,6 +337,31 @@ def _upload_one_time_keys_for_user(self, user_id, device_id, time_now,
)


def _exception_to_failure(e):
if isinstance(e, CodeMessageException):
return {
"status": e.code, "message": e.message,
}

if isinstance(e, NotRetryingDestination):
return {
"status": 503, "message": "Not ready for retry",
}

if isinstance(e, FederationDeniedError):
return {
"status": 403, "message": "Federation Denied",
}

# include ConnectionRefused and other errors
#
# Note that some Exceptions (notably twisted's ResponseFailed etc) don't
# give a string for e.message, which simplejson then fails to serialize.
return {
"status": 503, "message": str(e.message),
}


def _one_time_keys_match(old_key_json, new_key):
old_key = json.loads(old_key_json)

Expand Down