mihomo/dns/policy.go

35 lines
639 B
Go
Raw 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"
)
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
}
2024-08-15 20:04:24 +08:00
type domainRulePolicy struct {
rule C.Rule
dnsClients []dnsClient
}
2024-08-15 20:04:24 +08:00
func (p domainRulePolicy) Match(domain string) []dnsClient {
if ok, _ := p.rule.Match(&C.Metadata{Host: domain}); ok {
return p.dnsClients
2022-04-06 04:25:53 +08:00
}
return nil
}