github.com/kelleygo/clashcore@v1.0.2/dns/policy.go (about) 1 package dns 2 3 import ( 4 "github.com/kelleygo/clashcore/component/trie" 5 C "github.com/kelleygo/clashcore/constant" 6 "github.com/kelleygo/clashcore/constant/provider" 7 ) 8 9 type dnsPolicy interface { 10 Match(domain string) []dnsClient 11 } 12 13 type domainTriePolicy struct { 14 *trie.DomainTrie[[]dnsClient] 15 } 16 17 func (p domainTriePolicy) Match(domain string) []dnsClient { 18 record := p.DomainTrie.Search(domain) 19 if record != nil { 20 return record.Data() 21 } 22 return nil 23 } 24 25 type geositePolicy struct { 26 matcher fallbackDomainFilter 27 inverse bool 28 dnsClients []dnsClient 29 } 30 31 func (p geositePolicy) Match(domain string) []dnsClient { 32 matched := p.matcher.Match(domain) 33 if matched != p.inverse { 34 return p.dnsClients 35 } 36 return nil 37 } 38 39 type domainSetPolicy struct { 40 domainSetProvider provider.RuleProvider 41 dnsClients []dnsClient 42 } 43 44 func (p domainSetPolicy) Match(domain string) []dnsClient { 45 metadata := &C.Metadata{Host: domain} 46 if ok := p.domainSetProvider.Match(metadata); ok { 47 return p.dnsClients 48 } 49 return nil 50 }