ouisync icon indicating copy to clipboard operation
ouisync copied to clipboard

Bind the ipv6 DHT to the local address of the device instead of unspecified

Open madadam opened this issue 4 years ago • 1 comments
trafficstars

According to the "Source address selection" section in BEP 32, we should bind the DHT to a well defined ipv6 address and not use :: ("unspecified"). In order to do that, we need a way to obtain the local ipv6 address of the device. We can use getifaddrs function (or some higher-level wrapper of it) to do that but that function is not available on all platforms. A platform-agnostic way of doing this seems to be this:

let socket = UdpSocket::bind((Ipv6Addr::UNSPECIFIED, 0)).await?;
socket.connect(SOME_PUBLIC_IPV6_ADDR).await?;
socket.local_addr()

Where SOME_PUBLIC_IPV6_ADDR is some publicly reachable ipv6 address. Problem is that particular address might not work for various reasons so we would probably need a list of such addresses and try them all until one succeed.

madadam avatar Nov 10 '21 15:11 madadam