Skip to content

Commit bb9280a

Browse files
authored
Write a log line when cancelling verification (#4828)
... in an attempt to figure out what might have caused a spurious cancellation today
1 parent 00bd7f0 commit bb9280a

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

spec/unit/rust-crypto/verification.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import { type OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor";
3333
import { type IDeviceKeys } from "../../../src/@types/crypto";
3434
import { EventType, MatrixEvent, MsgType } from "../../../src";
35+
import { logger } from "../../../src/logger.ts";
3536

3637
describe("VerificationRequest", () => {
3738
describe("pending", () => {
@@ -147,6 +148,7 @@ describe("VerificationRequest", () => {
147148
methods,
148149
);
149150
const aliceVerificationRequest = new RustVerificationRequest(
151+
logger,
150152
aliceOlmMachine,
151153
innerVerificationRequest,
152154
aliceRequestLoop as unknown as OutgoingRequestProcessor,
@@ -174,6 +176,7 @@ describe("VerificationRequest", () => {
174176
"$m.key.verification.request",
175177
)!;
176178
const bobVerificationRequest = new RustVerificationRequest(
179+
logger,
177180
bobOlmMachine,
178181
bobInnerVerificationRequest,
179182
bobRequestLoop as unknown as OutgoingRequestProcessor,
@@ -278,6 +281,7 @@ describe("VerificationRequest", () => {
278281
methods,
279282
);
280283
const aliceVerificationRequest = new RustVerificationRequest(
284+
logger,
281285
aliceOlmMachine,
282286
innerVerificationRequest,
283287
aliceRequestLoop as unknown as OutgoingRequestProcessor,
@@ -305,6 +309,7 @@ describe("VerificationRequest", () => {
305309
"$m.key.verification.request",
306310
)!;
307311
const bobVerificationRequest = new RustVerificationRequest(
312+
logger,
308313
bobOlmMachine,
309314
bobInnerVerificationRequest,
310315
bobRequestLoop as unknown as OutgoingRequestProcessor,
@@ -392,6 +397,7 @@ describe("VerificationRequest", () => {
392397
methods,
393398
);
394399
const aliceVerificationRequest = new RustVerificationRequest(
400+
logger,
395401
aliceOlmMachine,
396402
innerVerificationRequest,
397403
aliceRequestLoop as unknown as OutgoingRequestProcessor,
@@ -419,6 +425,7 @@ describe("VerificationRequest", () => {
419425
"$m.key.verification.request",
420426
)!;
421427
const bobVerificationRequest = new RustVerificationRequest(
428+
logger,
422429
bobOlmMachine,
423430
bobInnerVerificationRequest,
424431
bobRequestLoop as unknown as OutgoingRequestProcessor,
@@ -496,7 +503,7 @@ function makeTestRequest(
496503
inner ??= makeMockedInner();
497504
olmMachine ??= {} as RustSdkCryptoJs.OlmMachine;
498505
outgoingRequestProcessor ??= {} as OutgoingRequestProcessor;
499-
return new RustVerificationRequest(olmMachine, inner, outgoingRequestProcessor, []);
506+
return new RustVerificationRequest(logger, olmMachine, inner, outgoingRequestProcessor, []);
500507
}
501508

502509
/** Mock up a rust-side VerificationRequest */

src/rust-crypto/rust-crypto.ts

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -969,15 +969,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
969969
);
970970
return requests
971971
.filter((request) => request.roomId === undefined)
972-
.map(
973-
(request) =>
974-
new RustVerificationRequest(
975-
this.olmMachine,
976-
request,
977-
this.outgoingRequestProcessor,
978-
this._supportedVerificationMethods,
979-
),
980-
);
972+
.map((request) => this.makeVerificationRequest(request));
981973
}
982974

983975
/**
@@ -1002,12 +994,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
1002994
const request = requests.find((request) => request.roomId?.toString() === roomId);
1003995

1004996
if (request) {
1005-
return new RustVerificationRequest(
1006-
this.olmMachine,
1007-
request,
1008-
this.outgoingRequestProcessor,
1009-
this._supportedVerificationMethods,
1010-
);
997+
return this.makeVerificationRequest(request);
1011998
}
1012999
}
10131000

@@ -1038,12 +1025,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
10381025
new RustSdkCryptoJs.EventId(eventId),
10391026
methods,
10401027
);
1041-
return new RustVerificationRequest(
1042-
this.olmMachine,
1043-
request,
1044-
this.outgoingRequestProcessor,
1045-
this._supportedVerificationMethods,
1046-
);
1028+
return this.makeVerificationRequest(request);
10471029
} finally {
10481030
userIdentity.free();
10491031
}
@@ -1114,12 +1096,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
11141096
this._supportedVerificationMethods.map(verificationMethodIdentifierToMethod),
11151097
);
11161098
await this.outgoingRequestProcessor.makeOutgoingRequest(outgoingRequest);
1117-
return new RustVerificationRequest(
1118-
this.olmMachine,
1119-
request,
1120-
this.outgoingRequestProcessor,
1121-
this._supportedVerificationMethods,
1122-
);
1099+
return this.makeVerificationRequest(request);
11231100
} finally {
11241101
userIdentity.free();
11251102
}
@@ -1152,12 +1129,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
11521129
this._supportedVerificationMethods.map(verificationMethodIdentifierToMethod),
11531130
);
11541131
await this.outgoingRequestProcessor.makeOutgoingRequest(outgoingRequest);
1155-
return new RustVerificationRequest(
1156-
this.olmMachine,
1157-
request,
1158-
this.outgoingRequestProcessor,
1159-
this._supportedVerificationMethods,
1160-
);
1132+
return this.makeVerificationRequest(request);
11611133
} finally {
11621134
device.free();
11631135
}
@@ -1667,15 +1639,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
16671639
);
16681640

16691641
if (request) {
1670-
this.emit(
1671-
CryptoEvent.VerificationRequestReceived,
1672-
new RustVerificationRequest(
1673-
this.olmMachine,
1674-
request,
1675-
this.outgoingRequestProcessor,
1676-
this._supportedVerificationMethods,
1677-
),
1678-
);
1642+
this.emit(CryptoEvent.VerificationRequestReceived, this.makeVerificationRequest(request));
16791643
} else {
16801644
// There are multiple reasons this can happen; probably the most likely is that the event is an
16811645
// in-room event which is too old.
@@ -1685,6 +1649,17 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
16851649
}
16861650
}
16871651

1652+
/** Utility function to wrap a rust `VerificationRequest` with our own {@link VerificationRequest}. */
1653+
private makeVerificationRequest(request: RustSdkCryptoJs.VerificationRequest): VerificationRequest {
1654+
return new RustVerificationRequest(
1655+
this.logger,
1656+
this.olmMachine,
1657+
request,
1658+
this.outgoingRequestProcessor,
1659+
this._supportedVerificationMethods,
1660+
);
1661+
}
1662+
16881663
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16891664
//
16901665
// Other public functions

src/rust-crypto/verification.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { type MatrixEvent } from "../models/event.ts";
3636
import { EventType, MsgType } from "../@types/event.ts";
3737
import { defer, type IDeferred } from "../utils.ts";
3838
import { VerificationMethod } from "../types.ts";
39+
import type { Logger } from "../logger.ts";
3940

4041
/**
4142
* An incoming, or outgoing, request to verify a user or a device via cross-signing.
@@ -60,12 +61,14 @@ export class RustVerificationRequest
6061
/**
6162
* Construct a new RustVerificationRequest to wrap the rust-level `VerificationRequest`.
6263
*
64+
* @param logger - A logger instance which will be used to log events.
6365
* @param olmMachine - The `OlmMachine` from the underlying rust crypto sdk.
6466
* @param inner - VerificationRequest from the Rust SDK.
6567
* @param outgoingRequestProcessor - `OutgoingRequestProcessor` to use for making outgoing HTTP requests.
6668
* @param supportedVerificationMethods - Verification methods to use when `accept()` is called.
6769
*/
6870
public constructor(
71+
private readonly logger: Logger,
6972
private readonly olmMachine: RustSdkCryptoJs.OlmMachine,
7073
private readonly inner: RustSdkCryptoJs.VerificationRequest,
7174
private readonly outgoingRequestProcessor: OutgoingRequestProcessor,
@@ -309,6 +312,7 @@ export class RustVerificationRequest
309312
return;
310313
}
311314

315+
this.logger.info("Cancelling verification request with params:", params);
312316
this._cancelling = true;
313317
try {
314318
const req: undefined | OutgoingRequest = this.inner.cancel();

0 commit comments

Comments
 (0)