-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Description
(test on: windows-v25.3.3)
in freedom-outbound and a tcp-connection, or in proxy-outbound and a tcp/udp(quic)-connection,
suppose that our connect-address is a "domain" and [ip1, ip2, ip3, ip4] is the list of resolved-IPs.
Current behavior:
- it tries to connect to ip1 for 30 seconds, and if it fails, it tries to connect to ip2 for 30 seconds, and ...
- so if, for example, ip1 and ip2 are unavailable for any reason, It takes 60 seconds to connect to the ip3 and as a result, it takes 60 seconds to connect to the destination !!!
Correct behavior (happy eyeballs RFC 8305):
- First, we sort the IP-list in such a way that v4 and v6 IPs appear one after the other, for example if ip1 and ip2 are version-4, and ip3 and ip4 are version-6 after sorting we have [ip1, ip3, ip2, ip4].
- then try to connect to ip1 in thread1, after for example 300ms try to connect to ip3 in thread2, ...
- As a result several attempts may be in flight at the same time, and whenever one of the attempts succeed, all other connections are cancelled, and the winning connection is used. This means a much shorter wait before one of the IP addresses connect successfully.
First application:
- Happy Eyeballs is particularly important for dual-stack clients, when some hosts may have resolvable IPv6 addresses that are somehow unreachable.
Second application:
- For any reason, some IPs may not be available, as a result, with happy eyeballs, we can find the IP that can be connected as soon as possible.
Application in iran:
- In Iran some instagram IPs are blocked and some are not, in resolved-ip-list some IPs are blocked and some are not, as a result, with happy eyeballs, we can find the IP that can be connected as soon as possible.
tips:
- For Happy eyballs, it doesn't matter whether the IP is version 4 or 6, but it is better to sort the resolved-ip-list so that v4 and v6 IPs appear one after the other.(RFC 8305)
- happy eyeballs is used in freedom-outbound when address is a domain and connection is tcp,
- or is used in proxy-outbounds when address is domain and connection is tcp or udp(quic).
///
in python stock asyncio supports Happy Eyeballs, so we just need to set the time to wait for a connection attempt to complete, before starting the next attempt in parallel.
so there should be a ready library for happy eyeballs for tcp-connections in Go too.
AmirReza2012, developer861 and ninja-vpn
Metadata
Metadata
Assignees
Labels
No labels