platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
97
selective-vpn-api/app/resolver_dns_attempt_policy.go
Normal file
97
selective-vpn-api/app/resolver_dns_attempt_policy.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func defaultDNSAttemptPolicy(dnsCount int) dnsAttemptPolicy {
|
||||
tryLimit := envInt("RESOLVE_DNS_TRY_LIMIT", 2)
|
||||
if tryLimit < 1 {
|
||||
tryLimit = 1
|
||||
}
|
||||
if dnsCount > 0 && tryLimit > dnsCount {
|
||||
tryLimit = dnsCount
|
||||
}
|
||||
budgetMS := envInt("RESOLVE_DNS_DOMAIN_BUDGET_MS", 1200)
|
||||
if budgetMS < 200 {
|
||||
budgetMS = 200
|
||||
}
|
||||
if budgetMS > 15000 {
|
||||
budgetMS = 15000
|
||||
}
|
||||
return dnsAttemptPolicy{
|
||||
TryLimit: tryLimit,
|
||||
DomainBudget: time.Duration(budgetMS) * time.Millisecond,
|
||||
StopOnNX: resolveNXEarlyStopEnabled(),
|
||||
}
|
||||
}
|
||||
|
||||
func directDNSAttemptPolicy(dnsCount int) dnsAttemptPolicy {
|
||||
tryLimit := envInt("RESOLVE_DIRECT_TRY_LIMIT", 2)
|
||||
if tryLimit < 1 {
|
||||
tryLimit = 1
|
||||
}
|
||||
if tryLimit > 3 {
|
||||
tryLimit = 3
|
||||
}
|
||||
if dnsCount > 0 && tryLimit > dnsCount {
|
||||
tryLimit = dnsCount
|
||||
}
|
||||
budgetMS := envInt("RESOLVE_DIRECT_BUDGET_MS", 1200)
|
||||
if budgetMS < 200 {
|
||||
budgetMS = 200
|
||||
}
|
||||
if budgetMS > 15000 {
|
||||
budgetMS = 15000
|
||||
}
|
||||
return dnsAttemptPolicy{
|
||||
TryLimit: tryLimit,
|
||||
DomainBudget: time.Duration(budgetMS) * time.Millisecond,
|
||||
StopOnNX: resolveNXEarlyStopEnabled(),
|
||||
}
|
||||
}
|
||||
|
||||
func wildcardDNSAttemptPolicy(dnsCount int) dnsAttemptPolicy {
|
||||
tryLimit := envInt("RESOLVE_WILDCARD_TRY_LIMIT", 1)
|
||||
if tryLimit < 1 {
|
||||
tryLimit = 1
|
||||
}
|
||||
if tryLimit > 2 {
|
||||
tryLimit = 2
|
||||
}
|
||||
if dnsCount > 0 && tryLimit > dnsCount {
|
||||
tryLimit = dnsCount
|
||||
}
|
||||
budgetMS := envInt("RESOLVE_WILDCARD_BUDGET_MS", 1200)
|
||||
if budgetMS < 200 {
|
||||
budgetMS = 200
|
||||
}
|
||||
if budgetMS > 15000 {
|
||||
budgetMS = 15000
|
||||
}
|
||||
return dnsAttemptPolicy{
|
||||
TryLimit: tryLimit,
|
||||
DomainBudget: time.Duration(budgetMS) * time.Millisecond,
|
||||
StopOnNX: resolveNXEarlyStopEnabled(),
|
||||
}
|
||||
}
|
||||
|
||||
func resolveNXEarlyStopEnabled() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("RESOLVE_NX_EARLY_STOP"))) {
|
||||
case "0", "false", "no", "off":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func resolveNXHardQuarantineEnabled() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("RESOLVE_NX_HARD_QUARANTINE"))) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user