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
This commit is contained in:
Simone Basso 2021-11-02 12:40:18 +01:00 committed by GitHub
parent d9c43f1d1b
commit a6f5388bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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