Browse Source

DNS: refine Android bootstrap DNS logic (#767)

CalmLong 4 years ago
parent
commit
630ec22108
3 changed files with 4 additions and 18 deletions
  1. 0 4
      infra/conf/dns.go
  2. 0 9
      infra/conf/dns_bootstrap.go
  3. 4 5
      infra/conf/dns_bootstrap_android.go

+ 0 - 4
infra/conf/dns.go

@@ -160,10 +160,6 @@ func (c *DNSConfig) Build() (*dns.Config, error) {
 		config.NameServer = append(config.NameServer, ns)
 		config.NameServer = append(config.NameServer, ns)
 	}
 	}
 
 
-	if BootstrapDNS() {
-		newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog()
-	}
-
 	if c.Hosts != nil && len(c.Hosts) > 0 {
 	if c.Hosts != nil && len(c.Hosts) > 0 {
 		domains := make([]string, 0, len(c.Hosts))
 		domains := make([]string, 0, len(c.Hosts))
 		for domain := range c.Hosts {
 		for domain := range c.Hosts {

+ 0 - 9
infra/conf/dns_bootstrap.go

@@ -1,9 +0,0 @@
-// +build !android
-
-package conf
-
-const bootstrapDNS = ""
-
-func BootstrapDNS() bool {
-	return false
-}

+ 4 - 5
infra/conf/dns_bootstrap_android.go

@@ -7,12 +7,11 @@ import (
 	"net"
 	"net"
 )
 )
 
 
-const bootstrapDNS = "8.8.8.8:53"
-
-func BootstrapDNS() bool {
+func init() {
+	const bootstrapDNS = "8.8.8.8:53"
 	var dialer net.Dialer
 	var dialer net.Dialer
 	net.DefaultResolver = &net.Resolver{
 	net.DefaultResolver = &net.Resolver{
-		PreferGo: false,
+		PreferGo: true,
 		Dial: func(context context.Context, _, _ string) (net.Conn, error) {
 		Dial: func(context context.Context, _, _ string) (net.Conn, error) {
 			conn, err := dialer.DialContext(context, "udp", bootstrapDNS)
 			conn, err := dialer.DialContext(context, "udp", bootstrapDNS)
 			if err != nil {
 			if err != nil {
@@ -21,5 +20,5 @@ func BootstrapDNS() bool {
 			return conn, nil
 			return conn, nil
 		},
 		},
 	}
 	}
-	return true
+	newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog()
 }
 }