No need to get the time if the connection is refused

This commit is contained in:
Frank Denis 2021-08-04 13:23:21 +02:00
parent b4a073f54f
commit d996e3424d
2 changed files with 3 additions and 3 deletions

View File

@ -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")

View File

@ -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