-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amend domain matcher with returning values of all matched subdomains #95
Conversation
{ // Will match server 4,3,1,2 and server 4 returns expected one | ||
ips, err := client.LookupIP("v2.api.google.com") | ||
if err != nil { | ||
t.Fatal("unexpected error: ", err) | ||
} | ||
|
||
if r := cmp.Diff(ips, []net.IP{{8, 8, 7, 8}}); r != "" { | ||
t.Fatal(r) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在DNS的测试使用如下四个用例:
- 查询google.com,匹配DNS [1, 2],DNS 1返回的IP是Expected的,直接返回;
- 查询ipv6.google.com,匹配DNS [1, 2],DNS 1返回的IP不是Expected的,这时并不直接Fallback到默认轮询,而是继续查询DNS 2,收到Expected IP并返回。
- 查询api.google.com,匹配DNS [3, 1, 2],这是因为
domain:api.google.com
的优先级更高。从DNS 3收到Expected IP并返回。 - 查询v2.api.google.com,匹配DNS [4, 3, 1, 2],这是因为Full Matcher的优先级最高。从DNS 4收到Expected IP并返回。
switch len(matches) { | ||
case 0: | ||
return nil | ||
case 1: | ||
return matches[0] | ||
default: | ||
result := []uint32{} | ||
for idx := range matches { | ||
// Insert reversely, the subdomain that matches further ranks higher | ||
result = append(result, matches[len(matches)-1-idx]...) | ||
} | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当没有match时,直接返回nil;当只有一个match时,返回matches里保存的数组引用,从而避免构造一个新数组。
{ // Matches [c.a.b.com, a.b.com] | ||
Domain: "c.a.b.com", | ||
Result: []uint32{4}, | ||
Result: []uint32{5, 4}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个测试用例似乎说明原作者是特意设计了级数最少的优先匹配
这个规则的(c.a.b.com添加时为5,最后匹配到了4)。不知最初的用意为何……
在本机上,原版、Amend PR 1、当前PR的Benchmark
原版实现
Amend PR 1 实现
Amend PR 2 实现
|
1e743f5
to
1e22242
Compare
Fixes #92 (comment)