mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 21:31:16 +08:00
35 lines
631 B
Go
35 lines
631 B
Go
package dns
|
|
|
|
import (
|
|
"github.com/metacubex/mihomo/component/trie"
|
|
C "github.com/metacubex/mihomo/constant"
|
|
)
|
|
|
|
type dnsPolicy interface {
|
|
Match(domain string) []dnsClient
|
|
}
|
|
|
|
type domainTriePolicy struct {
|
|
*trie.DomainTrie[[]dnsClient]
|
|
}
|
|
|
|
func (p domainTriePolicy) Match(domain string) []dnsClient {
|
|
record := p.DomainTrie.Search(domain)
|
|
if record != nil {
|
|
return record.Data()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type domainMatcherPolicy struct {
|
|
matcher C.DomainMatcher
|
|
dnsClients []dnsClient
|
|
}
|
|
|
|
func (p domainMatcherPolicy) Match(domain string) []dnsClient {
|
|
if p.matcher.MatchDomain(domain) {
|
|
return p.dnsClients
|
|
}
|
|
return nil
|
|
}
|