chore: code cleanup
This commit is contained in:
parent
1d1841f7aa
commit
b538aa6ca2
1 changed files with 7 additions and 6 deletions
|
@ -483,12 +483,15 @@ func NewResolver(config Config) *Resolver {
|
||||||
r.policy = make([]dnsPolicy, 0)
|
r.policy = make([]dnsPolicy, 0)
|
||||||
|
|
||||||
var triePolicy *trie.DomainTrie[[]dnsClient]
|
var triePolicy *trie.DomainTrie[[]dnsClient]
|
||||||
insertTriePolicy := func() {
|
insertPolicy := func(policy dnsPolicy) {
|
||||||
if triePolicy != nil {
|
if triePolicy != nil {
|
||||||
triePolicy.Optimize()
|
triePolicy.Optimize()
|
||||||
r.policy = append(r.policy, domainTriePolicy{triePolicy})
|
r.policy = append(r.policy, domainTriePolicy{triePolicy})
|
||||||
triePolicy = nil
|
triePolicy = nil
|
||||||
}
|
}
|
||||||
|
if policy != nil {
|
||||||
|
r.policy = append(r.policy, policy)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for pair := config.Policy.Oldest(); pair != nil; pair = pair.Next() {
|
for pair := config.Policy.Oldest(); pair != nil; pair = pair.Next() {
|
||||||
|
@ -501,8 +504,7 @@ func NewResolver(config Config) *Resolver {
|
||||||
case "rule-set":
|
case "rule-set":
|
||||||
if p, ok := config.RuleProviders[key]; ok {
|
if p, ok := config.RuleProviders[key]; ok {
|
||||||
log.Debugln("Adding rule-set policy: %s ", key)
|
log.Debugln("Adding rule-set policy: %s ", key)
|
||||||
insertTriePolicy()
|
insertPolicy(domainSetPolicy{
|
||||||
r.policy = append(r.policy, domainSetPolicy{
|
|
||||||
domainSetProvider: p,
|
domainSetProvider: p,
|
||||||
dnsClients: cacheTransform(nameserver),
|
dnsClients: cacheTransform(nameserver),
|
||||||
})
|
})
|
||||||
|
@ -522,8 +524,7 @@ func NewResolver(config Config) *Resolver {
|
||||||
log.Warnln("adding geosite policy %s error: %s", key, err)
|
log.Warnln("adding geosite policy %s error: %s", key, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
insertTriePolicy()
|
insertPolicy(geositePolicy{
|
||||||
r.policy = append(r.policy, geositePolicy{
|
|
||||||
matcher: matcher,
|
matcher: matcher,
|
||||||
inverse: inverse,
|
inverse: inverse,
|
||||||
dnsClients: cacheTransform(nameserver),
|
dnsClients: cacheTransform(nameserver),
|
||||||
|
@ -536,7 +537,7 @@ func NewResolver(config Config) *Resolver {
|
||||||
}
|
}
|
||||||
_ = triePolicy.Insert(domain, cacheTransform(nameserver))
|
_ = triePolicy.Insert(domain, cacheTransform(nameserver))
|
||||||
}
|
}
|
||||||
insertTriePolicy()
|
insertPolicy(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
fallbackIPFilters := []fallbackIPFilter{}
|
fallbackIPFilters := []fallbackIPFilter{}
|
||||||
|
|
Loading…
Reference in a new issue