diff --git a/rule/provider/classical_strategy.go b/rule/provider/classical_strategy.go index aba2a4e4..1c2cba4f 100644 --- a/rule/provider/classical_strategy.go +++ b/rule/provider/classical_strategy.go @@ -32,6 +32,7 @@ func (c *classicalStrategy) ShouldResolveIP() bool { func (c *classicalStrategy) OnUpdate(rules []string) { var classicalRules []C.Rule shouldResolveIP := false + count := 0 for _, rawRule := range rules { ruleType, rule, params := ruleParse(rawRule) r, err := parseRule(ruleType, rule, "", params) @@ -43,11 +44,12 @@ func (c *classicalStrategy) OnUpdate(rules []string) { } classicalRules = append(classicalRules, r) - c.count++ + count++ } } c.rules = classicalRules + c.count = count } func NewClassicalStrategy() *classicalStrategy { diff --git a/rule/provider/domain_strategy.go b/rule/provider/domain_strategy.go index 0288c8aa..81979658 100644 --- a/rule/provider/domain_strategy.go +++ b/rule/provider/domain_strategy.go @@ -27,16 +27,18 @@ func (d *domainStrategy) ShouldResolveIP() bool { func (d *domainStrategy) OnUpdate(rules []string) { domainTrie := trie.New[bool]() + count := 0 for _, rule := range rules { err := domainTrie.Insert(rule, true) if err != nil { log.Warnln("invalid domain:[%s]", rule) } else { - d.count++ + count++ } } d.domainRules = domainTrie + d.count = count } func ruleParse(ruleRaw string) (string, string, []string) { diff --git a/rule/provider/ipcidr_strategy.go b/rule/provider/ipcidr_strategy.go index 9853f47e..bba9ddc5 100644 --- a/rule/provider/ipcidr_strategy.go +++ b/rule/provider/ipcidr_strategy.go @@ -26,16 +26,18 @@ func (i *ipcidrStrategy) ShouldResolveIP() bool { func (i *ipcidrStrategy) OnUpdate(rules []string) { ipCidrTrie := trie.NewIpCidrTrie() + count := 0 for _, rule := range rules { err := ipCidrTrie.AddIpCidrForString(rule) if err != nil { log.Warnln("invalid Ipcidr:[%s]", rule) } else { - i.count++ + count++ } } i.trie = ipCidrTrie + i.count = count i.shouldResolveIP = i.count > 0 }