feat: refactor dns implementation in measurexlite (#857)

* refactor: remove query-based mapping and introducing resolver wrapper

* refactor dnsping to adapt to measurexlite

* dnsping: extra comments

* Apply suggestions from code review

* Update internal/measurexlite/dns_test.go

See https://github.com/ooni/probe/issues/2208

Co-authored-by: decfox <decfox@github.com>
Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
DecFox
2022-08-11 19:30:37 +05:30
committed by GitHub
parent 576b52b1e3
commit fc51590a67
5 changed files with 173 additions and 221 deletions
+9 -12
View File
@@ -12,7 +12,6 @@ import (
"sync"
"time"
"github.com/miekg/dns"
"github.com/ooni/probe-cli/v3/internal/measurexlite"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
@@ -148,18 +147,16 @@ func (m *Measurer) dnsRoundTrip(ctx context.Context, index int64, zeroTime time.
resolver := trace.NewParallelUDPResolver(logger, dialer, address)
_, err := resolver.LookupHost(ctx, domain)
ol.Stop(err)
// Add the dns.TypeA ping
pings = append(pings, m.makePingFromLookup(<-trace.DNSLookup[dns.TypeA]))
// Add the dns.TypeAAAA ping
pings = append(pings, m.makePingFromLookup(<-trace.DNSLookup[dns.TypeAAAA]))
tk.addPings(pings)
}
// makePingfromLookup returns a SinglePing from the result of a single query
func (m *Measurer) makePingFromLookup(lookup *model.ArchivalDNSLookupResult) (pings *SinglePing) {
return &SinglePing{
Query: lookup,
for _, lookup := range trace.DNSLookupsFromRoundTrip() {
// make sure we only include the query types we care about (in principle, there
// should be no other query, so we're doing this just for robustness).
if lookup.QueryType == "A" || lookup.QueryType == "AAAA" {
pings = append(pings, &SinglePing{
Query: lookup,
})
}
}
tk.addPings(pings)
}
// NewExperimentMeasurer creates a new ExperimentMeasurer.