Skip to content

Commit

Permalink
feat: advance epoch number on req_new_epoch call
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed Feb 7, 2023
1 parent f626e7f commit de478d0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@emotion/react": "11.10.5",
"@types/eslint": "^8.4.10",
"@wireapp/avs": "9.0.20",
"@wireapp/core": "38.9.1",
"@wireapp/core": "38.10.1",
"@wireapp/lru-cache": "3.8.1",
"@wireapp/react-ui-kit": "9.3.5",
"@wireapp/store-engine-dexie": "2.0.4",
Expand Down
27 changes: 14 additions & 13 deletions src/script/calling/mlsConference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import {SUBCONVERSATION_ID} from '@wireapp/api-client/lib/conversation/Subconversation';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import {MLSService} from '@wireapp/core/lib/messagingProtocols/mls';
import {constructFullyQualifiedClientId} from '@wireapp/core/lib/util/fullyQualifiedClientIdUtils';
Expand Down Expand Up @@ -50,15 +51,20 @@ const generateSubconversationMembers = async (

export const getSubconversationEpochInfo = async (
{mlsService}: {mlsService: MLSService},
subconversationGroupId: string,
parentGroupId: string,
conversationId: QualifiedId,
shouldAdvanceEpoch = false,
): Promise<{
members: SubconversationEpochInfoMember[];
epoch: number;
secretKey: string;
keyLength: number;
}> => {
const subconversationGroupId = await mlsService.getGroupIdFromConversationId(
conversationId,
SUBCONVERSATION_ID.CONFERENCE,
);
const parentGroupId = await mlsService.getGroupIdFromConversationId(conversationId);

const members = await generateSubconversationMembers({mlsService}, subconversationGroupId, parentGroupId);

if (shouldAdvanceEpoch) {
Expand All @@ -82,27 +88,22 @@ export const subscribeToEpochUpdates = async (
keyLength: number;
}) => void,
): Promise<() => void> => {
const subconversation = await mlsService.joinConferenceSubconversation(conversationId);
const {epoch: initialEpoch, groupId: subconversationGroupId} = await mlsService.joinConferenceSubconversation(
conversationId,
);

const forwardNewEpoch = async ({groupId, epoch}: {groupId: string; epoch: number}) => {
if (groupId !== subconversation.group_id) {
if (groupId !== subconversationGroupId) {
return;
}

const subconversationGroupId = subconversation.group_id;
const parentConversationGroupId = await mlsService.getGroupIdFromConversationId(conversationId);

const {keyLength, secretKey, members} = await getSubconversationEpochInfo(
{mlsService},
subconversationGroupId,
parentConversationGroupId,
);
const {keyLength, secretKey, members} = await getSubconversationEpochInfo({mlsService}, conversationId);
onEpochUpdate({epoch: Number(epoch), keyLength, secretKey, members});
};

mlsService.on('newEpoch', forwardNewEpoch);

await forwardNewEpoch({groupId: subconversation.group_id, epoch: subconversation.epoch});
await forwardNewEpoch({groupId: subconversationGroupId, epoch: initialEpoch});

return () => mlsService.off('newEpoch', forwardNewEpoch);
};
14 changes: 7 additions & 7 deletions src/script/view_model/CallingViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import {SUBCONVERSATION_ID} from '@wireapp/api-client/lib/conversation/Subconversation';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import ko from 'knockout';
import {container} from 'tsyringe';
Expand Down Expand Up @@ -213,21 +214,20 @@ export class CallingViewModel {
return;
}

const subconversation = await this.mlsService.getConferenceSubconversation(conversationId);
const subconversationGroupId = await this.mlsService.getGroupIdFromConversationId(
conversationId,
SUBCONVERSATION_ID.CONFERENCE,
);

//we don't want to react to avs callbacks when conversation was not yet established
const isMLSConversationEstablished = await this.mlsService.conversationExists(subconversation.group_id);
const isMLSConversationEstablished = await this.mlsService.conversationExists(subconversationGroupId);
if (!isMLSConversationEstablished) {
return;
}

const parentGroupId = await this.mlsService.getGroupIdFromConversationId(conversationId);
const subconversationGroupId = subconversation.group_id;

const {epoch, keyLength, secretKey, members} = await getSubconversationEpochInfo(
{mlsService: this.mlsService},
subconversationGroupId,
parentGroupId,
conversationId,
shouldAdvanceEpoch,
);
this.callingRepository.setEpochInfo(conversationId, {epoch, keyLength, secretKey}, members);
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4383,9 +4383,9 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:38.9.1":
version: 38.9.1
resolution: "@wireapp/core@npm:38.9.1"
"@wireapp/core@npm:38.10.1":
version: 38.10.1
resolution: "@wireapp/core@npm:38.10.1"
dependencies:
"@wireapp/api-client": ^22.15.2
"@wireapp/commons": ^5.0.4
Expand All @@ -4403,7 +4403,7 @@ __metadata:
logdown: 3.3.1
long: ^5.2.0
uuidjs: 4.2.13
checksum: 70b8acbc8f885b630d98f7963c4951bc5fc2be5db193d192545710136a25f1f42dfb8076e366a3c23aae9fc90dcad47b43d7603a04c1a10db5280a303b8f7e43
checksum: 5ba0480421d26be42bedbd7d90e2c9aa70dc76e9fe40013899919c2c14dbfa9ac304f7e02c456b3783d3854c4012d9ced956a94f7a3e9ac114877756dbcf3350
languageName: node
linkType: hard

Expand Down Expand Up @@ -16712,7 +16712,7 @@ __metadata:
"@typescript-eslint/parser": ^5.50.0
"@wireapp/avs": 9.0.20
"@wireapp/copy-config": 2.0.7
"@wireapp/core": 38.9.1
"@wireapp/core": 38.10.1
"@wireapp/eslint-config": 2.1.1
"@wireapp/lru-cache": 3.8.1
"@wireapp/prettier-config": 0.5.2
Expand Down

0 comments on commit de478d0

Please sign in to comment.