-
Notifications
You must be signed in to change notification settings - Fork 121
[E2E] track one time keys count in sync response #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
non-Jedi
left a comment
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 feel not great about blocking the _sync call to do other IO, but I think it would be a better situation if it was formulated as a listener where other such things would be expected to live? Still need to think about this a little more. Maybe we need to make that configurable with instantiation of MatrixClient object?
matrix_client/crypto/olm_device.py
Outdated
| user_id, | ||
| device_id, | ||
| signed_otk_proportion=1, | ||
| otk_threshold=0.1): |
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.
Is 0.1 the value used by Riot?
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 hadn't checked while writing this. Looking at it now it appears Riot uploads keys as soon as it can, and considers that generating a lot of one-time keys at time is slow. I tend to think that it is a JS thing, as on my machine generating the max number of one-time keys is a lot faster than any network operation. @richvdh may have some insight?
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.
According to what @richvdh told me, this should be fine.
matrix_client/crypto/olm_device.py
Outdated
| int(round(signed_otk_proportion * target_keys_number)) | ||
| self.otk_target_counts['curve25519'] = \ | ||
| int(round((1 - signed_otk_proportion) * target_keys_number)) | ||
| if not 0 <= otk_threshold <= 1: |
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.
Move this validity check to top of method as well please.
matrix_client/client.py
Outdated
| if room_id in self.rooms: | ||
| del self.rooms[room_id] | ||
|
|
||
| if self.encryption and 'device_one_time_keys_count' in response: |
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.
Any chance we could formulate this as a listener that gets automatically added if encryption=True so we can keep all _sync actions other than simply updating local state in a single place?
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.
Mmmh, I'm not seeing how without adding a new listener loop, which seems pretty overkill for doing exactly the same thing differently.
However, this is only the first sync extension of 3 (device_list and to_device are added later, and are non-blocking), so adding a loop might be worthwhile, although I'm not sure how clear it would look. Since we should get that right now, you may want to have a look at how _sync ends up looking at the end: https://github.com/matrix-org/matrix-python-sdk/pull/241/files#diff-6770c150117812114aea5a8aab1b7da9L554
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.
Ya. I see that listeners only work for events, and this is a top-level field in the response. Hm. After mulling it over, I think we should keep the listener system for user code.
I think this is probably fine for now, but could you add a # TODO comment above _sync mentioning this behavior so that when we get around to turning _sync into a proper public method with a docstring, we remember to document this?
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
|
We should also consider that it is very likely that under reasonable load the request will be triggered maybe once a day, or even once a week: someone claims one of our one-time key only the first time they speak to us in an encrypted room; the Olm session derived from this key is kept forever. |
|
Comparing with what the JS SDK does,
|
|
Thanks for those details @uhoreg. Here are the timings: I was too lazy to properly test the This reasoning also answers your last point. We don't want to set keys_threshold to 1 because then we would do a lot of requests with very few one-time keys. Also, this code is not asynchronous like JS, and we want to block as rarely as possible. Your second point is a very good catch! toDevice messages support is added in another PR, but I missed that and they are effectively handled after the key update. Will fix :) |
|
@Zil0 Thanks for the timings. That seems reasonable, then, at least for now. Perhaps in the future, we might want to make it configurable, but it should be fine for now. So this one seems good to go, aside from @non-Jedi's question of how to handle uploading the keys in the middle of the sync, which I don't really have an opinion on. |
This feature is currently undocumented, but quite self-explanatory.
Here is my try at the missing documentation, not yet reviewed: matrix-org/matrix-spec-proposals@fce04f0
I wonder if this crosses the red-line "never initiate a new request during /sync/ processing".
Signed-off-by: Valentin Deniaud <valentin.deniaud@inpt.fr>