Skip to content

Commit 7cdeb47

Browse files
WIP NWEndpoint changes
New macos 15.0+ APIs uses Network.NWEndpoint for both TCP remoteEndpoint (new name is remoteFlowEndpoint) and UDP localEndpoint (new name is localFlowEndpoint). The old APIs use a different type, which is NetworkExtension.NWEndpoint. Network.NWEndpoint is available also on older macos versions, so we can just use that type in our FlowTCP and FlowUDP classes, then for older versions convert from NetworkExtension.NWEndpoint to it
1 parent 7a40118 commit 7cdeb47

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ProxyExtension/IO/FlowProtocols.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import NetworkExtension
3+
import Network
34

45
// Flow base protocol we use in place of NEAppProxyFlow, it also provides shortcuts for common functions.
56
protocol Flow {
@@ -25,18 +26,19 @@ extension Flow {
2526
// Check if the address is an IPv6 address. IPv6 addresses always contain a ":"
2627
// We can't do the opposite (such as just checking for "." for an IPv4 address) due to IPv4-mapped IPv6 addresses
2728
// which are IPv6 addresses but include IPv4 address notation.
28-
if let endpoint = flowTCP.flowEndpoint as? NWEndpoint {
29+
let endpoint: Network.NWEndpoint? = flowTCP.flowEndpoint
30+
if endpoint != nil {
2931
// We have a valid NWEndpoint - let's see if it's IPv6
30-
if endpoint.hostname.contains(":") {
32+
if endpoint.host.contains(":") {
3133
return true
3234
}
3335
}
3436
} else if let flowUDP = self as? FlowUDP {
3537
// Use localEndpoint for UDP flows as UDP (as a "connectionless protocol")
3638
// doesn't have a fixed flowEndpoint
37-
if let endpoint = flowUDP.localEndpoint as? NWEndpoint {
39+
if let endpoint = flowUDP.localEndpoint {
3840
// We have a valid NWEndpoint - let's see if it's IPv6
39-
if endpoint.hostname.contains(":") {
41+
if endpoint.host.contains(":") {
4042
return true
4143
}
4244
}
@@ -51,13 +53,13 @@ extension Flow {
5153
// FlowTCP and FlowUDP protocols abstract the relevant parts of NEAppProxyTCPFlow
5254
// and NEAppProxyUDPFlow for increased flexibility and improved testability.
5355
protocol FlowTCP: Flow {
54-
var flowEndpoint: NWEndpoint { get }
56+
var flowEndpoint: Network.NWEndpoint { get }
5557
func readData(completionHandler: @escaping (Data?, Error?) -> Void)
5658
func write(_ data: Data, withCompletionHandler completionHandler: @escaping (Error?) -> Void)
5759
}
5860

5961
protocol FlowUDP: Flow {
6062
func readDatagrams(completionHandler: @escaping ([Data]?, [NWEndpoint]?, Error?) -> Void)
6163
func writeDatagrams(_ datagrams: [Data], sentBy remoteEndpoints: [NWEndpoint], completionHandler: @escaping (Error?) -> Void)
62-
var localEndpoint: NWEndpoint? { get }
64+
var localEndpoint: Network.NWEndpoint? { get }
6365
}

0 commit comments

Comments
 (0)