feat: перенести DoH-резолвер, добавить флаг -dns
Заменяет bschaatsbergen/dnsdialer (только UDP) на внутренний пакет dnsdial. Добавляет поддержку DNS-over-HTTPS и режим auto (проба UDP/53 → залипающий fallback на DoH при сбое). Новый флаг: -dns udp|doh|auto (по умолчанию: auto)
This commit is contained in:
1 parent
7a0f98f730
commit
4e5690cd04
7 files changed
+940
-115
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package dnsdial
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
dohResolverOnce sync.Once
|
||||
dohResolverInstance *DohResolver
|
||||
)
|
||||
|
||||
func sharedDohResolver() *DohResolver {
|
||||
dohResolverOnce.Do(func() {
|
||||
dohResolverInstance = NewDohResolver(nil)
|
||||
})
|
||||
return dohResolverInstance
|
||||
}
|
||||
|
||||
// AppDialer returns the net.Dialer used by tls-client and other HTTP callers.
|
||||
// DNS transport is selected by mode (udp | doh | auto).
|
||||
func AppDialer(mode string) net.Dialer {
|
||||
return buildDialer(mode, sharedDohResolver())
|
||||
}
|
||||
|
||||
// InstallGlobalResolver wires net.DefaultResolver to the same DNS transport
|
||||
// as AppDialer, so third-party libs that build their own http.Client without
|
||||
// our Dialer still use DoH / auto-fallback instead of the OS resolver.
|
||||
func InstallGlobalResolver(mode string) {
|
||||
d := AppDialer(mode)
|
||||
if d.Resolver != nil {
|
||||
net.DefaultResolver = d.Resolver
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user