-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
Make lots of OlmDevice asynchronous #524
Conversation
Prepare for some refactoring which will add an extra tick to decryption by adding some `awaitDecryption` calls in the integration tests.
Add an asynchronous `init` method to OlmDevice which initialises the OlmAccount.
* OlmDevice.getSessionIdsForDevice * OlmDevice.getSessionIdForDevice * OlmDevice.getSessionInfoForDevice
* OlmDevice.encryptMessage * OlmDevice.decryptMessage * OlmDevice.matchesSession
* OlmDevice.getOneTimeKeys * OlmDevice.markKeysAsPublished
* OlmDevice.generateOneTimeKeys becomes async * Stash maxOneTimeKeys at init so that maxNumberOfOneTimeKeys can remain sync
* OlmDevice.hasInboundSessionKeys * OlmDevice.getInboundGroupSessionKey The latter means that MegolmDecryption.shareKeysWithDevice takes longer before it sends out the keyshare, so means the unit test needed an update
console.log(client.credentials.userId + " received event", | ||
event); | ||
|
||
client.removeListener("event", onEvent); |
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.
You could've also used client.once
. https://nodejs.org/api/events.html#events_emitter_once_eventname_listener
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.
No, because then it would be harder to ignore the m.room.member
events
@@ -144,7 +148,7 @@ describe("MegolmDecryption", function() { | |||
megolmDecryption.shareKeysWithDevice(keyRequest); | |||
|
|||
// it's asynchronous, so we have to wait a bit | |||
return awaitEnsureSessions; | |||
return awaitEncryptForDevice; |
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.
Why are we waiting for something different now?
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 are two steps here:
1: ensure we have olm sessions for each of the devices (this has always been asynchronous as it involves API calls)
2: encrypt the content for each device (which used to be synchronous, but is now async)
In short, we now need to wait for step 2 to happen, whereas previously waiting for step 1 was sufficient
account.free(); | ||
} | ||
|
||
this.deviceCurve25519Key = e2eKeys.curve25519; |
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 will throw if _initialise_account
throws or if there are no identity keys as e2eKeys
will be undefined
.
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.
if _initialise_account
throws, we'll never get here.
OlmAccount.identity_keys()
is specced to return a JSON-encoded object, so e2eKeys
can't be undefined here.
src/crypto/OlmDevice.js
Outdated
@@ -367,10 +384,10 @@ OlmDevice.prototype.getSessionIdsForDevice = function(theirDeviceIdentityKey) { | |||
* | |||
* @param {string} theirDeviceIdentityKey Curve25519 identity key for the | |||
* remote device | |||
* @return {string?} session id, or null if no established session | |||
* @return {Promise<string?>} session id, or null if no established session |
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.
?string
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 e5565c6
}; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
MegolmDecryption.prototype.hasKeysForKeyRequest = async function(keyRequest) { | ||
MegolmDecryption.prototype.hasKeysForKeyRequest = function(keyRequest) { |
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'm struggling to see any rhyme or reason for which functions need to be async
and which don't? How are you determining 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.
They all need to be asynchronous. (The actual logic was that I wanted anything that touched sessionStore to be async, because I wanted to back the sessionStore with indexeddb, so sessionStore had to get an async interface).
Of course they can be asynchronous without being async
. In this case: hasInboundSessionKeys
is being changed to return a Promise, so the async
here is redundant. I agree it could have stayed.
utils.inherits(Crypto, EventEmitter); | ||
|
||
/** | ||
* Initialise the crypto module so that it is ready for use |
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.
You should mention that it returns a promise and that it is only initialised once said promise resolves.
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 e5565c6
I couldn't repro the failure locally, but this looks like it should fix the test failures.
Ok, this *really* ought to fix the racy test.
This failed a test, so let's just bump up the timeout a bit more.
I've had enough of this stuff. I'm taking the executive decision to merge it, in kegan's absence. |
A whole series of commits, each making a different method of OlmDevice asynchronous.
The tests in this code suffer from the races fixed in #523, so the tests are failing until that lands.