Fix #596 - Intelligent Optimal DNS Resolution

This commit is contained in:
Aleksey Dmitrevskiy 2019-02-26 18:19:05 +03:00
parent 71ab95f12f
commit 5bc6d00aa0
4 changed files with 72 additions and 0 deletions

View File

@ -114,6 +114,7 @@ var config = configuration{
QueryLogEnabled: true,
Ratelimit: 20,
RefuseAny: true,
AllServers: false,
BootstrapDNS: "8.8.8.8:53",
},
UpstreamDNS: defaultDNS,

View File

@ -94,6 +94,7 @@ func handleStatus(w http.ResponseWriter, r *http.Request) {
"running": isRunning(),
"bootstrap_dns": config.DNS.BootstrapDNS,
"upstream_dns": config.DNS.UpstreamDNS,
"all_servers": config.DNS.AllServers,
"version": VersionString,
"language": config.Language,
}
@ -361,6 +362,38 @@ func handleSetUpstreamDNS(w http.ResponseWriter, r *http.Request) {
}
}
func handleAllServersEnable(w http.ResponseWriter, r *http.Request) {
config.DNS.AllServers = true
httpUpdateConfigReloadDNSReturnOK(w, r)
}
func handleAllServersDisable(w http.ResponseWriter, r *http.Request) {
config.DNS.AllServers = false
httpUpdateConfigReloadDNSReturnOK(w, r)
}
func handleAllServersStatus(w http.ResponseWriter, r *http.Request) {
data := map[string]interface{}{
"enabled": config.DNS.AllServers,
}
jsonVal, err := json.Marshal(data)
if err != nil {
errorText := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errorText)
http.Error(w, errorText, 500)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(jsonVal)
if err != nil {
errorText := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errorText)
http.Error(w, errorText, 500)
return
}
}
func handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
@ -1317,6 +1350,9 @@ func registerControlHandlers() {
http.HandleFunc("/control/querylog_disable", postInstall(optionalAuth(ensurePOST(handleQueryLogDisable))))
http.HandleFunc("/control/set_upstream_dns", postInstall(optionalAuth(ensurePOST(handleSetUpstreamDNS))))
http.HandleFunc("/control/test_upstream_dns", postInstall(optionalAuth(ensurePOST(handleTestUpstreamDNS))))
http.HandleFunc("/control/all_servers/enable", postInstall(optionalAuth(ensurePOST(handleAllServersEnable))))
http.HandleFunc("/control/all_servers/disable", postInstall(optionalAuth(ensurePOST(handleAllServersDisable))))
http.HandleFunc("/control/all_servers/status", postInstall(optionalAuth(ensureGET(handleAllServersStatus))))
http.HandleFunc("/control/i18n/change_language", postInstall(optionalAuth(ensurePOST(handleI18nChangeLanguage))))
http.HandleFunc("/control/i18n/current_language", postInstall(optionalAuth(ensureGET(handleI18nCurrentLanguage))))
http.HandleFunc("/control/stats_top", postInstall(optionalAuth(ensureGET(handleStatsTop))))

View File

@ -67,6 +67,7 @@ type FilteringConfig struct {
RatelimitWhitelist []string `yaml:"ratelimit_whitelist"`
RefuseAny bool `yaml:"refuse_any"`
BootstrapDNS string `yaml:"bootstrap_dns"`
AllServers bool `yaml:"all_servers"`
dnsfilter.Config `yaml:",inline"`
}
@ -163,6 +164,7 @@ func (s *Server) startInternal(config *ServerConfig) error {
CacheEnabled: true,
Upstreams: s.Upstreams,
Handler: s.handleDNSRequest,
AllServers: s.AllServers,
}
if s.TLSListenAddr != nil && s.CertificateChain != "" && s.PrivateKey != "" {

View File

@ -111,6 +111,39 @@ paths:
200:
description: OK
/all_servers/enable:
post:
tags:
- global
operationId: allServersEnable
summary: 'Enable parallel queries'
responses:
200:
description: OK
/all_servers/disable:
post:
tags:
- global
operationId: allServersDisable
summary: 'Disable parallel queries'
responses:
200:
description: OK
/all_servers/status:
get:
tags:
- global
operationId: allServersStatus
summary: 'Get parallel queries status'
responses:
200:
description: OK
examples:
application/json:
enabled: false
/test_upstream_dns:
post:
tags: