remote: use separate queue for handling connections

This commit is contained in:
osy 2024-02-22 23:12:21 -08:00
parent f2f9db1efb
commit 31ebc6fb36
2 changed files with 5 additions and 3 deletions

View File

@ -23,6 +23,7 @@ let service = "_utm_server._tcp"
actor UTMRemoteClient {
let state: State
private let keyManager = UTMRemoteKeyManager(forClient: true)
private let connectionQueue = DispatchQueue(label: "UTM Remote Client Connection")
private var local: Local
private var scanTask: Task<Void, Error>?
@ -91,7 +92,7 @@ actor UTMRemoteClient {
var isSuccessful = false
let endpoint = server.endpoint ?? NWEndpoint.hostPort(host: .init(server.hostname), port: .init(integerLiteral: UInt16(server.port ?? 0)))
try await keyManager.load()
let connection = try await Connection(endpoint: endpoint, identity: keyManager.identity)
let connection = try await Connection(endpoint: endpoint, connectionQueue: connectionQueue, identity: keyManager.identity)
defer {
if !isSuccessful {
connection.close()

View File

@ -27,6 +27,7 @@ actor UTMRemoteServer {
fileprivate let data: UTMData
private let keyManager = UTMRemoteKeyManager(forClient: false)
private let center = UNUserNotificationCenter.current()
private let connectionQueue = DispatchQueue(label: "UTM Remote Server Connection")
let state: State
private var cancellables = Set<AnyCancellable>()
@ -146,8 +147,8 @@ actor UTMRemoteServer {
}
}
let port = serverPort > 0 ? NWEndpoint.Port(integerLiteral: UInt16(serverPort)) : .any
for try await connection in Connection.advertise(on: port, forServiceType: service, txtRecord: metadata, identity: keyManager.identity) {
if let connection = try? await Connection(connection: connection) {
for try await connection in Connection.advertise(on: port, forServiceType: service, txtRecord: metadata, connectionQueue: connectionQueue, identity: keyManager.identity) {
if let connection = try? await Connection(connection: connection, connectionQueue: connectionQueue) {
await newRemoteConnection(connection)
}
}