feat: implement Clash-like Fake IP feature for DNS optimization#146
Open
darkSuperman wants to merge 7 commits into
Open
feat: implement Clash-like Fake IP feature for DNS optimization#146darkSuperman wants to merge 7 commits into
darkSuperman wants to merge 7 commits into
Conversation
… clippy stripping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR introduces a Fake IP feature (similar to the implementation in Clash) to optimize DNS resolution and connection latency, as well as to prevent local DNS leaks.
How it works & Motivation
Normally, a client resolves a domain name first and then initiates a connection to the returned IP, costing an extra DNS RTT.
With this Fake IP implementation:
hickory-dns). When the client queries a domain, it immediately returns an unused pseudo-IP (e.g.,198.18.0.xfrom a configured pool) and records the mapping in an LRU cache.src/address.rs), the proxy detects the Fake IP, retrieves the original FQDN mapped in the cache, and routes the proxy request using the actual domain name.Implementation Details
FakeIpManager: A thread-safe LRU cache (exposed globally viastd::sync::OnceLock) to store#Domain -> Fake IPand#Fake IP -> Domainmappings.restore_fake_ip()globally into the address parsing phase so any outbound connection utilizing a Fake IP seamlessly recovers its target FQDN before leavingshoes.