Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/federation-sdk/src/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ export class EventService {
}
}

private async processIncomingPDUs(
origin: string,
pdus: Pdu[],
): Promise<void> {
async processIncomingPDUs(origin: string, pdus: Pdu[]): Promise<void> {
// organize events by room id
const eventsByRoomId = new Map<string, Pdu[]>();
for (const event of pdus) {
Expand Down Expand Up @@ -265,7 +262,17 @@ export class EventService {
throw new Error('M_MISSING_SIGNATURES_OR_HASHES');
}

await checkSignAndHashes(event, origin, getPublicKeyFromServer);
let originToValidateSignatures = origin;

// If the event does not have a signature for the origin server,
// but has a signature for our server, we validate using our server name.
// This happens on sendJoin process, where the join event is signed by our server,
// but the origin is the remote server since it just returns the event as we sent it.
if (!event.signatures[origin] && event.signatures[this.configService.serverName]) {
originToValidateSignatures = this.configService.serverName;
}

await checkSignAndHashes(event, originToValidateSignatures, getPublicKeyFromServer);
}

private async processIncomingEDUs(edus: BaseEDU[]): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class MissingEventService {
this.logger.debug(`Persisting fetched missing event ${eventId}`);

// TODO is there anything else we need to do with missing dependencies from received event?
await this.stateService.persistEvent(event);
await this.eventService.processIncomingPDUs(origin, [event]);
}
} catch (err: unknown) {
this.logger.error(
Expand Down
2 changes: 1 addition & 1 deletion packages/federation-sdk/src/services/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ export class RoomService {
);

// try to persist the join event now, should succeed with state in place
await stateService.persistStateEvent(joinEventFinal);
await this.eventService.processIncomingPDUs(residentServer || joinEventFinal.origin, [joinEventFinal.event]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

if (joinEventFinal.rejected) {
throw new Error(joinEventFinal.rejectedReason);
Expand Down
Loading