From 630ec221088152615b2a34e2dfc33f7467b30b0a Mon Sep 17 00:00:00 2001 From: CalmLong <37164399+CalmLong@users.noreply.github.com> Date: Wed, 10 Mar 2021 21:23:15 +0800 Subject: [PATCH] DNS: refine Android bootstrap DNS logic (#767) --- infra/conf/dns.go | 4 ---- infra/conf/dns_bootstrap.go | 9 --------- infra/conf/dns_bootstrap_android.go | 9 ++++----- 3 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 infra/conf/dns_bootstrap.go diff --git a/infra/conf/dns.go b/infra/conf/dns.go index 8f08aeb11..bcf31a4c0 100644 --- a/infra/conf/dns.go +++ b/infra/conf/dns.go @@ -160,10 +160,6 @@ func (c *DNSConfig) Build() (*dns.Config, error) { config.NameServer = append(config.NameServer, ns) } - if BootstrapDNS() { - newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() - } - if c.Hosts != nil && len(c.Hosts) > 0 { domains := make([]string, 0, len(c.Hosts)) for domain := range c.Hosts { diff --git a/infra/conf/dns_bootstrap.go b/infra/conf/dns_bootstrap.go deleted file mode 100644 index 3f741705c..000000000 --- a/infra/conf/dns_bootstrap.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build !android - -package conf - -const bootstrapDNS = "" - -func BootstrapDNS() bool { - return false -} diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index cbb8a922f..0d56bbe89 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -7,12 +7,11 @@ import ( "net" ) -const bootstrapDNS = "8.8.8.8:53" - -func BootstrapDNS() bool { +func init() { + const bootstrapDNS = "8.8.8.8:53" var dialer net.Dialer net.DefaultResolver = &net.Resolver{ - PreferGo: false, + PreferGo: true, Dial: func(context context.Context, _, _ string) (net.Conn, error) { conn, err := dialer.DialContext(context, "udp", bootstrapDNS) if err != nil { @@ -21,5 +20,5 @@ func BootstrapDNS() bool { return conn, nil }, } - return true + newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() }