Skip to content

Commit

Permalink
fix(minipipeline): sort A before AAAA (ooni#1509)
Browse files Browse the repository at this point in the history
Helps with ooni/probe#2677.
  • Loading branch information
bassosimone authored and Murphy-OrangeMud committed Feb 13, 2024
1 parent d0b85d0 commit afb8a36
Show file tree
Hide file tree
Showing 80 changed files with 10,549 additions and 10,238 deletions.
8 changes: 8 additions & 0 deletions internal/minipipeline/sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func SortDNSLookupResults(inputs []*model.ArchivalDNSLookupResult) (outputs []*m
return false
}

// we want A entries to appear before AAAA entries
if left.QueryType < right.QueryType {
return true
}
if left.QueryType > right.QueryType {
return false
}

// we want entries that are successful to appear first
fsget := func(value *string) string {
if value == nil {
Expand Down
28 changes: 28 additions & 0 deletions internal/minipipeline/sorting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ func TestSortDNSLookupResults(t *testing.T) {
ResolverAddress: "1.1.1.1:53",
TransactionID: 5,
},
{
Engine: "udp",
Failure: nil,
QueryType: "AAAA",
ResolverAddress: "1.1.1.1:53",
TransactionID: 5,
},
{
Engine: "udp",
Failure: newfailurestring("dns_no_answer"),
QueryType: "AAAA",
ResolverAddress: "8.8.8.8:53",
TransactionID: 3,
},
{
Engine: "udp",
Failure: nil,
QueryType: "AAAA",
ResolverAddress: "8.8.8.8:53",
TransactionID: 3,
},
{
Engine: "udp",
Failure: nil,
Expand Down Expand Up @@ -124,6 +138,13 @@ func TestSortDNSLookupResults(t *testing.T) {
ResolverAddress: "8.8.8.8:53",
TransactionID: 3,
},
{
Engine: "udp",
Failure: nil,
QueryType: "AAAA",
ResolverAddress: "8.8.8.8:53",
TransactionID: 3,
},
{
Engine: "udp",
Failure: newfailurestring("dns_no_answer"),
Expand All @@ -138,6 +159,13 @@ func TestSortDNSLookupResults(t *testing.T) {
ResolverAddress: "1.1.1.1:53",
TransactionID: 5,
},
{
Engine: "udp",
Failure: nil,
QueryType: "AAAA",
ResolverAddress: "1.1.1.1:53",
TransactionID: 5,
},
{
Engine: "udp",
Failure: newfailurestring("dns_no_answer"),
Expand Down
Loading

0 comments on commit afb8a36

Please sign in to comment.