feat: nameserver-policy
support domain-set, reduce domain-set memory usage
This commit is contained in:
@ -3,13 +3,11 @@ package provider
|
||||
import (
|
||||
"github.com/Dreamacro/clash/component/trie"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
type domainStrategy struct {
|
||||
count int
|
||||
domainRules *trie.DomainTrie[struct{}]
|
||||
domainRules *trie.Set
|
||||
}
|
||||
|
||||
func (d *domainStrategy) ShouldFindProcess() bool {
|
||||
@ -17,7 +15,7 @@ func (d *domainStrategy) ShouldFindProcess() bool {
|
||||
}
|
||||
|
||||
func (d *domainStrategy) Match(metadata *C.Metadata) bool {
|
||||
return d.domainRules != nil && d.domainRules.Search(metadata.RuleHost()) != nil
|
||||
return d.domainRules != nil && d.domainRules.Has(metadata.RuleHost())
|
||||
}
|
||||
|
||||
func (d *domainStrategy) Count() int {
|
||||
@ -29,21 +27,9 @@ func (d *domainStrategy) ShouldResolveIP() bool {
|
||||
}
|
||||
|
||||
func (d *domainStrategy) OnUpdate(rules []string) {
|
||||
domainTrie := trie.New[struct{}]()
|
||||
count := 0
|
||||
for _, rule := range rules {
|
||||
actualDomain, _ := idna.ToASCII(rule)
|
||||
err := domainTrie.Insert(actualDomain, struct{}{})
|
||||
if err != nil {
|
||||
log.Warnln("invalid domain:[%s]", rule)
|
||||
} else {
|
||||
count++
|
||||
}
|
||||
}
|
||||
domainTrie.Optimize()
|
||||
|
||||
domainTrie := trie.NewDomainTrieSet(rules)
|
||||
d.domainRules = domainTrie
|
||||
d.count = count
|
||||
d.count = len(rules)
|
||||
}
|
||||
|
||||
func NewDomainStrategy() *domainStrategy {
|
||||
|
Reference in New Issue
Block a user