Skip to content

Conversation

@Zil0
Copy link
Contributor

@Zil0 Zil0 commented Jun 13, 2018

First attempt at trying to integrate e2e into the existing code. No crypto stuff in this one.

With this PR and the later ones I aim at two things:

  • Introduce no breaking changes, every existing code built upon the SDK should keep working without any noticeable difference.
  • Making it real simple to enable and use e2e. Right now it is as simple as passing encryption=True to MatrixClient.

Not sure about the optional dependency handling in this one, that is why I made it a separate commit. If it's the right way to do it, let me know and I'll squash 'em.

Signed-off-by: Valentin Deniaud <valentin.deniaud@inpt.fr>

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good in general. I'm fine with how encryption is configured here. :)

self.device_id = response["device_id"]

if self.encryption:
if ENCRYPTION_SUPPORT:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this check in __init__ instead? Immediately raise error (rather than logging an error) if instantiating with encryption=True and ENCRYPTION_SUPPORT=False. Also change self.encryption to self._encryption to signal that it isn't something that should be changed at runtime, and then we can drop this check from here entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, way better design!

the token) if supplying a token; otherwise, ignored.
valid_cert_check (bool): Check the homeservers
certificate on connections?
encryption (bool): Optional. Wether or not to enable end-to-end encryption
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Wether" spelling

@@ -59,6 +59,11 @@ class MatrixClient(object):
the token) if supplying a token; otherwise, ignored.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. Why do we have a docstring on both the class and on the __init__ method with subtly different information on arguments? Poking around, most people seem to just not have a docstring on __init__ methods. I'll open an issue to move all info in __init__ docstrings to class docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered this too. Also the __init__ docstrings are ignored by Sphinx.
Added a commit to fix this.

def __init__(self, base_url, token=None, user_id=None,
valid_cert_check=True, sync_filter_limit=20,
cache_level=CACHE.ALL, encryption=False):
cache_level=CACHE.ALL, encryption=False, encryption_conf={}):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default args to methods should almost never be mutable objects. See #236 for example of bugs caused.

@@ -106,27 +108,6 @@ def global_callback(incoming_event):
def __init__(self, base_url, token=None, user_id=None,
valid_cert_check=True, sync_filter_limit=20,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to make of the undocumented sync_filter_limit, which is marked as deprecated in login docstring, so I left it undocumented.

@Zil0
Copy link
Contributor Author

Zil0 commented Jul 2, 2018

Done

@Zil0
Copy link
Contributor Author

Zil0 commented Jul 4, 2018

Just had a thought, what about the logout method? Since the client attribute set when logging in are not reset when logging out, it is probably OK to keep the same OlmDevice, but it feels a bit weird nonetheless.

@non-Jedi
Copy link
Collaborator

non-Jedi commented Jul 5, 2018

Just had a thought, what about the logout method? Since the client attribute set when logging in are not reset when logging out, it is probably OK to keep the same OlmDevice, but it feels a bit weird nonetheless.

To be honest, I wouldn't worry about it. I know for a fact that logging back in on a MatrixClient that was previously logged out would already cause havoc with the client if the clients join state for any rooms had changed since the previous logout.

self.ephemeral_listeners = []
self.device_id = None
self._encryption = encryption
self.encryption_conf = encryption_conf or {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tricksy one-liner there. Had to double-check in REPL to make sure it did what I expected.

@non-Jedi
Copy link
Collaborator

non-Jedi commented Jul 5, 2018

This is good to merge once prereq commits are in. :)

@uhoreg uhoreg mentioned this pull request Jul 13, 2018
@non-Jedi non-Jedi merged commit 3df920a into matrix-org:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants