fix: count error
This commit is contained in:
parent
ffb49ba4c5
commit
30eaa8add6
3 changed files with 9 additions and 3 deletions
|
@ -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 a new issue