-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(minipipeline): change DNSDiff algorithm (#1407)
We were running the algorithm on single IP addresses resolved by the probe against the set resolved by the control. This is incorrect, because we should compare to the whole set resolved by the probe. This fact is relevant because v0.4 says there's consistency if a single IP address or ASN resolved by the probe intersects with the corresponding control set. Conversely, our comparison required that each IP address resolved by the probe belonged to the control set of addresses or ASNs. This diff solves the problem. While there, remove DNSPossiblyInvalidAddrs. I have determined we need to run DNSDiff independently of bogons checks. Incidentally, the new DNSDiff code I am adding is straight from Web Connectivity v0.4, so we should be good. Part of ooni/probe#2634
- Loading branch information
1 parent
689c243
commit 00a37ce
Showing
140 changed files
with
80 additions
and
1,149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package minipipeline | ||
|
||
import "github.com/ooni/probe-cli/v3/internal/geoipx" | ||
|
||
// DNSDiffFindCommonIPAddressIntersection returns the set of IP addresses that | ||
// belong to both the measurement and the control sets. | ||
func DNSDiffFindCommonIPAddressIntersection(measurement, control Set[string]) Set[string] { | ||
const ( | ||
inMeasurement = 1 << 0 | ||
inControl = 1 << 1 | ||
inBoth = inMeasurement | inControl | ||
) | ||
|
||
ipmap := make(map[string]int) | ||
for _, ipAddr := range measurement.Keys() { | ||
ipmap[ipAddr] |= inMeasurement | ||
} | ||
for _, ipAddr := range control.Keys() { | ||
ipmap[ipAddr] |= inControl | ||
} | ||
|
||
state := NewSet[string]() | ||
for key, value := range ipmap { | ||
// just in case an empty string slipped through | ||
if key != "" && (value&inBoth) == inBoth { | ||
state.Add(key) | ||
} | ||
} | ||
|
||
return state | ||
} | ||
|
||
// DNSDiffFindCommonIPAddressIntersection returns the set of ASNs that belong to both the set of ASNs | ||
// obtained from the measurement and the one obtained from the control. | ||
func DNSDiffFindCommonASNsIntersection(measurement, control Set[string]) Set[int64] { | ||
const ( | ||
inMeasurement = 1 << 0 | ||
inControl = 1 << 1 | ||
inBoth = inMeasurement | inControl | ||
) | ||
|
||
asnmap := make(map[int64]int) | ||
for _, ipAddr := range measurement.Keys() { | ||
if asn, _, err := geoipx.LookupASN(ipAddr); err == nil && asn > 0 { | ||
asnmap[int64(asn)] |= inMeasurement | ||
} | ||
} | ||
for _, ipAddr := range control.Keys() { | ||
if asn, _, err := geoipx.LookupASN(ipAddr); err == nil && asn > 0 { | ||
asnmap[int64(asn)] |= inControl | ||
} | ||
} | ||
|
||
state := NewSet[int64]() | ||
for key, value := range asnmap { | ||
// zero means that ASN lookup failed | ||
if key != 0 && (value&inBoth) == inBoth { | ||
state.Add(key) | ||
} | ||
} | ||
|
||
return state | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.