Skip to content
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

Query & claim needed keys before encrypting #270

Merged
merged 3 commits into from Dec 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/e2ee/RustEngine.ts
Expand Up @@ -33,9 +33,14 @@ export class RustEngine {
}

public async run() {
await this.runOnly(); // run everything, but with syntactic sugar
}

private async runOnly(...types: RequestType[]) {
// Note: we should not be running this until it runs out, so cache the value into a variable
const requests = await this.machine.outgoingRequests();
for (const request of requests) {
if (types.length && !types.includes(request.type)) continue;
switch (request.type) {
case RequestType.KeysUpload:
await this.processKeysUploadRequest(request);
Expand Down Expand Up @@ -106,6 +111,14 @@ export class RustEngine {
settings.rotationPeriod = BigInt(encEv.rotationPeriodMs);
settings.rotationPeriodMessages = BigInt(encEv.rotationPeriodMessages);

await this.lock.acquire(SYNC_LOCK_NAME, async () => {
await this.runOnly(RequestType.KeysQuery);
const keysClaim = await this.machine.getMissingSessions(members);
if (keysClaim) {
await this.processKeysClaimRequest(keysClaim);
}
});

await this.lock.acquire(roomId, async () => {
const requests = JSON.parse(await this.machine.shareRoomKey(new RoomId(roomId), members, settings));
for (const req of requests) {
Expand Down