-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
I took a quick look at @dbkr's changes, and they look fine to me. It would be great to get a full review from a Synapse dev. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just needs a little bit of sprucing up.
FTR: I've only really been reviewing the code, rather than trying to grok how E2E backups are meant to work as a whole.
For future reference, it'd also be good to avoid using @defer.inlineCallbacks
in tests and instead use the test reactor infrastructure (which is also fairly nice). There are a number of advantages to this (Though personally the main one is that if you CTRL^C trial it sometimes completely wedges if using a real reactor)
synapse/api/errors.py
Outdated
return exception.error_dict() | ||
else: | ||
logger.error("Unknown exception type: %s", type(exception)) | ||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm, so it does
synapse/handlers/e2e_room_keys.py
Outdated
@@ -0,0 +1,283 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright 2017 New Vector Ltd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its 2018
room, or a given session. | ||
See EndToEndRoomKeyStore.get_e2e_room_keys for full details. | ||
|
||
Returns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add Args
section, giving types (and description if not obvious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And the same for the other functions.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
synapse/handlers/e2e_room_keys.py
Outdated
if e.code == 404: | ||
raise SynapseError(404, "Version '%s' not found" % (version,)) | ||
else: | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just use raise
rather than raise e
as you end up losing a bunch of stack traces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good to know
if E2eRoomKeysHandler._should_replace_room_key(current_room_key, room_key): | ||
yield self.store.set_e2e_room_key( | ||
user_id, version, room_id, session_id, room_key | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not want to be in the lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where by lock you mean try block? I don't think so as the try is just catching 404s from the get.
""" | ||
|
||
if version: | ||
raise SynapseError(405, "Cannot POST to a specific version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please split this servlet into two: 1) which doesn't accept a version and only works for PUT and 2) which requires a version and only works with GET/DELETE.
This has the advantages of:
- Its easier to grasp the API shapes without having to read the code
- Don't have to re-implement all the validations/error handling
It does somewhat look like we've forgotten to check that we're actually given a version in GET/DELETE handlers for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if e.code == 404: | ||
e.errcode = Codes.NOT_FOUND | ||
e.msg = "No backup found" | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a new error rather than rewriting the existing one please? Otherwise we may end up with bizarre hybrid exceptions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm not even sure we want to bother rewriting anything here. If we do, we should probably do the same for the DELETE handler.
In fact, for consistency sake we should probably make the exceptions returned by the handler on unknown version be consistent, rather than the exception being specific to each REST endpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes :)
synapse/storage/e2e_room_keys.py
Outdated
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import simplejson as json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use just import json
nowadays
synapse/storage/e2e_room_keys.py
Outdated
session_id(str): the session whose room_key we're setting | ||
room_key(dict): the room_key being set | ||
Raises: | ||
StoreError if stuff goes wrong, probably |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think its worth having this comment :)
@@ -0,0 +1,361 @@ | |||
# -*- coding: utf-8 -*- | |||
# Copyright 2017 New Vector Ltd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully all addressed now - ptal
synapse/api/errors.py
Outdated
return exception.error_dict() | ||
else: | ||
logger.error("Unknown exception type: %s", type(exception)) | ||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm, so it does
room, or a given session. | ||
See EndToEndRoomKeyStore.get_e2e_room_keys for full details. | ||
|
||
Returns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
synapse/handlers/e2e_room_keys.py
Outdated
if e.code == 404: | ||
raise SynapseError(404, "Version '%s' not found" % (version,)) | ||
else: | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good to know
if E2eRoomKeysHandler._should_replace_room_key(current_room_key, room_key): | ||
yield self.store.set_e2e_room_key( | ||
user_id, version, room_id, session_id, room_key | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where by lock you mean try block? I don't think so as the try is just catching 404s from the get.
synapse/handlers/e2e_room_keys.py
Outdated
# purely for legibility. | ||
|
||
if room_key['is_verified'] and not current_room_key['is_verified']: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm, agreed
synapse/handlers/e2e_room_keys.py
Outdated
""" | ||
|
||
results = yield self.store.get_e2e_room_keys_version_info(user_id, version) | ||
defer.returnValue(results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm, I see what you mean
""" | ||
|
||
if version: | ||
raise SynapseError(405, "Cannot POST to a specific version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if e.code == 404: | ||
e.errcode = Codes.NOT_FOUND | ||
e.msg = "No backup found" | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this goes live we should probably move this functionality into a worker, as it sounds like this API is going to get hit a lot
@dbkr please please please can we squash-merge things like this in future? |
**Warning**: This release removes the example email notification templates from `res/templates` (they are now internal to the python package). This should only affect you if you (a) deploy your Synapse instance from a git checkout or a github snapshot URL, and (b) have email notifications enabled. If you have email notifications enabled, you should ensure that `email.template_dir` is either configured to point at a directory where you have installed customised templates, or leave it unset to use the default templates. The configuration parser will try to detect the situation where `email.template_dir` is incorrectly set to `res/templates` and do the right thing, but will warn about this. Features -------- - Ship the example email templates as part of the package ([\#4052](#4052)) - Add support for end-to-end key backup (MSC1687) ([\#4019](#4019)) Bugfixes -------- - Fix bug which made get_missing_events return too few events ([\#4045](#4045)) - Fix bug in event persistence logic which caused 'NoneType is not iterable' ([\#3995](#3995)) - Fix exception in background metrics collection ([\#3996](#3996)) - Fix exception handling in fetching remote profiles ([\#3997](#3997)) - Fix handling of rejected threepid invites ([\#3999](#3999)) - Workers now start on Python 3. ([\#4027](#4027)) - Synapse now starts on Python 3.7. ([\#4033](#4033)) Internal Changes ---------------- - Log exceptions in looping calls ([\#4008](#4008)) - Optimisation for serving federation requests ([\#4017](#4017)) - Add metric to count number of non-empty sync responses ([\#4022](#4022))
Supersedes #3757 and #2731
Note that most of this has already been reviewed when it was in 2731 (unsure if it would be easier or more confusing to merge this branch over to that one and re-open that PR).
This is MSC1687: https://github.com/uhoreg/matrix-doc/blob/e2e_backup/proposals/1219-storing-megolm-keys-serverside.md
Sytests: matrix-org/sytest#503