From d996e3424d690796a2ae415e6e62542373fd14e8 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 4 Aug 2021 13:23:21 +0200 Subject: [PATCH] No need to get the time if the connection is refused --- dnscrypt-proxy/local-doh.go | 2 +- dnscrypt-proxy/proxy.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dnscrypt-proxy/local-doh.go b/dnscrypt-proxy/local-doh.go index 00ed6bee..a3e08230 100644 --- a/dnscrypt-proxy/local-doh.go +++ b/dnscrypt-proxy/local-doh.go @@ -35,13 +35,13 @@ func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *ht writer.Write([]byte("dnscrypt-proxy local DoH server\n")) return } - start := time.Now() clientAddr, err := net.ResolveTCPAddr("tcp", request.RemoteAddr) if err != nil { dlog.Errorf("Unable to get the client address: [%v]", err) return } xClientAddr := net.Addr(clientAddr) + start := time.Now() packet, err := ioutil.ReadAll(io.LimitReader(request.Body, MaxHTTPBodyLength)) if err != nil { dlog.Warnf("No body in a local DoH query") diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 7d213e20..891f83a1 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -370,12 +370,12 @@ func (proxy *Proxy) udpListener(clientPc *net.UDPConn) { } packet := buffer[:length] go func() { - start := time.Now() if !proxy.clientsCountInc() { dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients) return } defer proxy.clientsCountDec() + start := time.Now() proxy.processIncomingQuery("udp", proxy.mainProto, packet, &clientAddr, clientPc, start) }() } @@ -389,7 +389,6 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) { continue } go func() { - start := time.Now() defer clientPc.Close() if !proxy.clientsCountInc() { dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients) @@ -399,6 +398,7 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) { if err := clientPc.SetDeadline(time.Now().Add(proxy.timeout)); err != nil { return } + start := time.Now() packet, err := ReadPrefixed(&clientPc) if err != nil { return