2022-04-06 04:25:53 +08:00
|
|
|
package dns
|
|
|
|
|
2023-11-08 19:29:26 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-11-08 19:29:26 +08:00
|
|
|
type domainTriePolicy struct {
|
|
|
|
*trie.DomainTrie[[]dnsClient]
|
2022-04-06 04:25:53 +08:00
|
|
|
}
|
|
|
|
|
2023-11-08 19:29:26 +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
|
|
|
}
|
2023-11-08 19:29:26 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-08-28 12:25:45 +08:00
|
|
|
type domainMatcherPolicy struct {
|
|
|
|
matcher C.DomainMatcher
|
2023-11-08 19:29:26 +08:00
|
|
|
dnsClients []dnsClient
|
|
|
|
}
|
|
|
|
|
2024-08-28 12:25:45 +08:00
|
|
|
func (p domainMatcherPolicy) Match(domain string) []dnsClient {
|
|
|
|
if p.matcher.MatchDomain(domain) {
|
2023-11-08 19:29:26 +08:00
|
|
|
return p.dnsClients
|
2022-04-06 04:25:53 +08:00
|
|
|
}
|
2023-11-08 19:29:26 +08:00
|
|
|
return nil
|
|
|
|
}
|