mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 08:04:27 +00:00
Matrix: consolidate decrypt retry wiring and harden sdk imports
This commit is contained in:
@@ -7,8 +7,8 @@ import {
|
||||
type MatrixClient as MatrixJsClient,
|
||||
type MatrixEvent,
|
||||
} from "matrix-js-sdk";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto-api/CryptoEvent.ts";
|
||||
import { VerificationMethod } from "matrix-js-sdk/src/types.ts";
|
||||
import { CryptoEvent } from "matrix-js-sdk/lib/crypto-api/CryptoEvent.js";
|
||||
import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
|
||||
import { EventEmitter } from "node:events";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
@@ -438,21 +438,7 @@ export class MatrixClient {
|
||||
}
|
||||
});
|
||||
|
||||
const triggerDecryptRetry = (reason: string): void => {
|
||||
this.decryptBridge.retryPendingNow(reason);
|
||||
};
|
||||
crypto.on(CryptoEvent.KeyBackupDecryptionKeyCached, () => {
|
||||
triggerDecryptRetry("crypto.keyBackupDecryptionKeyCached");
|
||||
});
|
||||
crypto.on(CryptoEvent.RehydrationCompleted, () => {
|
||||
triggerDecryptRetry("dehydration.RehydrationCompleted");
|
||||
});
|
||||
crypto.on(CryptoEvent.DevicesUpdated, () => {
|
||||
triggerDecryptRetry("crypto.devicesUpdated");
|
||||
});
|
||||
crypto.on(CryptoEvent.KeysChanged, () => {
|
||||
triggerDecryptRetry("crossSigning.keysChanged");
|
||||
});
|
||||
this.decryptBridge.bindCryptoRetrySignals(crypto);
|
||||
|
||||
LogService.info("MatrixClientLite", "Verification request handler registered");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { MatrixEventEvent, type MatrixEvent } from "matrix-js-sdk";
|
||||
import { CryptoEvent } from "matrix-js-sdk/lib/crypto-api/CryptoEvent.js";
|
||||
import { LogService, noop } from "./logger.js";
|
||||
|
||||
type MatrixDecryptIfNeededClient = {
|
||||
@@ -23,6 +24,10 @@ type DecryptBridgeRawEvent = {
|
||||
event_id: string;
|
||||
};
|
||||
|
||||
type MatrixCryptoRetrySignalSource = {
|
||||
on: (eventName: string, listener: (...args: unknown[]) => void) => void;
|
||||
};
|
||||
|
||||
const MATRIX_DECRYPT_RETRY_BASE_DELAY_MS = 1_500;
|
||||
const MATRIX_DECRYPT_RETRY_MAX_DELAY_MS = 30_000;
|
||||
const MATRIX_DECRYPT_RETRY_MAX_ATTEMPTS = 8;
|
||||
@@ -46,6 +51,7 @@ export class MatrixDecryptBridge<TRawEvent extends DecryptBridgeRawEvent> {
|
||||
private readonly decryptedMessageDedupe = new Map<string, number>();
|
||||
private readonly decryptRetries = new Map<string, MatrixDecryptRetryState>();
|
||||
private readonly failedDecryptionsNotified = new Set<string>();
|
||||
private cryptoRetrySignalsBound = false;
|
||||
|
||||
constructor(
|
||||
private readonly deps: {
|
||||
@@ -103,6 +109,30 @@ export class MatrixDecryptBridge<TRawEvent extends DecryptBridgeRawEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
bindCryptoRetrySignals(crypto: MatrixCryptoRetrySignalSource | undefined): void {
|
||||
if (!crypto || this.cryptoRetrySignalsBound) {
|
||||
return;
|
||||
}
|
||||
this.cryptoRetrySignalsBound = true;
|
||||
|
||||
const trigger = (reason: string): void => {
|
||||
this.retryPendingNow(reason);
|
||||
};
|
||||
|
||||
crypto.on(CryptoEvent.KeyBackupDecryptionKeyCached, () => {
|
||||
trigger("crypto.keyBackupDecryptionKeyCached");
|
||||
});
|
||||
crypto.on(CryptoEvent.RehydrationCompleted, () => {
|
||||
trigger("dehydration.RehydrationCompleted");
|
||||
});
|
||||
crypto.on(CryptoEvent.DevicesUpdated, () => {
|
||||
trigger("crypto.devicesUpdated");
|
||||
});
|
||||
crypto.on(CryptoEvent.KeysChanged, () => {
|
||||
trigger("crossSigning.keysChanged");
|
||||
});
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
for (const retryKey of this.decryptRetries.keys()) {
|
||||
this.clearDecryptRetry(retryKey);
|
||||
|
||||
@@ -2,8 +2,8 @@ import {
|
||||
VerificationPhase,
|
||||
VerificationRequestEvent,
|
||||
VerifierEvent,
|
||||
} from "matrix-js-sdk/src/crypto-api/verification.ts";
|
||||
import { VerificationMethod } from "matrix-js-sdk/src/types.ts";
|
||||
} from "matrix-js-sdk/lib/crypto-api/verification.js";
|
||||
import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
|
||||
|
||||
export type MatrixVerificationMethod = "sas" | "show-qr" | "scan-qr";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user