-
Notifications
You must be signed in to change notification settings - Fork 2
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d8ad698
feat: add XPC communication to Network Extension
coadler 12e803c
fixup
coadler 38a9388
fmt
coadler 90e352d
fix xpc target
coadler 61e0a29
fix xpc module
coadler c0e5813
change to framework
coadler 11a79a9
test
coadler a5305cd
Merge branch 'main' into colin/xpc
coadler dc56a96
XPC fixes
coadler b43a407
fixes
coadler a48b691
add app group entitlement
ethanndickson a439536
Merge branch 'main' into colin/xpc
coadler c4c9f3f
working now
coadler e3eba6b
Merge branch 'main' into colin/xpc
coadler 7724bc6
lint
coadler 44f191f
remove unused import
coadler 31f0b3b
fix import
ethanndickson deb773a
Merge branch 'main' into colin/xpc
ethanndickson 207da24
force review
ethanndickson 139157d
fixup
ethanndickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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> |
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
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,76 @@ | ||
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 = { [weak self] in | ||
guard let self else { return } | ||
Task { @MainActor in | ||
self.logger.error("XPC connection invalidated.") | ||
} | ||
} | ||
xpcConn.interruptionHandler = { [weak self] in | ||
guard let self else { return } | ||
Task { @MainActor in | ||
self.logger.error("XPC connection interrupted.") | ||
} | ||
} | ||
xpcConn.resume() | ||
|
||
xpc.ping { | ||
print("Got response from XPC") | ||
} | ||
} | ||
|
||
func ping() { | ||
xpc.ping { | ||
Task { @MainActor in | ||
print("Got response from 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) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, since it's a chicken & egg problem. The alternative is to use an optional, probably with
!
- lazy lets us skip the unwrap.