From ac6fd3db3970e71e6a5eb182648386091fe73e0d Mon Sep 17 00:00:00 2001 From: Alison Winters Date: Sat, 19 Oct 2019 16:15:41 +0800 Subject: [PATCH] differentiate between timeout and other error for dnscrypt servers --- dnscrypt-proxy/plugins.go | 2 ++ dnscrypt-proxy/proxy.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index a350f740..55287c12 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -44,6 +44,7 @@ const ( PluginsReturnCodeResponseError PluginsReturnCodeServerError PluginsReturnCodeCloak + PluginsReturnCodeServerTimeout ) var PluginsReturnCodeToString = map[PluginsReturnCode]string{ @@ -57,6 +58,7 @@ var PluginsReturnCodeToString = map[PluginsReturnCode]string{ PluginsReturnCodeResponseError: "RESPONSE_ERROR", PluginsReturnCodeServerError: "SERVER_ERROR", PluginsReturnCodeCloak: "CLOAK", + PluginsReturnCodeServerTimeout: "SERVER_TIMEOUT", } type PluginsState struct { diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 53ae94fc..feaf3640 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -419,7 +419,11 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce) } if err != nil { - pluginsState.returnCode = PluginsReturnCodeServerError + if neterr, ok := err.(net.Error); ok && neterr.Timeout() { + pluginsState.returnCode = PluginsReturnCodeServerTimeout + } else { + pluginsState.returnCode = PluginsReturnCodeServerError + } pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) serverInfo.noticeFailure(proxy) return