- Notifications
You must be signed in to change notification settings - Fork5
chore: run coder connect networking from launchdaemon#203
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import Foundation | ||
import NetworkExtension | ||
import os | ||
import VPNLib | ||
// This is the client for the app to communicate with the privileged helper. | ||
@objc final class HelperXPCClient: NSObject, @unchecked Sendable { | ||
private var svc: CoderVPNService | ||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "HelperXPCClient") | ||
private var connection: NSXPCConnection? | ||
init(vpn: CoderVPNService) { | ||
svc = vpn | ||
super.init() | ||
} | ||
func connect() -> NSXPCConnection { | ||
if let connection { | ||
return connection | ||
} | ||
let connection = NSXPCConnection( | ||
machServiceName: helperAppMachServiceName, | ||
options: .privileged | ||
) | ||
connection.remoteObjectInterface = NSXPCInterface(with: HelperAppXPCInterface.self) | ||
connection.exportedInterface = NSXPCInterface(with: AppXPCInterface.self) | ||
connection.exportedObject = self | ||
connection.invalidationHandler = { | ||
self.logger.error("XPC connection invalidated") | ||
self.connection = nil | ||
_ = self.connect() | ||
} | ||
connection.interruptionHandler = { | ||
self.logger.error("XPC connection interrupted") | ||
self.connection = nil | ||
_ = self.connect() | ||
} | ||
logger.info("connecting to \(helperAppMachServiceName)") | ||
connection.resume() | ||
self.connection = connection | ||
return connection | ||
} | ||
// Establishes a connection to the Helper, so it can send messages back. | ||
func ping() async throws { | ||
let conn = connect() | ||
return try await withCheckedThrowingContinuation { continuation in | ||
guard let proxy = conn.remoteObjectProxyWithErrorHandler({ err in | ||
self.logger.error("failed to connect to HelperXPC \(err.localizedDescription, privacy: .public)") | ||
continuation.resume(throwing: err) | ||
}) as? HelperAppXPCInterface else { | ||
self.logger.error("failed to get proxy for HelperXPC") | ||
continuation.resume(throwing: XPCError.wrongProxyType) | ||
return | ||
} | ||
proxy.ping { | ||
self.logger.info("Connected to Helper over XPC") | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
func getPeerState() async throws { | ||
let conn = connect() | ||
return try await withCheckedThrowingContinuation { continuation in | ||
guard let proxy = conn.remoteObjectProxyWithErrorHandler({ err in | ||
self.logger.error("failed to connect to HelperXPC \(err.localizedDescription, privacy: .public)") | ||
continuation.resume(throwing: err) | ||
}) as? HelperAppXPCInterface else { | ||
self.logger.error("failed to get proxy for HelperXPC") | ||
continuation.resume(throwing: XPCError.wrongProxyType) | ||
return | ||
} | ||
proxy.getPeerState { data in | ||
Task { @MainActor in | ||
self.svc.onExtensionPeerState(data) | ||
} | ||
continuation.resume() | ||
} | ||
} | ||
} | ||
} | ||
// These methods are called by the Helper over XPC | ||
extension HelperXPCClient: AppXPCInterface { | ||
func onPeerUpdate(_ diff: Data, reply: @escaping () -> Void) { | ||
let reply = CompletionWrapper(reply) | ||
Task { @MainActor in | ||
svc.onExtensionPeerUpdate(diff) | ||
reply() | ||
} | ||
} | ||
func onProgress(stage: ProgressStage, downloadProgress: DownloadProgress?, reply: @escaping () -> Void) { | ||
let reply = CompletionWrapper(reply) | ||
Task { @MainActor in | ||
svc.onProgress(stage: stage, downloadProgress: downloadProgress) | ||
reply() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -90,7 +90,7 @@ struct LoginForm: View { | ||
return | ||
} | ||
// x.compare(y) is .orderedDescending if x > y | ||
guardValidator.minimumCoderVersion.compare(semver, options: .numeric) != .orderedDescending else { | ||
loginError = .outdatedCoderVersion | ||
return | ||
} | ||
@@ -192,13 +192,13 @@ struct LoginForm: View { | ||
@discardableResult | ||
func validateURL(_ url: String) throws(LoginError) -> URL { | ||
guard let url = URL(string: url) else { | ||
throw .invalidURL | ||
} | ||
guard url.scheme == "https" else { | ||
throw .httpsRequired | ||
} | ||
guard url.host != nil else { | ||
throw .noHost | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
return url | ||
} | ||
@@ -221,7 +221,7 @@ enum LoginError: Error { | ||
"Invalid URL" | ||
case .outdatedCoderVersion: | ||
""" | ||
The Coder deployment must be version \(Validator.minimumCoderVersion) | ||
or higher to use Coder Desktop. | ||
""" | ||
case let .failedAuth(err): | ||
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.