-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNEAppProxyFlow+Extensions.swift
More file actions
41 lines (36 loc) · 1.44 KB
/
NEAppProxyFlow+Extensions.swift
File metadata and controls
41 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Foundation
import NetworkExtension
// Simulate a "Connection refused" error
fileprivate let connectionRefusedError = NSError(domain: NSPOSIXErrorDomain, code: Int(ECONNREFUSED), userInfo: nil)
// Implement the shortcuts
extension NEAppProxyFlow: Flow {
// Kill a flow
func closeReadAndWrite() {
self.closeReadWithError(connectionRefusedError)
self.closeWriteWithError(connectionRefusedError)
}
// Open a flow
func openFlow(completionHandler: @escaping (Error?) -> Void) {
if #available(macOS 15.0, *) {
open(withLocalFlowEndpoint: nil, completionHandler: completionHandler)
} else {
open(withLocalEndpoint: nil, completionHandler: completionHandler)
}
}
// Flow metadata
var sourceAppSigningIdentifier: String { self.metaData.sourceAppSigningIdentifier }
var sourceAppAuditToken: Data? { self.metaData.sourceAppAuditToken }
}
// Enforce Flow protocol conformance for NEAppProxyTCPFlow and NEAppProxyUDPFlow subclasses.
// This approach allows using Flow protocols universally instead of specific NEAppProxyFlow classes,
// facilitating easier stubbing/mocking in tests as Flow protocols are simpler to satisfy.
extension NEAppProxyTCPFlow: FlowTCP {
var flowEndpoint: NWEndpoint {
if #available(macOS 15.0, *) {
self.remoteFlowEndpoint
} else {
self.remoteEndpoint
}
}
}
extension NEAppProxyUDPFlow: FlowUDP {}