refactor: merge dnsx and errorsx into netxlite (#517)
When preparing a tutorial for netxlite, I figured it is easier to tell people "hey, this is the package you should use for all low-level networking stuff" rather than introducing people to a set of packages working together where some piece of functionality is here and some other piece is there. Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
||||
legacyerrorsx "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
// ControlRequest is the request that we send to the control
|
||||
@@ -62,7 +62,7 @@ func Control(
|
||||
// make sure error is wrapped
|
||||
err = legacyerrorsx.SafeErrWrapperBuilder{
|
||||
Error: clnt.PostJSON(ctx, "/", creq, &out),
|
||||
Operation: errorsx.TopLevelOperation,
|
||||
Operation: netxlite.TopLevelOperation,
|
||||
}.MaybeBuild()
|
||||
sess.Logger().Infof("control for %s... %+v", creq.HTTPRequest, err)
|
||||
(&out.DNS).FillASNs(sess)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
// DNSAnalysisResult contains the results of analysing comparing
|
||||
@@ -44,7 +44,7 @@ func DNSAnalysis(URL *url.URL, measurement DNSLookupResult,
|
||||
switch *control.DNS.Failure {
|
||||
case DNSNameError: // the control returns this on NXDOMAIN error
|
||||
switch *measurement.Failure {
|
||||
case errorsx.FailureDNSNXDOMAINError:
|
||||
case netxlite.FailureDNSNXDOMAINError:
|
||||
out.DNSConsistency = &DNSConsistent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
func TestDNSAnalysis(t *testing.T) {
|
||||
measurementFailure := errorsx.FailureDNSNXDOMAINError
|
||||
measurementFailure := netxlite.FailureDNSNXDOMAINError
|
||||
controlFailure := webconnectivity.DNSNameError
|
||||
eofFailure := io.EOF.Error()
|
||||
type args struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity/internal"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
// The following set of status flags identifies in a more nuanced way the
|
||||
@@ -127,7 +127,7 @@ func Summarize(tk *TestKeys) (out Summary) {
|
||||
// If DNS failed with NXDOMAIN and the control DNS is consistent, then it
|
||||
// means this website does not exist anymore.
|
||||
if tk.DNSExperimentFailure != nil &&
|
||||
*tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError &&
|
||||
*tk.DNSExperimentFailure == netxlite.FailureDNSNXDOMAINError &&
|
||||
tk.DNSConsistency != nil && *tk.DNSConsistency == DNSConsistent {
|
||||
// TODO(bassosimone): MK flags this as accessible. This result is debatable. We
|
||||
// are doing what MK does. But we most likely want to make it better later.
|
||||
@@ -140,7 +140,7 @@ func Summarize(tk *TestKeys) (out Summary) {
|
||||
// Otherwise, if DNS failed with NXDOMAIN, it's DNS based blocking.
|
||||
// TODO(bassosimone): do we wanna include other errors here? Like timeout?
|
||||
if tk.DNSExperimentFailure != nil &&
|
||||
*tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError {
|
||||
*tk.DNSExperimentFailure == netxlite.FailureDNSNXDOMAINError {
|
||||
out.Accessible = &inaccessible
|
||||
out.BlockingReason = &dns
|
||||
out.Status |= StatusAnomalyDNS | StatusExperimentDNS
|
||||
@@ -184,41 +184,41 @@ func Summarize(tk *TestKeys) (out Summary) {
|
||||
if tk.Requests[0].Failure != nil {
|
||||
out.Status |= StatusExperimentHTTP
|
||||
switch *tk.Requests[0].Failure {
|
||||
case errorsx.FailureConnectionRefused:
|
||||
case netxlite.FailureConnectionRefused:
|
||||
// This is possibly because a subsequent connection to some
|
||||
// other endpoint has been blocked. We call this http-failure
|
||||
// because this is what MK would actually do.
|
||||
out.BlockingReason = &httpFailure
|
||||
out.Accessible = &inaccessible
|
||||
out.Status |= StatusAnomalyConnect
|
||||
case errorsx.FailureConnectionReset:
|
||||
case netxlite.FailureConnectionReset:
|
||||
// We don't currently support TLS failures and we don't have a
|
||||
// way to know if it was during TLS or later. So, for now we are
|
||||
// going to call this error condition an http-failure.
|
||||
out.BlockingReason = &httpFailure
|
||||
out.Accessible = &inaccessible
|
||||
out.Status |= StatusAnomalyReadWrite
|
||||
case errorsx.FailureDNSNXDOMAINError:
|
||||
case netxlite.FailureDNSNXDOMAINError:
|
||||
// This is possibly because a subsequent resolution to
|
||||
// some other domain name has been blocked.
|
||||
out.BlockingReason = &dns
|
||||
out.Accessible = &inaccessible
|
||||
out.Status |= StatusAnomalyDNS
|
||||
case errorsx.FailureEOFError:
|
||||
case netxlite.FailureEOFError:
|
||||
// We have seen this happening with TLS handshakes as well as
|
||||
// sometimes with HTTP blocking. So http-failure.
|
||||
out.BlockingReason = &httpFailure
|
||||
out.Accessible = &inaccessible
|
||||
out.Status |= StatusAnomalyReadWrite
|
||||
case errorsx.FailureGenericTimeoutError:
|
||||
case netxlite.FailureGenericTimeoutError:
|
||||
// Alas, here we don't know whether it's connect or whether it's
|
||||
// perhaps the TLS handshake. So use the same classification used by MK.
|
||||
out.BlockingReason = &httpFailure
|
||||
out.Accessible = &inaccessible
|
||||
out.Status |= StatusAnomalyUnknown
|
||||
case errorsx.FailureSSLInvalidHostname,
|
||||
errorsx.FailureSSLInvalidCertificate,
|
||||
errorsx.FailureSSLUnknownAuthority:
|
||||
case netxlite.FailureSSLInvalidHostname,
|
||||
netxlite.FailureSSLInvalidCertificate,
|
||||
netxlite.FailureSSLUnknownAuthority:
|
||||
// We treat these three cases equally. Misconfiguration is a bit
|
||||
// less likely since we also checked with the control. Since there
|
||||
// is no TLS, for now we're going to call this http-failure.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
func TestSummarize(t *testing.T) {
|
||||
@@ -18,14 +18,14 @@ func TestSummarize(t *testing.T) {
|
||||
httpDiff = "http-diff"
|
||||
httpFailure = "http-failure"
|
||||
nilstring *string
|
||||
probeConnectionRefused = errorsx.FailureConnectionRefused
|
||||
probeConnectionReset = errorsx.FailureConnectionReset
|
||||
probeEOFError = errorsx.FailureEOFError
|
||||
probeNXDOMAIN = errorsx.FailureDNSNXDOMAINError
|
||||
probeTimeout = errorsx.FailureGenericTimeoutError
|
||||
probeSSLInvalidHost = errorsx.FailureSSLInvalidHostname
|
||||
probeSSLInvalidCert = errorsx.FailureSSLInvalidCertificate
|
||||
probeSSLUnknownAuth = errorsx.FailureSSLUnknownAuthority
|
||||
probeConnectionRefused = netxlite.FailureConnectionRefused
|
||||
probeConnectionReset = netxlite.FailureConnectionReset
|
||||
probeEOFError = netxlite.FailureEOFError
|
||||
probeNXDOMAIN = netxlite.FailureDNSNXDOMAINError
|
||||
probeTimeout = netxlite.FailureGenericTimeoutError
|
||||
probeSSLInvalidHost = netxlite.FailureSSLInvalidHostname
|
||||
probeSSLInvalidCert = netxlite.FailureSSLInvalidCertificate
|
||||
probeSSLUnknownAuth = netxlite.FailureSSLUnknownAuthority
|
||||
tcpIP = "tcp_ip"
|
||||
trueValue = true
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
func TestNewExperimentMeasurer(t *testing.T) {
|
||||
@@ -69,10 +69,10 @@ func TestMeasureWithCancelledContext(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tk := measurement.TestKeys.(*webconnectivity.TestKeys)
|
||||
if *tk.ControlFailure != errorsx.FailureInterrupted {
|
||||
if *tk.ControlFailure != netxlite.FailureInterrupted {
|
||||
t.Fatal("unexpected control_failure")
|
||||
}
|
||||
if *tk.DNSExperimentFailure != errorsx.FailureInterrupted {
|
||||
if *tk.DNSExperimentFailure != netxlite.FailureInterrupted {
|
||||
t.Fatal("unexpected dns_experiment_failure")
|
||||
}
|
||||
if tk.HTTPExperimentFailure != nil {
|
||||
|
||||
Reference in New Issue
Block a user