I would like to understand the behaviour of Network framework when I have established a connection between 2 iOS devices which are connected through LAN and the same Wifi. Assumptions:
- Enabled
includePeerToPeer. - Devices are discovered and connected through Bonjour:
- When the connection establishes for the first time, does it automatically decide which interface to pick? I see some posts which point to Happy Eyeball algorithm but that seem to point more towards ipv4 vs ipv6 rather than Wifi vs LAN vs P2P.
- In the middle of a connection, if the established connection has issues, does the Network framework automatically switch to the best available interface?
- If not, I would assume the app will have to handle the switching in
betterPathUpdateHandlercallback? I’m curious what needs to be done here. Do I just create a new connection and hope that it picks the actual better path? - The
NWInterface.InterfaceTypedoesnt have a type for peer to peer wifi. Does that mean that when the interface actually switches to peer to peer, the InterfaceType will beother?
It would be great if there is a workflow or example of how this needs to be handled with multiple available Interfaces.
does it automatically decide which interface to pick?
Yes.
There’s no way to avoid that if you’re using TCP. That protocol necessarily runs over a specific interface, and if there are paths via multiple interfaces the system has to pick one.
Happy Eyeball algorithm but that seem to point more towards ipv4 vs ipv6
While Happy Eyeballs was introduced to improve the IPv6 experience, it’s not exclusively about the IP version. Rather, it starts candidate connections across multiple network paths and then races them, discarding the ones that don’t win that race. See Understanding Also-Ran Connections. IPv4 and IPv6 are different paths, but so are infrastructure and peer-to-peer Wi-Fi.
Happy Eyeballs is a general description of the approach and Apple platforms implement a lot of smarts on top of that. I suspect you’ll find a strong preference for infrastructure Wi-Fi over peer-to-peer Wi-Fi, because peer-to-peer Wi-Fi is ridiculously expensive. So, if two device are on the same infrastructure Wi-Fi, Network framework will always connect over that in practice.
if the established connection has issues, does the Network framework automatically switch to the best available interface?
No.
At least not with TCP. In TCP, a connection is identified by the local IP / local port / remote IP / remote port tuple. Given that, it’s not possible to switch a TCP connection to a different interface, because that’d have a different local IP.
You can do this sort of thing with more advanced protocols, like MPTCP and QUIC.
I would assume the app will have to handle the switching in betterPathUpdateHandler callback?
Yes. But also no (-:
The concept of a better path is tricky, and I usually see it kick in when you’re running over WWAN and Wi-Fi becomes available. I doubt it’ll fire if you’re running over peer-to-peer Wi-Fi and then the device joins an infrastructure Wi-Fi network, but I must admit that I’ve never actually tried that.
Do I just create a new connection and hope that it picks the actual better path?
Yes.
Once the new connection is… well… connected, you can analyse its path to see if it’s better based on your own criteria.
The NWInterface.InterfaceType doesnt have a type for peer to peer wifi.
Indeed. You can actually distinguish the two via the functional type concept, as explained in Network Interface APIs.
Does that mean … the InterfaceType will be other?
I believe that both IFRTYPE_FUNCTIONAL_WIFI_INFRA and IFRTYPE_FUNCTIONAL_WIFI_AWDL map to .wifi.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"