Closed
Conversation
A new item "useFake" in DnsObject for controlling fake IP function. After the fake IP function enabled, the local DNS server of v2ray will response with a unique fake IP for every unique domain name. Once v2ray received a request to one of the fake IP, it will replace the domain name of its destination with the previously saved one.
Move the rules parser to the V2Ray. Considering we parse the rules in the strmatcher package, programers only need to care about the rules themselves now. In the previous version, we prase the configure file in the V2Ctl and only send the base rules to the V2Ray. It works, but is hard to add complex rules and to reuse code.
Add a class implementing strmatcher.Matcher, which is used to check whether a domain is in the fake IP list or not. Using rules from dns.useFake, which is an array, to generate domain matching rules.
Testing is necessary!
Move useFake to fake.fakeRules, and add fake.fakeNet. Fake IP will be generated in the fakeNet domain.
dc948c8 to
5e06a29
Compare
We don't need StaticHosts anymore.
To be compatible with a old version of V2Ctl, StaticHosts are still processed on the V2Ray.
Update the matching rules handler of the DNS server. Revert the name dns.Config_HostMapping.Pattern back to Domain for compatibility. Add a new matching type DomainMatchingType_New for compatibility.
Seperating means sharing. Also remove redundant code in DNS host.
WOW, what a mess. Add a argument for compressPattern method to specify the default matching method. Add external rules data to router's protobuf structure.
Merge ParsePattern method of MatcherGroup and OrMatcher. Remove Type.New method, it's not needed anymore. Change OrMatcher.New() to NewOrMatcher() for convenience.
Closed
It should not query for domain if the income is already domain.
Add LookupRealIP methods in the features.dns interface, so that others can always get the real IP no matter the fake IP is enabled or not.
Add LookupRealIP support for test cases.
Now, there are three regeneration methods when fake IP pool runs out: None: Stop generating fake IP. Oldest: Reuse the earliest generated IP. LRU: Reuse the least recently used IP.
Save generated fake IP to file to keep fake IP mapping from losing.
Comment on lines
+124
to
+129
| type lruMapper struct { | ||
| domainMapper map[string]*addressNode | ||
| addressMapper map[uint32]*domainNode | ||
| lru *list.List | ||
| next uint32 | ||
| } |
There was a problem hiding this comment.
domainMapper和addressMapper有线程安全问题,会发生并发读写错误,建议加锁。
| if c.Fake != nil { | ||
| config.Fake = new(dns.Config_Fake) | ||
| if c.Fake.FakeNet == "" { | ||
| config.Fake.FakeNet = "224.0.0.0/22" |
Contributor
|
Please move to https://github.com/v2fly/v2ray-core/pulls |
Contributor
|
麻烦及时提交到 https://github.com/v2fly/v2ray-core/pulls (如果无回应,我们有可能会使用您的 commits) |
|
It has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days |
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.
Fake IP / Fake DNS 的详情见 issue #2233
语法
其中,
fakeRules指明了需要启用 Fake IP 功能的域名。fakeNet指明了返回的 Fake IP 所在的生成域。regeneration指明了生成域用尽时 Fake IP 的生成方式,共三种,分别为:lru: 默认值,替换最近最少使用的 IP。oldest: 替换最早被生成的 IP。none: 在 IP 用尽后停止使用 Fake IP 功能。path指明了 Fake IP 映射储存的文件位置,不指定则不储存 Fake IP 映射,将导致重启 V2Ray 之后丢失 Fake IP 于域名的映射数据。关于对规则匹配系统的重构的 commit 6c7d324
原因
为了对规则指定的域名启用 Fake IP 功能,需要用到规则匹配系统。V2Ray 现有两处可以使用匹配规则:DnsObject 和 RoutingObject 。
在原先的代码中, DnsObject 的规则匹配采用了映射 RoutingObject 的匹配规则的方式。这对于 Fake IP 的规则匹配功能开发极不友好,需要添加重复代码堆在 RoutingObject 上,因此我才重构了规则系统。
特性
后续工作
commit 66b42ab 开始对匹配规则重构的后续工作。
目前只有 Fake IP,重构后的 DnsObject 使用这种规则匹配方式。commit 5501729 完成了对所有规则匹配代码的重构。
之后可以便捷地添加新的匹配规则 / 为其他地方启用匹配规则功能。