Skip to content

Commit c0a46aa

Browse files
committed
reconnect xpc on each request
1 parent 27ab4a7 commit c0a46aa

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Coder Desktop/Coder Desktop/VPNService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ final class CoderVPNService: NSObject, VPNService {
7373
.unconfigured
7474
}
7575
}
76+
xpc.connect()
7677
xpc.getPeerState()
7778
NotificationCenter.default.addObserver(
7879
self,
@@ -100,7 +101,7 @@ final class CoderVPNService: NSObject, VPNService {
100101
}
101102

102103
await startTunnel()
103-
// this ping is somewhat load bearing since it causes xpc to init
104+
xpc.connect()
104105
xpc.ping()
105106
logger.debug("network extension enabled")
106107
}

Coder Desktop/Coder Desktop/XPCInterface.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import VPNLib
66
@objc final class VPNXPCInterface: NSObject, VPNXPCClientCallbackProtocol, @unchecked Sendable {
77
private var svc: CoderVPNService
88
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "VPNXPCInterface")
9-
private let xpc: VPNXPCProtocol
9+
private var xpc: VPNXPCProtocol? = nil
1010

1111
init(vpn: CoderVPNService) {
1212
svc = vpn
13+
super.init()
14+
}
1315

16+
func connect() {
1417
let networkExtDict = Bundle.main.object(forInfoDictionaryKey: "NetworkExtension") as? [String: Any]
1518
let machServiceName = networkExtDict?["NEMachServiceName"] as? String
1619
let xpcConn = NSXPCConnection(machServiceName: machServiceName!)
@@ -21,32 +24,32 @@ import VPNLib
2124
}
2225
xpc = proxy
2326

24-
super.init()
25-
2627
xpcConn.exportedObject = self
2728
xpcConn.invalidationHandler = { [logger] in
2829
Task { @MainActor in
2930
logger.error("XPC connection invalidated.")
31+
self.xpc = nil
3032
}
3133
}
3234
xpcConn.interruptionHandler = { [logger] in
3335
Task { @MainActor in
3436
logger.error("XPC connection interrupted.")
37+
self.xpc = nil
3538
}
3639
}
3740
xpcConn.resume()
3841
}
3942

4043
func ping() {
41-
xpc.ping {
44+
xpc?.ping {
4245
Task { @MainActor in
4346
self.logger.info("Connected to NE over XPC")
4447
}
4548
}
4649
}
4750

4851
func getPeerState() {
49-
xpc.getPeerState { data in
52+
xpc?.getPeerState { data in
5053
Task { @MainActor in
5154
self.svc.onExtensionPeerState(data)
5255
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy