diff --git a/NearbyShare/InboundNearbyConnection.swift b/NearbyShare/InboundNearbyConnection.swift index 770d5c8..a0db99f 100644 --- a/NearbyShare/InboundNearbyConnection.swift +++ b/NearbyShare/InboundNearbyConnection.swift @@ -64,19 +64,23 @@ class InboundNearbyConnection: NearbyConnection { try processConnectionResponseFrame(frame) default: + var smsg: Securemessage_SecureMessage? = nil + do { - let smsg = try Securemessage_SecureMessage(serializedBytes: frameData) - try decryptAndProcessReceivedSecureMessage(smsg) + smsg = try Securemessage_SecureMessage(serializedBytes: frameData) } catch { - log("Error deserializing secure message (probably due to packet filter)") lastError = NearbyError.packetFilterError protocolError() } + + if let smsg = smsg { + try decryptAndProcessReceivedSecureMessage(smsg) + } } } catch { lastError = error - log("Deserialization error: \(error) in state \(currentState).") + log("Error receiving frame: \(error) in state \(currentState).") protocolError() } } @@ -117,9 +121,15 @@ class InboundNearbyConnection: NearbyConnection { guard currentOffset + Int64(frame.payloadChunk.body.count) <= fileInfo.meta.size else { throw NearbyError.protocolError("Transferred file size exceeds previously specified value") } if frame.payloadChunk.body.count > 0 { - fileInfo.fileHandle?.write(frame.payloadChunk.body) - transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count) - fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred + do { + try fileInfo.fileHandle?.write(contentsOf: frame.payloadChunk.body) + transferredFiles[id]!.bytesTransferred += Int64(frame.payloadChunk.body.count) + fileInfo.progress?.completedUnitCount = transferredFiles[id]!.bytesTransferred + } catch { + log("Error occurred during writing file: \(error.localizedDescription)") + + throw NearbyError.protocolError(error.localizedDescription) + } } else if (frame.payloadChunk.flags & 1) == 1 { try fileInfo.fileHandle?.close() diff --git a/QuickDrop.xcodeproj/project.pbxproj b/QuickDrop.xcodeproj/project.pbxproj index 62923d5..3524329 100644 --- a/QuickDrop.xcodeproj/project.pbxproj +++ b/QuickDrop.xcodeproj/project.pbxproj @@ -827,8 +827,8 @@ MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; - SHARED_BUILD = 48; - SHARED_VERSION = 1.10; + SHARED_BUILD = 49; + SHARED_VERSION = 1.10.1; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; @@ -886,8 +886,8 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = macosx; - SHARED_BUILD = 48; - SHARED_VERSION = 1.10; + SHARED_BUILD = 49; + SHARED_VERSION = 1.10.1; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; }; diff --git a/QuickDrop/AppDelegate.swift b/QuickDrop/AppDelegate.swift index 5d65508..a17e8d8 100644 --- a/QuickDrop/AppDelegate.swift +++ b/QuickDrop/AppDelegate.swift @@ -465,14 +465,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele switch ne { case .inputOutput: description = "I/O Error" - case .protocolError: - description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(ne.localizedDescription))" + case .protocolError(errorMessage: let errorMessage): + log("Protocol error ") + description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + " (\(errorMessage))" case .packetFilterError: openAlert(type: .NetworkFilter) plusWindow?.close() return - case .requiredFieldMissing: - description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(ne.localizedDescription))" + case .requiredFieldMissing(errorMessage: let errorMessage): + description = NSLocalizedString("Error.Protocol", value: "Communication error", comment: "") + "(\(errorMessage))" case .ukey2: description = NSLocalizedString("Error.Crypto", value: "Encryption error", comment: "") + "(\(ne.localizedDescription))" case .canceled(reason: _):