get_pingtime: set a lower value for preferred host #351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
preferred_hosts
doesn't work under a rare network condition called Fake-IP, used by TUN based proxies apps/clients, like Surge, Clash (one of clash's fork calledmihomo
, is in our macports-ports repo).Please bear with me while I'm explaining this Fake-IP concept.
Proxy clients like Clash, set up a TUN to intercept all traffic. It also sets up a local (forwarding) DNS server and set it as the system DNS, to keep track of the DNS requests. So it can match the IP from a TCP connection to its domain, which makes the
DOMAIN-SUFFIX
rules above works both for HTTP and TCP connections.When an HTTP request comes, the proxy client first resolves the IP for it to set up a TCP connection. Otherwise the HTTP client like a browser will tell the user IP not found and request stops.
DIRECT
rule is matched, the local proxy client help us finish this HTTP request, reusing the IP resolved by the local DNS server.ProxyServer
rule is matched, the HTTP reuqest is wrapped and sent to the remote proxy server. The server doesn't use the IP resolved by the local DNS on our computure, but resolves it again by itself.Fake-IP is introduced to optimize the workflow above, cuz for the 2nd situation, resolving an IP for the request at the local side, is redundant.
So when this Fake-IP feature is enabled, every mirror host is resolved immediately,
ping -noq -c3 -t3
and compare the cost time doens't work as expected.Here is the pingtimes I printed out during debug.
You can see every host gets a much lower time cost value. In fact, the
1
returned inget_pingtime
for apreferred_hosts
, make the preferred hosts rank last.Since the value
0
is returned for local mirror starts withfile://
, i used0.001
to putpreferred_hosts
in the front of the ranking result.ref