mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
fix: count error
This commit is contained in:
parent
7421c5f70a
commit
3a136cce56
|
@ -32,6 +32,7 @@ func (c *classicalStrategy) ShouldResolveIP() bool {
|
||||||
func (c *classicalStrategy) OnUpdate(rules []string) {
|
func (c *classicalStrategy) OnUpdate(rules []string) {
|
||||||
var classicalRules []C.Rule
|
var classicalRules []C.Rule
|
||||||
shouldResolveIP := false
|
shouldResolveIP := false
|
||||||
|
count := 0
|
||||||
for _, rawRule := range rules {
|
for _, rawRule := range rules {
|
||||||
ruleType, rule, params := ruleParse(rawRule)
|
ruleType, rule, params := ruleParse(rawRule)
|
||||||
r, err := parseRule(ruleType, rule, "", params)
|
r, err := parseRule(ruleType, rule, "", params)
|
||||||
|
@ -43,11 +44,12 @@ func (c *classicalStrategy) OnUpdate(rules []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
classicalRules = append(classicalRules, r)
|
classicalRules = append(classicalRules, r)
|
||||||
c.count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.rules = classicalRules
|
c.rules = classicalRules
|
||||||
|
c.count = count
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClassicalStrategy() *classicalStrategy {
|
func NewClassicalStrategy() *classicalStrategy {
|
||||||
|
|
|
@ -27,16 +27,18 @@ func (d *domainStrategy) ShouldResolveIP() bool {
|
||||||
|
|
||||||
func (d *domainStrategy) OnUpdate(rules []string) {
|
func (d *domainStrategy) OnUpdate(rules []string) {
|
||||||
domainTrie := trie.New[bool]()
|
domainTrie := trie.New[bool]()
|
||||||
|
count := 0
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
err := domainTrie.Insert(rule, true)
|
err := domainTrie.Insert(rule, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("invalid domain:[%s]", rule)
|
log.Warnln("invalid domain:[%s]", rule)
|
||||||
} else {
|
} else {
|
||||||
d.count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.domainRules = domainTrie
|
d.domainRules = domainTrie
|
||||||
|
d.count = count
|
||||||
}
|
}
|
||||||
|
|
||||||
func ruleParse(ruleRaw string) (string, string, []string) {
|
func ruleParse(ruleRaw string) (string, string, []string) {
|
||||||
|
|
|
@ -26,16 +26,18 @@ func (i *ipcidrStrategy) ShouldResolveIP() bool {
|
||||||
|
|
||||||
func (i *ipcidrStrategy) OnUpdate(rules []string) {
|
func (i *ipcidrStrategy) OnUpdate(rules []string) {
|
||||||
ipCidrTrie := trie.NewIpCidrTrie()
|
ipCidrTrie := trie.NewIpCidrTrie()
|
||||||
|
count := 0
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
err := ipCidrTrie.AddIpCidrForString(rule)
|
err := ipCidrTrie.AddIpCidrForString(rule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("invalid Ipcidr:[%s]", rule)
|
log.Warnln("invalid Ipcidr:[%s]", rule)
|
||||||
} else {
|
} else {
|
||||||
i.count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i.trie = ipCidrTrie
|
i.trie = ipCidrTrie
|
||||||
|
i.count = count
|
||||||
i.shouldResolveIP = i.count > 0
|
i.shouldResolveIP = i.count > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user