Skip to content

Commit

Permalink
swift6 fixes for iOS, and fixing fallout from error initializer updates
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Apr 11, 2024
1 parent 667423c commit 30f3edd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public actor PeerToPeerProvider: NetworkProvider {
// we were the initiating side of the connection.

guard case let .peer(peerMsg) = nextMessage else {
throw SyncV1Msg.Errors.UnexpectedMsg(msg: nextMessage)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: nextMessage.debugDescription)
}

holder.peerId = peerMsg.senderId
Expand Down Expand Up @@ -659,7 +659,7 @@ public actor PeerToPeerProvider: NetworkProvider {
// we were the initiating side of the connection.

guard case let .join(joinMsg) = nextMessage else {
throw SyncV1Msg.Errors.UnexpectedMsg(msg: nextMessage)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: nextMessage.debugDescription)
}

// send the peer candidate information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct PeerToPeerProviderConfiguration: Sendable {
let peerName: String
let passcode: String

init(reconnectOnError: Bool, listening: Bool, peerName: String?, passcode: String, autoconnect: Bool? = nil) {
init(reconnectOnError: Bool, listening: Bool, peerName: String?, passcode: String, autoconnect: Bool? = nil) async {
self.reconnectOnError = reconnectOnError
self.listening = listening
if let auto = autoconnect {
Expand All @@ -25,17 +25,19 @@ public struct PeerToPeerProviderConfiguration: Sendable {
if let name = peerName {
self.peerName = name
} else {
self.peerName = Self.defaultSharingIdentity()
self.peerName = await Self.defaultSharingIdentity()
}
self.passcode = passcode
}

// MARK: default sharing identity

public static func defaultSharingIdentity() -> String {
public static func defaultSharingIdentity() async -> String {
let defaultName: String
#if os(iOS)
defaultName = UIDevice().name
defaultName = await MainActor.run(body: {
UIDevice().name
})
#elseif os(macOS)
defaultName = Host.current().localizedName ?? "Automerge User"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ public actor WebSocketProvider: NetworkProvider {
let decodeAttempted = SyncV1Msg.decode(raw_data)
Logger.webSocket
.warning(
"Decoding websocket message, expecting peer only - and it wasn't a peer message. RECEIVED MSG: \(decodeAttempted.debugDescription)"
"Decoding websocket message, expecting peer only - and it wasn't a peer message. RECEIVED MSG: \(String(describing: decodeAttempted))"
)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: decodeAttempted)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: String(describing: decodeAttempted))
}
} else {
let decodedMsg = SyncV1Msg.decode(raw_data)
if case .unknown = decodedMsg {
throw SyncV1Msg.Errors.UnexpectedMsg(msg: decodedMsg)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: decodedMsg.debugDescription)
}
return decodedMsg
}
Expand All @@ -131,12 +131,12 @@ public actor WebSocketProvider: NetworkProvider {
// In the handshake phase and received anything other than a valid peer message
Logger.webSocket
.warning("Unknown websocket message received: .string(\(string))")
throw SyncV1Msg.Errors.UnexpectedMsg(msg: msg)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: string)
@unknown default:
// In the handshake phase and received anything other than a valid peer message
Logger.webSocket
.error("Unknown websocket message received: \(String(describing: msg))")
throw SyncV1Msg.Errors.UnexpectedMsg(msg: msg)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: String(describing: msg))
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public actor WebSocketProvider: NetworkProvider {
// For the sync protocol handshake phase, it's essentially "peer or die" since
// we were the initiating side of the connection.
guard case let .peer(peerMsg) = try attemptToDecode(websocketMsg, peerOnly: true) else {
throw SyncV1Msg.Errors.UnexpectedMsg(msg: websocketMsg)
throw SyncV1Msg.Errors.UnexpectedMsg(msg: String(describing: websocketMsg))
}

let newPeerConnection = PeerConnection(peerId: peerMsg.senderId, peerMetadata: peerMsg.peerMetadata)
Expand Down

0 comments on commit 30f3edd

Please sign in to comment.