-
Notifications
You must be signed in to change notification settings - Fork 3
fix: improve wake & sleep handling #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,16 +48,17 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable { | |
options _: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void | ||
) { | ||
logger.info("startTunnel called") | ||
guard manager == nil else { | ||
logger.error("startTunnel called with non-nil Manager") | ||
// If the tunnel is already running, then we can just mark as connected. | ||
completionHandler(nil) | ||
return | ||
} | ||
start(completionHandler) | ||
} | ||
|
||
// called by `startTunnel` and on `wake` | ||
func start(_ completionHandler: @escaping (Error?) -> Void) { | ||
guard manager == nil else { | ||
logger.error("startTunnel called with non-nil Manager") | ||
completionHandler(makeNSError(suffix: "PTP", desc: "Already running")) | ||
return | ||
} | ||
guard let proto = protocolConfiguration as? NETunnelProviderProtocol, | ||
let baseAccessURL = proto.serverAddress | ||
else { | ||
|
@@ -123,9 +124,11 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable { | |
logger.error("error stopping manager: \(error.description, privacy: .public)") | ||
} | ||
globalXPCListenerDelegate.vpnXPCInterface.manager = nil | ||
// Mark teardown as complete by setting manager to nil, and | ||
// calling the completion handler. | ||
self.manager = nil | ||
completionHandler() | ||
} | ||
self.manager = nil | ||
} | ||
|
||
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)?) { | ||
|
@@ -142,6 +145,13 @@ class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable { | |
} | ||
|
||
override func wake() { | ||
// It's possible the tunnel is still starting up, if it is, wake should | ||
// be a no-op. | ||
guard !reasserting else { return } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. macOS does indeed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Would you also mind adding that as a code comment? |
||
guard manager == nil else { | ||
logger.error("wake called with non-nil Manager") | ||
return | ||
} | ||
Comment on lines
+151
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was previously in the |
||
logger.debug("wake called") | ||
reasserting = true | ||
currentSettings = .init(tunnelRemoteAddress: "127.0.0.1") | ||
|
Uh oh!
There was an error while loading. Please reload this page.