1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

feat: update bootstrap_dns_android (#966)

* update with non_specified network

* remove wrongs

* add alternative bootstrapDialer

* do test

* Update dns_bootstrap_android_test.go

* example of alternative dialer

* public method

* move const

* Update dns_bootstrap_android_test.go

* no duplicated

* Rename infra/conf/dns_bootstrap_android.go to transport/internet/system_dns_android.go

* Update system_dns_android.go

* Update and rename infra/conf/dns_bootstrap_android_test.go to transport/internet/system_dns_android_test.go

* no imports

* Update system_dns_android.go

* Update system_dns_android_test.go

* create systemDNS

* Create system_dns_android.go

* Update system_dialer.go

* call Resolver on systemDialer

* create system_dns_test.go

* resolver.LookupIP params

* param fix

* noneed TestSystemDNSResolver

* revert: no specified resolver

* Delete system_dns.go

* android only

* android only test

* typo
This commit is contained in:
rurirei 2021-05-05 05:22:01 +08:00 committed by GitHub
parent c66a1678da
commit 2129c6e1e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 52 deletions

View File

@ -1,24 +0,0 @@
// +build android
package conf
import (
"context"
"net"
)
func init() {
const bootstrapDNS = "8.8.8.8:53"
var dialer net.Dialer
net.DefaultResolver = &net.Resolver{
PreferGo: true,
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
},
}
newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog()
}

View File

@ -1,28 +0,0 @@
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)
}
}

View File

@ -0,0 +1,26 @@
// +build android
package internet
import (
"context"
"net"
)
const SystemDNS = "8.8.8.8:53"
type DNSResolverFunc func() *net.Resolver
var NewDNSResolver DNSResolverFunc = func() *net.Resolver {
return &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
var dialer net.Dialer
return dialer.DialContext(ctx, network, SystemDNS)
},
}
}
func init() {
net.DefaultResolver = NewDNSResolver()
}

View File

@ -0,0 +1,15 @@
// +build android
package internet
import (
"context"
"testing"
)
func TestDNSResolver(t *testing.T) {
resolver := NewDNSResolver()
if ips, err := resolver.LookupIP(context.Background(), "ip", "www.google.com"); err != nil {
t.Errorf("failed to lookupIP, %v, %v", ips, err)
}
}