Skip to content

Commit

Permalink
Merge pull request #1720 from matrix-org/andy/curb_logs
Browse files Browse the repository at this point in the history
Minor crypto logging changes
  • Loading branch information
Anderas authored Feb 22, 2023
2 parents 7b3fd7d + d4b3621 commit 5821aa5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
}

func decrypt(events: [MXEvent]) -> [MXEventDecryptionResult] {
log.debug("Decrypting \(events.count) event(s)")
let results = events.map(decrypt(event:))

let undecrypted = results.filter {
Expand All @@ -63,8 +64,8 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
"total": events.count,
"undecrypted": undecrypted.count
])
} else {
log.debug("Decrypted all \(events.count) event(s)")
} else if events.count > 1 {
log.debug("Decrypted all \(events.count) events")
}

return results
Expand Down Expand Up @@ -120,7 +121,7 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
do {
let decryptedEvent = try handler.decryptRoomEvent(event)
let result = try MXEventDecryptionResult(event: decryptedEvent)
log.debug("Successfully decrypted event `\(result.clearEvent["type"] ?? "unknown")` eventId `\(eventId)`")
log.debug("Decrypted event `\(result.clearEvent["type"] ?? "unknown")` eventId `\(eventId)`")
return result

} catch let error as DecryptionError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,13 @@ struct MXRoomEventEncryption: MXRoomEventEncrypting {
for: room,
historyVisibility: state.historyVisibility
)
log.debug("Collected \(users.count) eligible users")

let settings = try encryptionSettings(for: state)
try await handler.shareRoomKeysIfNecessary(
roomId: roomId,
users: users,
settings: settings
)

log.debug("Encryption and room keys up to date")
}

/// Make sure that we recognize (and store if necessary) the claimed room encryption algorithm
Expand Down
28 changes: 22 additions & 6 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ extension MXCryptoMachine: MXCryptoSyncing {
// MARK: - Private

private func handleRequest(_ request: Request) async throws {
log.debug("Handling request \(request)")
log.debug("Handling request `\(request.type)`")

switch request {
case .toDevice(let requestId, let eventType, let body):
Expand Down Expand Up @@ -276,8 +276,6 @@ extension MXCryptoMachine: MXCryptoSyncing {
}

private func handleOutgoingRequests() async throws {
log.debug("->")

let requests = try machine.outgoingRequests()

try await withThrowingTaskGroup(of: Void.self) { [weak self] group in
Expand Down Expand Up @@ -386,7 +384,6 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
log.debug("Checking room keys in room \(roomId)")

try await sessionsQueue.sync { [weak self] in
self?.log.debug("Collecting missing sessions")
try await self?.getMissingSessions(users: users)
}

Expand All @@ -397,8 +394,6 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
self?.log.debug("Sharing room keys")
try await self?.shareRoomKey(roomId: roomId, users: users, settings: settings)
}

log.debug("All room keys have been shared")
}

func encryptRoomEvent(
Expand Down Expand Up @@ -781,3 +776,24 @@ extension MXCryptoMachine: MXCryptoBackup {
isComputingRoomKeyCounts = false
}
}

extension Request {
var type: RequestType {
switch self {
case .toDevice:
return .toDevice
case .keysUpload:
return .keysUpload
case .keysQuery:
return .keysQuery
case .keysClaim:
return .keysClaim
case .keysBackup:
return .keysBackup
case .roomMessage:
return .roomMessage
case .signatureUpload:
return .signatureUpload
}
}
}
6 changes: 5 additions & 1 deletion MatrixSDK/Crypto/CryptoMachine/MXCryptoSDKLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class MXCryptoSDKLogger: Logger {
// This will be changed in rust-sdk directly
let ignored = [
"::uniffi_api:",
"::backup_recovery_key: decrypt_v1"
"::backup_recovery_key: decrypt_v1",
"matrix_sdk_crypto_ffi::machine: backup_enabled",
"matrix_sdk_crypto_ffi::machine: room_key_counts",
"matrix_sdk_crypto_ffi::machine: user_id",
"matrix_sdk_crypto_ffi::machine: identity_keys"
]

for ignore in ignored {
Expand Down
6 changes: 3 additions & 3 deletions MatrixSDK/Crypto/KeyBackup/MXKeyBackup.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ - (void)maybeSendKeyBackup
}
else
{
MXLogDebug(@"[MXKeyBackup] maybeSendKeyBackup: Skip it because state: %@", @(_state));
MXLogDebug(@"[MXKeyBackup] maybeSendKeyBackup: Skip it because state: %@", [self descriptionForState:_state]);

// If not already done, check for a valid backup version on the homeserver.
// If one, maybeSendKeyBackup will be called again.
Expand Down Expand Up @@ -231,7 +231,7 @@ - (void)sendKeyBackup
// Sanity check
if (!self.enabled || !_keyBackupVersion)
{
MXLogDebug(@"[MXKeyBackup] sendKeyBackup: Invalid state: %@", @(_state));
MXLogDebug(@"[MXKeyBackup] sendKeyBackup: Invalid state: %@", [self descriptionForState:_state]);
if (backupAllGroupSessionsFailure)
{
NSError *error = [NSError errorWithDomain:MXKeyBackupErrorDomain
Expand Down Expand Up @@ -522,7 +522,7 @@ - (MXHTTPOperation*)forceRefresh:(nullable void (^)(BOOL valid))success
{
if (_state == MXKeyBackupStateUnknown || _state == MXKeyBackupStateCheckingBackUpOnHomeserver)
{
MXLogDebug(@"[MXKeyBackup] forceRefresh: Invalid state (%@) to force the refresh", @(_state));
MXLogDebug(@"[MXKeyBackup] forceRefresh: Invalid state (%@) to force the refresh", [self descriptionForState:_state]);
if (failure)
{
NSError *error = [NSError errorWithDomain:MXKeyBackupErrorDomain
Expand Down
3 changes: 1 addition & 2 deletions MatrixSDK/Crypto/MXCryptoV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,13 @@ class MXCryptoV2: NSObject, MXCrypto {
onComplete: (([MXEventDecryptionResult]) -> Void)?
) {
guard session?.isEventStreamInitialised == true else {
log.debug("Ignoring \(events.count) encrypted event(s) during initial sync in timeline \(timeline ?? "") (we most likely do not have the keys yet)")
log.debug("Ignoring \(events.count) encrypted event(s) during initial sync (we most likely do not have the keys yet)")
let results = events.map { _ in MXEventDecryptionResult() }
onComplete?(results)
return
}

Task {
log.debug("Decrypting \(events.count) event(s) in timeline \(timeline ?? "")")
let results = await decryptor.decrypt(events: events)
await MainActor.run {
onComplete?(results)
Expand Down

0 comments on commit 5821aa5

Please sign in to comment.