Open Osiris-Team opened 4 months ago
@miroslavpejic85 we could switch to ipv6 where each device has an unique ip anyways, and skip stun servers altogether.
Are you able to test it out?
Stun server doesn't work
The reason Is explained here.
@miroslavpejic85 I have no idea how STUN really works, after a bit of research I'm not sure IPv6 would even make a difference since there still is the issue of all ports being closed in the router firewall and actual pc firewall (if we talk about a regular home network). IPv6 would skip NAT, and thus easify identifying the actual device we want to talk to, but not fix the port issue.
I just have a basic understanding of networking, so take this with a grain of salt.
I did some research and UPnP seems to be promissing, just checked my router and it had UPnP enabled by default too:
So the optimal case would be if UPnP together with IPv6 is supported, this would skip NAT, open a port and thus allow direct communication from peer-to-peer without any extra complicated steps. Otherwise UPnP with IPv4 would also work, however this would still require a STUN server inbetween if I understood it correctly, but this would fix the ports/firewall issue.
Confirmed. If you have full IPv6 support (computer, router, and ISP) then STUN binding requests will fail when trying to connect to the server's IPv6 address.
Easy fix is to make sure DNS resolve for your STUN server only returns IPv4 addresses as follows. This didn't seem like a big enough deal for a PR.
Change this line from:
IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(host)[0], port);
to:
IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(host, AddressFamily.InterNetwork)[0], port);
Confirmed. If you have full IPv6 support (computer, router, and ISP) then STUN binding requests will fail when trying to connect to the server's IPv6 address.
Good find, what about?
// IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.Dns.GetHostAddresses(host)[0], port);
// Get IPv4 and IPv6 addresses
var addresses = Dns.GetHostAddresses(host);
var ipv4Address = addresses.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
var ipv6Address = addresses.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetworkV6);
// Use the IPv4 address if available, otherwise use the IPv6 address
IPAddress selectedAddress = ipv4Address ?? ipv6Address;
if (selectedAddress == null)
{
throw new Exception("No valid IP address found for the host.");
}
IPEndPoint remoteEndPoint = new IPEndPoint(selectedAddress, port);
Console.WriteLine($"Selected IP: {selectedAddress}");
Console.WriteLine($"Remote Endpoint: {remoteEndPoint}");
@miroslavpejic85 we could switch to ipv6 where each device has an unique ip anyways, and skip stun servers altogether.