- Notifications
You must be signed in to change notification settings - Fork3
feat: add XPC communication to Network Extension#29
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
20 commits Select commitHold shift + click to select a range
d8ad698
feat: add XPC communication to Network Extension
coadler12e803c
fixup
coadler38a9388
fmt
coadler90e352d
fix xpc target
coadler61e0a29
fix xpc module
coadlerc0e5813
change to framework
coadler11a79a9
test
coadlera5305cd
Merge branch 'main' into colin/xpc
coadlerdc56a96
XPC fixes
coadlerb43a407
fixes
coadlera48b691
add app group entitlement
ethanndicksona439536
Merge branch 'main' into colin/xpc
coadlerc4c9f3f
working now
coadlere3eba6b
Merge branch 'main' into colin/xpc
coadler7724bc6
lint
coadler44f191f
remove unused import
coadler31f0b3b
fix import
ethanndicksondeb773a
Merge branch 'main' into colin/xpc
ethanndickson207da24
force review
ethanndickson139157d
fixup
ethanndicksonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsCoder Desktop/Coder Desktop/Coder_Desktop.entitlements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletionsCoder Desktop/Coder Desktop/Coder_DesktopApp.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletionsCoder Desktop/Coder Desktop/Info.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NetworkExtension</key> | ||
<dict> | ||
<key>NEMachServiceName</key> | ||
<string>$(TeamIdentifierPrefix)com.coder.Coder-Desktop.VPN</string> | ||
</dict> | ||
</dict> | ||
</plist> |
89 changes: 61 additions & 28 deletionsCoder Desktop/Coder Desktop/VPNService.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletionsCoder Desktop/Coder Desktop/XPCInterface.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Foundation | ||
import os | ||
import VPNXPC | ||
@objc final class VPNXPCInterface: NSObject, VPNXPCClientCallbackProtocol, @unchecked Sendable { | ||
private var svc: CoderVPNService | ||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "VPNXPCInterface") | ||
private let xpc: VPNXPCProtocol | ||
init(vpn: CoderVPNService) { | ||
svc = vpn | ||
let networkExtDict = Bundle.main.object(forInfoDictionaryKey: "NetworkExtension") as? [String: Any] | ||
let machServiceName = networkExtDict?["NEMachServiceName"] as? String | ||
let xpcConn = NSXPCConnection(machServiceName: machServiceName!) | ||
xpcConn.remoteObjectInterface = NSXPCInterface(with: VPNXPCProtocol.self) | ||
xpcConn.exportedInterface = NSXPCInterface(with: VPNXPCClientCallbackProtocol.self) | ||
guard let proxy = xpcConn.remoteObjectProxy as? VPNXPCProtocol else { | ||
fatalError("invalid xpc cast") | ||
} | ||
xpc = proxy | ||
super.init() | ||
xpcConn.exportedObject = self | ||
xpcConn.invalidationHandler = { [logger] in | ||
Task { @MainActor in | ||
logger.error("XPC connection invalidated.") | ||
} | ||
} | ||
xpcConn.interruptionHandler = { [logger] in | ||
Task { @MainActor in | ||
logger.error("XPC connection interrupted.") | ||
} | ||
} | ||
xpcConn.resume() | ||
} | ||
func ping() { | ||
xpc.ping { | ||
Task { @MainActor in | ||
self.logger.info("Connected to NE over XPC") | ||
} | ||
} | ||
} | ||
func onPeerUpdate(_ data: Data) { | ||
Task { @MainActor in | ||
svc.onExtensionPeerUpdate(data) | ||
} | ||
} | ||
func onStart() { | ||
Task { @MainActor in | ||
svc.onExtensionStart() | ||
} | ||
} | ||
func onStop() { | ||
Task { @MainActor in | ||
svc.onExtensionStop() | ||
} | ||
} | ||
func onError(_ err: NSError) { | ||
Task { @MainActor in | ||
svc.onExtensionError(err) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.