|
|
@ -17,20 +17,22 @@ import (
|
|
|
|
"golang.org/x/sync/singleflight"
|
|
|
|
"golang.org/x/sync/singleflight"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var single = func() *Resolver {
|
|
|
|
var single = &Resolver{
|
|
|
|
r := &Resolver{
|
|
|
|
Forward: &net.Resolver{PreferGo: preferGoResolver()},
|
|
|
|
Forward: &net.Resolver{PreferGo: true},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func preferGoResolver() bool {
|
|
|
|
// There does not appear to be a local resolver running
|
|
|
|
// There does not appear to be a local resolver running
|
|
|
|
// on iOS, and NetworkExtension is good at isolating DNS.
|
|
|
|
// on iOS, and NetworkExtension is good at isolating DNS.
|
|
|
|
// So do not use the Go resolver on macOS/iOS.
|
|
|
|
// So do not use the Go resolver on macOS/iOS.
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
r.Forward.PreferGo = false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return r
|
|
|
|
// Otherwise, the Go resolver is fine and slightly preferred
|
|
|
|
}()
|
|
|
|
// since it's lighter, not using cgo calls & threads.
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get returns a caching Resolver singleton.
|
|
|
|
// Get returns a caching Resolver singleton.
|
|
|
|
func Get() *Resolver { return single }
|
|
|
|
func Get() *Resolver { return single }
|
|
|
|