87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"time"
|
|
|
|
resolverpkg "selective-vpn-api/app/resolver"
|
|
)
|
|
|
|
func executeResolverBatch(
|
|
toResolve []string,
|
|
workers int,
|
|
now int,
|
|
staleKeepSec int,
|
|
resolved map[string][]string,
|
|
domainCache *domainCacheState,
|
|
cacheSourceForHost func(string) domainCacheSource,
|
|
resolveHost func(string) ([]string, dnsMetrics),
|
|
logf func(string, ...any),
|
|
) resolverResolveBatchResult {
|
|
if domainCache == nil {
|
|
return resolverResolveBatchResult{}
|
|
}
|
|
sourceFn := func(host string) resolverpkg.DomainCacheSource {
|
|
if cacheSourceForHost == nil {
|
|
return resolverpkg.DomainCacheSourceDirect
|
|
}
|
|
return resolverpkg.DomainCacheSource(cacheSourceForHost(host))
|
|
}
|
|
resolveFn := func(host string) ([]string, resolverpkg.DNSMetrics) {
|
|
if resolveHost == nil {
|
|
return nil, resolverpkg.DNSMetrics{}
|
|
}
|
|
return resolveHost(host)
|
|
}
|
|
return resolverpkg.ExecuteResolveBatch(
|
|
resolverpkg.ResolveBatchInput{
|
|
ToResolve: toResolve,
|
|
Workers: workers,
|
|
Now: now,
|
|
StaleKeepSec: staleKeepSec,
|
|
},
|
|
resolved,
|
|
(*resolverpkg.DomainCacheState)(domainCache),
|
|
sourceFn,
|
|
resolveFn,
|
|
logf,
|
|
)
|
|
}
|
|
|
|
func runTimeoutQuarantineRecheck(
|
|
domains []string,
|
|
cfg dnsConfig,
|
|
metaSpecial []string,
|
|
wildcards wildcardMatcher,
|
|
timeout time.Duration,
|
|
domainCache *domainCacheState,
|
|
cacheSourceForHost func(string) domainCacheSource,
|
|
now int,
|
|
limit int,
|
|
workers int,
|
|
) resolverTimeoutRecheckStats {
|
|
if domainCache == nil {
|
|
return resolverTimeoutRecheckStats{}
|
|
}
|
|
sourceFn := func(host string) resolverpkg.DomainCacheSource {
|
|
if cacheSourceForHost == nil {
|
|
return resolverpkg.DomainCacheSourceDirect
|
|
}
|
|
return resolverpkg.DomainCacheSource(cacheSourceForHost(host))
|
|
}
|
|
return resolverpkg.RunTimeoutQuarantineRecheck(
|
|
domains,
|
|
now,
|
|
limit,
|
|
workers,
|
|
(*resolverpkg.DomainCacheState)(domainCache),
|
|
sourceFn,
|
|
func(host string) ([]string, resolverpkg.DNSMetrics) {
|
|
return resolveHostGo(host, cfg, metaSpecial, wildcards, timeout, nil, nil)
|
|
},
|
|
)
|
|
}
|
|
|
|
func buildResolverArtifacts(resolved map[string][]string, staticLabels map[string][]string, isWildcardHost func(string) bool) resolverpkg.ResolverArtifacts {
|
|
return resolverpkg.BuildResolverArtifacts(resolved, staticLabels, isWildcardHost)
|
|
}
|