In Network.framework the documentation for nw_connection_force_cancel() suggests that it's possible to provide fall through endpoints?
/// Cancel the currently connected endpoint, causing the connection to fall through to the next endpoint if
/// available, or to go to the waiting state if no more endpoints are available.
However I can't seem find a way to provide multiple endpoints to an NWConnection. The ability to fall through to a different endpoint in the case of failure on a primary one, or indeed simply being able to cancel the current one and move to the next, would be pretty nice. Is this functionality available currently or am I misunderstanding the docu in this case?
Thanks!
Short:
I've made a test and it seem it's true.
Long:
I've created hostname that points to multiple ip addresses
test.tridigy.com. 86400 IN A 212.122.90.147
test.tridigy.com. 86400 IN A 212.122.90.146
test.tridigy.com. 86400 IN A 89.117.128.41
And only one IP responds to HTTPS - 89.117.128.41
I've captured packet dump and see that it tries to connect to second one, first one and then establishes connection to third one:
23:57:09.337331 IP 192.168.62.132.49353 > 212.122.90.147.443: Flags [SEW], seq 2091855968, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 377923258 ecr 0,sackOK,eol], length 0
23:57:09.485493 IP 192.168.62.132.49354 > 212.122.90.146.443: Flags [SEW], seq 996630428, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 377923405 ecr 0,sackOK,eol], length 0
23:57:09.629142 IP 192.168.62.132.49355 > 89.117.128.41.443: Flags [SEW], seq 1320591488, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 377923548 ecr 0,sackOK,eol], length 0
23:57:09.675129 IP 89.117.128.41.443 > 192.168.62.132.49355: Flags [S.], seq 436958124, ack 1320591489, win 64240, options [mss 1460], length 0
23:57:09.675237 IP 192.168.62.132.49355 > 89.117.128.41.443: Flags [.], ack 1, win 65535, length 0
Here's the sample code for command line project main.swift:
import Foundation
import Network
let queue = DispatchQueue(label: "test")
let tcpParameters = NWProtocolTCP.Options()
let connectionParameters = NWParameters(tls: nil, tcp: tcpParameters)
let connection = NWConnection(host: "test.tridigy.com", port: 443, using: connectionParameters)
print("")
connection.stateUpdateHandler = { (newState) in
print("connection state changed \(newState)")
}
if(connection.state == .setup) {
connection.start(queue: queue)
}
RunLoop.main.run()