mihomo/dns/policy.go

51 lines
1,013 B
Go
Raw Permalink Normal View History

2022-04-06 04:25:53 +08:00
package dns
import (
"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/provider"
)
type dnsPolicy interface {
Match(domain string) []dnsClient
2022-04-06 04:25:53 +08:00
}
type domainTriePolicy struct {
*trie.DomainTrie[[]dnsClient]
2022-04-06 04:25:53 +08:00
}
func (p domainTriePolicy) Match(domain string) []dnsClient {
record := p.DomainTrie.Search(domain)
if record != nil {
return record.Data()
2022-04-06 04:25:53 +08:00
}
return nil
}
type geositePolicy struct {
matcher fallbackDomainFilter
inverse bool
dnsClients []dnsClient
}
func (p geositePolicy) Match(domain string) []dnsClient {
matched := p.matcher.Match(domain)
if matched != p.inverse {
return p.dnsClients
2022-04-06 04:25:53 +08:00
}
return nil
}
type domainSetPolicy struct {
domainSetProvider provider.RuleProvider
dnsClients []dnsClient
2022-04-06 04:25:53 +08:00
}
func (p domainSetPolicy) Match(domain string) []dnsClient {
metadata := &C.Metadata{Host: domain}
if ok := p.domainSetProvider.Match(metadata); ok {
return p.dnsClients
2022-04-06 04:25:53 +08:00
}
return nil
2022-04-06 04:25:53 +08:00
}