From a6f5388bac26b3b8bfc4d35c78e5171f3ee57090 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 2 Nov 2021 12:40:18 +0100 Subject: [PATCH] fix(filtering/dns.go): serve requests in parallel (#564) Without this change, it takes too much to serve a single query and we cannot properly use this code for QA. See https://github.com/ooni/probe/issues/1803#issuecomment-957323297 --- internal/netxlite/filtering/dns.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/netxlite/filtering/dns.go b/internal/netxlite/filtering/dns.go index 3fcb4d2..452dc2a 100644 --- a/internal/netxlite/filtering/dns.go +++ b/internal/netxlite/filtering/dns.go @@ -92,20 +92,24 @@ func (p *DNSProxy) oneloop(pconn net.PacketConn) bool { return !strings.HasSuffix(err.Error(), "use of closed network connection") } buffer = buffer[:count] + go p.serveAsync(pconn, addr, buffer) + return true +} + +func (p *DNSProxy) serveAsync(pconn net.PacketConn, addr net.Addr, buffer []byte) { query := &dns.Msg{} if err := query.Unpack(buffer); err != nil { - return true // can continue + return } reply, err := p.reply(query) if err != nil { - return true // can continue + return } replyBytes, err := reply.Pack() if err != nil { - return true // can continue + return } pconn.WriteTo(replyBytes, addr) - return true // can continue } func (p *DNSProxy) reply(query *dns.Msg) (*dns.Msg, error) {