Skip to content
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

Merged
merged 1 commit into from Mar 7, 2024
Merged

Conversation

WaterLemons2k
Copy link
Contributor

@WaterLemons2k WaterLemons2k commented Mar 7, 2024

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 function WaitForNetworkConnected to internet and Wait to make the names more concise.

Also renamed function NewDialerResolver to SetDNS for the same reason.


The use of net.SplitHostPort instead of strings.Contains in the function SetDNS is for use custom ports in IPv6 DNS. See:

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
Copy link
Owner

@jeessy2 jeessy2 left a 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

@jeessy2 jeessy2 merged commit ae0f47f into jeessy2:master Mar 7, 2024
2 checks passed
@WaterLemons2k WaterLemons2k deleted the internet branch March 7, 2024 13:32

const (
// fallbackDNS used when a fallback occurs.
fallbackDNS = "1.1.1.1"
Copy link
Owner

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可能不通

Copy link
Contributor Author

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 比较好。

另外,感觉是不是应该更严格一点,失败多次再回落?

Copy link
Owner

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

Copy link
Owner

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?

Copy link
Contributor Author

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 在没有 /etc/resolv.conf 文件的环境中正常工作,引入了太多不必要的复杂性(DNS 不可用时自动回落、维护国内/国外 DNS 列表等);还破坏了其他用户的体验,所以是时候停止了

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内置也还行吧。系统虽然复杂点,减少用户操作复杂度。不过可以简化下系统复杂度,达到更好效果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants