android: only use google dns server when the default dns server cannot be obtained (#4236)

This commit is contained in:
fatedier 2024-05-23 16:09:58 +08:00 committed by GitHub
parent 522e2c94c1
commit e680acf42d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -5,3 +5,4 @@
### Changes ### Changes
* Updated the default value of `transport.tcpMuxKeepaliveInterval` from 60 to 30. * Updated the default value of `transport.tcpMuxKeepaliveInterval` from 60 to 30.
* On the Android platform, the Google DNS server is used only when the default DNS server cannot be obtained.

View File

@ -59,8 +59,12 @@ func fixDNSResolver() {
// Note: If there are other methods to obtain the default DNS servers, the default DNS servers should be used preferentially. // Note: If there are other methods to obtain the default DNS servers, the default DNS servers should be used preferentially.
net.DefaultResolver = &net.Resolver{ net.DefaultResolver = &net.Resolver{
PreferGo: true, PreferGo: true,
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
return net.Dial(network, "8.8.8.8:53") if addr == "127.0.0.1:53" || addr == "[::1]:53" {
addr = "8.8.8.8:53"
}
var d net.Dialer
return d.DialContext(ctx, network, addr)
}, },
} }
} }