mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-25 19:55:38 +08:00
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"github.com/Dreamacro/clash/component/trie"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
"github.com/Dreamacro/clash/log"
|
|
)
|
|
|
|
type domainStrategy struct {
|
|
count int
|
|
domainTrie *trie.DomainTrie[struct{}]
|
|
domainSet *trie.DomainSet
|
|
}
|
|
|
|
func (d *domainStrategy) ShouldFindProcess() bool {
|
|
return false
|
|
}
|
|
|
|
func (d *domainStrategy) Match(metadata *C.Metadata) bool {
|
|
return d.domainSet != nil && d.domainSet.Has(metadata.RuleHost())
|
|
}
|
|
|
|
func (d *domainStrategy) Count() int {
|
|
return d.count
|
|
}
|
|
|
|
func (d *domainStrategy) ShouldResolveIP() bool {
|
|
return false
|
|
}
|
|
|
|
func (d *domainStrategy) Reset() {
|
|
d.domainTrie = trie.New[struct{}]()
|
|
d.domainSet = nil
|
|
d.count = 0
|
|
}
|
|
|
|
func (d *domainStrategy) Insert(rule string) {
|
|
err := d.domainTrie.Insert(rule, struct{}{})
|
|
if err != nil {
|
|
log.Warnln("invalid domain:[%s]", rule)
|
|
} else {
|
|
d.count++
|
|
}
|
|
}
|
|
|
|
func (d *domainStrategy) FinishInsert() {
|
|
d.domainSet = d.domainTrie.NewDomainSet()
|
|
d.domainTrie = nil
|
|
}
|
|
|
|
func NewDomainStrategy() *domainStrategy {
|
|
return &domainStrategy{}
|
|
}
|