Add more logging

This commit is contained in:
Leon Böttger committed 2025-05-30 19:43:48 +02:00
1 parent 20af028cc3
commit e5ae0c250e
3 files changed
+22 -7

No files matched your search

+6 -4
View File
@@ -45,10 +45,8 @@ class InboundNearbyConnection: NearbyConnection {
} }
override func processReceivedFrame(frameData: Data) { override func processReceivedFrame(frameData: Data) {
if currentState != .receivingFiles { log("Received frame in state \(currentState)...")
log("Received frame in state \(currentState)...")
}
do { do {
switch currentState { switch currentState {
case .initial: case .initial:
@@ -132,6 +130,7 @@ class InboundNearbyConnection: NearbyConnection {
transferredFiles.removeValue(forKey: id) transferredFiles.removeValue(forKey: id)
if transferredFiles.isEmpty { if transferredFiles.isEmpty {
log("All files received, sending disconnection frame and disconnecting.")
try sendDisconnectionAndDisconnect() try sendDisconnectionAndDisconnect()
} }
} }
@@ -154,6 +153,7 @@ class InboundNearbyConnection: NearbyConnection {
} }
} }
log("Received text payload. Disconnecting...")
try sendDisconnectionAndDisconnect() try sendDisconnectionAndDisconnect()
return true return true
} }
@@ -166,6 +166,8 @@ class InboundNearbyConnection: NearbyConnection {
fileInfo.progress?.unpublish() fileInfo.progress?.unpublish()
transferredFiles.removeValue(forKey: id) transferredFiles.removeValue(forKey: id)
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL) SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
log("Received file payload. Disconnecting...")
try sendDisconnectionAndDisconnect() try sendDisconnectionAndDisconnect()
return true return true
} }
+14 -3
View File
@@ -79,6 +79,7 @@ class NearbyConnection {
} }
func protocolError() { func protocolError() {
log("Protocol error: \(String(describing: lastError))")
disconnect() disconnect()
} }
@@ -108,6 +109,7 @@ class NearbyConnection {
return return
} }
if isComplete { if isComplete {
log("Connection closed by peer during receiveFrameAsync")
self.handleConnectionClosure() self.handleConnectionClosure()
return return
} }
@@ -136,6 +138,7 @@ class NearbyConnection {
return return
} }
if isComplete { if isComplete {
log("Connection closed by peer during receiveFrameAsync")
self.handleConnectionClosure() self.handleConnectionClosure()
return return
} }
@@ -410,11 +413,15 @@ class NearbyConnection {
} }
func disconnect() { func disconnect() {
log("Disconnecting from connection.")
connection.stateUpdateHandler = nil
connectionClosed = true
self.handleConnectionClosure()
connection.send(content: nil, isComplete: true, completion: .contentProcessed { _ in connection.send(content: nil, isComplete: true, completion: .contentProcessed { _ in
}) })
self.handleConnectionClosure()
connectionClosed = true
connection.stateUpdateHandler = nil
} }
func sendDisconnectionAndDisconnect() throws { func sendDisconnectionAndDisconnect() throws {
@@ -428,6 +435,8 @@ class NearbyConnection {
} else { } else {
try sendFrameAsync(offlineFrame.serializedData()) try sendFrameAsync(offlineFrame.serializedData())
} }
log("Sent disconnection frame during sendDisconnectionAndDisconnect")
disconnect() disconnect()
} }
@@ -438,6 +447,8 @@ class NearbyConnection {
msg.messageType = .alert msg.messageType = .alert
msg.messageData = try! alert.serializedData() msg.messageData = try! alert.serializedData()
sendFrameAsync(try! msg.serializedData()) sendFrameAsync(try! msg.serializedData())
log("Sent UKEY2 alert: \(type)")
disconnect() disconnect()
} }
@@ -269,6 +269,8 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
public func submitUserConsent(transferID: String, accept: Bool, storeInTemp: Bool = false) { public func submitUserConsent(transferID: String, accept: Bool, storeInTemp: Bool = false) {
guard let conn = activeConnections[transferID] else { return } 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) conn.submitUserConsent(accepted: accept, storeInTemp: storeInTemp)
} }