From b86e7f268e008efd66f3185fe7a651c1de8722e0 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 10 Jan 2018 12:09:59 +0100 Subject: [PATCH] Use more things from the config file --- dnscrypt-proxy/common.go | 4 ---- dnscrypt-proxy/main.go | 8 ++++++-- dnscrypt-proxy/plugins.go | 4 ++-- dnscrypt-proxy/serversInfo.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dnscrypt-proxy/common.go b/dnscrypt-proxy/common.go index 4f8cf42c..32688cfa 100644 --- a/dnscrypt-proxy/common.go +++ b/dnscrypt-proxy/common.go @@ -4,7 +4,6 @@ import ( "encoding/binary" "errors" "net" - "time" ) type CryptoConstruction uint16 @@ -22,9 +21,6 @@ var ( MaxDNSPacketSize = 4096 MaxDNSUDPPacketSize = 1252 InitialMinQuestionSize = 256 - TimeoutMin = 1 * time.Second - TimeoutMax = 5 * time.Second - CertRefreshDelay = 30 * time.Minute ) func PrefixWithSize(packet []byte) ([]byte, error) { diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index d0face00..c504d8b4 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -58,7 +58,7 @@ func (proxy *Proxy) StartProxy() { } } for { - time.Sleep(CertRefreshDelay) + time.Sleep(proxy.certRefreshDelay) proxy.serversInfo.refresh(proxy) } } @@ -155,7 +155,11 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, serverProto str if len(query) < MinDNSPacketSize { return } - pluginsState := NewPluginsState() + clientProto := "udp" + if clientAddr == nil { + clientProto = "tcp" + } + pluginsState := NewPluginsState(clientProto) query, _ = pluginsState.ApplyQueryPlugins(query) encryptedQuery, clientNonce, err := proxy.Encrypt(serverInfo, query, serverProto) if err != nil { diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index 603f7047..1f29fbfe 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -29,11 +29,11 @@ type Plugin interface { Eval(pluginsState *PluginsState, msg *dns.Msg) error } -func NewPluginsState() PluginsState { +func NewPluginsState(proto string) PluginsState { queryPlugins := &[]Plugin{Plugin(new(PluginGetSetPayloadSize))} responsePlugins := &[]Plugin{} return PluginsState{action: PluginsActionForward, maxPayloadSize: MaxDNSUDPPacketSize - ResponseOverhead, - queryPlugins: queryPlugins, responsePlugins: responsePlugins} + queryPlugins: queryPlugins, responsePlugins: responsePlugins, proto: proto} } func (pluginsState *PluginsState) ApplyQueryPlugins(packet []byte) ([]byte, error) { diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index f6c6a369..531d8879 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -107,7 +107,7 @@ func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp SharedKey: certInfo.SharedKey, CryptoConstruction: certInfo.CryptoConstruction, Name: name, - Timeout: TimeoutMin, + Timeout: proxy.timeout, UDPAddr: remoteUDPAddr, TCPAddr: remoteTCPAddr, }