keepsimple1 / mdns-sd

Rust library for mDNS based Service Discovery
Apache License 2.0
102 stars 39 forks source link

Change intf_socks to a map of (Interface, Socket) #242

Closed keepsimple1 closed 3 months ago

keepsimple1 commented 3 months ago

This is triggered by a test failure in the integration_success test case on macOS locally. It turns out that macOS could have two network interfaces on the same IPv6 address.

intf:: Interface { name: "awdl0", 
addr: V6(Ifv6Addr { ip: fe80::f000:4aff:fe03:6c4c, netmask: ffff:ffff:ffff:ffff::, broadcast: None }), 
index: Some(13) }

intf:: Interface { name: "llw0", 
addr: V6(Ifv6Addr { ip: fe80::f000:4aff:fe03:6c4c, netmask: ffff:ffff:ffff:ffff::, broadcast: None }), 
index: Some(14) }

(According to chatGPT, awdl stands for Apple Wireless Direct Link, and llw stands for Low-Latency Wi-Fi)

But their interface index (i.e. scope_id in IPv6) are different.

As Zeroconf.intf_socks uses IP address as its key, these two interfaces are merged into a single entry in the intf_socks map, and later failed the test when checking metrics["unregister-resend"].

This patch is to use Interface as the key instead to identify each interface even when they share the same IPv6 address. Also simplify the value type to be Socket instead of struct IntfSock.