Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 3 commits intomainfromethan/improve-sleep
Feb 24, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletionsCoder Desktop/VPN/PacketTunnelProvider.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 {
Expand DownExpand Up@@ -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)?) {
Expand All@@ -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 }
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

macOS does indeedwake a bunch during sleep to check the network. For us dogfooding, this means it might attempt to download a new dylib while the device sleeps, which the user won't be able to approve. In that case it'll get stuck inreasserting, in this case (and in any case, really) we don't want to try and start it up a second time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Got it. Would you also mind adding that as a code comment?

ethanndickson reacted with thumbs up emoji
guard manager == nil else {
logger.error("wake called with non-nil Manager")
return
}
Comment on lines +151 to +154
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This was previously in thestart function called right after, but we should avoid resetting the network settings needlessly if we can.

ethanndickson reacted with thumbs up emoji
logger.debug("wake called")
reasserting = true
currentSettings = .init(tunnelRemoteAddress: "127.0.0.1")
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp