mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"github.com/metacubex/mihomo/component/trie"
|
|
C "github.com/metacubex/mihomo/constant"
|
|
"github.com/metacubex/mihomo/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{}
|
|
}
|