platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
53
selective-vpn-api/app/resolver/error_policy.go
Normal file
53
selective-vpn-api/app/resolver/error_policy.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SmartDNSFallbackForTimeoutEnabled() bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv("RESOLVE_SMARTDNS_TIMEOUT_FALLBACK"))) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
case "0", "false", "no", "off":
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func ShouldFallbackToSmartDNS(stats DNSMetrics) bool {
|
||||
if stats.OK > 0 {
|
||||
return false
|
||||
}
|
||||
if stats.NXDomain > 0 {
|
||||
return false
|
||||
}
|
||||
if stats.Timeout > 0 || stats.Temporary > 0 {
|
||||
return true
|
||||
}
|
||||
return stats.Other > 0
|
||||
}
|
||||
|
||||
func ClassifyHostErrorKind(stats DNSMetrics) (DNSErrorKind, bool) {
|
||||
if stats.Timeout > 0 {
|
||||
return DNSErrorTimeout, true
|
||||
}
|
||||
if stats.Temporary > 0 {
|
||||
return DNSErrorTemporary, true
|
||||
}
|
||||
if stats.Other > 0 {
|
||||
return DNSErrorOther, true
|
||||
}
|
||||
if stats.NXDomain > 0 {
|
||||
return DNSErrorNXDomain, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func ShouldUseStaleOnError(stats DNSMetrics) bool {
|
||||
if stats.OK > 0 {
|
||||
return false
|
||||
}
|
||||
return stats.Timeout > 0 || stats.Temporary > 0 || stats.Other > 0
|
||||
}
|
||||
Reference in New Issue
Block a user