1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Grab bag of Element-R cleanups (#3773)

* `RustBackupManager.getActiveBackupVersion`: check that backup is enabled

The previous check on `isBackupEnabled` was a no-op

* Fix log spam on shieldless events

* Reduce log spam about tracking users

* Reduce log spam about decrypting events

Logging the entire event is excessive
This commit is contained in:
Richard van der Hoff
2023-10-04 10:15:54 +01:00
committed by GitHub
parent 6e8d15e5ed
commit 10b6c2463d
4 changed files with 11 additions and 13 deletions

View File

@@ -498,7 +498,7 @@ describe("RustCrypto", () => {
[RustSdkCryptoJs.ShieldColor.Red, EventShieldColour.RED], [RustSdkCryptoJs.ShieldColor.Red, EventShieldColour.RED],
])("gets the right shield color (%i)", async (rustShield, expectedShield) => { ])("gets the right shield color (%i)", async (rustShield, expectedShield) => {
const mockEncryptionInfo = { const mockEncryptionInfo = {
shieldState: jest.fn().mockReturnValue({ color: rustShield, message: null }), shieldState: jest.fn().mockReturnValue({ color: rustShield, message: undefined }),
} as unknown as RustSdkCryptoJs.EncryptionInfo; } as unknown as RustSdkCryptoJs.EncryptionInfo;
olmMachine.getRoomEventEncryptionInfo.mockResolvedValue(mockEncryptionInfo); olmMachine.getRoomEventEncryptionInfo.mockResolvedValue(mockEncryptionInfo);
@@ -509,7 +509,7 @@ describe("RustCrypto", () => {
}); });
it.each([ it.each([
[null, null], [undefined, null],
["Encrypted by an unverified user.", EventShieldReason.UNVERIFIED_IDENTITY], ["Encrypted by an unverified user.", EventShieldReason.UNVERIFIED_IDENTITY],
["Encrypted by a device not verified by its owner.", EventShieldReason.UNSIGNED_DEVICE], ["Encrypted by a device not verified by its owner.", EventShieldReason.UNSIGNED_DEVICE],
[ [

View File

@@ -65,15 +65,14 @@ export class RoomEncryptor {
* @param member - new membership state * @param member - new membership state
*/ */
public onRoomMembership(member: RoomMember): void { public onRoomMembership(member: RoomMember): void {
this.prefixedLogger.debug(`${member.membership} event for ${member.userId}`);
if ( if (
member.membership == "join" || member.membership == "join" ||
(member.membership == "invite" && this.room.shouldEncryptForInvitedMembers()) (member.membership == "invite" && this.room.shouldEncryptForInvitedMembers())
) { ) {
// make sure we are tracking the deviceList for this user // make sure we are tracking the deviceList for this user
this.prefixedLogger.debug(`starting to track devices for: ${member.userId}`); this.olmMachine.updateTrackedUsers([new UserId(member.userId)]).catch((e) => {
this.olmMachine.updateTrackedUsers([new UserId(member.userId)]); this.prefixedLogger.error("Unable to update tracked users", e);
});
} }
// TODO: handle leaves (including our own) // TODO: handle leaves (including our own)

View File

@@ -82,7 +82,7 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
* Get the backup version we are currently backing up to, if any * Get the backup version we are currently backing up to, if any
*/ */
public async getActiveBackupVersion(): Promise<string | null> { public async getActiveBackupVersion(): Promise<string | null> {
if (!this.olmMachine.isBackupEnabled()) return null; if (!(await this.olmMachine.isBackupEnabled())) return null;
return this.activeBackupVersion; return this.activeBackupVersion;
} }

View File

@@ -1223,10 +1223,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
// start tracking devices for any users already known to be in this room. // start tracking devices for any users already known to be in this room.
const members = await room.getEncryptionTargetMembers(); const members = await room.getEncryptionTargetMembers();
logger.debug(
`[${room.roomId} encryption] starting to track devices for: `,
members.map((u) => `${u.userId} (${u.membership})`),
);
await this.olmMachine.updateTrackedUsers(members.map((u) => new RustSdkCryptoJs.UserId(u.userId))); await this.olmMachine.updateTrackedUsers(members.map((u) => new RustSdkCryptoJs.UserId(u.userId)));
} }
@@ -1518,7 +1514,10 @@ class EventDecryptor {
public constructor(private readonly olmMachine: RustSdkCryptoJs.OlmMachine, private readonly crypto: RustCrypto) {} public constructor(private readonly olmMachine: RustSdkCryptoJs.OlmMachine, private readonly crypto: RustCrypto) {}
public async attemptEventDecryption(event: MatrixEvent): Promise<IEventDecryptionResult> { public async attemptEventDecryption(event: MatrixEvent): Promise<IEventDecryptionResult> {
logger.info("Attempting decryption of event", event); logger.info(
`Attempting decryption of event ${event.getId()} in ${event.getRoomId()} from ${event.getSender()}`,
);
// add the event to the pending list *before* attempting to decrypt. // add the event to the pending list *before* attempting to decrypt.
// then, if the key turns up while decryption is in progress (and // then, if the key turns up while decryption is in progress (and
// decryption fails), we will schedule a retry. // decryption fails), we will schedule a retry.
@@ -1691,7 +1690,7 @@ function rustEncryptionInfoToJsEncryptionInfo(
} }
let shieldReason: EventShieldReason | null; let shieldReason: EventShieldReason | null;
if (shieldState.message === null) { if (shieldState.message === undefined) {
shieldReason = null; shieldReason = null;
} else if (shieldState.message === "Encrypted by an unverified user.") { } else if (shieldState.message === "Encrypted by an unverified user.") {
// this case isn't actually used with lax shield semantics. // this case isn't actually used with lax shield semantics.