mihomo/rules/provider/domain_strategy.go

38 lines
738 B
Go
Raw Normal View History

2022-03-26 18:34:15 +08:00
package provider
import (
"github.com/Dreamacro/clash/component/trie"
C "github.com/Dreamacro/clash/constant"
)
type domainStrategy struct {
count int
domainRules *trie.DomainSet
2022-03-26 18:34:15 +08:00
}
func (d *domainStrategy) ShouldFindProcess() bool {
return false
}
2022-03-26 18:34:15 +08:00
func (d *domainStrategy) Match(metadata *C.Metadata) bool {
return d.domainRules != nil && d.domainRules.Has(metadata.RuleHost())
2022-03-26 18:34:15 +08:00
}
func (d *domainStrategy) Count() int {
return d.count
}
func (d *domainStrategy) ShouldResolveIP() bool {
return false
2022-03-26 18:34:15 +08:00
}
func (d *domainStrategy) OnUpdate(rules []string) {
domainTrie := trie.NewDomainSet(rules)
2022-03-26 18:34:15 +08:00
d.domainRules = domainTrie
d.count = len(rules)
2022-03-26 18:34:15 +08:00
}
func NewDomainStrategy() *domainStrategy {
return &domainStrategy{}
2022-03-26 18:34:15 +08:00
}