From bbb183458077304af3ca9408be8614246f8d65be Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 10:43:12 +0800 Subject: [PATCH 01/29] update with non_specified network --- infra/conf/dns_bootstrap_android.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index 0d56bbe8929..f7c4c04f2a9 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -7,18 +7,16 @@ import ( "net" ) +const bootstrapDNS = "8.8.8.8:53" + 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 + Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, bootstrapDNS) }, } - newError("Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() + newError("Android Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() } From 602e34dae35da92bccc85254306c6b7c9a6a532f Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 10:43:51 +0800 Subject: [PATCH 02/29] remove wrongs --- infra/conf/dns_bootstrap_android.go | 1 - 1 file changed, 1 deletion(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index f7c4c04f2a9..1c5d0d26b70 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -10,7 +10,6 @@ import ( const bootstrapDNS = "8.8.8.8:53" func init() { - const bootstrapDNS = "8.8.8.8:53" net.DefaultResolver = &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { From de31ea36d1b0f8e4c33927341534da321ad4e2e0 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 10:59:33 +0800 Subject: [PATCH 03/29] add alternative bootstrapDialer --- infra/conf/dns_bootstrap_android.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index 1c5d0d26b70..7145b358937 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -7,15 +7,19 @@ import ( "net" ) -const bootstrapDNS = "8.8.8.8:53" +type DialerFunc func(context.Context, string, string) (net.Conn, error) + +var BootstrapDialer DialerFunc = func(ctx context.Context, network, _ string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, BootstrapDNS) +} + +var BootstrapDNS = "8.8.8.8:53" func init() { net.DefaultResolver = &net.Resolver{ PreferGo: true, - Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { - var dialer net.Dialer - return dialer.DialContext(ctx, network, bootstrapDNS) - }, + Dial: BootstrapDialer, } - newError("Android Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() + newError("Android Bootstrap DNS: ", BootstrapDNS).AtWarning().WriteToLog() } From fbdf7834bee078b6e690a30d5a10df68f04f8978 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:04:21 +0800 Subject: [PATCH 04/29] do test --- infra/conf/dns_bootstrap_android_test.go | 15 +++++++++++++ infra/conf/dns_bootstrap_test.go | 28 ------------------------ 2 files changed, 15 insertions(+), 28 deletions(-) create mode 100644 infra/conf/dns_bootstrap_android_test.go delete mode 100644 infra/conf/dns_bootstrap_test.go diff --git a/infra/conf/dns_bootstrap_android_test.go b/infra/conf/dns_bootstrap_android_test.go new file mode 100644 index 00000000000..a08fcdee561 --- /dev/null +++ b/infra/conf/dns_bootstrap_android_test.go @@ -0,0 +1,15 @@ +// +build android + +package conf + +import ( + "context" + "net" + "testing" +) + +func TestBootstrapDNS(t *testing.T) { + if ips, err := net.LookupIP("www.google.com"); len(ips) == 0 { + t.Errorf("failed to lookupIP with BootstrapDNS, %v", err) + } +} diff --git a/infra/conf/dns_bootstrap_test.go b/infra/conf/dns_bootstrap_test.go deleted file mode 100644 index 95e5ecb2c3c..00000000000 --- a/infra/conf/dns_bootstrap_test.go +++ /dev/null @@ -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) - } -} From c7158f40828529527d21f3788be7042927bdf2b1 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:21:12 +0800 Subject: [PATCH 05/29] Update dns_bootstrap_android_test.go --- infra/conf/dns_bootstrap_android_test.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/infra/conf/dns_bootstrap_android_test.go b/infra/conf/dns_bootstrap_android_test.go index a08fcdee561..2d78b007823 100644 --- a/infra/conf/dns_bootstrap_android_test.go +++ b/infra/conf/dns_bootstrap_android_test.go @@ -4,12 +4,29 @@ package conf import ( "context" - "net" + "fmt" + gonet "net" "testing" + + "github.com/v2fly/v2ray-core/v4/common/net" + "github.com/v2fly/v2ray-core/v4/transport/internet" ) func TestBootstrapDNS(t *testing.T) { - if ips, err := net.LookupIP("www.google.com"); len(ips) == 0 { + if ips, err := gonet.LookupIP("www.google.com"); len(ips) == 0 { t.Errorf("failed to lookupIP with BootstrapDNS, %v", err) } } + +func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { + BootstrapDialer := func(ctx context.Context, network, _ string) (gonet.Conn, error) { + dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, BootstrapDNS)) + if err != nil { + return nil, err + } + return internet.DialSystem(ctx, dest, nil) + } + UseAlternativeBootstrapDNS(BootstrapDialer) + + TestBootstrapDNS(t *testing.T) +} From 35ffcd2f50fd05712736a324079a31cb4f6f0b81 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:22:31 +0800 Subject: [PATCH 06/29] example of alternative dialer --- infra/conf/dns_bootstrap_android_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/conf/dns_bootstrap_android_test.go b/infra/conf/dns_bootstrap_android_test.go index 2d78b007823..91347256bbe 100644 --- a/infra/conf/dns_bootstrap_android_test.go +++ b/infra/conf/dns_bootstrap_android_test.go @@ -28,5 +28,5 @@ func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { } UseAlternativeBootstrapDNS(BootstrapDialer) - TestBootstrapDNS(t *testing.T) + TestBootstrapDNS(t) } From 2bf158f09366acc3692d217542608b4b4fc31d6e Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:33:00 +0800 Subject: [PATCH 07/29] public method --- infra/conf/dns_bootstrap_android.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index 7145b358937..f87c0d31507 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -7,19 +7,24 @@ import ( "net" ) +const bootstrapDNS = "8.8.8.8:53" + type DialerFunc func(context.Context, string, string) (net.Conn, error) -var BootstrapDialer DialerFunc = func(ctx context.Context, network, _ string) (net.Conn, error) { - var dialer net.Dialer - return dialer.DialContext(ctx, network, BootstrapDNS) +func UseAlternativeBootstrapDNS(dialer DialerFunc) { + net.DefaultResolver = &net.Resolver{ + PreferGo: true, + Dial: dialer, + } } -var BootstrapDNS = "8.8.8.8:53" - func init() { net.DefaultResolver = &net.Resolver{ PreferGo: true, - Dial: BootstrapDialer, + Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, bootstrapDNS) + }, } - newError("Android Bootstrap DNS: ", BootstrapDNS).AtWarning().WriteToLog() + newError("Android Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() } From 6dc353f847969596fe942ddce93a1df523a2efd8 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:34:53 +0800 Subject: [PATCH 08/29] move const --- infra/conf/dns_bootstrap_android.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index f87c0d31507..d9b8a8794d0 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -7,8 +7,6 @@ import ( "net" ) -const bootstrapDNS = "8.8.8.8:53" - type DialerFunc func(context.Context, string, string) (net.Conn, error) func UseAlternativeBootstrapDNS(dialer DialerFunc) { @@ -19,6 +17,7 @@ func UseAlternativeBootstrapDNS(dialer DialerFunc) { } func init() { + const bootstrapDNS = "8.8.8.8:53" net.DefaultResolver = &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { From 60a043ebb52748c5b47149bc4923be2f9ea4f649 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:37:14 +0800 Subject: [PATCH 09/29] Update dns_bootstrap_android_test.go --- infra/conf/dns_bootstrap_android_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/infra/conf/dns_bootstrap_android_test.go b/infra/conf/dns_bootstrap_android_test.go index 91347256bbe..f1eee5d1de6 100644 --- a/infra/conf/dns_bootstrap_android_test.go +++ b/infra/conf/dns_bootstrap_android_test.go @@ -19,14 +19,15 @@ func TestBootstrapDNS(t *testing.T) { } func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { - BootstrapDialer := func(ctx context.Context, network, _ string) (gonet.Conn, error) { - dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, BootstrapDNS)) + const bootstrapDNS = "8.8.4.4:53" + bootstrapDialer := func(ctx context.Context, network, _ string) (gonet.Conn, error) { + dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, bootstrapDNS)) if err != nil { return nil, err } return internet.DialSystem(ctx, dest, nil) } - UseAlternativeBootstrapDNS(BootstrapDialer) + UseAlternativeBootstrapDNS(bootstrapDialer) TestBootstrapDNS(t) } From 90d5a298b325e850edcd1003713abb5990dda258 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:40:49 +0800 Subject: [PATCH 10/29] no duplicated --- infra/conf/dns_bootstrap_android.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/infra/conf/dns_bootstrap_android.go b/infra/conf/dns_bootstrap_android.go index d9b8a8794d0..29ca2d1c25c 100644 --- a/infra/conf/dns_bootstrap_android.go +++ b/infra/conf/dns_bootstrap_android.go @@ -18,12 +18,11 @@ func UseAlternativeBootstrapDNS(dialer DialerFunc) { func init() { const bootstrapDNS = "8.8.8.8:53" - net.DefaultResolver = &net.Resolver{ - PreferGo: true, - Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { - var dialer net.Dialer - return dialer.DialContext(ctx, network, bootstrapDNS) - }, + bootstrapDialer := func(ctx context.Context, network, _ string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, bootstrapDNS) } + UseAlternativeBootstrapDNS(bootstrapDialer) + newError("Android Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() } From 1c12258fc90d4081812cc9685a6d71e740306355 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:46:44 +0800 Subject: [PATCH 11/29] Rename infra/conf/dns_bootstrap_android.go to transport/internet/system_dns_android.go --- .../internet/system_dns_android.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename infra/conf/dns_bootstrap_android.go => transport/internet/system_dns_android.go (100%) diff --git a/infra/conf/dns_bootstrap_android.go b/transport/internet/system_dns_android.go similarity index 100% rename from infra/conf/dns_bootstrap_android.go rename to transport/internet/system_dns_android.go From 995f793de833826e50f1f9a4e63c9243757c6d38 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:46:59 +0800 Subject: [PATCH 12/29] Update system_dns_android.go --- transport/internet/system_dns_android.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go index 29ca2d1c25c..f92a2fb3384 100644 --- a/transport/internet/system_dns_android.go +++ b/transport/internet/system_dns_android.go @@ -1,6 +1,6 @@ // +build android -package conf +package internet import ( "context" From aba9fbdf6795fa40e186d5c6425a4044207e7429 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:47:48 +0800 Subject: [PATCH 13/29] Update and rename infra/conf/dns_bootstrap_android_test.go to transport/internet/system_dns_android_test.go --- .../internet/system_dns_android_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename infra/conf/dns_bootstrap_android_test.go => transport/internet/system_dns_android_test.go (97%) diff --git a/infra/conf/dns_bootstrap_android_test.go b/transport/internet/system_dns_android_test.go similarity index 97% rename from infra/conf/dns_bootstrap_android_test.go rename to transport/internet/system_dns_android_test.go index f1eee5d1de6..2e452d17e50 100644 --- a/infra/conf/dns_bootstrap_android_test.go +++ b/transport/internet/system_dns_android_test.go @@ -1,6 +1,6 @@ // +build android -package conf +package internet import ( "context" From 88f030244f07febc159852ff4669c0df82a5d537 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 11:51:29 +0800 Subject: [PATCH 14/29] no imports --- transport/internet/system_dns_android_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/transport/internet/system_dns_android_test.go b/transport/internet/system_dns_android_test.go index 2e452d17e50..1b8b68f38f7 100644 --- a/transport/internet/system_dns_android_test.go +++ b/transport/internet/system_dns_android_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/v2fly/v2ray-core/v4/common/net" - "github.com/v2fly/v2ray-core/v4/transport/internet" ) func TestBootstrapDNS(t *testing.T) { @@ -25,7 +24,7 @@ func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { if err != nil { return nil, err } - return internet.DialSystem(ctx, dest, nil) + return DialSystem(ctx, dest, nil) } UseAlternativeBootstrapDNS(bootstrapDialer) From 33b6d12a37b2eb26d6da56a0fd714c46c0f1322a Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 14:56:17 +0800 Subject: [PATCH 15/29] Update system_dns_android.go --- transport/internet/system_dns_android.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go index f92a2fb3384..c52afc0ae52 100644 --- a/transport/internet/system_dns_android.go +++ b/transport/internet/system_dns_android.go @@ -7,9 +7,9 @@ import ( "net" ) -type DialerFunc func(context.Context, string, string) (net.Conn, error) +type BootstrapDialerFunc func(context.Context, string, string) (net.Conn, error) -func UseAlternativeBootstrapDNS(dialer DialerFunc) { +func UseAlternativeBootstrapDNS(dialer BootstrapDialerFunc) { net.DefaultResolver = &net.Resolver{ PreferGo: true, Dial: dialer, @@ -18,7 +18,7 @@ func UseAlternativeBootstrapDNS(dialer DialerFunc) { func init() { const bootstrapDNS = "8.8.8.8:53" - bootstrapDialer := func(ctx context.Context, network, _ string) (net.Conn, error) { + var bootstrapDialer BootstrapDialerFunc = func(ctx context.Context, network, _ string) (net.Conn, error) { var dialer net.Dialer return dialer.DialContext(ctx, network, bootstrapDNS) } From 25551288283e6554d07f3ca5f6db12405a0e516c Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 14:57:27 +0800 Subject: [PATCH 16/29] Update system_dns_android_test.go --- transport/internet/system_dns_android_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport/internet/system_dns_android_test.go b/transport/internet/system_dns_android_test.go index 1b8b68f38f7..abb6ea6af99 100644 --- a/transport/internet/system_dns_android_test.go +++ b/transport/internet/system_dns_android_test.go @@ -19,7 +19,7 @@ func TestBootstrapDNS(t *testing.T) { func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { const bootstrapDNS = "8.8.4.4:53" - bootstrapDialer := func(ctx context.Context, network, _ string) (gonet.Conn, error) { + var bootstrapDialer BootstrapDialerFunc = func(ctx context.Context, network, _ string) (gonet.Conn, error) { dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, bootstrapDNS)) if err != nil { return nil, err From b98f06d600de0189a699bd99d3ba1e00d52006d0 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:13:40 +0800 Subject: [PATCH 17/29] create systemDNS --- transport/internet/system_dns.go | 18 +++++++++++++++ transport/internet/system_dns_android.go | 28 ------------------------ 2 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 transport/internet/system_dns.go delete mode 100644 transport/internet/system_dns_android.go diff --git a/transport/internet/system_dns.go b/transport/internet/system_dns.go new file mode 100644 index 00000000000..bc93660e35b --- /dev/null +++ b/transport/internet/system_dns.go @@ -0,0 +1,18 @@ +package internet + +import ( + "context" + "net" +) + +type DNSResolverFunc func() *net.Resolver + +var NewDNSResolver DNSResolverFunc = func() *net.Resolver { + return &net.Resolver{ + PreferGo: true, + Dial: func(ctx context.Context, network, address string) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, network, address) + }, + } +} diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go deleted file mode 100644 index c52afc0ae52..00000000000 --- a/transport/internet/system_dns_android.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build android - -package internet - -import ( - "context" - "net" -) - -type BootstrapDialerFunc func(context.Context, string, string) (net.Conn, error) - -func UseAlternativeBootstrapDNS(dialer BootstrapDialerFunc) { - net.DefaultResolver = &net.Resolver{ - PreferGo: true, - Dial: dialer, - } -} - -func init() { - const bootstrapDNS = "8.8.8.8:53" - var bootstrapDialer BootstrapDialerFunc = func(ctx context.Context, network, _ string) (net.Conn, error) { - var dialer net.Dialer - return dialer.DialContext(ctx, network, bootstrapDNS) - } - UseAlternativeBootstrapDNS(bootstrapDialer) - - newError("Android Bootstrap DNS: ", bootstrapDNS).AtWarning().WriteToLog() -} From 066a1eb3306cf26b6bd8fea03e76385feafc475c Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:19:42 +0800 Subject: [PATCH 18/29] Create system_dns_android.go --- transport/internet/system_dns_android.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 transport/internet/system_dns_android.go diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go new file mode 100644 index 00000000000..22c53c19a23 --- /dev/null +++ b/transport/internet/system_dns_android.go @@ -0,0 +1,21 @@ +// +build android + +package internet + +import ( + "context" + "net" +) + +func init() { + NewDNSResolver = func() *net.Resolver { + return &net.Resolver{ + PreferGo: true, + Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { + const systemDNS = "8.8.8.8:53" + var dialer net.Dialer + return dialer.DialContext(ctx, network, systemDNS) + }, + } + } +} From 02c1267624cbf3e792c2ca9eb3a3f5648ee74f8e Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:21:45 +0800 Subject: [PATCH 19/29] Update system_dialer.go --- transport/internet/system_dialer.go | 1 - 1 file changed, 1 deletion(-) diff --git a/transport/internet/system_dialer.go b/transport/internet/system_dialer.go index f46cb54847b..3724590b864 100644 --- a/transport/internet/system_dialer.go +++ b/transport/internet/system_dialer.go @@ -68,7 +68,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne dialer := &net.Dialer{ Timeout: time.Second * 16, - DualStack: true, LocalAddr: resolveSrcAddr(dest.Network, src), } From 528c268ff56ef83b963513c5ec951cfd4617c0a7 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:22:34 +0800 Subject: [PATCH 20/29] call Resolver on systemDialer --- transport/internet/system_dialer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/transport/internet/system_dialer.go b/transport/internet/system_dialer.go index 3724590b864..c52f711bece 100644 --- a/transport/internet/system_dialer.go +++ b/transport/internet/system_dialer.go @@ -69,6 +69,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne dialer := &net.Dialer{ Timeout: time.Second * 16, LocalAddr: resolveSrcAddr(dest.Network, src), + Resolver: NewDNSResolver(), } if sockopt != nil || len(d.controllers) > 0 { From 4376c72c391f5d9b36a78c054cbc73b4c684fc90 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:34:15 +0800 Subject: [PATCH 21/29] create system_dns_test.go --- transport/internet/system_dns_android_test.go | 32 ----------------- transport/internet/system_dns_test.go | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 transport/internet/system_dns_android_test.go create mode 100644 transport/internet/system_dns_test.go diff --git a/transport/internet/system_dns_android_test.go b/transport/internet/system_dns_android_test.go deleted file mode 100644 index abb6ea6af99..00000000000 --- a/transport/internet/system_dns_android_test.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build android - -package internet - -import ( - "context" - "fmt" - gonet "net" - "testing" - - "github.com/v2fly/v2ray-core/v4/common/net" -) - -func TestBootstrapDNS(t *testing.T) { - if ips, err := gonet.LookupIP("www.google.com"); len(ips) == 0 { - t.Errorf("failed to lookupIP with BootstrapDNS, %v", err) - } -} - -func TestBootstrapDNSWithV2raySystemDialer(t *testing.T) { - const bootstrapDNS = "8.8.4.4:53" - var bootstrapDialer BootstrapDialerFunc = func(ctx context.Context, network, _ string) (gonet.Conn, error) { - dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, bootstrapDNS)) - if err != nil { - return nil, err - } - return DialSystem(ctx, dest, nil) - } - UseAlternativeBootstrapDNS(bootstrapDialer) - - TestBootstrapDNS(t) -} diff --git a/transport/internet/system_dns_test.go b/transport/internet/system_dns_test.go new file mode 100644 index 00000000000..919fc9c2ad3 --- /dev/null +++ b/transport/internet/system_dns_test.go @@ -0,0 +1,35 @@ +package internet + +import ( + "context" + "fmt" + gonet "net" + "testing" + + "github.com/v2fly/v2ray-core/v4/common/net" +) + +func TestDNSResolver(t *testing.T) { + resolver := NewDNSResolver() + if ips, err := resolver.LookupIP("www.google.com"); err != nil { + t.Errorf("failed to lookupIP with BootstrapDNS, %v, %v", ips, err) + } +} + +func TestSystemDNSResolver(t *testing.T) { + NewDNSResolver = func() *gonet.Resolver { + return &gonet.Resolver{ + PreferGo: true, + Dial: func(ctx context.Context, network, _ string) (gonet.Conn, error) { + const systemDNS = "8.8.8.8:53" + dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, systemDNS)) + if err != nil { + return nil, err + } + return DialSystem(ctx, dest, nil) + }, + } + } + + TestDNSResolver(t) +} From 63a800f805d7a4f41d5bc3f4fe8e4aa1c7502c5a Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:38:09 +0800 Subject: [PATCH 22/29] resolver.LookupIP params --- transport/internet/system_dns_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport/internet/system_dns_test.go b/transport/internet/system_dns_test.go index 919fc9c2ad3..83a4ba1bc31 100644 --- a/transport/internet/system_dns_test.go +++ b/transport/internet/system_dns_test.go @@ -11,7 +11,7 @@ import ( func TestDNSResolver(t *testing.T) { resolver := NewDNSResolver() - if ips, err := resolver.LookupIP("www.google.com"); err != nil { + if ips, err := resolver.LookupIP(context.Background(), "tcp", "www.google.com"); err != nil { t.Errorf("failed to lookupIP with BootstrapDNS, %v, %v", ips, err) } } From 06129f81e338aa4ee6e3ad7ba4d0e68818c60283 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:45:35 +0800 Subject: [PATCH 23/29] param fix --- transport/internet/system_dns_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport/internet/system_dns_test.go b/transport/internet/system_dns_test.go index 83a4ba1bc31..7f94841c4fb 100644 --- a/transport/internet/system_dns_test.go +++ b/transport/internet/system_dns_test.go @@ -11,7 +11,7 @@ import ( func TestDNSResolver(t *testing.T) { resolver := NewDNSResolver() - if ips, err := resolver.LookupIP(context.Background(), "tcp", "www.google.com"); err != nil { + if ips, err := resolver.LookupIP(context.Background(), "ip", "www.google.com"); err != nil { t.Errorf("failed to lookupIP with BootstrapDNS, %v, %v", ips, err) } } From 56614cca69460195b621bed43bdfb4d2fd55aa14 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 17:57:03 +0800 Subject: [PATCH 24/29] noneed TestSystemDNSResolver --- transport/internet/system_dns_test.go | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/transport/internet/system_dns_test.go b/transport/internet/system_dns_test.go index 7f94841c4fb..12551760439 100644 --- a/transport/internet/system_dns_test.go +++ b/transport/internet/system_dns_test.go @@ -2,34 +2,12 @@ package internet import ( "context" - "fmt" - gonet "net" "testing" - - "github.com/v2fly/v2ray-core/v4/common/net" ) 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 with BootstrapDNS, %v, %v", ips, err) + t.Errorf("failed to lookupIP, %v, %v", ips, err) } } - -func TestSystemDNSResolver(t *testing.T) { - NewDNSResolver = func() *gonet.Resolver { - return &gonet.Resolver{ - PreferGo: true, - Dial: func(ctx context.Context, network, _ string) (gonet.Conn, error) { - const systemDNS = "8.8.8.8:53" - dest, err := net.ParseDestination(fmt.Sprintf("%s:%s", network, systemDNS)) - if err != nil { - return nil, err - } - return DialSystem(ctx, dest, nil) - }, - } - } - - TestDNSResolver(t) -} From f35b82c712140a21015b8512c3700a461a6d42d2 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 21:53:40 +0800 Subject: [PATCH 25/29] revert: no specified resolver --- transport/internet/system_dialer.go | 1 - 1 file changed, 1 deletion(-) diff --git a/transport/internet/system_dialer.go b/transport/internet/system_dialer.go index c52f711bece..3724590b864 100644 --- a/transport/internet/system_dialer.go +++ b/transport/internet/system_dialer.go @@ -69,7 +69,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne dialer := &net.Dialer{ Timeout: time.Second * 16, LocalAddr: resolveSrcAddr(dest.Network, src), - Resolver: NewDNSResolver(), } if sockopt != nil || len(d.controllers) > 0 { From 00c452b722579019cf6029e201b23c392a1b1f22 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 21:54:01 +0800 Subject: [PATCH 26/29] Delete system_dns.go --- transport/internet/system_dns.go | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 transport/internet/system_dns.go diff --git a/transport/internet/system_dns.go b/transport/internet/system_dns.go deleted file mode 100644 index bc93660e35b..00000000000 --- a/transport/internet/system_dns.go +++ /dev/null @@ -1,18 +0,0 @@ -package internet - -import ( - "context" - "net" -) - -type DNSResolverFunc func() *net.Resolver - -var NewDNSResolver DNSResolverFunc = func() *net.Resolver { - return &net.Resolver{ - PreferGo: true, - Dial: func(ctx context.Context, network, address string) (net.Conn, error) { - var dialer net.Dialer - return dialer.DialContext(ctx, network, address) - }, - } -} From 6033eaf45aca4fcabf03b77a5cc04ee1098d5384 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 21:59:26 +0800 Subject: [PATCH 27/29] android only --- transport/internet/system_dns_android.go | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go index 22c53c19a23..df98c3fe928 100644 --- a/transport/internet/system_dns_android.go +++ b/transport/internet/system_dns_android.go @@ -7,15 +7,23 @@ import ( "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() { - NewDNSResolver = func() *net.Resolver { - return &net.Resolver{ - PreferGo: true, - Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { - const systemDNS = "8.8.8.8:53" - var dialer net.Dialer - return dialer.DialContext(ctx, network, systemDNS) - }, - } + net.DefaultResolver = &net.Resolver{ + PreferGo: true, + Dial: NewDNSResolver(), } } From b424575158610832c37178930b5d6bea4680c3c9 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 22:00:40 +0800 Subject: [PATCH 28/29] android only test --- .../internet/{system_dns_test.go => system_dns_android_test.go} | 2 ++ 1 file changed, 2 insertions(+) rename transport/internet/{system_dns_test.go => system_dns_android_test.go} (93%) diff --git a/transport/internet/system_dns_test.go b/transport/internet/system_dns_android_test.go similarity index 93% rename from transport/internet/system_dns_test.go rename to transport/internet/system_dns_android_test.go index 12551760439..d019c03917d 100644 --- a/transport/internet/system_dns_test.go +++ b/transport/internet/system_dns_android_test.go @@ -1,3 +1,5 @@ +// +build android + package internet import ( From f7903f2a390a779876c4e790fe283ebc383974eb Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Tue, 4 May 2021 22:06:21 +0800 Subject: [PATCH 29/29] typo --- transport/internet/system_dns_android.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/transport/internet/system_dns_android.go b/transport/internet/system_dns_android.go index df98c3fe928..5591d811c63 100644 --- a/transport/internet/system_dns_android.go +++ b/transport/internet/system_dns_android.go @@ -22,8 +22,5 @@ var NewDNSResolver DNSResolverFunc = func() *net.Resolver { } func init() { - net.DefaultResolver = &net.Resolver{ - PreferGo: true, - Dial: NewDNSResolver(), - } + net.DefaultResolver = NewDNSResolver() }