mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-22 22:36:01 +00:00
Better logging
This commit is contained in:
1 parent
aacd95570b
commit
dc32e92d9a
4 files changed
+61
-61
No files matched your search
@@ -57,7 +57,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
override func processReceivedFrame(frameData: Data) {
|
||||
|
||||
if currentState != .receivingFiles {
|
||||
log("[InboundNearbyConnection] Received frame in state \(currentState)...")
|
||||
log("[InboundNearbyConnection \(self.id)] Received frame in state \(currentState)...")
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -82,7 +82,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
do {
|
||||
smsg = try Securemessage_SecureMessage(serializedBytes: frameData)
|
||||
} catch {
|
||||
log("[InboundNearbyConnection] Error deserializing secure message (probably due to packet filter)")
|
||||
log("[InboundNearbyConnection \(self.id)] Error deserializing secure message (probably due to packet filter)")
|
||||
lastError = NearbyError.packetFilterError
|
||||
protocolError()
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
}
|
||||
} catch {
|
||||
lastError = error
|
||||
log("[InboundNearbyConnection] Error receiving frame: \(error) in state \(currentState).")
|
||||
log("[InboundNearbyConnection \(self.id)] Error receiving frame: \(error) in state \(currentState).")
|
||||
protocolError()
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
if frame.hasV1 && frame.v1.hasType, case .cancel = frame.v1.type {
|
||||
self.lastError = NearbyError.canceled(reason: .userCanceled)
|
||||
self.cancelled = true
|
||||
log("[InboundNearbyConnection] Transfer canceled")
|
||||
log("[InboundNearbyConnection \(self.id)] Transfer canceled")
|
||||
try sendDisconnectionAndDisconnect()
|
||||
return
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
case .receivedPairedKeyResult:
|
||||
try processIntroductionFrame(frame)
|
||||
default:
|
||||
log("[InboundNearbyConnection] Unexpected connection state in processTransferSetupFrame: \(currentState)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unexpected connection state in processTransferSetupFrame: \(currentState)")
|
||||
log(frame.debugDescription)
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
// only for logging
|
||||
self.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||
} catch {
|
||||
log("[InboundNearbyConnection] Error occurred during writing file: \(error.localizedDescription)")
|
||||
log("[InboundNearbyConnection \(self.id)] Error occurred during writing file: \(error.localizedDescription)")
|
||||
|
||||
throw NearbyError.protocolError(error.localizedDescription)
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
filesToBeReceived.removeValue(forKey: id)
|
||||
|
||||
if filesToBeReceived.isEmpty {
|
||||
log("[InboundNearbyConnection] All files received, sending disconnection frame and disconnecting.")
|
||||
log("[InboundNearbyConnection \(self.id)] All files received, sending disconnection frame and disconnecting.")
|
||||
try sendDisconnectionAndDisconnect()
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
}
|
||||
}
|
||||
|
||||
log("[InboundNearbyConnection] Received text payload. Disconnecting...")
|
||||
log("[InboundNearbyConnection \(self.id)] Received text payload. Disconnecting...")
|
||||
try sendDisconnectionAndDisconnect()
|
||||
return true
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
filesToBeReceived.removeValue(forKey: id)
|
||||
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
||||
|
||||
log("[InboundNearbyConnection] Received file payload. Disconnecting...")
|
||||
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
||||
try sendDisconnectionAndDisconnect()
|
||||
return true
|
||||
}
|
||||
@@ -250,7 +250,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing("clientInit ukey2message.type|data") }
|
||||
guard case .clientInit = msg.messageType else {
|
||||
sendUkey2Alert(type: .badMessageType)
|
||||
log("[InboundNearbyConnection] Unsupported message type: \(msg.messageType)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unsupported message type: \(msg.messageType)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
let clientInit: Securegcm_Ukey2ClientInit
|
||||
@@ -258,17 +258,17 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
clientInit = try Securegcm_Ukey2ClientInit(serializedBytes: msg.messageData)
|
||||
} catch {
|
||||
sendUkey2Alert(type: .badMessageData)
|
||||
log("[InboundNearbyConnection] Failed to parse clientInit: \(error)")
|
||||
log("[InboundNearbyConnection \(self.id)] Failed to parse clientInit: \(error)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
guard clientInit.version == 1 else {
|
||||
sendUkey2Alert(type: .badVersion)
|
||||
log("[InboundNearbyConnection] Unsupported clientInit version: \(clientInit.version)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unsupported clientInit version: \(clientInit.version)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
guard clientInit.random.count == 32 else {
|
||||
sendUkey2Alert(type: .badRandom)
|
||||
log("[InboundNearbyConnection] Unsupported clientInit random: \(clientInit.random.count)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unsupported clientInit random: \(clientInit.random.count)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
var found = false
|
||||
@@ -281,12 +281,12 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
}
|
||||
guard found else {
|
||||
sendUkey2Alert(type: .badHandshakeCipher)
|
||||
log("[InboundNearbyConnection] Unsupported clientInit handshakeCipher: \(clientInit.cipherCommitments)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unsupported clientInit handshakeCipher: \(clientInit.cipherCommitments)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
guard clientInit.nextProtocol == "AES_256_CBC-HMAC_SHA256" else {
|
||||
sendUkey2Alert(type: .badNextProtocol)
|
||||
log("[InboundNearbyConnection] Unsupported clientInit nextProtocol: \(clientInit.nextProtocol)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unsupported clientInit nextProtocol: \(clientInit.nextProtocol)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
|
||||
@@ -320,14 +320,14 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
private func processUkey2ClientFinish(_ msg: Securegcm_Ukey2Message, raw: Data) throws {
|
||||
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing("clientFinish ukey2message.type|data") }
|
||||
guard case .clientFinish = msg.messageType else {
|
||||
log("[InboundNearbyConnection] Unexpected message type \(msg.messageType)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unexpected message type \(msg.messageType)")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
|
||||
var sha = SHA512()
|
||||
sha.update(data: raw)
|
||||
guard cipherCommitment == Data(sha.finalize()) else {
|
||||
log("[InboundNearbyConnection] Invalid cipherCommitment in clientFinish")
|
||||
log("[InboundNearbyConnection \(self.id)] Invalid cipherCommitment in clientFinish")
|
||||
throw NearbyError.ukey2
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
try sendTransferSetupFrame(pairedEncryption)
|
||||
currentState = .sentConnectionResponse
|
||||
} else {
|
||||
log("[InboundNearbyConnection] Unhandled offline frame plaintext: \(frame)")
|
||||
log("[InboundNearbyConnection \(self.id)] Unhandled offline frame plaintext: \(frame)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +459,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
func rejectDueToUnsupportedFileType(_ frame: Sharing_Nearby_Frame) {
|
||||
|
||||
log("[InboundNearbyConnection] Rejecting transfer due to unsupported file type. Frame is \(frame.debugDescription)")
|
||||
log("[InboundNearbyConnection \(self.id)] Rejecting transfer due to unsupported file type. Frame is \(frame.debugDescription)")
|
||||
|
||||
NearbyConnectionManager.shared.mainAppDelegate?.showUnsupportedFileAlert(for: remoteDeviceInfo)
|
||||
rejectTransfer(with: .unsupportedAttachmentType)
|
||||
@@ -479,7 +479,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
private func acceptTransfer(storeInTemp: Bool) {
|
||||
if currentState == .disconnected {
|
||||
log("[InboundNearbyConnection] Detected timeout, not accepting transfer")
|
||||
log("[InboundNearbyConnection \(self.id)] Detected timeout, not accepting transfer")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
filesToBeReceived[id]!.progress = progress
|
||||
filesToBeReceived[id]!.created = true
|
||||
|
||||
log("[InboundNearbyConnection] Accepted file with size \(file.meta.size)")
|
||||
log("[InboundNearbyConnection \(self.id)] Accepted file with size \(file.meta.size)")
|
||||
}
|
||||
|
||||
var frame = Sharing_Nearby_Frame()
|
||||
@@ -527,7 +527,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
self.wasRejected = true
|
||||
|
||||
log("[InboundNearbyConnection] Rejecting transfer because of \( reason)")
|
||||
log("[InboundNearbyConnection \(self.id)] Rejecting transfer because of \( reason)")
|
||||
|
||||
var frame = Sharing_Nearby_Frame()
|
||||
frame.version = .v1
|
||||
@@ -537,7 +537,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
try sendTransferSetupFrame(frame)
|
||||
try sendDisconnectionAndDisconnect()
|
||||
} catch {
|
||||
log("[InboundNearbyConnection] Error \(error)")
|
||||
log("[InboundNearbyConnection \(self.id)] Error \(error)")
|
||||
protocolError()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user