mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00:00
chore: no longer used net.DefaultResolver when dns section is disabled, now is equally only "system://"
This commit is contained in:
@@ -12,6 +12,12 @@ func FlushCacheWithDefaultResolver() {
|
||||
if r := resolver.DefaultResolver; r != nil {
|
||||
r.ClearCache()
|
||||
}
|
||||
if r := resolver.ProxyServerHostResolver; r != nil {
|
||||
r.ClearCache()
|
||||
}
|
||||
if r := resolver.SystemResolver; r != nil {
|
||||
r.ClearCache()
|
||||
}
|
||||
resolver.ResetConnection()
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
"github.com/metacubex/mihomo/component/trie"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/constant/provider"
|
||||
"github.com/metacubex/mihomo/log"
|
||||
|
||||
D "github.com/miekg/dns"
|
||||
@@ -436,7 +435,6 @@ type Config struct {
|
||||
Pool *fakeip.Pool
|
||||
Hosts *trie.DomainTrie[resolver.HostValue]
|
||||
Policy []Policy
|
||||
Tunnel provider.Tunnel
|
||||
CacheAlgorithm string
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/component/resolver"
|
||||
|
||||
D "github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -24,12 +26,17 @@ type systemClient struct {
|
||||
mu sync.Mutex
|
||||
dnsClients map[string]*systemDnsClient
|
||||
lastFlush time.Time
|
||||
defaultNS []dnsClient
|
||||
}
|
||||
|
||||
func (c *systemClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
|
||||
dnsClients, err := c.getDnsClients()
|
||||
if err != nil {
|
||||
return
|
||||
if len(c.defaultNS) > 0 {
|
||||
dnsClients = c.defaultNS
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
msg, _, err = batchExchange(ctx, dnsClients, m)
|
||||
return
|
||||
@@ -52,3 +59,11 @@ func newSystemClient() *systemClient {
|
||||
dnsClients: map[string]*systemDnsClient{},
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
r, _ := NewResolver(Config{})
|
||||
c := newSystemClient()
|
||||
c.defaultNS = transform([]NameServer{{Addr: "114.114.114.114:53"}, {Addr: "8.8.8.8:53"}}, nil)
|
||||
r.main = []dnsClient{c}
|
||||
resolver.SystemResolver = r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user