differentiate between timeout and other error for dnscrypt servers

This commit is contained in:
Alison Winters 2019-10-19 16:15:41 +08:00 committed by Frank Denis
parent 0058bc063e
commit ac6fd3db39
2 changed files with 7 additions and 1 deletions

View File

@ -44,6 +44,7 @@ const (
PluginsReturnCodeResponseError PluginsReturnCodeResponseError
PluginsReturnCodeServerError PluginsReturnCodeServerError
PluginsReturnCodeCloak PluginsReturnCodeCloak
PluginsReturnCodeServerTimeout
) )
var PluginsReturnCodeToString = map[PluginsReturnCode]string{ var PluginsReturnCodeToString = map[PluginsReturnCode]string{
@ -57,6 +58,7 @@ var PluginsReturnCodeToString = map[PluginsReturnCode]string{
PluginsReturnCodeResponseError: "RESPONSE_ERROR", PluginsReturnCodeResponseError: "RESPONSE_ERROR",
PluginsReturnCodeServerError: "SERVER_ERROR", PluginsReturnCodeServerError: "SERVER_ERROR",
PluginsReturnCodeCloak: "CLOAK", PluginsReturnCodeCloak: "CLOAK",
PluginsReturnCodeServerTimeout: "SERVER_TIMEOUT",
} }
type PluginsState struct { type PluginsState struct {

View File

@ -419,7 +419,11 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce) response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce)
} }
if err != nil { if err != nil {
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
pluginsState.returnCode = PluginsReturnCodeServerTimeout
} else {
pluginsState.returnCode = PluginsReturnCodeServerError pluginsState.returnCode = PluginsReturnCodeServerError
}
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy) serverInfo.noticeFailure(proxy)
return return