-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
perf: check internet with DNS lookup #1034
Conversation
DNS lookups are much cheaper than HTTP requests since we only need to check if the Internet is available. See: https://stackoverflow.com/a/50058255
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.
You’ve been a big help
|
||
const ( | ||
// fallbackDNS used when a fallback occurs. | ||
fallbackDNS = "1.1.1.1" |
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.
是不是这里的,默认1.1.1.1可能会把自定义的dns覆盖,有些地区1.1.1.1可能不通
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.
是不是这里的,默认1.1.1.1可能会把自定义的dns覆盖,有些地区1.1.1.1可能不通
想一下用哪个国内的 DNS 比较好。
另外,感觉是不是应该更严格一点,失败多次再回落?
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.
可以考虑失败多次再回落,回落可以多个,国内主流的,如223.5.5.5
114.114.114.114
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,只使用自定义DNS,回落也不回落到公共DNS
如果没有自定义的DNS,根据浏览器语言来回落不同DNS?
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,即使配置有误。
如果 DNS 配置有误,尽到提醒义务即可;自行寻找可用的 DNS 并不是一个网络工具该做的。
现在,为了让 DNS 在没有 /etc/resolv.conf
文件的环境中正常工作,引入了太多不必要的复杂性(DNS 不可用时自动回落、维护国内/国外 DNS 列表等);还破坏了其他用户的体验,所以是时候停止了。
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.
内置也还行吧。系统虽然复杂点,减少用户操作复杂度。不过可以简化下系统复杂度,达到更好效果
What does this PR do?
Checks the Internet connection with a DNS lookup instead of an HTTP GET.
Motivation
DNS lookups are much cheaper than HTTP requests since we only need to check if the Internet is available. See https://stackoverflow.com/a/50058255 for more information.
Also inspired by:
Additional Notes
Renamed package
internal
and functionWaitForNetworkConnected
tointernet
andWait
to make the names more concise.Also renamed function
NewDialerResolver
toSetDNS
for the same reason.The use of
net.SplitHostPort
instead ofstrings.Contains
in the functionSetDNS
is for use custom ports in IPv6 DNS. See: