I’m still debugging my UdpFlowCopier and could use some guidance as some aspects are confusing.
I need to copy datagrams between a provider flow object and an actual UDP socket or “connection”. Can you help me understand the difference between a NetworkExtension.NWEndpoint and Network.NWEndpoint and where I would need to use one versus the other?
Following the TCP example, the PassThroughProviderCore calls handleNewUDPFlow(_ flow: NEAppProxyUDPFlow). There’s no remote endpoint but I can retrieve the local endpoint as
guard let nwEndpoint = flow.localEndpoint?.nwEndpoint else { return }
I’m trying to open a UDP listener on this endpoint as follows but it mostly returns failed to create listener on port 0
private func handleStart() -> State {
let port = portForEndpoint(self.localEndpoint) ?? 0
logger.debug("UDPFlowCopier - handleStart copier \(self.osLogID) port \(port.rawValue, privacy: .public)")
let params = NWParameters.udp
params.allowFastOpen = true
self.listener = try? NWListener(using: params, on: port)
self.listener?.stateUpdateHandler = { update in
switch update {
case .ready:
self.isReady = true
//self.processEvent(.didOpenConnection)
case .failed, .cancelled:
// Announce we are no longer able to listen
self.listening = false
self.isReady = false
logger.debug("UDPFlowCopier - copier \(self.osLogID) failed to create listener on port \(port.rawValue, privacy: .public)")
self.stop()
default:
()
}
}
self.listener?.newConnectionHandler = { connection in
self.createConnection(connection: connection)
}
self.listener?.start(queue: self.queue)
return .openingConnection
}
Can you offer any insight? Thanks