Handle clientsCount in the local DoH handler, too

This commit is contained in:
Frank Denis 2019-12-03 13:04:58 +01:00
parent 0de2246af2
commit 3a4bc98073
2 changed files with 7 additions and 2 deletions

View File

@ -18,6 +18,11 @@ type localDoHHandler struct {
func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
proxy := handler.proxy proxy := handler.proxy
if !proxy.clientsCountInc() {
dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
return
}
defer proxy.clientsCountDec()
dataType := "application/dns-message" dataType := "application/dns-message"
writer.Header().Set("Server", "dnscrypt-proxy") writer.Header().Set("Server", "dnscrypt-proxy")
if request.URL.Path != proxy.localDoHPath { if request.URL.Path != proxy.localDoHPath {

View File

@ -264,7 +264,7 @@ func (proxy *Proxy) udpListener(clientPc *net.UDPConn) {
go func() { go func() {
start := time.Now() start := time.Now()
if !proxy.clientsCountInc() { if !proxy.clientsCountInc() {
dlog.Warnf("Too many connections (max=%d)", proxy.maxClients) dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
return return
} }
defer proxy.clientsCountDec() defer proxy.clientsCountDec()
@ -294,7 +294,7 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) {
start := time.Now() start := time.Now()
defer clientPc.Close() defer clientPc.Close()
if !proxy.clientsCountInc() { if !proxy.clientsCountInc() {
dlog.Warnf("Too many connections (max=%d)", proxy.maxClients) dlog.Warnf("Too many incoming connections (max=%d)", proxy.maxClients)
return return
} }
defer proxy.clientsCountDec() defer proxy.clientsCountDec()