From e5ae0c250e1bff7dcb71848ed9003f5cb26b9a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Fri, 30 May 2025 19:43:48 +0200 Subject: [PATCH] Add more logging --- NearbyShare/InboundNearbyConnection.swift | 10 ++++++---- NearbyShare/NearbyConnection.swift | 17 ++++++++++++++--- NearbyShare/NearbyConnectionManager.swift | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/NearbyShare/InboundNearbyConnection.swift b/NearbyShare/InboundNearbyConnection.swift index bdfca4f..06a6742 100644 --- a/NearbyShare/InboundNearbyConnection.swift +++ b/NearbyShare/InboundNearbyConnection.swift @@ -45,10 +45,8 @@ class InboundNearbyConnection: NearbyConnection { } override func processReceivedFrame(frameData: Data) { - if currentState != .receivingFiles { - log("Received frame in state \(currentState)...") - } - + log("Received frame in state \(currentState)...") + do { switch currentState { case .initial: @@ -132,6 +130,7 @@ class InboundNearbyConnection: NearbyConnection { transferredFiles.removeValue(forKey: id) if transferredFiles.isEmpty { + log("All files received, sending disconnection frame and disconnecting.") try sendDisconnectionAndDisconnect() } } @@ -154,6 +153,7 @@ class InboundNearbyConnection: NearbyConnection { } } + log("Received text payload. Disconnecting...") try sendDisconnectionAndDisconnect() return true } @@ -166,6 +166,8 @@ class InboundNearbyConnection: NearbyConnection { fileInfo.progress?.unpublish() transferredFiles.removeValue(forKey: id) SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL) + + log("Received file payload. Disconnecting...") try sendDisconnectionAndDisconnect() return true } diff --git a/NearbyShare/NearbyConnection.swift b/NearbyShare/NearbyConnection.swift index 637e800..7b8ab2a 100644 --- a/NearbyShare/NearbyConnection.swift +++ b/NearbyShare/NearbyConnection.swift @@ -79,6 +79,7 @@ class NearbyConnection { } func protocolError() { + log("Protocol error: \(String(describing: lastError))") disconnect() } @@ -108,6 +109,7 @@ class NearbyConnection { return } if isComplete { + log("Connection closed by peer during receiveFrameAsync") self.handleConnectionClosure() return } @@ -136,6 +138,7 @@ class NearbyConnection { return } if isComplete { + log("Connection closed by peer during receiveFrameAsync") self.handleConnectionClosure() return } @@ -410,11 +413,15 @@ class NearbyConnection { } func disconnect() { + log("Disconnecting from connection.") + + connection.stateUpdateHandler = nil + connectionClosed = true + + self.handleConnectionClosure() + connection.send(content: nil, isComplete: true, completion: .contentProcessed { _ in }) - self.handleConnectionClosure() - connectionClosed = true - connection.stateUpdateHandler = nil } func sendDisconnectionAndDisconnect() throws { @@ -428,6 +435,8 @@ class NearbyConnection { } else { try sendFrameAsync(offlineFrame.serializedData()) } + + log("Sent disconnection frame during sendDisconnectionAndDisconnect") disconnect() } @@ -438,6 +447,8 @@ class NearbyConnection { msg.messageType = .alert msg.messageData = try! alert.serializedData() sendFrameAsync(try! msg.serializedData()) + + log("Sent UKEY2 alert: \(type)") disconnect() } diff --git a/NearbyShare/NearbyConnectionManager.swift b/NearbyShare/NearbyConnectionManager.swift index 63b66cd..64ba5b6 100644 --- a/NearbyShare/NearbyConnectionManager.swift +++ b/NearbyShare/NearbyConnectionManager.swift @@ -269,6 +269,8 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb public func submitUserConsent(transferID: String, accept: Bool, storeInTemp: Bool = false) { guard let conn = activeConnections[transferID] else { return } + + log("Submitting user consent for transfer, accepted: \(accept), store in temp: \(storeInTemp)") conn.submitUserConsent(accepted: accept, storeInTemp: storeInTemp) }