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

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

Merged
ethanndickson merged 2 commits intomainfromethan/networking-in-launchdaemon
Aug 6, 2025
Merged
Show file tree
Hide file tree
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
102 changes: 102 additions & 0 deletionsCoder-Desktop/Coder-Desktop/AppHelperXPCClient.swift
View file
Open in desktop
Original file line numberDiff line numberDiff 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()
}
}
}
16 changes: 9 additions & 7 deletionsCoder-Desktop/Coder-Desktop/VPN/VPNService.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ enum VPNServiceError: Error, Equatable {
@MainActor
final class CoderVPNService: NSObject, VPNService {
var logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "vpn")
lazy var xpc:VPNXPCInterface = .init(vpn: self)
lazy var xpc:HelperXPCClient = .init(vpn: self)

@Published var tunnelState: VPNServiceState = .disabled {
didSet {
Expand DownExpand Up@@ -138,10 +138,10 @@ final class CoderVPNService: NSObject, VPNService {
}
}

func onExtensionPeerUpdate(_data: Data) {
func onExtensionPeerUpdate(_diff: Data) {
logger.info("network extension peer update")
do {
let msg = try Vpn_PeerUpdate(serializedBytes:data)
let msg = try Vpn_PeerUpdate(serializedBytes:diff)
debugPrint(msg)
applyPeerUpdate(with: msg)
} catch {
Expand DownExpand Up@@ -199,16 +199,18 @@ extension CoderVPNService {
break
// Non-connecting -> Connecting: Establish XPC
case (_, .connecting):
xpc.connect()
xpc.ping()
// Detached to run ASAP
// TODO: Switch to `Task.immediate` once stable
Task.detached { try? await self.xpc.ping() }
tunnelState = .connecting
// Non-connected -> Connected:
// - Retrieve Peers
// - Run `onStart` closure
case (_, .connected):
onStart?()
xpc.connect()
xpc.getPeerState()
// Detached to run ASAP
// TODO: Switch to `Task.immediate` once stable
Task.detached { try? await self.xpc.getPeerState() }
tunnelState = .connected
// Any -> Reasserting
case (_, .reasserting):
Expand Down
10 changes: 5 additions & 5 deletionsCoder-Desktop/Coder-Desktop/Views/LoginForm.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,7 +90,7 @@ struct LoginForm: View {
return
}
// x.compare(y) is .orderedDescending if x > y
guardSignatureValidator.minimumCoderVersion.compare(semver, options: .numeric) != .orderedDescending else {
guardValidator.minimumCoderVersion.compare(semver, options: .numeric) != .orderedDescending else {
loginError = .outdatedCoderVersion
return
}
Expand DownExpand Up@@ -192,13 +192,13 @@ struct LoginForm: View {
@discardableResult
func validateURL(_ url: String) throws(LoginError) -> URL {
guard let url = URL(string: url) else {
throwLoginError.invalidURL
throw .invalidURL
}
guard url.scheme == "https" else {
throwLoginError.httpsRequired
throw .httpsRequired
}
guard url.host != nil else {
throwLoginError.noHost
throw .noHost
}
return url
}
Expand All@@ -221,7 +221,7 @@ enum LoginError: Error {
"Invalid URL"
case .outdatedCoderVersion:
"""
The Coder deployment must be version \(SignatureValidator.minimumCoderVersion)
The Coder deployment must be version \(Validator.minimumCoderVersion)
or higher to use Coder Desktop.
"""
case let .failedAuth(err):
Expand Down
114 changes: 0 additions & 114 deletionsCoder-Desktop/Coder-Desktop/XPCInterface.swift
View file
Open in desktop

This file was deleted.

Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp