mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 13:55:58 +00:00
Fix connection to Windows
This commit is contained in:
1 parent
6766ef69d9
commit
daa1ab77df
8 files changed
+51
-37
No files matched your search
@@ -242,19 +242,9 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
guard case .connectionRequest = frame.v1.type else { throw NearbyError.protocolError("Unexpected frame type \(frame.v1.type)") }
|
||||
|
||||
let endpointInfo = frame.v1.connectionRequest.endpointInfo
|
||||
let endpointInfo = EndpointInfo(data: frame.v1.connectionRequest.endpointInfo)
|
||||
|
||||
guard endpointInfo.count > 17 else { throw NearbyError.protocolError("Endpoint info too short") }
|
||||
|
||||
let deviceNameLength = Int(endpointInfo[17])
|
||||
|
||||
guard endpointInfo.count >= deviceNameLength + 18 else { throw NearbyError.protocolError("Endpoint info too short to contain the device name") }
|
||||
|
||||
guard let deviceName = String(data: endpointInfo[18 ..< (18 + deviceNameLength)], encoding: .utf8) else { throw NearbyError.protocolError("Device name is not valid UTF-8") }
|
||||
|
||||
let rawDeviceType = Int(endpointInfo[0] & 7) >> 1
|
||||
|
||||
remoteDeviceInfo = RemoteDeviceInfo(name: deviceName, type: RemoteDeviceInfo.DeviceType.fromRawValue(value: rawDeviceType))
|
||||
remoteDeviceInfo = RemoteDeviceInfo(name: endpointInfo?.name, type: endpointInfo?.deviceType)
|
||||
currentState = .receivedConnectionRequest
|
||||
}
|
||||
|
||||
|
||||
@@ -175,8 +175,8 @@ class OutboundNearbyConnection: NearbyConnection {
|
||||
frame.v1 = Location_Nearby_Connections_V1Frame()
|
||||
frame.v1.type = .connectionRequest
|
||||
frame.v1.connectionRequest = Location_Nearby_Connections_ConnectionRequestFrame()
|
||||
frame.v1.connectionRequest.endpointID = String(bytes: NearbyConnectionManager.shared.endpointID, encoding: .ascii)!
|
||||
frame.v1.connectionRequest.endpointName = endpointInfo.name ?? "QuickDrop"
|
||||
frame.v1.connectionRequest.endpointID = Data(NearbyConnectionManager.shared.endpointID)
|
||||
frame.v1.connectionRequest.endpointName = Data((endpointInfo.name ?? "QuickDrop").utf8)
|
||||
frame.v1.connectionRequest.endpointInfo = endpointInfo.serialize()
|
||||
frame.v1.connectionRequest.mediums = [.wifiLan]
|
||||
try sendFrameAsync(frame.serializedData())
|
||||
|
||||
@@ -9,6 +9,7 @@ import Foundation
|
||||
import Network
|
||||
import CryptoKit
|
||||
import SwiftECC
|
||||
import LUI
|
||||
|
||||
|
||||
protocol InboundNearbyConnectionDelegate {
|
||||
@@ -56,9 +57,9 @@ public struct RemoteDeviceInfo: Codable, Identifiable, Equatable {
|
||||
public let qrCodeData: Data?
|
||||
public var id: String?
|
||||
|
||||
init(name: String, type: DeviceType, id: String? = nil) {
|
||||
init(name: String?, type: DeviceType?, id: String? = nil) {
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.type = type ?? .phone
|
||||
self.id = id
|
||||
self.qrCodeData = nil
|
||||
}
|
||||
@@ -191,7 +192,10 @@ public struct EndpointInfo {
|
||||
|
||||
|
||||
init?(data: Data) {
|
||||
guard data.count > 17 else { return nil }
|
||||
guard data.count > 17 else {
|
||||
log("[EndpointInfo] Invalid endpoint info data received (too short)")
|
||||
return nil
|
||||
}
|
||||
|
||||
let hasName = (data[0] & 0x10) == 0
|
||||
let deviceNameLength: Int
|
||||
@@ -199,8 +203,14 @@ public struct EndpointInfo {
|
||||
|
||||
if hasName {
|
||||
deviceNameLength = Int(data[17])
|
||||
guard data.count >= deviceNameLength + 18 else { return nil }
|
||||
guard let newDeviceName = String(data: data[18..<(18 + deviceNameLength)], encoding: .utf8) else { return nil }
|
||||
guard data.count >= deviceNameLength + 18 else {
|
||||
log("[EndpointInfo] Invalid endpoint info data received (name length mismatch)")
|
||||
return nil
|
||||
}
|
||||
guard let newDeviceName = String(data: data[18..<(18 + deviceNameLength)], encoding: .utf8) else {
|
||||
log("[EndpointInfo] Invalid endpoint info data received (name decoding failed)")
|
||||
return nil
|
||||
}
|
||||
deviceName = newDeviceName
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -245,8 +245,8 @@ struct Location_Nearby_Connections_ConnectionRequestFrame: @unchecked Sendable {
|
||||
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
|
||||
// methods supported on all messages.
|
||||
|
||||
var endpointID: String {
|
||||
get {return _storage._endpointID ?? String()}
|
||||
var endpointID: Data {
|
||||
get {return _storage._endpointID ?? Data()}
|
||||
set {_uniqueStorage()._endpointID = newValue}
|
||||
}
|
||||
/// Returns true if `endpointID` has been explicitly set.
|
||||
@@ -254,8 +254,8 @@ struct Location_Nearby_Connections_ConnectionRequestFrame: @unchecked Sendable {
|
||||
/// Clears the value of `endpointID`. Subsequent reads from it will return its default value.
|
||||
mutating func clearEndpointID() {_uniqueStorage()._endpointID = nil}
|
||||
|
||||
var endpointName: String {
|
||||
get {return _storage._endpointName ?? String()}
|
||||
var endpointName: Data {
|
||||
get {return _storage._endpointName ?? Data()}
|
||||
set {_uniqueStorage()._endpointName = newValue}
|
||||
}
|
||||
/// Returns true if `endpointName` has been explicitly set.
|
||||
@@ -2550,8 +2550,8 @@ extension Location_Nearby_Connections_ConnectionRequestFrame: SwiftProtobuf.Mess
|
||||
static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{3}endpoint_id\0\u{3}endpoint_name\0\u{3}handshake_data\0\u{1}nonce\0\u{1}mediums\0\u{3}endpoint_info\0\u{3}medium_metadata\0\u{3}keep_alive_interval_millis\0\u{3}keep_alive_timeout_millis\0\u{3}device_type\0\u{3}device_info\0\u{3}connections_device\0\u{3}presence_device\0\u{3}connection_mode\0\u{3}location_hint\0")
|
||||
|
||||
fileprivate class _StorageClass {
|
||||
var _endpointID: String? = nil
|
||||
var _endpointName: String? = nil
|
||||
var _endpointID: Data? = nil
|
||||
var _endpointName: Data? = nil
|
||||
var _handshakeData: Data? = nil
|
||||
var _nonce: Int32? = nil
|
||||
var _mediums: [Location_Nearby_Connections_ConnectionRequestFrame.Medium] = []
|
||||
@@ -2606,8 +2606,8 @@ extension Location_Nearby_Connections_ConnectionRequestFrame: SwiftProtobuf.Mess
|
||||
// allocates stack space for every case branch when no optimizations are
|
||||
// enabled. https://github.com/apple/swift-protobuf/issues/1034
|
||||
switch fieldNumber {
|
||||
case 1: try { try decoder.decodeSingularStringField(value: &_storage._endpointID) }()
|
||||
case 2: try { try decoder.decodeSingularStringField(value: &_storage._endpointName) }()
|
||||
case 1: try { try decoder.decodeSingularBytesField(value: &_storage._endpointID) }()
|
||||
case 2: try { try decoder.decodeSingularBytesField(value: &_storage._endpointName) }()
|
||||
case 3: try { try decoder.decodeSingularBytesField(value: &_storage._handshakeData) }()
|
||||
case 4: try { try decoder.decodeSingularInt32Field(value: &_storage._nonce) }()
|
||||
case 5: try { try decoder.decodeRepeatedEnumField(value: &_storage._mediums) }()
|
||||
@@ -2658,10 +2658,10 @@ extension Location_Nearby_Connections_ConnectionRequestFrame: SwiftProtobuf.Mess
|
||||
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
|
||||
// https://github.com/apple/swift-protobuf/issues/1182
|
||||
try { if let v = _storage._endpointID {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 1)
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 1)
|
||||
} }()
|
||||
try { if let v = _storage._endpointName {
|
||||
try visitor.visitSingularStringField(value: v, fieldNumber: 2)
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 2)
|
||||
} }()
|
||||
try { if let v = _storage._handshakeData {
|
||||
try visitor.visitSingularBytesField(value: v, fieldNumber: 3)
|
||||
|
||||
@@ -96,8 +96,8 @@ message ConnectionRequestFrame {
|
||||
}
|
||||
// LINT.ThenChange(//depot/google3/third_party/nearby/proto/connections_enums.proto)
|
||||
|
||||
optional string endpoint_id = 1;
|
||||
optional string endpoint_name = 2;
|
||||
optional bytes endpoint_id = 1;
|
||||
optional bytes endpoint_name = 2;
|
||||
optional bytes handshake_data = 3;
|
||||
// A random number generated for each outgoing connection that is presently
|
||||
// used to act as a tiebreaker when 2 devices connect to each other
|
||||
|
||||
Reference in new issue
Block a user