From 0ef1f246170496fa9f8a14aa63fbbd0d39792b73 Mon Sep 17 00:00:00 2001 From: DecFox <33030671+DecFox@users.noreply.github.com> Date: Thu, 25 Aug 2022 17:29:24 +0530 Subject: [PATCH] feat: record delayed DNS responses in dnsping (#878) See https://github.com/ooni/probe/issues/2231 Co-authored-by: decfox Co-authored-by: Simone Basso --- internal/engine/experiment/dnsping/dnsping.go | 17 +++++++++++++---- .../engine/experiment/dnsping/dnsping_test.go | 2 +- internal/engine/experiment/dnsping/testkeys.go | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/engine/experiment/dnsping/dnsping.go b/internal/engine/experiment/dnsping/dnsping.go index ae835c1..648b323 100644 --- a/internal/engine/experiment/dnsping/dnsping.go +++ b/internal/engine/experiment/dnsping/dnsping.go @@ -19,7 +19,7 @@ import ( const ( testName = "dnsping" - testVersion = "0.2.0" + testVersion = "0.3.0" ) // Config contains the experiment configuration. @@ -147,13 +147,22 @@ 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) + delayedResp := trace.DelayedDNSResponseWithTimeout(ctx, 250*time.Millisecond) 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, - }) + sp := &SinglePing{ + Query: lookup, + DelayedResponses: []*model.ArchivalDNSLookupResult{}, + } + // record the delayed responses of the corresponding query + for _, resp := range delayedResp { + if resp.QueryType == lookup.QueryType { + sp.DelayedResponses = append(sp.DelayedResponses, resp) + } + } + pings = append(pings, sp) } } tk.addPings(pings) diff --git a/internal/engine/experiment/dnsping/dnsping_test.go b/internal/engine/experiment/dnsping/dnsping_test.go index 5fdc012..3255a31 100644 --- a/internal/engine/experiment/dnsping/dnsping_test.go +++ b/internal/engine/experiment/dnsping/dnsping_test.go @@ -50,7 +50,7 @@ func TestMeasurer_run(t *testing.T) { if m.ExperimentName() != "dnsping" { t.Fatal("invalid experiment name") } - if m.ExperimentVersion() != "0.2.0" { + if m.ExperimentVersion() != "0.3.0" { t.Fatal("invalid experiment version") } ctx := context.Background() diff --git a/internal/engine/experiment/dnsping/testkeys.go b/internal/engine/experiment/dnsping/testkeys.go index 21cf3e3..0fa952b 100644 --- a/internal/engine/experiment/dnsping/testkeys.go +++ b/internal/engine/experiment/dnsping/testkeys.go @@ -16,7 +16,8 @@ type TestKeys struct { // SinglePing contains the results of a single ping. type SinglePing struct { - Query *model.ArchivalDNSLookupResult `json:"query"` + Query *model.ArchivalDNSLookupResult `json:"query"` + DelayedResponses []*model.ArchivalDNSLookupResult `json:"delayed_responses"` } // NewTestKeys creates new dnsping TestKeys