Files
elmprodvpn/selective-vpn-api/app/resolver/error_policy.go

54 lines
1021 B
Go

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
}