-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: android binary runtime default dns set 8.8.8.8:53 (#572)
ref golang/go#8877 ref v2ray/v2ray-core#1909
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build !android | ||
|
||
package conf | ||
|
||
const bootstrapDNS = "" | ||
|
||
func BootstrapDNS() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build android | ||
|
||
package conf | ||
|
||
import ( | ||
"context" | ||
"net" | ||
) | ||
|
||
const bootstrapDNS = "8.8.8.8:53" | ||
|
||
func BootstrapDNS() bool { | ||
var dialer net.Dialer | ||
net.DefaultResolver = &net.Resolver{ | ||
PreferGo: false, | ||
Dial: func(context context.Context, _, _ string) (net.Conn, error) { | ||
conn, err := dialer.DialContext(context, "udp", bootstrapDNS) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return conn, nil | ||
}, | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package conf | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
) | ||
|
||
func TestBootstrapDNS(t *testing.T) { | ||
const ( | ||
defaultNS = "8.8.8.8:53" | ||
domain = "github.com" | ||
) | ||
var dialer net.Dialer | ||
net.DefaultResolver = &net.Resolver{ | ||
PreferGo: true, | ||
Dial: func(context context.Context, network, address string) (net.Conn, error) { | ||
conn, err := dialer.DialContext(context, "udp", defaultNS) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return conn, nil | ||
}, | ||
} | ||
if ips, err := net.LookupIP(domain); len(ips) == 0 { | ||
t.Error("set BootstrapDNS failed: ", err) | ||
} | ||
} |