From 6d3a4f1db8aed911dc2b0056288274ae7dd57ed8 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 28 Sep 2021 12:42:01 +0200 Subject: [PATCH] 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 --- CONTRIBUTING.md | 4 +- cmd/ooniprobe/internal/config/parser_test.go | 4 +- cmd/ooniprobe/internal/database/database.go | 4 +- internal/cmd/jafar/badproxy/badproxy.go | 4 +- .../cmd/jafar/httpproxy/httpproxy_test.go | 6 +- .../cmd/jafar/uncensored/uncensored_test.go | 4 +- internal/cmd/oohelper/internal/client.go | 4 +- internal/cmd/oohelper/internal/fake_test.go | 4 +- .../internal/webconnectivity/fake_test.go | 4 +- .../internal/webconnectivity/http.go | 4 +- .../webconnectivity/webconnectivity.go | 4 +- .../webconnectivity/webconnectivity_test.go | 3 +- .../internal/websteps/generate_test.go | 4 +- .../internal/websteps/measure_test.go | 4 +- .../oohelperd/internal/websteps/websteps.go | 4 +- .../internal/websteps/websteps_test.go | 6 +- internal/engine/experiment/dash/dash.go | 7 +- internal/engine/experiment/dash/dash_test.go | 6 +- .../experiment/fbmessenger/fbmessenger.go | 6 +- .../fbmessenger/fbmessenger_test.go | 6 +- internal/engine/experiment/hhfm/fake_test.go | 4 +- internal/engine/experiment/hhfm/hhfm.go | 9 ++- internal/engine/experiment/hhfm/hhfm_test.go | 8 +-- internal/engine/experiment/hirl/hirl.go | 4 +- internal/engine/experiment/hirl/hirl_test.go | 4 +- internal/engine/experiment/ndt7/download.go | 8 +-- .../experiment/riseupvpn/riseupvpn_test.go | 10 +-- .../engine/experiment/signal/signal_test.go | 6 +- .../experiment/sniblocking/sniblocking.go | 22 +++--- .../sniblocking/sniblocking_test.go | 32 ++++----- .../stunreachability/stunreachability_test.go | 4 +- .../engine/experiment/telegram/telegram.go | 4 +- .../experiment/telegram/telegram_test.go | 30 ++++---- internal/engine/experiment/tor/tor.go | 4 +- internal/engine/experiment/tor/tor_test.go | 8 +-- .../engine/experiment/urlgetter/getter.go | 4 +- .../urlgetter/getter_integration_test.go | 20 +++--- .../engine/experiment/urlgetter/runner.go | 9 ++- .../experiment/webconnectivity/control.go | 4 +- .../experiment/webconnectivity/dnsanalysis.go | 4 +- .../webconnectivity/dnsanalysis_test.go | 4 +- .../experiment/webconnectivity/summary.go | 22 +++--- .../webconnectivity/summary_test.go | 18 ++--- .../webconnectivity/webconnectivity_test.go | 6 +- .../engine/experiment/websteps/control.go | 4 +- internal/engine/geolocate/fake_test.go | 4 +- internal/engine/httpx/fake_test.go | 4 +- internal/engine/httpx/jsonapi.go | 4 +- internal/engine/legacy/errorsx/dialer.go | 18 ++--- internal/engine/legacy/errorsx/dialer_test.go | 26 +++---- internal/engine/legacy/errorsx/errorsx.go | 22 +++--- .../engine/legacy/errorsx/errorsx_test.go | 28 ++++---- .../engine/legacy/errorsx/integration_test.go | 3 +- internal/engine/legacy/errorsx/quic.go | 12 ++-- internal/engine/legacy/errorsx/quic_test.go | 8 +-- internal/engine/legacy/errorsx/resolver.go | 6 +- .../engine/legacy/errorsx/resolver_test.go | 8 +-- internal/engine/legacy/errorsx/tls.go | 6 +- internal/engine/legacy/errorsx/tls_test.go | 8 +-- internal/engine/legacy/netx/http.go | 6 +- internal/engine/legacy/netx/http_test.go | 9 ++- .../engine/legacy/netx/modelx/modelx_test.go | 4 +- .../netx/oldhttptransport/bodytracer_test.go | 4 +- .../oldhttptransport/httptransport_test.go | 4 +- .../netx/oldhttptransport/tracetripper.go | 15 ++-- .../oldhttptransport/tracetripper_test.go | 6 +- internal/engine/legacy/netx/resolver.go | 3 +- .../legacy/netxlogger/netxlogger_test.go | 4 +- .../legacy/oonidatamodel/oonidatamodel.go | 7 +- .../oonidatamodel/oonidatamodel_test.go | 26 +++---- .../legacy/oonitemplates/oonitemplates.go | 4 +- .../oonitemplates/oonitemplates_test.go | 6 +- internal/engine/netx/archival/archival.go | 22 +++--- .../engine/netx/archival/archival_test.go | 68 +++++++++---------- .../engine/netx/dialer/bytecounter_test.go | 4 +- internal/engine/netx/dialer/saver.go | 8 +-- internal/engine/netx/dialer/saver_test.go | 4 +- internal/engine/netx/fake_test.go | 4 +- .../netx/httptransport/bytecounter_test.go | 6 +- .../engine/netx/httptransport/fake_test.go | 4 +- internal/engine/netx/httptransport/saver.go | 4 +- .../engine/netx/httptransport/saver_test.go | 6 +- internal/engine/netx/integration_test.go | 9 ++- internal/engine/netx/netx.go | 3 +- internal/engine/netx/quicdialer/system.go | 6 +- .../engine/netx/quicdialer/system_test.go | 3 +- internal/engine/netx/resolver/bogon.go | 4 +- internal/engine/netx/resolver/bogon_test.go | 4 +- .../engine/netx/resolver/integration_test.go | 4 +- internal/engine/netx/resolver/legacy.go | 32 ++++----- internal/engine/netx/tlsdialer/saver_test.go | 3 +- .../engine/probeservices/collector_test.go | 4 +- .../probeservices/probeservices_test.go | 4 +- internal/engine/session_integration_test.go | 4 +- internal/fsx/example_test.go | 4 +- internal/mlablocate/mlablocate.go | 4 +- internal/mlablocatev2/fake_test.go | 4 +- internal/mlablocatev2/mlablocatev2.go | 4 +- internal/netxlite/certifi.go | 2 +- internal/netxlite/{errorsx => }/classify.go | 2 +- .../netxlite/{errorsx => }/classify_test.go | 2 +- internal/netxlite/dialer.go | 14 ++-- internal/netxlite/dialer_test.go | 23 +++---- internal/netxlite/{dnsx => }/dnsdecoder.go | 21 ++---- .../netxlite/{dnsx => }/dnsdecoder_test.go | 15 ++-- internal/netxlite/{dnsx => }/dnsencoder.go | 2 +- .../netxlite/{dnsx => }/dnsencoder_test.go | 2 +- internal/netxlite/{dnsx => }/dnsoverhttps.go | 5 +- .../netxlite/{dnsx => }/dnsoverhttps_test.go | 2 +- internal/netxlite/{dnsx => }/dnsovertcp.go | 2 +- .../netxlite/{dnsx => }/dnsovertcp_test.go | 2 +- internal/netxlite/{dnsx => }/dnsoverudp.go | 8 +-- .../netxlite/{dnsx => }/dnsoverudp_test.go | 5 +- internal/netxlite/{dnsx => }/dnstransport.go | 2 +- .../netxlite/dnsx/{model/model.go => dnsx.go} | 4 +- internal/netxlite/dnsx/mocks/doc.go | 2 - internal/netxlite/{errorsx => }/errno.go | 4 +- internal/netxlite/{errorsx => }/errno_test.go | 4 +- internal/netxlite/{errorsx => }/errno_unix.go | 4 +- .../netxlite/{errorsx => }/errno_windows.go | 4 +- internal/netxlite/errorsx/doc.go | 20 ------ internal/netxlite/{errorsx => }/errwrapper.go | 2 +- .../netxlite/{errorsx => }/errwrapper_test.go | 2 +- internal/netxlite/http_test.go | 3 +- internal/netxlite/internal/gencertifi/main.go | 4 +- .../{errorsx => }/internal/generrno/main.go | 6 +- internal/netxlite/{iox => }/iox.go | 3 +- internal/netxlite/iox/example_test.go | 21 ------ internal/netxlite/{iox => }/iox_test.go | 2 +- .../netxlite/{dnsx => }/mocks/dnsdecoder.go | 4 +- .../{dnsx => }/mocks/dnsdecoder_test.go | 0 .../netxlite/{dnsx => }/mocks/dnsencoder.go | 0 .../{dnsx => }/mocks/dnsencoder_test.go | 0 .../netxlite/{dnsx => }/mocks/dnstransport.go | 0 .../{dnsx => }/mocks/dnstransport_test.go | 0 internal/netxlite/mocks/resolver.go | 5 -- internal/netxlite/{errorsx => }/operations.go | 2 +- internal/netxlite/quic.go | 17 ++--- internal/netxlite/quic_test.go | 11 ++- internal/netxlite/quirks.go | 4 +- internal/netxlite/quirks_test.go | 17 +++-- internal/netxlite/resolver.go | 7 +- internal/netxlite/resolver_test.go | 5 +- .../netxlite/{dnsx => }/serialresolver.go | 2 +- .../{dnsx => }/serialresolver_test.go | 11 ++- internal/netxlite/tls.go | 5 +- internal/netxlite/tls_test.go | 3 +- internal/ooapi/apis.go | 2 +- internal/ooapi/apis_test.go | 26 +++---- internal/ooapi/caching.go | 2 +- internal/ooapi/caching_test.go | 2 +- internal/ooapi/callers.go | 2 +- internal/ooapi/clientcall.go | 2 +- internal/ooapi/clientcall_test.go | 22 +++--- internal/ooapi/cloners.go | 2 +- internal/ooapi/fake_test.go | 4 +- internal/ooapi/fakeapi_test.go | 2 +- internal/ooapi/internal/generator/apistest.go | 4 +- .../internal/generator/clientcalltest.go | 4 +- .../ooapi/internal/generator/responses.go | 4 +- internal/ooapi/login.go | 2 +- internal/ooapi/login_test.go | 2 +- internal/ooapi/loginhandler_test.go | 6 +- internal/ooapi/requests.go | 2 +- internal/ooapi/responses.go | 26 +++---- internal/ooapi/swagger_test.go | 4 +- internal/ooapi/swaggerdiff_test.go | 4 +- internal/ptx/ptx.go | 6 +- internal/ptx/ptx_test.go | 4 +- 169 files changed, 575 insertions(+), 671 deletions(-) rename internal/netxlite/{errorsx => }/classify.go (99%) rename internal/netxlite/{errorsx => }/classify_test.go (99%) rename internal/netxlite/{dnsx => }/dnsdecoder.go (82%) rename internal/netxlite/{dnsx => }/dnsdecoder_test.go (95%) rename internal/netxlite/{dnsx => }/dnsencoder.go (99%) rename internal/netxlite/{dnsx => }/dnsencoder_test.go (99%) rename internal/netxlite/{dnsx => }/dnsoverhttps.go (95%) rename internal/netxlite/{dnsx => }/dnsoverhttps_test.go (99%) rename internal/netxlite/{dnsx => }/dnsovertcp.go (99%) rename internal/netxlite/{dnsx => }/dnsovertcp_test.go (99%) rename internal/netxlite/{dnsx => }/dnsoverudp.go (88%) rename internal/netxlite/{dnsx => }/dnsoverudp_test.go (97%) rename internal/netxlite/{dnsx => }/dnstransport.go (97%) rename internal/netxlite/dnsx/{model/model.go => dnsx.go} (80%) delete mode 100644 internal/netxlite/dnsx/mocks/doc.go rename internal/netxlite/{errorsx => }/errno.go (98%) rename internal/netxlite/{errorsx => }/errno_test.go (98%) rename internal/netxlite/{errorsx => }/errno_unix.go (92%) rename internal/netxlite/{errorsx => }/errno_windows.go (93%) delete mode 100644 internal/netxlite/errorsx/doc.go rename internal/netxlite/{errorsx => }/errwrapper.go (99%) rename internal/netxlite/{errorsx => }/errwrapper_test.go (99%) rename internal/netxlite/{errorsx => }/internal/generrno/main.go (98%) rename internal/netxlite/{iox => }/iox.go (96%) delete mode 100644 internal/netxlite/iox/example_test.go rename internal/netxlite/{iox => }/iox_test.go (99%) rename internal/netxlite/{dnsx => }/mocks/dnsdecoder.go (85%) rename internal/netxlite/{dnsx => }/mocks/dnsdecoder_test.go (100%) rename internal/netxlite/{dnsx => }/mocks/dnsencoder.go (100%) rename internal/netxlite/{dnsx => }/mocks/dnsencoder_test.go (100%) rename internal/netxlite/{dnsx => }/mocks/dnstransport.go (100%) rename internal/netxlite/{dnsx => }/mocks/dnstransport_test.go (100%) rename internal/netxlite/{errorsx => }/operations.go (98%) rename internal/netxlite/{dnsx => }/serialresolver.go (99%) rename internal/netxlite/{dnsx => }/serialresolver_test.go (95%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5a79986..320d6c0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,8 +65,8 @@ run `go mod tidy` to minimize such changes. - use `./internal/fsx.OpenFile` when you need to open a file -- use `./internal/netxlite/iox.ReadAllContext` instead of `io.ReadAll` -and `./internal/netxlite/iox.CopyContext` instead of `io.Copy` +- use `./internal/netxlite.ReadAllContext` instead of `io.ReadAll` +and `./internal/netxlite.CopyContext` instead of `io.Copy` ## Code testing requirements diff --git a/cmd/ooniprobe/internal/config/parser_test.go b/cmd/ooniprobe/internal/config/parser_test.go index 0399f15..cc4c4cc 100644 --- a/cmd/ooniprobe/internal/config/parser_test.go +++ b/cmd/ooniprobe/internal/config/parser_test.go @@ -8,7 +8,7 @@ import ( "os" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func getShasum(path string) (string, error) { @@ -19,7 +19,7 @@ func getShasum(path string) (string, error) { return "", err } defer f.Close() - if _, err := iox.CopyContext(context.Background(), hasher, f); err != nil { + if _, err := netxlite.CopyContext(context.Background(), hasher, f); err != nil { return "", err } return hex.EncodeToString(hasher.Sum(nil)), nil diff --git a/cmd/ooniprobe/internal/database/database.go b/cmd/ooniprobe/internal/database/database.go index 0673156..5b6d9be 100644 --- a/cmd/ooniprobe/internal/database/database.go +++ b/cmd/ooniprobe/internal/database/database.go @@ -6,7 +6,7 @@ import ( "embed" "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" migrate "github.com/rubenv/sql-migrate" "upper.io/db.v3/lib/sqlbuilder" "upper.io/db.v3/sqlite" @@ -20,7 +20,7 @@ func readAsset(path string) ([]byte, error) { if err != nil { return nil, err } - return iox.ReadAllContext(context.Background(), filep) + return netxlite.ReadAllContext(context.Background(), filep) } func readAssetDir(path string) ([]string, error) { diff --git a/internal/cmd/jafar/badproxy/badproxy.go b/internal/cmd/jafar/badproxy/badproxy.go index 4c85ada..3690bb6 100644 --- a/internal/cmd/jafar/badproxy/badproxy.go +++ b/internal/cmd/jafar/badproxy/badproxy.go @@ -16,7 +16,7 @@ import ( "time" "github.com/google/martian/v3/mitm" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // CensoringProxy is a proxy that does not behave correctly. @@ -57,7 +57,7 @@ func (p *CensoringProxy) serve(conn net.Conn) { } else { const maxread = 1 << 17 reader := io.LimitReader(conn, maxread) - iox.ReadAllContext(context.Background(), reader) + netxlite.ReadAllContext(context.Background(), reader) } conn.Close() } diff --git a/internal/cmd/jafar/httpproxy/httpproxy_test.go b/internal/cmd/jafar/httpproxy/httpproxy_test.go index b24654b..d6e7f95 100644 --- a/internal/cmd/jafar/httpproxy/httpproxy_test.go +++ b/internal/cmd/jafar/httpproxy/httpproxy_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/cmd/jafar/uncensored" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestPass(t *testing.T) { @@ -102,7 +102,7 @@ func checkrequest( if !foundProduct && expectVia { t.Fatal("Via header not found") } - proxiedData, err := iox.ReadAllContext(context.Background(), resp.Body) + proxiedData, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -120,7 +120,7 @@ func checkbody(t *testing.T, proxiedData []byte, host string) { t.Fatal("unexpected status code") } defer resp.Body.Close() - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/cmd/jafar/uncensored/uncensored_test.go b/internal/cmd/jafar/uncensored/uncensored_test.go index 4ce05cc..df0ac23 100644 --- a/internal/cmd/jafar/uncensored/uncensored_test.go +++ b/internal/cmd/jafar/uncensored/uncensored_test.go @@ -7,7 +7,7 @@ import ( "net/url" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestGood(t *testing.T) { @@ -56,7 +56,7 @@ func TestGood(t *testing.T) { if resp.StatusCode != 200 { t.Fatal("invalid status-code") } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/cmd/oohelper/internal/client.go b/internal/cmd/oohelper/internal/client.go index 7132337..2b7e5cc 100644 --- a/internal/cmd/oohelper/internal/client.go +++ b/internal/cmd/oohelper/internal/client.go @@ -13,7 +13,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/engine/httpheader" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/version" ) @@ -130,7 +130,7 @@ func (oo OOClient) Do(ctx context.Context, config OOConfig) (*CtrlResponse, erro if resp.StatusCode != 200 { return nil, ErrHTTPStatusCode } - data, err = iox.ReadAllContext(ctx, resp.Body) + data, err = netxlite.ReadAllContext(ctx, resp.Body) if err != nil { return nil, err } diff --git a/internal/cmd/oohelper/internal/fake_test.go b/internal/cmd/oohelper/internal/fake_test.go index 0b5382f..e6687e5 100644 --- a/internal/cmd/oohelper/internal/fake_test.go +++ b/internal/cmd/oohelper/internal/fake_test.go @@ -9,7 +9,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeResolver struct { @@ -63,7 +63,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/cmd/oohelperd/internal/webconnectivity/fake_test.go b/internal/cmd/oohelperd/internal/webconnectivity/fake_test.go index 9787499..7bcab42 100644 --- a/internal/cmd/oohelperd/internal/webconnectivity/fake_test.go +++ b/internal/cmd/oohelperd/internal/webconnectivity/fake_test.go @@ -9,7 +9,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeResolver struct { @@ -63,7 +63,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/cmd/oohelperd/internal/webconnectivity/http.go b/internal/cmd/oohelperd/internal/webconnectivity/http.go index 5fd2bd5..b661583 100644 --- a/internal/cmd/oohelperd/internal/webconnectivity/http.go +++ b/internal/cmd/oohelperd/internal/webconnectivity/http.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // CtrlHTTPResponse is the result of the HTTP check performed by @@ -62,7 +62,7 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) { headers[k] = resp.Header.Get(k) } reader := &io.LimitedReader{R: resp.Body, N: config.MaxAcceptableBody} - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) config.Out <- CtrlHTTPResponse{ BodyLength: int64(len(data)), Failure: newfailure(err), diff --git a/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity.go b/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity.go index 5d35af6..44a855f 100644 --- a/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity.go +++ b/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity.go @@ -7,7 +7,7 @@ import ( "net/http" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/version" ) @@ -29,7 +29,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } reader := &io.LimitedReader{R: req.Body, N: h.MaxAcceptableBody} - data, err := iox.ReadAllContext(req.Context(), reader) + data, err := netxlite.ReadAllContext(req.Context(), reader) if err != nil { w.WriteHeader(400) return diff --git a/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity_test.go b/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity_test.go index c03e18f..a4881df 100644 --- a/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity_test.go +++ b/internal/cmd/oohelperd/internal/webconnectivity/webconnectivity_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" ) const simplerequest = `{ @@ -126,7 +125,7 @@ func TestWorkingAsIntended(t *testing.T) { if v := resp.Header.Get("content-type"); v != expect.respContentType { t.Fatalf("unexpected content-type: %s", v) } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/cmd/oohelperd/internal/websteps/generate_test.go b/internal/cmd/oohelperd/internal/websteps/generate_test.go index 93c8ab6..2919647 100644 --- a/internal/cmd/oohelperd/internal/websteps/generate_test.go +++ b/internal/cmd/oohelperd/internal/websteps/generate_test.go @@ -11,7 +11,7 @@ import ( "testing" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" ) @@ -68,7 +68,7 @@ func TestGenerateDNSFailure(t *testing.T) { if urlMeasurements[0].DNS == nil { t.Fatal("DNS should not be nil") } - if urlMeasurements[0].DNS.Failure == nil || *urlMeasurements[0].DNS.Failure != errorsx.FailureDNSNXDOMAINError { + if urlMeasurements[0].DNS.Failure == nil || *urlMeasurements[0].DNS.Failure != netxlite.FailureDNSNXDOMAINError { t.Fatal("unexpected DNS failure type") } } diff --git a/internal/cmd/oohelperd/internal/websteps/measure_test.go b/internal/cmd/oohelperd/internal/websteps/measure_test.go index 24730ee..a0ace19 100644 --- a/internal/cmd/oohelperd/internal/websteps/measure_test.go +++ b/internal/cmd/oohelperd/internal/websteps/measure_test.go @@ -6,7 +6,7 @@ import ( "net/url" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestMeasureSuccess(t *testing.T) { @@ -79,7 +79,7 @@ func TestMeasureInitialChecksFailWithNXDOMAIN(t *testing.T) { if resp.URLs[0].DNS == nil { t.Fatal("DNS entry should not be nil") } - if *resp.URLs[0].DNS.Failure != errorsx.FailureDNSNXDOMAINError { + if *resp.URLs[0].DNS.Failure != netxlite.FailureDNSNXDOMAINError { t.Fatal("unexpected failure") } } diff --git a/internal/cmd/oohelperd/internal/websteps/websteps.go b/internal/cmd/oohelperd/internal/websteps/websteps.go index f9a46e2..907838b 100644 --- a/internal/cmd/oohelperd/internal/websteps/websteps.go +++ b/internal/cmd/oohelperd/internal/websteps/websteps.go @@ -13,7 +13,7 @@ import ( "net/http" "github.com/ooni/probe-cli/v3/internal/engine/netx/archival" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/version" ) @@ -42,7 +42,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } reader := &io.LimitedReader{R: req.Body, N: maxAcceptableBody} - data, err := iox.ReadAllContext(req.Context(), reader) + data, err := netxlite.ReadAllContext(req.Context(), reader) if err != nil { w.WriteHeader(400) return diff --git a/internal/cmd/oohelperd/internal/websteps/websteps_test.go b/internal/cmd/oohelperd/internal/websteps/websteps_test.go index e00596d..567097e 100644 --- a/internal/cmd/oohelperd/internal/websteps/websteps_test.go +++ b/internal/cmd/oohelperd/internal/websteps/websteps_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) const requestnoredirect = `{ @@ -188,7 +188,7 @@ func TestWorkingAsIntended(t *testing.T) { if resp.StatusCode != expect.respStatusCode { t.Fatalf("unexpected status code: %+v", resp.StatusCode) } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -220,7 +220,7 @@ func TestHandlerWithInternalServerError(t *testing.T) { if resp.StatusCode != 500 { t.Fatalf("unexpected status code: %+v", resp.StatusCode) } - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/experiment/dash/dash.go b/internal/engine/experiment/dash/dash.go index 42077a9..3792de8 100644 --- a/internal/engine/experiment/dash/dash.go +++ b/internal/engine/experiment/dash/dash.go @@ -18,8 +18,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "github.com/ooni/probe-cli/v3/internal/humanize" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) const ( @@ -87,7 +86,7 @@ func (r runner) NewHTTPRequest(meth, url string, body io.Reader) (*http.Request, } func (r runner) ReadAllContext(ctx context.Context, reader io.Reader) ([]byte, error) { - return iox.ReadAllContext(ctx, reader) + return netxlite.ReadAllContext(ctx, reader) } func (r runner) Scheme() string { @@ -172,7 +171,7 @@ func (r runner) measure( // of the latest connect time. We should have one sample in most // cases, because the connection should be persistent. for _, ev := range r.saver.Read() { - if ev.Name == errorsx.ConnectOperation { + if ev.Name == netxlite.ConnectOperation { connectTime = ev.Duration.Seconds() } } diff --git a/internal/engine/experiment/dash/dash_test.go b/internal/engine/experiment/dash/dash_test.go index 7151c2c..9dd290d 100644 --- a/internal/engine/experiment/dash/dash_test.go +++ b/internal/engine/experiment/dash/dash_test.go @@ -14,7 +14,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestRunnerLoopLocateFailure(t *testing.T) { @@ -108,7 +108,7 @@ func TestRunnerLoopMeasureFailure(t *testing.T) { func TestRunnerLoopCollectFailure(t *testing.T) { expected := errors.New("mocked error") saver := new(trace.Saver) - saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond}) + saver.Write(trace.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond}) r := runner{ callbacks: model.NewPrinterCallbacks(log.Log), httpClient: &http.Client{ @@ -152,7 +152,7 @@ func TestRunnerLoopCollectFailure(t *testing.T) { func TestRunnerLoopSuccess(t *testing.T) { saver := new(trace.Saver) - saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond}) + saver.Write(trace.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond}) r := runner{ callbacks: model.NewPrinterCallbacks(log.Log), httpClient: &http.Client{ diff --git a/internal/engine/experiment/fbmessenger/fbmessenger.go b/internal/engine/experiment/fbmessenger/fbmessenger.go index 75e6350..bb96455 100644 --- a/internal/engine/experiment/fbmessenger/fbmessenger.go +++ b/internal/engine/experiment/fbmessenger/fbmessenger.go @@ -11,7 +11,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -111,7 +111,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo // start where all is unknown *dns, *tcp = nil, nil // process DNS first - if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorsx.ResolveOperation { + if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == netxlite.ResolveOperation { tk.FacebookDNSBlocking = &trueValue *dns = &falseValue return // we know that the DNS has failed @@ -127,7 +127,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo } *dns = &trueValue // now process connect - if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == errorsx.ConnectOperation { + if v.TestKeys.FailedOperation != nil && *v.TestKeys.FailedOperation == netxlite.ConnectOperation { tk.FacebookTCPBlocking = &trueValue *tcp = &falseValue return // because connect failed diff --git a/internal/engine/experiment/fbmessenger/fbmessenger_test.go b/internal/engine/experiment/fbmessenger/fbmessenger_test.go index 33adb42..93b8613 100644 --- a/internal/engine/experiment/fbmessenger/fbmessenger_test.go +++ b/internal/engine/experiment/fbmessenger/fbmessenger_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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) { @@ -162,7 +162,7 @@ func TestWithCancelledContext(t *testing.T) { func TestComputeEndpointStatsTCPBlocking(t *testing.T) { failure := io.EOF.Error() - operation := errorsx.ConnectOperation + operation := netxlite.ConnectOperation tk := fbmessenger.TestKeys{} tk.Update(urlgetter.MultiOutput{ Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, @@ -192,7 +192,7 @@ func TestComputeEndpointStatsTCPBlocking(t *testing.T) { func TestComputeEndpointStatsDNSIsLying(t *testing.T) { failure := io.EOF.Error() - operation := errorsx.ConnectOperation + operation := netxlite.ConnectOperation tk := fbmessenger.TestKeys{} tk.Update(urlgetter.MultiOutput{ Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, diff --git a/internal/engine/experiment/hhfm/fake_test.go b/internal/engine/experiment/hhfm/fake_test.go index 0c7e3c6..ca7dfe6 100644 --- a/internal/engine/experiment/hhfm/fake_test.go +++ b/internal/engine/experiment/hhfm/fake_test.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeDialer struct { @@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/engine/experiment/hhfm/hhfm.go b/internal/engine/experiment/hhfm/hhfm.go index 560b32f..047ff03 100644 --- a/internal/engine/experiment/hhfm/hhfm.go +++ b/internal/engine/experiment/hhfm/hhfm.go @@ -20,8 +20,7 @@ import ( "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/engine/netx/dialer" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/randx" ) @@ -165,7 +164,7 @@ func (m Measurer) Run( // parse response body var jsonHeaders JSONHeaders if err := json.Unmarshal(data, &jsonHeaders); err != nil { - failure := errorsx.FailureJSONParseError + failure := netxlite.FailureJSONParseError tk.Failure = &failure tk.Tampering.Total = true return nil // measurement did not fail, we measured tampering @@ -182,7 +181,7 @@ func Transact(txp Transport, req *http.Request, // make sure that we return a wrapped error here resp, data, err := transact(txp, req, callbacks) err = errorsxlegacy.SafeErrWrapperBuilder{ - Error: err, Operation: errorsx.TopLevelOperation}.MaybeBuild() + Error: err, Operation: netxlite.TopLevelOperation}.MaybeBuild() return resp, data, err } @@ -199,7 +198,7 @@ func transact(txp Transport, req *http.Request, return nil, nil, urlgetter.ErrHTTPRequestFailed } callbacks.OnProgress(0.75, "reading response body...") - data, err := iox.ReadAllContext(req.Context(), resp.Body) + data, err := netxlite.ReadAllContext(req.Context(), resp.Body) callbacks.OnProgress(1.00, fmt.Sprintf("got reseponse body... %+v", err)) if err != nil { return nil, nil, err diff --git a/internal/engine/experiment/hhfm/hhfm_test.go b/internal/engine/experiment/hhfm/hhfm_test.go index 8ca15e8..a2e757e 100644 --- a/internal/engine/experiment/hhfm/hhfm_test.go +++ b/internal/engine/experiment/hhfm/hhfm_test.go @@ -18,7 +18,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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) { @@ -161,14 +161,14 @@ func TestCancelledContext(t *testing.T) { if tk.Agent != "agent" { t.Fatal("invalid Agent") } - if *tk.Failure != errorsx.FailureInterrupted { + if *tk.Failure != netxlite.FailureInterrupted { t.Fatal("invalid Failure") } if len(tk.Requests) != 1 { t.Fatal("invalid Requests") } request := tk.Requests[0] - if *request.Failure != errorsx.FailureInterrupted { + if *request.Failure != netxlite.FailureInterrupted { t.Fatal("invalid Requests[0].Failure") } if request.Request.Body.Value != "" { @@ -480,7 +480,7 @@ func TestInvalidJSONBody(t *testing.T) { if tk.Agent != "agent" { t.Fatal("invalid Agent") } - if *tk.Failure != errorsx.FailureJSONParseError { + if *tk.Failure != netxlite.FailureJSONParseError { t.Fatal("invalid Failure") } if len(tk.Requests) != 1 { diff --git a/internal/engine/experiment/hirl/hirl.go b/internal/engine/experiment/hirl/hirl.go index b4b9e7f..dd42020 100644 --- a/internal/engine/experiment/hirl/hirl.go +++ b/internal/engine/experiment/hirl/hirl.go @@ -14,7 +14,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" "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" "github.com/ooni/probe-cli/v3/internal/randx" ) @@ -293,7 +293,7 @@ func RunMethod(ctx context.Context, config RunMethodConfig) { count, err := conn.Read(data) if err != nil { // We expect this method to terminate w/ timeout - if err.Error() == errorsx.FailureGenericTimeoutError { + if err.Error() == netxlite.FailureGenericTimeoutError { err = nil } result.Err = err diff --git a/internal/engine/experiment/hirl/hirl_test.go b/internal/engine/experiment/hirl/hirl_test.go index 1b13f6c..6b99f2d 100644 --- a/internal/engine/experiment/hirl/hirl_test.go +++ b/internal/engine/experiment/hirl/hirl_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/netx" "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) { @@ -97,7 +97,7 @@ func TestCancelledContext(t *testing.T) { t.Fatal("unexpected FailureList length") } for _, failure := range tk.FailureList { - if *failure != errorsx.FailureInterrupted { + if *failure != netxlite.FailureInterrupted { t.Fatal("unexpected failure") } } diff --git a/internal/engine/experiment/ndt7/download.go b/internal/engine/experiment/ndt7/download.go index 98dc204..0804de5 100644 --- a/internal/engine/experiment/ndt7/download.go +++ b/internal/engine/experiment/ndt7/download.go @@ -7,7 +7,7 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type downloadManager struct { @@ -46,7 +46,7 @@ func (mgr downloadManager) run(ctx context.Context) error { // we used to return `nil` on context errors, this function is // here to keep the previous behavior by filtering the error // returned when reading messages, given that now reading messages -// can fail midway because we use iox.ReadAllContext. +// can fail midway because we use netxlite.ReadAllContext. func (mgr downloadManager) reduceErr(err error) error { if errors.Is(err, context.Canceled) { return nil @@ -72,7 +72,7 @@ func (mgr downloadManager) doRun(ctx context.Context) error { return err } if kind == websocket.TextMessage { - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return err } @@ -82,7 +82,7 @@ func (mgr downloadManager) doRun(ctx context.Context) error { } continue } - n, err := iox.CopyContext(ctx, io.Discard, reader) + n, err := netxlite.CopyContext(ctx, io.Discard, reader) if err != nil { return err } diff --git a/internal/engine/experiment/riseupvpn/riseupvpn_test.go b/internal/engine/experiment/riseupvpn/riseupvpn_test.go index ed61b54..c2eb9a4 100644 --- a/internal/engine/experiment/riseupvpn/riseupvpn_test.go +++ b/internal/engine/experiment/riseupvpn/riseupvpn_test.go @@ -17,7 +17,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) const ( @@ -270,11 +270,11 @@ func TestUpdateWithMixedResults(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.HTTPRoundTripOperation + s := netxlite.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -291,7 +291,7 @@ func TestUpdateWithMixedResults(t *testing.T) { if tk.APIStatus != "blocked" { t.Fatal("ApiStatus should be blocked") } - if *tk.APIFailure != errorsx.FailureEOFError { + if *tk.APIFailure != netxlite.FailureEOFError { t.Fatal("invalid ApiFailure") } if tk.FailingGateways != nil { @@ -730,7 +730,7 @@ func generateMockGetter(requestResponse map[string]string, responseStatus map[st responseBody = "" eofError := io.EOF.Error() failure = &eofError - connectOperation := errorsx.ConnectOperation + connectOperation := netxlite.ConnectOperation failedOperation = &connectOperation responseStatus = 0 } diff --git a/internal/engine/experiment/signal/signal_test.go b/internal/engine/experiment/signal/signal_test.go index e3bff24..d025db0 100644 --- a/internal/engine/experiment/signal/signal_test.go +++ b/internal/engine/experiment/signal/signal_test.go @@ -9,7 +9,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -85,7 +85,7 @@ func TestUpdate(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -93,7 +93,7 @@ func TestUpdate(t *testing.T) { if tk.SignalBackendStatus != "blocked" { t.Fatal("SignalBackendStatus should be blocked") } - if *tk.SignalBackendFailure != errorsx.FailureEOFError { + if *tk.SignalBackendFailure != netxlite.FailureEOFError { t.Fatal("invalid SignalBackendError") } } diff --git a/internal/engine/experiment/sniblocking/sniblocking.go b/internal/engine/experiment/sniblocking/sniblocking.go index d043da8..f6adc0a 100644 --- a/internal/engine/experiment/sniblocking/sniblocking.go +++ b/internal/engine/experiment/sniblocking/sniblocking.go @@ -15,7 +15,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -64,24 +64,24 @@ func (tk *TestKeys) classify() string { return classSuccessGotServerHello } switch *tk.Target.Failure { - case errorsx.FailureConnectionRefused: + case netxlite.FailureConnectionRefused: return classAnomalyTestHelperUnreachable - case errorsx.FailureConnectionReset: + case netxlite.FailureConnectionReset: return classInterferenceReset - case errorsx.FailureDNSNXDOMAINError: + case netxlite.FailureDNSNXDOMAINError: return classAnomalyTestHelperUnreachable - case errorsx.FailureEOFError: + case netxlite.FailureEOFError: return classInterferenceClosed - case errorsx.FailureGenericTimeoutError: + case netxlite.FailureGenericTimeoutError: if tk.Control.Failure != nil { return classAnomalyTestHelperUnreachable } return classAnomalyTimeout - case errorsx.FailureSSLInvalidCertificate: + case netxlite.FailureSSLInvalidCertificate: return classInterferenceInvalidCertificate - case errorsx.FailureSSLInvalidHostname: + case netxlite.FailureSSLInvalidHostname: return classSuccessGotServerHello - case errorsx.FailureSSLUnknownAuthority: + case netxlite.FailureSSLUnknownAuthority: return classInterferenceUnknownAuthority } return classAnomalyUnexpectedFailure @@ -117,8 +117,8 @@ func (m *Measurer) measureone( select { case <-time.After(sleeptime): case <-ctx.Done(): - s := errorsx.FailureInterrupted - failedop := errorsx.TopLevelOperation + s := netxlite.FailureInterrupted + failedop := netxlite.TopLevelOperation return Subresult{ TestKeys: urlgetter.TestKeys{ FailedOperation: &failedop, diff --git a/internal/engine/experiment/sniblocking/sniblocking_test.go b/internal/engine/experiment/sniblocking/sniblocking_test.go index fdb0081..51fc1e9 100644 --- a/internal/engine/experiment/sniblocking/sniblocking_test.go +++ b/internal/engine/experiment/sniblocking/sniblocking_test.go @@ -9,7 +9,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) const ( @@ -29,64 +29,64 @@ func TestTestKeysClassify(t *testing.T) { }) t.Run("with tk.Target.Failure == connection_refused", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureConnectionRefused) + tk.Target.Failure = asStringPtr(netxlite.FailureConnectionRefused) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == dns_nxdomain_error", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureDNSNXDOMAINError) + tk.Target.Failure = asStringPtr(netxlite.FailureDNSNXDOMAINError) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == connection_reset", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureConnectionReset) + tk.Target.Failure = asStringPtr(netxlite.FailureConnectionReset) if tk.classify() != classInterferenceReset { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == eof_error", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureEOFError) + tk.Target.Failure = asStringPtr(netxlite.FailureEOFError) if tk.classify() != classInterferenceClosed { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_invalid_hostname", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidHostname) + tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidHostname) if tk.classify() != classSuccessGotServerHello { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_unknown_authority", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureSSLUnknownAuthority) + tk.Target.Failure = asStringPtr(netxlite.FailureSSLUnknownAuthority) if tk.classify() != classInterferenceUnknownAuthority { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == ssl_invalid_certificate", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidCertificate) + tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidCertificate) if tk.classify() != classInterferenceInvalidCertificate { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == generic_timeout_error #1", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) + tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError) if tk.classify() != classAnomalyTimeout { t.Fatal("unexpected result") } }) t.Run("with tk.Target.Failure == generic_timeout_error #2", func(t *testing.T) { tk := new(TestKeys) - tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) - tk.Control.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) + tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError) + tk.Control.Failure = asStringPtr(netxlite.FailureGenericTimeoutError) if tk.classify() != classAnomalyTestHelperUnreachable { t.Fatal("unexpected result") } @@ -191,10 +191,10 @@ func TestMeasureoneCancelledContext(t *testing.T) { if result.DNSCache != nil { t.Fatal("not the expected DNSCache") } - if result.FailedOperation == nil || *result.FailedOperation != errorsx.TopLevelOperation { + if result.FailedOperation == nil || *result.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the expected FailedOperation") } - if result.Failure == nil || *result.Failure != errorsx.FailureInterrupted { + if result.Failure == nil || *result.Failure != netxlite.FailureInterrupted { t.Fatal("not the expected failure") } if result.NetworkEvents != nil { @@ -295,10 +295,10 @@ func TestMeasureoneSuccess(t *testing.T) { if result.DNSCache != nil { t.Fatal("not the expected DNSCache") } - if result.FailedOperation == nil || *result.FailedOperation != errorsx.TLSHandshakeOperation { + if result.FailedOperation == nil || *result.FailedOperation != netxlite.TLSHandshakeOperation { t.Fatal("not the expected FailedOperation") } - if result.Failure == nil || *result.Failure != errorsx.FailureSSLInvalidHostname { + if result.Failure == nil || *result.Failure != netxlite.FailureSSLInvalidHostname { t.Fatal("unexpected failure") } if len(result.NetworkEvents) < 1 { @@ -348,7 +348,7 @@ func TestMeasureonewithcacheWorks(t *testing.T) { if result.Cached != expected { t.Fatal("unexpected cached") } - if *result.Failure != errorsx.FailureSSLInvalidHostname { + if *result.Failure != netxlite.FailureSSLInvalidHostname { t.Fatal("unexpected failure") } if result.SNI != "kernel.org" { diff --git a/internal/engine/experiment/stunreachability/stunreachability_test.go b/internal/engine/experiment/stunreachability/stunreachability_test.go index 19e6077..2bbc1ba 100644 --- a/internal/engine/experiment/stunreachability/stunreachability_test.go +++ b/internal/engine/experiment/stunreachability/stunreachability_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/stunreachability" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" "github.com/pion/stun" ) @@ -213,7 +213,7 @@ func TestReadFailure(t *testing.T) { t.Fatal("not the error we expected") } tk := measurement.TestKeys.(*stunreachability.TestKeys) - if *tk.Failure != errorsx.FailureGenericTimeoutError { + if *tk.Failure != netxlite.FailureGenericTimeoutError { t.Fatal("expected different failure here") } if tk.Endpoint != "stun.l.google.com:19302" { diff --git a/internal/engine/experiment/telegram/telegram.go b/internal/engine/experiment/telegram/telegram.go index 2821591..b9faf3c 100644 --- a/internal/engine/experiment/telegram/telegram.go +++ b/internal/engine/experiment/telegram/telegram.go @@ -11,7 +11,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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" ) const ( @@ -56,7 +56,7 @@ func (tk *TestKeys) Update(v urlgetter.MultiOutput) { tk.TelegramTCPBlocking = false return // found successful access point connection } - if v.TestKeys.FailedOperation == nil || *v.TestKeys.FailedOperation != errorsx.ConnectOperation { + if v.TestKeys.FailedOperation == nil || *v.TestKeys.FailedOperation != netxlite.ConnectOperation { tk.TelegramTCPBlocking = false } return diff --git a/internal/engine/experiment/telegram/telegram_test.go b/internal/engine/experiment/telegram/telegram_test.go index 9f8296b..dfcd514 100644 --- a/internal/engine/experiment/telegram/telegram_test.go +++ b/internal/engine/experiment/telegram/telegram_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" ) func TestNewExperimentMeasurer(t *testing.T) { @@ -94,7 +94,7 @@ func TestUpdateWithNoAccessPointsBlocking(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -125,7 +125,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -137,7 +137,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -159,11 +159,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.ConnectOperation + s := netxlite.ConnectOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -175,11 +175,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.HTTPRoundTripOperation + s := netxlite.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -201,11 +201,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.ConnectOperation + s := netxlite.ConnectOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -217,11 +217,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.ConnectOperation + s := netxlite.ConnectOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -243,11 +243,11 @@ func TestUpdateWebWithMixedResults(t *testing.T) { }, TestKeys: urlgetter.TestKeys{ FailedOperation: (func() *string { - s := errorsx.HTTPRoundTripOperation + s := netxlite.HTTPRoundTripOperation return &s })(), Failure: (func() *string { - s := errorsx.FailureEOFError + s := netxlite.FailureEOFError return &s })(), }, @@ -265,7 +265,7 @@ func TestUpdateWebWithMixedResults(t *testing.T) { if tk.TelegramWebStatus != "blocked" { t.Fatal("TelegramWebStatus should be blocked") } - if *tk.TelegramWebFailure != errorsx.FailureEOFError { + if *tk.TelegramWebFailure != netxlite.FailureEOFError { t.Fatal("invalid TelegramWebFailure") } } diff --git a/internal/engine/experiment/tor/tor.go b/internal/engine/experiment/tor/tor.go index c899b32..3f22dbc 100644 --- a/internal/engine/experiment/tor/tor.go +++ b/internal/engine/experiment/tor/tor.go @@ -18,7 +18,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonidatamodel" "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "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" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/scrubber" ) @@ -77,7 +77,7 @@ func (tr *TargetResults) fillSummary() { if len(tr.TCPConnect) < 1 { return } - tr.Summary[errorsx.ConnectOperation] = Summary{ + tr.Summary[netxlite.ConnectOperation] = Summary{ Failure: tr.TCPConnect[0].Status.Failure, } switch tr.TargetProtocol { diff --git a/internal/engine/experiment/tor/tor_test.go b/internal/engine/experiment/tor/tor_test.go index 1f3624c..fdf33ee 100644 --- a/internal/engine/experiment/tor/tor_test.go +++ b/internal/engine/experiment/tor/tor_test.go @@ -17,7 +17,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "github.com/ooni/probe-cli/v3/internal/engine/mockable" "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" "github.com/ooni/probe-cli/v3/internal/scrubber" ) @@ -446,7 +446,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) != 1 { t.Fatal("cannot find expected entry") } - if *tr.Summary[errorsx.ConnectOperation].Failure != failure { + if *tr.Summary[netxlite.ConnectOperation].Failure != failure { t.Fatal("invalid failure") } }) @@ -465,7 +465,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) != 2 { t.Fatal("cannot find expected entry") } - if tr.Summary[errorsx.ConnectOperation].Failure != nil { + if tr.Summary[netxlite.ConnectOperation].Failure != nil { t.Fatal("invalid failure") } if *tr.Summary["handshake"].Failure != failure { @@ -489,7 +489,7 @@ func TestSummary(t *testing.T) { if len(tr.Summary) < 1 { t.Fatal("cannot find expected entry") } - if tr.Summary[errorsx.ConnectOperation].Failure != nil { + if tr.Summary[netxlite.ConnectOperation].Failure != nil { t.Fatal("invalid failure") } if handshake == nil { diff --git a/internal/engine/experiment/urlgetter/getter.go b/internal/engine/experiment/urlgetter/getter.go index 9a658cd..fbcedf4 100644 --- a/internal/engine/experiment/urlgetter/getter.go +++ b/internal/engine/experiment/urlgetter/getter.go @@ -10,7 +10,7 @@ import ( "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/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/tunnel" ) @@ -57,7 +57,7 @@ func (g Getter) Get(ctx context.Context) (TestKeys, error) { // hitting our httptransport that does error wrapping. err = legacyerrorsx.SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.TopLevelOperation, + Operation: netxlite.TopLevelOperation, }.MaybeBuild() tk.FailedOperation = archival.NewFailedOperation(err) tk.Failure = archival.NewFailure(err) diff --git a/internal/engine/experiment/urlgetter/getter_integration_test.go b/internal/engine/experiment/urlgetter/getter_integration_test.go index 31e0b73..b7f6717 100644 --- a/internal/engine/experiment/urlgetter/getter_integration_test.go +++ b/internal/engine/experiment/urlgetter/getter_integration_test.go @@ -10,7 +10,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "github.com/ooni/probe-cli/v3/internal/engine/mockable" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestGetterWithVeryShortTimeout(t *testing.T) { @@ -31,7 +31,7 @@ func TestGetterWithVeryShortTimeout(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "generic_timeout_error" { @@ -98,7 +98,7 @@ func TestGetterWithCancelledContextVanilla(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -166,7 +166,7 @@ func TestGetterWithCancelledContextAndMethod(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -236,7 +236,7 @@ func TestGetterWithCancelledContextNoFollowRedirects(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { @@ -306,7 +306,7 @@ func TestGetterWithCancelledContextCannotStartTunnel(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "interrupted" { @@ -361,7 +361,7 @@ func TestGetterWithCancelledContextUnknownResolverURL(t *testing.T) { if tk.BootstrapTime != 0 { t.Fatal("not the BootstrapTime we expected") } - if tk.FailedOperation == nil || *tk.FailedOperation != errorsx.TopLevelOperation { + if tk.FailedOperation == nil || *tk.FailedOperation != netxlite.TopLevelOperation { t.Fatal("not the FailedOperation we expected") } if tk.Failure == nil || *tk.Failure != "unknown_failure: unsupported resolver scheme" { @@ -446,7 +446,7 @@ func TestGetterIntegrationHTTPS(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorsx.ConnectOperation: + case netxlite.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true @@ -587,7 +587,7 @@ func TestGetterIntegrationTLSHandshake(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorsx.ConnectOperation: + case netxlite.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true @@ -705,7 +705,7 @@ func TestGetterHTTPSWithTunnel(t *testing.T) { resolveStart = true case "resolve_done": resolveDone = true - case errorsx.ConnectOperation: + case netxlite.ConnectOperation: connect = true case "tls_handshake_start": tlsHandshakeStart = true diff --git a/internal/engine/experiment/urlgetter/runner.go b/internal/engine/experiment/urlgetter/runner.go index 0d0f5e4..7a476dd 100644 --- a/internal/engine/experiment/urlgetter/runner.go +++ b/internal/engine/experiment/urlgetter/runner.go @@ -11,17 +11,16 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/httpheader" "github.com/ooni/probe-cli/v3/internal/engine/netx" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" ) const httpRequestFailed = "http_request_failed" // ErrHTTPRequestFailed indicates that the HTTP request failed. -var ErrHTTPRequestFailed = &errorsx.ErrWrapper{ +var ErrHTTPRequestFailed = &netxlite.ErrWrapper{ Failure: httpRequestFailed, - Operation: errorsx.TopLevelOperation, + Operation: netxlite.TopLevelOperation, WrappedErr: errors.New(httpRequestFailed), } @@ -92,7 +91,7 @@ func (r Runner) httpGet(ctx context.Context, url string) error { return err } defer resp.Body.Close() - if _, err = iox.CopyContext(ctx, io.Discard, resp.Body); err != nil { + if _, err = netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil { return err } // Implementation note: we shall check for this error once we have read the diff --git a/internal/engine/experiment/webconnectivity/control.go b/internal/engine/experiment/webconnectivity/control.go index e460ff1..23c4e06 100644 --- a/internal/engine/experiment/webconnectivity/control.go +++ b/internal/engine/experiment/webconnectivity/control.go @@ -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) diff --git a/internal/engine/experiment/webconnectivity/dnsanalysis.go b/internal/engine/experiment/webconnectivity/dnsanalysis.go index 9b8a916..daa656d 100644 --- a/internal/engine/experiment/webconnectivity/dnsanalysis.go +++ b/internal/engine/experiment/webconnectivity/dnsanalysis.go @@ -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 } } diff --git a/internal/engine/experiment/webconnectivity/dnsanalysis_test.go b/internal/engine/experiment/webconnectivity/dnsanalysis_test.go index ad20eaf..906f75c 100644 --- a/internal/engine/experiment/webconnectivity/dnsanalysis_test.go +++ b/internal/engine/experiment/webconnectivity/dnsanalysis_test.go @@ -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 { diff --git a/internal/engine/experiment/webconnectivity/summary.go b/internal/engine/experiment/webconnectivity/summary.go index 892fde4..5635275 100644 --- a/internal/engine/experiment/webconnectivity/summary.go +++ b/internal/engine/experiment/webconnectivity/summary.go @@ -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. diff --git a/internal/engine/experiment/webconnectivity/summary_test.go b/internal/engine/experiment/webconnectivity/summary_test.go index b335f2d..ee1af7e 100644 --- a/internal/engine/experiment/webconnectivity/summary_test.go +++ b/internal/engine/experiment/webconnectivity/summary_test.go @@ -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 ) diff --git a/internal/engine/experiment/webconnectivity/webconnectivity_test.go b/internal/engine/experiment/webconnectivity/webconnectivity_test.go index 4a5e79a..7fed0a5 100644 --- a/internal/engine/experiment/webconnectivity/webconnectivity_test.go +++ b/internal/engine/experiment/webconnectivity/webconnectivity_test.go @@ -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 { diff --git a/internal/engine/experiment/websteps/control.go b/internal/engine/experiment/websteps/control.go index a333543..b968bec 100644 --- a/internal/engine/experiment/websteps/control.go +++ b/internal/engine/experiment/websteps/control.go @@ -6,7 +6,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/httpx" errorsxlegacy "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" ) // Control performs the control request and returns the response. @@ -21,7 +21,7 @@ func Control( // make sure error is wrapped err = errorsxlegacy.SafeErrWrapperBuilder{ Error: clnt.PostJSON(ctx, resourcePath, creq, &out), - Operation: errorsx.TopLevelOperation, + Operation: netxlite.TopLevelOperation, }.MaybeBuild() return } diff --git a/internal/engine/geolocate/fake_test.go b/internal/engine/geolocate/fake_test.go index 16c5487..5dc683f 100644 --- a/internal/engine/geolocate/fake_test.go +++ b/internal/engine/geolocate/fake_test.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeTransport struct { @@ -15,7 +15,7 @@ type FakeTransport struct { func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { time.Sleep(10 * time.Microsecond) if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/engine/httpx/fake_test.go b/internal/engine/httpx/fake_test.go index 60ef9bd..dfc9fc0 100644 --- a/internal/engine/httpx/fake_test.go +++ b/internal/engine/httpx/fake_test.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeTransport struct { @@ -19,7 +19,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/engine/httpx/jsonapi.go b/internal/engine/httpx/jsonapi.go index 8e6ce42..76a2ae9 100644 --- a/internal/engine/httpx/jsonapi.go +++ b/internal/engine/httpx/jsonapi.go @@ -10,7 +10,7 @@ import ( "net/http" "net/url" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // Logger is the definition of Logger used by this package. @@ -101,7 +101,7 @@ func (c Client) Do(request *http.Request) ([]byte, error) { if response.StatusCode >= 400 { return nil, fmt.Errorf("httpx: request failed: %s", response.Status) } - return iox.ReadAllContext(request.Context(), response.Body) + return netxlite.ReadAllContext(request.Context(), response.Body) } // DoJSON performs the provided request and unmarshals the JSON response body diff --git a/internal/engine/legacy/errorsx/dialer.go b/internal/engine/legacy/errorsx/dialer.go index 0a49fc6..9de2ac5 100644 --- a/internal/engine/legacy/errorsx/dialer.go +++ b/internal/engine/legacy/errorsx/dialer.go @@ -4,7 +4,7 @@ import ( "context" "net" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // Dialer establishes network connections. @@ -25,8 +25,8 @@ func (d *ErrorWrapperDialer) DialContext(ctx context.Context, network, address s conn, err := d.Dialer.DialContext(ctx, network, address) if err != nil { return nil, SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyGenericError, - Operation: errorsx.ConnectOperation, + Classifier: netxlite.ClassifyGenericError, + Operation: netxlite.ConnectOperation, Error: err, }.MaybeBuild() } @@ -44,8 +44,8 @@ func (c *errorWrapperConn) Read(b []byte) (int, error) { count, err := c.Conn.Read(b) if err != nil { return 0, SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyGenericError, - Operation: errorsx.ReadOperation, + Classifier: netxlite.ClassifyGenericError, + Operation: netxlite.ReadOperation, Error: err, }.MaybeBuild() } @@ -57,8 +57,8 @@ func (c *errorWrapperConn) Write(b []byte) (int, error) { count, err := c.Conn.Write(b) if err != nil { return 0, SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyGenericError, - Operation: errorsx.WriteOperation, + Classifier: netxlite.ClassifyGenericError, + Operation: netxlite.WriteOperation, Error: err, }.MaybeBuild() } @@ -70,8 +70,8 @@ func (c *errorWrapperConn) Close() error { err := c.Conn.Close() if err != nil { return SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyGenericError, - Operation: errorsx.CloseOperation, + Classifier: netxlite.ClassifyGenericError, + Operation: netxlite.CloseOperation, Error: err, }.MaybeBuild() } diff --git a/internal/engine/legacy/errorsx/dialer_test.go b/internal/engine/legacy/errorsx/dialer_test.go index 73eb532..2239862 100644 --- a/internal/engine/legacy/errorsx/dialer_test.go +++ b/internal/engine/legacy/errorsx/dialer_test.go @@ -7,7 +7,7 @@ import ( "net" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -19,14 +19,14 @@ func TestErrorWrapperDialerFailure(t *testing.T) { }, }} conn, err := d.DialContext(ctx, "tcp", "www.google.com:443") - var ew *errorsx.ErrWrapper + var ew *netxlite.ErrWrapper if !errors.As(err, &ew) { t.Fatal("cannot convert to ErrWrapper") } - if ew.Operation != errorsx.ConnectOperation { + if ew.Operation != netxlite.ConnectOperation { t.Fatal("unexpected operation", ew.Operation) } - if ew.Failure != errorsx.FailureEOFError { + if ew.Failure != netxlite.FailureEOFError { t.Fatal("unexpected failure", ew.Failure) } if !errors.Is(ew.WrappedErr, io.EOF) { @@ -68,14 +68,14 @@ func TestErrorWrapperConnReadFailure(t *testing.T) { } buf := make([]byte, 1024) cnt, err := c.Read(buf) - var ew *errorsx.ErrWrapper + var ew *netxlite.ErrWrapper if !errors.As(err, &ew) { t.Fatal("cannot cast error to ErrWrapper") } - if ew.Operation != errorsx.ReadOperation { + if ew.Operation != netxlite.ReadOperation { t.Fatal("invalid operation", ew.Operation) } - if ew.Failure != errorsx.FailureEOFError { + if ew.Failure != netxlite.FailureEOFError { t.Fatal("invalid failure", ew.Failure) } if !errors.Is(ew.WrappedErr, io.EOF) { @@ -114,14 +114,14 @@ func TestErrorWrapperConnWriteFailure(t *testing.T) { } buf := make([]byte, 1024) cnt, err := c.Write(buf) - var ew *errorsx.ErrWrapper + var ew *netxlite.ErrWrapper if !errors.As(err, &ew) { t.Fatal("cannot cast error to ErrWrapper") } - if ew.Operation != errorsx.WriteOperation { + if ew.Operation != netxlite.WriteOperation { t.Fatal("invalid operation", ew.Operation) } - if ew.Failure != errorsx.FailureEOFError { + if ew.Failure != netxlite.FailureEOFError { t.Fatal("invalid failure", ew.Failure) } if !errors.Is(ew.WrappedErr, io.EOF) { @@ -159,14 +159,14 @@ func TestErrorWrapperConnCloseFailure(t *testing.T) { }, } err := c.Close() - var ew *errorsx.ErrWrapper + var ew *netxlite.ErrWrapper if !errors.As(err, &ew) { t.Fatal("cannot cast error to ErrWrapper") } - if ew.Operation != errorsx.CloseOperation { + if ew.Operation != netxlite.CloseOperation { t.Fatal("invalid operation", ew.Operation) } - if ew.Failure != errorsx.FailureEOFError { + if ew.Failure != netxlite.FailureEOFError { t.Fatal("invalid failure", ew.Failure) } if !errors.Is(ew.WrappedErr, io.EOF) { diff --git a/internal/engine/legacy/errorsx/errorsx.go b/internal/engine/legacy/errorsx/errorsx.go index 757c3a8..45d5b28 100644 --- a/internal/engine/legacy/errorsx/errorsx.go +++ b/internal/engine/legacy/errorsx/errorsx.go @@ -4,7 +4,7 @@ package errorsx import ( "errors" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // SafeErrWrapperBuilder contains a builder for ErrWrapper that @@ -27,9 +27,9 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) { if b.Error != nil { classifier := b.Classifier if classifier == nil { - classifier = errorsx.ClassifyGenericError + classifier = netxlite.ClassifyGenericError } - err = &errorsx.ErrWrapper{ + err = &netxlite.ErrWrapper{ Failure: classifier(b.Error), Operation: toOperationString(b.Error, b.Operation), WrappedErr: b.Error, @@ -39,30 +39,30 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) { } func toOperationString(err error, operation string) string { - var errwrapper *errorsx.ErrWrapper + var errwrapper *netxlite.ErrWrapper if errors.As(err, &errwrapper) { // Basically, as explained in ErrWrapper docs, let's // keep the child major operation, if any. - if errwrapper.Operation == errorsx.ConnectOperation { + if errwrapper.Operation == netxlite.ConnectOperation { return errwrapper.Operation } - if errwrapper.Operation == errorsx.HTTPRoundTripOperation { + if errwrapper.Operation == netxlite.HTTPRoundTripOperation { return errwrapper.Operation } - if errwrapper.Operation == errorsx.ResolveOperation { + if errwrapper.Operation == netxlite.ResolveOperation { return errwrapper.Operation } - if errwrapper.Operation == errorsx.TLSHandshakeOperation { + if errwrapper.Operation == netxlite.TLSHandshakeOperation { return errwrapper.Operation } - if errwrapper.Operation == errorsx.QUICHandshakeOperation { + if errwrapper.Operation == netxlite.QUICHandshakeOperation { return errwrapper.Operation } if errwrapper.Operation == "quic_handshake_start" { - return errorsx.QUICHandshakeOperation + return netxlite.QUICHandshakeOperation } if errwrapper.Operation == "quic_handshake_done" { - return errorsx.QUICHandshakeOperation + return netxlite.QUICHandshakeOperation } // FALLTHROUGH } diff --git a/internal/engine/legacy/errorsx/errorsx_test.go b/internal/engine/legacy/errorsx/errorsx_test.go index c5883ba..7311b03 100644 --- a/internal/engine/legacy/errorsx/errorsx_test.go +++ b/internal/engine/legacy/errorsx/errorsx_test.go @@ -4,14 +4,14 @@ import ( "errors" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestMaybeBuildFactory(t *testing.T) { err := SafeErrWrapperBuilder{ Error: errors.New("mocked error"), }.MaybeBuild() - var target *errorsx.ErrWrapper + var target *netxlite.ErrWrapper if errors.As(err, &target) == false { t.Fatal("not the expected error type") } @@ -27,32 +27,32 @@ func TestToOperationString(t *testing.T) { t.Run("for connect", func(t *testing.T) { // You're doing HTTP and connect fails. You want to know // that connect failed not that HTTP failed. - err := &errorsx.ErrWrapper{Operation: errorsx.ConnectOperation} - if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.ConnectOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.ConnectOperation} + if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.ConnectOperation { t.Fatal("unexpected result") } }) t.Run("for http_round_trip", func(t *testing.T) { // You're doing DoH and something fails inside HTTP. You want // to know about the internal HTTP error, not resolve. - err := &errorsx.ErrWrapper{Operation: errorsx.HTTPRoundTripOperation} - if toOperationString(err, errorsx.ResolveOperation) != errorsx.HTTPRoundTripOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.HTTPRoundTripOperation} + if toOperationString(err, netxlite.ResolveOperation) != netxlite.HTTPRoundTripOperation { t.Fatal("unexpected result") } }) t.Run("for resolve", func(t *testing.T) { // You're doing HTTP and the DNS fails. You want to // know that resolve failed. - err := &errorsx.ErrWrapper{Operation: errorsx.ResolveOperation} - if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.ResolveOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.ResolveOperation} + if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.ResolveOperation { t.Fatal("unexpected result") } }) t.Run("for tls_handshake", func(t *testing.T) { // You're doing HTTP and the TLS handshake fails. You want // to know about a TLS handshake error. - err := &errorsx.ErrWrapper{Operation: errorsx.TLSHandshakeOperation} - if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.TLSHandshakeOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.TLSHandshakeOperation} + if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.TLSHandshakeOperation { t.Fatal("unexpected result") } }) @@ -60,16 +60,16 @@ func TestToOperationString(t *testing.T) { // You just noticed that TLS handshake failed and you // have a child error telling you that read failed. Here // you want to know about a TLS handshake error. - err := &errorsx.ErrWrapper{Operation: errorsx.ReadOperation} - if toOperationString(err, errorsx.TLSHandshakeOperation) != errorsx.TLSHandshakeOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.ReadOperation} + if toOperationString(err, netxlite.TLSHandshakeOperation) != netxlite.TLSHandshakeOperation { t.Fatal("unexpected result") } }) t.Run("for quic_handshake", func(t *testing.T) { // You're doing HTTP and the TLS handshake fails. You want // to know about a TLS handshake error. - err := &errorsx.ErrWrapper{Operation: errorsx.QUICHandshakeOperation} - if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.QUICHandshakeOperation { + err := &netxlite.ErrWrapper{Operation: netxlite.QUICHandshakeOperation} + if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.QUICHandshakeOperation { t.Fatal("unexpected result") } }) diff --git a/internal/engine/legacy/errorsx/integration_test.go b/internal/engine/legacy/errorsx/integration_test.go index 2c183bf..d1d5f06 100644 --- a/internal/engine/legacy/errorsx/integration_test.go +++ b/internal/engine/legacy/errorsx/integration_test.go @@ -8,7 +8,6 @@ import ( "github.com/lucas-clemente/quic-go" errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) func TestErrorWrapperQUICDialerInvalidCertificate(t *testing.T) { @@ -31,7 +30,7 @@ func TestErrorWrapperQUICDialerInvalidCertificate(t *testing.T) { if sess != nil { t.Fatal("expected nil sess here") } - if err.Error() != errorsx.FailureSSLInvalidCertificate { + if err.Error() != netxlite.FailureSSLInvalidCertificate { t.Fatal("unexpected failure") } } diff --git a/internal/engine/legacy/errorsx/quic.go b/internal/engine/legacy/errorsx/quic.go index fb532a3..cf88d70 100644 --- a/internal/engine/legacy/errorsx/quic.go +++ b/internal/engine/legacy/errorsx/quic.go @@ -6,7 +6,7 @@ import ( "net" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -39,7 +39,7 @@ func (qls *ErrorWrapperQUICListener) Listen(addr *net.UDPAddr) (quicx.UDPLikeCon if err != nil { return nil, SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.QUICListenOperation, + Operation: netxlite.QUICListenOperation, }.MaybeBuild() } return &errorWrapperUDPConn{pconn}, nil @@ -59,7 +59,7 @@ func (c *errorWrapperUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { if err != nil { return 0, SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.WriteToOperation, + Operation: netxlite.WriteToOperation, }.MaybeBuild() } return count, nil @@ -71,7 +71,7 @@ func (c *errorWrapperUDPConn) ReadFrom(b []byte) (int, net.Addr, error) { if err != nil { return 0, nil, SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.ReadFromOperation, + Operation: netxlite.ReadFromOperation, }.MaybeBuild() } return n, addr, nil @@ -89,9 +89,9 @@ func (d *ErrorWrapperQUICDialer) DialContext( sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg) if err != nil { return nil, SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyQUICHandshakeError, + Classifier: netxlite.ClassifyQUICHandshakeError, Error: err, - Operation: errorsx.QUICHandshakeOperation, + Operation: netxlite.QUICHandshakeOperation, }.MaybeBuild() } return sess, nil diff --git a/internal/engine/legacy/errorsx/quic_test.go b/internal/engine/legacy/errorsx/quic_test.go index af66cab..cc88822 100644 --- a/internal/engine/legacy/errorsx/quic_test.go +++ b/internal/engine/legacy/errorsx/quic_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -143,14 +143,14 @@ func TestErrorWrapperQUICDialerFailure(t *testing.T) { if !errors.Is(err, io.EOF) { t.Fatal("expected another error here") } - var errWrapper *errorsx.ErrWrapper + var errWrapper *netxlite.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot cast to ErrWrapper") } - if errWrapper.Operation != errorsx.QUICHandshakeOperation { + if errWrapper.Operation != netxlite.QUICHandshakeOperation { t.Fatal("unexpected Operation") } - if errWrapper.Failure != errorsx.FailureEOFError { + if errWrapper.Failure != netxlite.FailureEOFError { t.Fatal("unexpected failure") } } diff --git a/internal/engine/legacy/errorsx/resolver.go b/internal/engine/legacy/errorsx/resolver.go index 2b5a01d..90c8e28 100644 --- a/internal/engine/legacy/errorsx/resolver.go +++ b/internal/engine/legacy/errorsx/resolver.go @@ -3,7 +3,7 @@ package errorsx import ( "context" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // Resolver is a DNS resolver. The *net.Resolver used by Go implements @@ -24,9 +24,9 @@ var _ Resolver = &ErrorWrapperResolver{} func (r *ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) { addrs, err := r.Resolver.LookupHost(ctx, hostname) err = SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyResolverError, + Classifier: netxlite.ClassifyResolverError, Error: err, - Operation: errorsx.ResolveOperation, + Operation: netxlite.ResolveOperation, }.MaybeBuild() return addrs, err } diff --git a/internal/engine/legacy/errorsx/resolver_test.go b/internal/engine/legacy/errorsx/resolver_test.go index df41fd1..704508b 100644 --- a/internal/engine/legacy/errorsx/resolver_test.go +++ b/internal/engine/legacy/errorsx/resolver_test.go @@ -6,7 +6,7 @@ import ( "net" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -41,14 +41,14 @@ func TestErrorWrapperResolverFailure(t *testing.T) { if addrs != nil { t.Fatal("expected nil addr here") } - var errWrapper *errorsx.ErrWrapper + var errWrapper *netxlite.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot properly cast the returned error") } - if errWrapper.Failure != errorsx.FailureDNSNXDOMAINError { + if errWrapper.Failure != netxlite.FailureDNSNXDOMAINError { t.Fatal("unexpected failure") } - if errWrapper.Operation != errorsx.ResolveOperation { + if errWrapper.Operation != netxlite.ResolveOperation { t.Fatal("unexpected Operation") } } diff --git a/internal/engine/legacy/errorsx/tls.go b/internal/engine/legacy/errorsx/tls.go index 2011562..7fb251c 100644 --- a/internal/engine/legacy/errorsx/tls.go +++ b/internal/engine/legacy/errorsx/tls.go @@ -5,7 +5,7 @@ import ( "crypto/tls" "net" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // TLSHandshaker is the generic TLS handshaker @@ -25,9 +25,9 @@ func (h *ErrorWrapperTLSHandshaker) Handshake( ) (net.Conn, tls.ConnectionState, error) { tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config) err = SafeErrWrapperBuilder{ - Classifier: errorsx.ClassifyTLSHandshakeError, + Classifier: netxlite.ClassifyTLSHandshakeError, Error: err, - Operation: errorsx.TLSHandshakeOperation, + Operation: netxlite.TLSHandshakeOperation, }.MaybeBuild() return tlsconn, state, err } diff --git a/internal/engine/legacy/errorsx/tls_test.go b/internal/engine/legacy/errorsx/tls_test.go index 954fc98..fcc4e1d 100644 --- a/internal/engine/legacy/errorsx/tls_test.go +++ b/internal/engine/legacy/errorsx/tls_test.go @@ -8,7 +8,7 @@ import ( "net" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -30,14 +30,14 @@ func TestErrorWrapperTLSHandshakerFailure(t *testing.T) { if conn != nil { t.Fatal("expected nil con here") } - var errWrapper *errorsx.ErrWrapper + var errWrapper *netxlite.ErrWrapper if !errors.As(err, &errWrapper) { t.Fatal("cannot cast to ErrWrapper") } - if errWrapper.Failure != errorsx.FailureEOFError { + if errWrapper.Failure != netxlite.FailureEOFError { t.Fatal("unexpected Failure") } - if errWrapper.Operation != errorsx.TLSHandshakeOperation { + if errWrapper.Operation != netxlite.TLSHandshakeOperation { t.Fatal("unexpected Operation") } } diff --git a/internal/engine/legacy/netx/http.go b/internal/engine/legacy/netx/http.go index 73dc7a1..c03e976 100644 --- a/internal/engine/legacy/netx/http.go +++ b/internal/engine/legacy/netx/http.go @@ -9,7 +9,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/oldhttptransport" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "golang.org/x/net/http2" ) @@ -82,10 +82,10 @@ func (t *HTTPTransport) RoundTrip( resp, err = t.roundTripper.RoundTrip(req) // For safety wrap the error as modelx.HTTPRoundTripOperation but this // will only be used if the error chain does not contain any - // other major operation failure. See errorsx.ErrWrapper. + // other major operation failure. See netxlite.ErrWrapper. err = errorsxlegacy.SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.HTTPRoundTripOperation, + Operation: netxlite.HTTPRoundTripOperation, }.MaybeBuild() return resp, err } diff --git a/internal/engine/legacy/netx/http_test.go b/internal/engine/legacy/netx/http_test.go index 5de2b57..1d97d0d 100644 --- a/internal/engine/legacy/netx/http_test.go +++ b/internal/engine/legacy/netx/http_test.go @@ -13,8 +13,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func dowithclient(t *testing.T, client *netx.HTTPClient) { @@ -24,7 +23,7 @@ func dowithclient(t *testing.T, client *netx.HTTPClient) { t.Fatal(err) } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -126,7 +125,7 @@ func httpProxyTestMain(t *testing.T, client *http.Client, expect int) { t.Fatal(err) } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -148,7 +147,7 @@ func TestHTTPTransportTimeout(t *testing.T) { if err == nil { t.Fatal("expected an error here") } - if !strings.HasSuffix(err.Error(), errorsx.FailureGenericTimeoutError) { + if !strings.HasSuffix(err.Error(), netxlite.FailureGenericTimeoutError) { t.Fatal("not the error we expected") } if resp != nil { diff --git a/internal/engine/legacy/netx/modelx/modelx_test.go b/internal/engine/legacy/netx/modelx/modelx_test.go index fd8ddd3..77dd37e 100644 --- a/internal/engine/legacy/netx/modelx/modelx_test.go +++ b/internal/engine/legacy/netx/modelx/modelx_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestNewTLSConnectionState(t *testing.T) { @@ -61,7 +61,7 @@ func TestMeasurementRootWithMeasurementRootPanic(t *testing.T) { func TestErrWrapperPublicAPI(t *testing.T) { child := errors.New("mocked error") - wrapper := &errorsx.ErrWrapper{ + wrapper := &netxlite.ErrWrapper{ Failure: "moobar", WrappedErr: child, } diff --git a/internal/engine/legacy/netx/oldhttptransport/bodytracer_test.go b/internal/engine/legacy/netx/oldhttptransport/bodytracer_test.go index e0b9406..16cf011 100644 --- a/internal/engine/legacy/netx/oldhttptransport/bodytracer_test.go +++ b/internal/engine/legacy/netx/oldhttptransport/bodytracer_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestBodyTracerSuccess(t *testing.T) { @@ -17,7 +17,7 @@ func TestBodyTracerSuccess(t *testing.T) { t.Fatal(err) } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/legacy/netx/oldhttptransport/httptransport_test.go b/internal/engine/legacy/netx/oldhttptransport/httptransport_test.go index 40b67ab..05c1bd3 100644 --- a/internal/engine/legacy/netx/oldhttptransport/httptransport_test.go +++ b/internal/engine/legacy/netx/oldhttptransport/httptransport_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestGood(t *testing.T) { @@ -17,7 +17,7 @@ func TestGood(t *testing.T) { t.Fatal(err) } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/legacy/netx/oldhttptransport/tracetripper.go b/internal/engine/legacy/netx/oldhttptransport/tracetripper.go index 569e478..46777ff 100644 --- a/internal/engine/legacy/netx/oldhttptransport/tracetripper.go +++ b/internal/engine/legacy/netx/oldhttptransport/tracetripper.go @@ -13,8 +13,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/atomicx" errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // TraceTripper performs single HTTP transactions. @@ -28,7 +27,7 @@ type TraceTripper struct { func NewTraceTripper(roundTripper http.RoundTripper) *TraceTripper { return &TraceTripper{ readAllErrs: &atomicx.Int64{}, - readAllContext: iox.ReadAllContext, + readAllContext: netxlite.ReadAllContext, roundTripper: roundTripper, } } @@ -84,7 +83,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) { var ( err error - majorOp = errorsx.HTTPRoundTripOperation + majorOp = netxlite.HTTPRoundTripOperation majorOpMu sync.Mutex requestBody []byte requestHeaders = http.Header{} @@ -104,7 +103,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) { tracer := &httptrace.ClientTrace{ TLSHandshakeStart: func() { majorOpMu.Lock() - majorOp = errorsx.TLSHandshakeOperation + majorOp = netxlite.TLSHandshakeOperation majorOpMu.Unlock() // Event emitted by net/http when DialTLS is not // configured in the http.Transport @@ -119,7 +118,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) { // less confusing to users to see the wrapped name err = errorsxlegacy.SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.TLSHandshakeOperation, + Operation: netxlite.TLSHandshakeOperation, }.MaybeBuild() durationSinceBeginning := time.Since(root.Beginning) // Event emitted by net/http when DialTLS is not @@ -134,7 +133,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) { }, GotConn: func(info httptrace.GotConnInfo) { majorOpMu.Lock() - majorOp = errorsx.HTTPRoundTripOperation + majorOp = netxlite.HTTPRoundTripOperation majorOpMu.Unlock() root.Handler.OnMeasurement(modelx.Measurement{ HTTPConnectionReady: &modelx.HTTPConnectionReadyEvent{ @@ -174,7 +173,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) { // less confusing to users to see the wrapped name err := errorsxlegacy.SafeErrWrapperBuilder{ Error: info.Err, - Operation: errorsx.HTTPRoundTripOperation, + Operation: netxlite.HTTPRoundTripOperation, }.MaybeBuild() root.Handler.OnMeasurement(modelx.Measurement{ HTTPRequestDone: &modelx.HTTPRequestDoneEvent{ diff --git a/internal/engine/legacy/netx/oldhttptransport/tracetripper_test.go b/internal/engine/legacy/netx/oldhttptransport/tracetripper_test.go index 24f5856..ac1c6ae 100644 --- a/internal/engine/legacy/netx/oldhttptransport/tracetripper_test.go +++ b/internal/engine/legacy/netx/oldhttptransport/tracetripper_test.go @@ -13,7 +13,7 @@ import ( "github.com/miekg/dns" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestTraceTripperSuccess(t *testing.T) { @@ -25,7 +25,7 @@ func TestTraceTripperSuccess(t *testing.T) { t.Fatal(err) } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -156,7 +156,7 @@ func TestTraceTripperWithCorrectSnaps(t *testing.T) { // Read the whole response body, parse it as valid DNS // reply and verify we obtained what we expected - replyData, err := iox.ReadAllContext(context.Background(), resp.Body) + replyData, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/legacy/netx/resolver.go b/internal/engine/legacy/netx/resolver.go index 988ad32..cea6fc4 100644 --- a/internal/engine/legacy/netx/resolver.go +++ b/internal/engine/legacy/netx/resolver.go @@ -118,7 +118,8 @@ func newResolver( if network == "udp" { // Same rationale as above: avoid possible endless loop return newResolverWrapper(beginning, handler, newResolverUDP( - newDialer(beginning, handler), withPort(address, "53"), + netxlite.NewDialerLegacyAdapter(newDialer(beginning, handler)), + withPort(address, "53"), )), nil } return nil, errors.New("resolver.New: unsupported network value") diff --git a/internal/engine/legacy/netxlogger/netxlogger_test.go b/internal/engine/legacy/netxlogger/netxlogger_test.go index fc40578..ca8d998 100644 --- a/internal/engine/legacy/netxlogger/netxlogger_test.go +++ b/internal/engine/legacy/netxlogger/netxlogger_test.go @@ -10,7 +10,7 @@ import ( "github.com/apex/log/handlers/discard" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestGood(t *testing.T) { @@ -33,7 +33,7 @@ func TestGood(t *testing.T) { t.Fatal("expected non-nil resp here") } defer resp.Body.Close() - _, err = iox.ReadAllContext(context.Background(), resp.Body) + _, err = netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/legacy/oonidatamodel/oonidatamodel.go b/internal/engine/legacy/oonidatamodel/oonidatamodel.go index f6d8229..ca6bd3b 100644 --- a/internal/engine/legacy/oonidatamodel/oonidatamodel.go +++ b/internal/engine/legacy/oonidatamodel/oonidatamodel.go @@ -20,7 +20,6 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) // ExtSpec describes a data format extension @@ -418,7 +417,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList { out = append(out, &NetworkEvent{ Address: in.Connect.RemoteAddress, Failure: makeFailure(in.Connect.Error), - Operation: errorsx.ConnectOperation, + Operation: netxlite.ConnectOperation, T: in.Connect.DurationSinceBeginning.Seconds(), }) // fallthrough @@ -426,7 +425,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList { if in.Read != nil { out = append(out, &NetworkEvent{ Failure: makeFailure(in.Read.Error), - Operation: errorsx.ReadOperation, + Operation: netxlite.ReadOperation, NumBytes: in.Read.NumBytes, T: in.Read.DurationSinceBeginning.Seconds(), }) @@ -435,7 +434,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList { if in.Write != nil { out = append(out, &NetworkEvent{ Failure: makeFailure(in.Write.Error), - Operation: errorsx.WriteOperation, + Operation: netxlite.WriteOperation, NumBytes: in.Write.NumBytes, T: in.Write.DurationSinceBeginning.Seconds(), }) diff --git a/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go b/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go index 95512cd..270c35f 100644 --- a/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go +++ b/internal/engine/legacy/oonidatamodel/oonidatamodel_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" "github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestNewTCPConnectListEmpty(t *testing.T) { @@ -67,7 +67,7 @@ func TestNewTCPConnectListFailure(t *testing.T) { Connects: []*modelx.ConnectEvent{ { RemoteAddress: "8.8.8.8:53", - Error: errors.New(errorsx.FailureConnectionReset), + Error: errors.New(netxlite.FailureConnectionReset), }, }, }) @@ -80,7 +80,7 @@ func TestNewTCPConnectListFailure(t *testing.T) { if out[0].Port != 53 { t.Fatal("unexpected out[0].Port") } - if *out[0].Status.Failure != errorsx.FailureConnectionReset { + if *out[0].Status.Failure != netxlite.FailureConnectionReset { t.Fatal("unexpected out[0].Failure") } if out[0].Status.Success != false { @@ -93,7 +93,7 @@ func TestNewTCPConnectListInvalidInput(t *testing.T) { Connects: []*modelx.ConnectEvent{ { RemoteAddress: "8.8.8.8", - Error: errors.New(errorsx.FailureConnectionReset), + Error: errors.New(netxlite.FailureConnectionReset), }, }, }) @@ -106,7 +106,7 @@ func TestNewTCPConnectListInvalidInput(t *testing.T) { if out[0].Port != 0 { t.Fatal("unexpected out[0].Port") } - if *out[0].Status.Failure != errorsx.FailureConnectionReset { + if *out[0].Status.Failure != netxlite.FailureConnectionReset { t.Fatal("unexpected out[0].Failure") } if out[0].Status.Success != false { @@ -649,7 +649,7 @@ func TestNewDNSQueriesListSuccess(t *testing.T) { TransportNetwork: "system", }, { - Error: errors.New(errorsx.FailureDNSNXDOMAINError), + Error: errors.New(netxlite.FailureDNSNXDOMAINError), Hostname: "dns.googlex", TransportNetwork: "system", }, @@ -768,7 +768,7 @@ func dnscheckbad(e DNSQueryEntry) error { if e.Engine != "system" { return errors.New("invalid engine") } - if *e.Failure != errorsx.FailureDNSNXDOMAINError { + if *e.Failure != netxlite.FailureDNSNXDOMAINError { return errors.New("invalid failure") } if e.Hostname != "dns.googlex" { @@ -854,7 +854,7 @@ func TestNewNetworkEventsListGood(t *testing.T) { if out[0].NumBytes != 0 { t.Fatal("wrong out[0].NumBytes") } - if out[0].Operation != errorsx.ConnectOperation { + if out[0].Operation != netxlite.ConnectOperation { t.Fatal("wrong out[0].Operation") } if !floatEquals(out[0].T, 0.010) { @@ -870,7 +870,7 @@ func TestNewNetworkEventsListGood(t *testing.T) { if out[1].NumBytes != 1789 { t.Fatal("wrong out[1].NumBytes") } - if out[1].Operation != errorsx.ReadOperation { + if out[1].Operation != netxlite.ReadOperation { t.Fatal("wrong out[1].Operation") } if !floatEquals(out[1].T, 0.020) { @@ -886,7 +886,7 @@ func TestNewNetworkEventsListGood(t *testing.T) { if out[2].NumBytes != 17714 { t.Fatal("wrong out[2].NumBytes") } - if out[2].Operation != errorsx.WriteOperation { + if out[2].Operation != netxlite.WriteOperation { t.Fatal("wrong out[2].Operation") } if !floatEquals(out[2].T, 0.030) { @@ -933,7 +933,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) { if out[0].NumBytes != 0 { t.Fatal("wrong out[0].NumBytes") } - if out[0].Operation != errorsx.ConnectOperation { + if out[0].Operation != netxlite.ConnectOperation { t.Fatal("wrong out[0].Operation") } if !floatEquals(out[0].T, 0.010) { @@ -949,7 +949,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) { if out[1].NumBytes != 1789 { t.Fatal("wrong out[1].NumBytes") } - if out[1].Operation != errorsx.ReadOperation { + if out[1].Operation != netxlite.ReadOperation { t.Fatal("wrong out[1].Operation") } if !floatEquals(out[1].T, 0.020) { @@ -965,7 +965,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) { if out[2].NumBytes != 17714 { t.Fatal("wrong out[2].NumBytes") } - if out[2].Operation != errorsx.WriteOperation { + if out[2].Operation != netxlite.WriteOperation { t.Fatal("wrong out[2].Operation") } if !floatEquals(out[2].T, 0.030) { diff --git a/internal/engine/legacy/oonitemplates/oonitemplates.go b/internal/engine/legacy/oonitemplates/oonitemplates.go index 0daace8..4a6651a 100644 --- a/internal/engine/legacy/oonitemplates/oonitemplates.go +++ b/internal/engine/legacy/oonitemplates/oonitemplates.go @@ -24,7 +24,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" "gitlab.com/yawning/obfs4.git/transports" obfs4base "gitlab.com/yawning/obfs4.git/transports/base" @@ -327,7 +327,7 @@ func HTTPDo( config.MaxResponseBodySnapSize, ), ) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) mu.Lock() results.BodySnap, results.Error = data, err mu.Unlock() diff --git a/internal/engine/legacy/oonitemplates/oonitemplates_test.go b/internal/engine/legacy/oonitemplates/oonitemplates_test.go index e06ed83..7ee27d9 100644 --- a/internal/engine/legacy/oonitemplates/oonitemplates_test.go +++ b/internal/engine/legacy/oonitemplates/oonitemplates_test.go @@ -11,7 +11,7 @@ import ( goptlib "git.torproject.org/pluggable-transports/goptlib.git" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "gitlab.com/yawning/obfs4.git/transports" obfs4base "gitlab.com/yawning/obfs4.git/transports/base" ) @@ -55,7 +55,7 @@ func TestDNSLookupCancellation(t *testing.T) { if results.Error == nil { t.Fatal("expected an error here") } - if results.Error.Error() != errorsx.FailureGenericTimeoutError { + if results.Error.Error() != netxlite.FailureGenericTimeoutError { t.Fatal("not the error we expected") } if len(results.Addresses) > 0 { @@ -170,7 +170,7 @@ func TestTLSConnectCancellation(t *testing.T) { if results.Error == nil { t.Fatal("expected an error here") } - if results.Error.Error() != errorsx.FailureGenericTimeoutError { + if results.Error.Error() != netxlite.FailureGenericTimeoutError { t.Fatal("not the error we expected") } } diff --git a/internal/engine/netx/archival/archival.go b/internal/engine/netx/archival/archival.go index 09d8491..576e31b 100644 --- a/internal/engine/netx/archival/archival.go +++ b/internal/engine/netx/archival/archival.go @@ -20,7 +20,7 @@ import ( errorsxlegacy "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/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // ExtSpec describes a data format extension @@ -81,7 +81,7 @@ type TCPConnectEntry struct { func NewTCPConnectList(begin time.Time, events []trace.Event) []TCPConnectEntry { var out []TCPConnectEntry for _, event := range events { - if event.Name != errorsx.ConnectOperation { + if event.Name != netxlite.ConnectOperation { continue } if event.Proto != "tcp" { @@ -113,9 +113,9 @@ func NewFailure(err error) *string { // in which this happen is with context deadline for HTTP. err = errorsxlegacy.SafeErrWrapperBuilder{ Error: err, - Operation: errorsx.TopLevelOperation, + Operation: netxlite.TopLevelOperation, }.MaybeBuild() - errWrapper := err.(*errorsx.ErrWrapper) + errWrapper := err.(*netxlite.ErrWrapper) s := errWrapper.Failure if s == "" { s = "unknown_failure: errWrapper.Failure is empty" @@ -129,8 +129,8 @@ func NewFailedOperation(err error) *string { return nil } var ( - errWrapper *errorsx.ErrWrapper - s = errorsx.UnknownOperation + errWrapper *netxlite.ErrWrapper + s = netxlite.UnknownOperation ) if errors.As(err, &errWrapper) && errWrapper.Operation != "" { s = errWrapper.Operation @@ -475,7 +475,7 @@ type NetworkEvent struct { func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent { var out []NetworkEvent for _, ev := range events { - if ev.Name == errorsx.ConnectOperation { + if ev.Name == netxlite.ConnectOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), @@ -485,7 +485,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorsx.ReadOperation { + if ev.Name == netxlite.ReadOperation { out = append(out, NetworkEvent{ Failure: NewFailure(ev.Err), Operation: ev.Name, @@ -494,7 +494,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorsx.WriteOperation { + if ev.Name == netxlite.WriteOperation { out = append(out, NetworkEvent{ Failure: NewFailure(ev.Err), Operation: ev.Name, @@ -503,7 +503,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorsx.ReadFromOperation { + if ev.Name == netxlite.ReadFromOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), @@ -513,7 +513,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent }) continue } - if ev.Name == errorsx.WriteToOperation { + if ev.Name == netxlite.WriteToOperation { out = append(out, NetworkEvent{ Address: ev.Address, Failure: NewFailure(ev.Err), diff --git a/internal/engine/netx/archival/archival_test.go b/internal/engine/netx/archival/archival_test.go index d8b8bc1..dfd0f52 100644 --- a/internal/engine/netx/archival/archival_test.go +++ b/internal/engine/netx/archival/archival_test.go @@ -15,7 +15,7 @@ import ( "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/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestNewTCPConnectList(t *testing.T) { @@ -47,20 +47,20 @@ func TestNewTCPConnectList(t *testing.T) { }, { Address: "8.8.8.8:853", Duration: 30 * time.Millisecond, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: "tcp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.8.8:853", Duration: 55 * time.Millisecond, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: "udp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.4.4:53", Duration: 50 * time.Millisecond, Err: io.EOF, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: "tcp", Time: begin.Add(180 * time.Millisecond), }}, @@ -314,14 +314,14 @@ func TestNewDNSQueriesList(t *testing.T) { }, { Address: "8.8.8.8:853", Duration: 30 * time.Millisecond, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: "tcp", Time: begin.Add(130 * time.Millisecond), }, { Address: "8.8.4.4:53", Duration: 50 * time.Millisecond, Err: io.EOF, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: "tcp", Time: begin.Add(180 * time.Millisecond), }}, @@ -371,7 +371,7 @@ func TestNewDNSQueriesList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Err: &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}, + Err: &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError}, Hostname: "dns.google.com", Name: "resolve_done", Time: begin.Add(200 * time.Millisecond), @@ -380,14 +380,14 @@ func TestNewDNSQueriesList(t *testing.T) { want: []archival.DNSQueryEntry{{ Answers: nil, Failure: archival.NewFailure( - &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), + &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError}), Hostname: "dns.google.com", QueryType: "A", T: 0.2, }, { Answers: nil, Failure: archival.NewFailure( - &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), + &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError}), Hostname: "dns.google.com", QueryType: "AAAA", T: 0.2, @@ -425,35 +425,35 @@ func TestNewNetworkEventsList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Address: "8.8.8.8:853", Err: io.EOF, Proto: "tcp", Time: begin.Add(7 * time.Millisecond), }, { - Name: errorsx.ReadOperation, + Name: netxlite.ReadOperation, Err: context.Canceled, NumBytes: 7117, Time: begin.Add(11 * time.Millisecond), }, { Address: "8.8.8.8:853", - Name: errorsx.ReadFromOperation, + Name: netxlite.ReadFromOperation, Err: context.Canceled, NumBytes: 7117, Time: begin.Add(11 * time.Millisecond), }, { - Name: errorsx.WriteOperation, + Name: netxlite.WriteOperation, Err: websocket.ErrBadHandshake, NumBytes: 4114, Time: begin.Add(14 * time.Millisecond), }, { Address: "8.8.8.8:853", - Name: errorsx.WriteToOperation, + Name: netxlite.WriteToOperation, Err: websocket.ErrBadHandshake, NumBytes: 4114, Time: begin.Add(14 * time.Millisecond), }, { - Name: errorsx.CloseOperation, + Name: netxlite.CloseOperation, Err: websocket.ErrReadLimit, Time: begin.Add(17 * time.Millisecond), }}, @@ -461,34 +461,34 @@ func TestNewNetworkEventsList(t *testing.T) { want: []archival.NetworkEvent{{ Address: "8.8.8.8:853", Failure: archival.NewFailure(io.EOF), - Operation: errorsx.ConnectOperation, + Operation: netxlite.ConnectOperation, Proto: "tcp", T: 0.007, }, { Failure: archival.NewFailure(context.Canceled), NumBytes: 7117, - Operation: errorsx.ReadOperation, + Operation: netxlite.ReadOperation, T: 0.011, }, { Address: "8.8.8.8:853", Failure: archival.NewFailure(context.Canceled), NumBytes: 7117, - Operation: errorsx.ReadFromOperation, + Operation: netxlite.ReadFromOperation, T: 0.011, }, { Failure: archival.NewFailure(websocket.ErrBadHandshake), NumBytes: 4114, - Operation: errorsx.WriteOperation, + Operation: netxlite.WriteOperation, T: 0.014, }, { Address: "8.8.8.8:853", Failure: archival.NewFailure(websocket.ErrBadHandshake), NumBytes: 4114, - Operation: errorsx.WriteToOperation, + Operation: netxlite.WriteToOperation, T: 0.014, }, { Failure: archival.NewFailure(websocket.ErrReadLimit), - Operation: errorsx.CloseOperation, + Operation: netxlite.CloseOperation, T: 0.017, }}, }} @@ -523,7 +523,7 @@ func TestNewTLSHandshakesList(t *testing.T) { args: args{ begin: begin, events: []trace.Event{{ - Name: errorsx.CloseOperation, + Name: netxlite.CloseOperation, Err: websocket.ErrReadLimit, Time: begin.Add(17 * time.Millisecond), }, { @@ -929,18 +929,18 @@ func TestNewFailure(t *testing.T) { }, { name: "when error is wrapped and failure meaningful", args: args{ - err: &errorsx.ErrWrapper{ - Failure: errorsx.FailureConnectionRefused, + err: &netxlite.ErrWrapper{ + Failure: netxlite.FailureConnectionRefused, }, }, want: func() *string { - s := errorsx.FailureConnectionRefused + s := netxlite.FailureConnectionRefused return &s }(), }, { name: "when error is wrapped and failure is not meaningful", args: args{ - err: &errorsx.ErrWrapper{}, + err: &netxlite.ErrWrapper{}, }, want: func() *string { s := "unknown_failure: errWrapper.Failure is empty" @@ -1002,24 +1002,24 @@ func TestNewFailedOperation(t *testing.T) { }, { name: "With wrapped error and non-empty operation", args: args{ - err: &errorsx.ErrWrapper{ - Failure: errorsx.FailureConnectionRefused, - Operation: errorsx.ConnectOperation, + err: &netxlite.ErrWrapper{ + Failure: netxlite.FailureConnectionRefused, + Operation: netxlite.ConnectOperation, }, }, want: (func() *string { - s := errorsx.ConnectOperation + s := netxlite.ConnectOperation return &s })(), }, { name: "With wrapped error and empty operation", args: args{ - err: &errorsx.ErrWrapper{ - Failure: errorsx.FailureConnectionRefused, + err: &netxlite.ErrWrapper{ + Failure: netxlite.FailureConnectionRefused, }, }, want: (func() *string { - s := errorsx.UnknownOperation + s := netxlite.UnknownOperation return &s })(), }, { @@ -1028,7 +1028,7 @@ func TestNewFailedOperation(t *testing.T) { err: io.EOF, }, want: (func() *string { - s := errorsx.UnknownOperation + s := netxlite.UnknownOperation return &s })(), }} diff --git a/internal/engine/netx/dialer/bytecounter_test.go b/internal/engine/netx/dialer/bytecounter_test.go index 23c39eb..2df3e07 100644 --- a/internal/engine/netx/dialer/bytecounter_test.go +++ b/internal/engine/netx/dialer/bytecounter_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/bytecounter" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -27,7 +27,7 @@ func dorequest(ctx context.Context, url string) error { if err != nil { return err } - if _, err := iox.CopyContext(ctx, io.Discard, resp.Body); err != nil { + if _, err := netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil { return err } return resp.Body.Close() diff --git a/internal/engine/netx/dialer/saver.go b/internal/engine/netx/dialer/saver.go index cded652..8f9345c 100644 --- a/internal/engine/netx/dialer/saver.go +++ b/internal/engine/netx/dialer/saver.go @@ -6,7 +6,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // saverDialer saves events occurring during the dial @@ -24,7 +24,7 @@ func (d *saverDialer) DialContext(ctx context.Context, network, address string) Address: address, Duration: stop.Sub(start), Err: err, - Name: errorsx.ConnectOperation, + Name: netxlite.ConnectOperation, Proto: network, Time: stop, }) @@ -61,7 +61,7 @@ func (c *saverConn) Read(p []byte) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorsx.ReadOperation, + Name: netxlite.ReadOperation, Time: stop, }) return count, err @@ -76,7 +76,7 @@ func (c *saverConn) Write(p []byte) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorsx.WriteOperation, + Name: netxlite.WriteOperation, Time: stop, }) return count, err diff --git a/internal/engine/netx/dialer/saver_test.go b/internal/engine/netx/dialer/saver_test.go index 3534023..167406d 100644 --- a/internal/engine/netx/dialer/saver_test.go +++ b/internal/engine/netx/dialer/saver_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -44,7 +44,7 @@ func TestSaverDialerFailure(t *testing.T) { if !errors.Is(ev[0].Err, expected) { t.Fatal("unexpected Err") } - if ev[0].Name != errorsx.ConnectOperation { + if ev[0].Name != netxlite.ConnectOperation { t.Fatal("unexpected Name") } if ev[0].Proto != "tcp" { diff --git a/internal/engine/netx/fake_test.go b/internal/engine/netx/fake_test.go index 5553c61..bdfcce2 100644 --- a/internal/engine/netx/fake_test.go +++ b/internal/engine/netx/fake_test.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeDialer struct { @@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/engine/netx/httptransport/bytecounter_test.go b/internal/engine/netx/httptransport/bytecounter_test.go index c2905a4..eadf040 100644 --- a/internal/engine/netx/httptransport/bytecounter_test.go +++ b/internal/engine/netx/httptransport/bytecounter_test.go @@ -10,7 +10,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/bytecounter" "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestByteCounterFailure(t *testing.T) { @@ -69,7 +69,7 @@ func TestByteCounterSuccess(t *testing.T) { if err != nil { t.Fatal(err) } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } @@ -105,7 +105,7 @@ func TestByteCounterSuccessWithEOF(t *testing.T) { if err != nil { t.Fatal(err) } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/netx/httptransport/fake_test.go b/internal/engine/netx/httptransport/fake_test.go index 1877211..83c72a0 100644 --- a/internal/engine/netx/httptransport/fake_test.go +++ b/internal/engine/netx/httptransport/fake_test.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeDialer struct { @@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/engine/netx/httptransport/saver.go b/internal/engine/netx/httptransport/saver.go index 3141327..c8b4534 100644 --- a/internal/engine/netx/httptransport/saver.go +++ b/internal/engine/netx/httptransport/saver.go @@ -10,7 +10,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // SaverPerformanceHTTPTransport is a RoundTripper that saves @@ -172,7 +172,7 @@ func ignoreExpectedEOF(err error, resp *http.Response) error { } func saverSnapRead(ctx context.Context, r io.ReadCloser, snapsize int) ([]byte, error) { - return iox.ReadAllContext(ctx, io.LimitReader(r, int64(snapsize))) + return netxlite.ReadAllContext(ctx, io.LimitReader(r, int64(snapsize))) } func saverCompose(data []byte, r io.ReadCloser) io.ReadCloser { diff --git a/internal/engine/netx/httptransport/saver_test.go b/internal/engine/netx/httptransport/saver_test.go index 6ede801..9682b6a 100644 --- a/internal/engine/netx/httptransport/saver_test.go +++ b/internal/engine/netx/httptransport/saver_test.go @@ -12,7 +12,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestSaverPerformanceNoMultipleEvents(t *testing.T) { @@ -248,7 +248,7 @@ func TestSaverBodySuccess(t *testing.T) { txp := httptransport.SaverBodyHTTPTransport{ RoundTripper: httptransport.FakeTransport{ Func: func(req *http.Request) (*http.Response, error) { - data, err := iox.ReadAllContext(context.Background(), req.Body) + data, err := netxlite.ReadAllContext(context.Background(), req.Body) if err != nil { t.Fatal(err) } @@ -277,7 +277,7 @@ func TestSaverBodySuccess(t *testing.T) { t.Fatal("unexpected status code") } defer resp.Body.Close() - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/netx/integration_test.go b/internal/engine/netx/integration_test.go index 3e2ede4..050686b 100644 --- a/internal/engine/netx/integration_test.go +++ b/internal/engine/netx/integration_test.go @@ -10,8 +10,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/bytecounter" "github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestSuccess(t *testing.T) { @@ -38,7 +37,7 @@ func TestSuccess(t *testing.T) { if err != nil { t.Fatal(err) } - if _, err = iox.ReadAllContext(context.Background(), resp.Body); err != nil { + if _, err = netxlite.ReadAllContext(context.Background(), resp.Body); err != nil { t.Fatal(err) } if err = resp.Body.Close(); err != nil { @@ -78,10 +77,10 @@ func TestBogonResolutionNotBroken(t *testing.T) { Logger: log.Log, }) addrs, err := r.LookupHost(context.Background(), "www.google.com") - if !errors.Is(err, errorsx.ErrDNSBogon) { + if !errors.Is(err, netxlite.ErrDNSBogon) { t.Fatal("not the error we expected") } - if err.Error() != errorsx.FailureDNSBogonError { + if err.Error() != netxlite.FailureDNSBogonError { t.Fatal("error not correctly wrapped") } if len(addrs) > 0 { diff --git a/internal/engine/netx/netx.go b/internal/engine/netx/netx.go index 97eec27..d800f4e 100644 --- a/internal/engine/netx/netx.go +++ b/internal/engine/netx/netx.go @@ -354,7 +354,8 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride, if err != nil { return c, err } - var txp resolver.RoundTripper = resolver.NewDNSOverUDP(dialer, endpoint) + var txp resolver.RoundTripper = resolver.NewDNSOverUDP( + netxlite.NewDialerLegacyAdapter(dialer), endpoint) if config.ResolveSaver != nil { txp = resolver.SaverDNSTransport{ RoundTripper: txp, diff --git a/internal/engine/netx/quicdialer/system.go b/internal/engine/netx/quicdialer/system.go index 57db87a..939cbe9 100644 --- a/internal/engine/netx/quicdialer/system.go +++ b/internal/engine/netx/quicdialer/system.go @@ -5,7 +5,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -53,7 +53,7 @@ func (c *saverUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { Duration: stop.Sub(start), Err: err, NumBytes: count, - Name: errorsx.WriteToOperation, + Name: netxlite.WriteToOperation, Time: stop, }) return count, err @@ -73,7 +73,7 @@ func (c *saverUDPConn) ReadFrom(b []byte) (int, net.Addr, error) { Duration: stop.Sub(start), Err: err, NumBytes: n, - Name: errorsx.ReadFromOperation, + Name: netxlite.ReadFromOperation, Time: stop, }) return n, addr, err diff --git a/internal/engine/netx/quicdialer/system_test.go b/internal/engine/netx/quicdialer/system_test.go index 6cc363a..91caa9a 100644 --- a/internal/engine/netx/quicdialer/system_test.go +++ b/internal/engine/netx/quicdialer/system_test.go @@ -11,7 +11,6 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -76,7 +75,7 @@ func TestSystemDialerSuccessWithReadWrite(t *testing.T) { t.Fatal("unexpected NumBytes") } switch ev[idx].Name { - case errorsx.ReadFromOperation, errorsx.WriteToOperation: + case netxlite.ReadFromOperation, netxlite.WriteToOperation: default: t.Fatal("unexpected Name") } diff --git a/internal/engine/netx/resolver/bogon.go b/internal/engine/netx/resolver/bogon.go index 63f40eb..1de1e41 100644 --- a/internal/engine/netx/resolver/bogon.go +++ b/internal/engine/netx/resolver/bogon.go @@ -4,7 +4,7 @@ import ( "context" "net" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/runtimex" ) @@ -65,7 +65,7 @@ func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]strin addrs, err := r.Resolver.LookupHost(ctx, hostname) for _, addr := range addrs { if IsBogon(addr) { - return nil, errorsx.ErrDNSBogon + return nil, netxlite.ErrDNSBogon } } return addrs, err diff --git a/internal/engine/netx/resolver/bogon_test.go b/internal/engine/netx/resolver/bogon_test.go index d5c2d73..c282c01 100644 --- a/internal/engine/netx/resolver/bogon_test.go +++ b/internal/engine/netx/resolver/bogon_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/engine/netx/resolver" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func TestResolverIsBogon(t *testing.T) { @@ -29,7 +29,7 @@ func TestBogonAwareResolverWithBogon(t *testing.T) { Resolver: resolver.NewFakeResolverWithResult([]string{"127.0.0.1"}), } addrs, err := r.LookupHost(context.Background(), "dns.google.com") - if !errors.Is(err, errorsx.ErrDNSBogon) { + if !errors.Is(err, netxlite.ErrDNSBogon) { t.Fatal("not the error we expected") } if len(addrs) > 0 { diff --git a/internal/engine/netx/resolver/integration_test.go b/internal/engine/netx/resolver/integration_test.go index b8d7a75..280214e 100644 --- a/internal/engine/netx/resolver/integration_test.go +++ b/internal/engine/netx/resolver/integration_test.go @@ -70,14 +70,14 @@ func TestNewResolverSystem(t *testing.T) { func TestNewResolverUDPAddress(t *testing.T) { reso := resolver.NewSerialResolver( - resolver.NewDNSOverUDP(new(net.Dialer), "8.8.8.8:53")) + resolver.NewDNSOverUDP(netxlite.NewDialerLegacyAdapter(&net.Dialer{}), "8.8.8.8:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } func TestNewResolverUDPDomain(t *testing.T) { reso := resolver.NewSerialResolver( - resolver.NewDNSOverUDP(new(net.Dialer), "dns.google.com:53")) + resolver.NewDNSOverUDP(netxlite.NewDialerLegacyAdapter(&net.Dialer{}), "dns.google.com:53")) testresolverquick(t, reso) testresolverquickidna(t, reso) } diff --git a/internal/engine/netx/resolver/legacy.go b/internal/engine/netx/resolver/legacy.go index 9e58a2a..e73096a 100644 --- a/internal/engine/netx/resolver/legacy.go +++ b/internal/engine/netx/resolver/legacy.go @@ -1,28 +1,28 @@ package resolver -import "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx" +import "github.com/ooni/probe-cli/v3/internal/netxlite" // Variables that other packages expect to find here but have been // moved into the internal/netxlite/dnsx package. var ( - NewSerialResolver = dnsx.NewSerialResolver - NewDNSOverUDP = dnsx.NewDNSOverUDP - NewDNSOverTCP = dnsx.NewDNSOverTCP - NewDNSOverTLS = dnsx.NewDNSOverTLS - NewDNSOverHTTPS = dnsx.NewDNSOverHTTPS - NewDNSOverHTTPSWithHostOverride = dnsx.NewDNSOverHTTPSWithHostOverride + NewSerialResolver = netxlite.NewSerialResolver + NewDNSOverUDP = netxlite.NewDNSOverUDP + NewDNSOverTCP = netxlite.NewDNSOverTCP + NewDNSOverTLS = netxlite.NewDNSOverTLS + NewDNSOverHTTPS = netxlite.NewDNSOverHTTPS + NewDNSOverHTTPSWithHostOverride = netxlite.NewDNSOverHTTPSWithHostOverride ) // Types that other packages expect to find here but have been // moved into the internal/netxlite/dnsx package. type ( - DNSOverHTTPS = dnsx.DNSOverHTTPS - DNSOverTCP = dnsx.DNSOverTCP - DNSOverUDP = dnsx.DNSOverUDP - MiekgEncoder = dnsx.DNSEncoderMiekg - MiekgDecoder = dnsx.DNSDecoderMiekg - RoundTripper = dnsx.DNSTransport - SerialResolver = dnsx.SerialResolver - Dialer = dnsx.Dialer - DialContextFunc = dnsx.DialContextFunc + DNSOverHTTPS = netxlite.DNSOverHTTPS + DNSOverTCP = netxlite.DNSOverTCP + DNSOverUDP = netxlite.DNSOverUDP + MiekgEncoder = netxlite.DNSEncoderMiekg + MiekgDecoder = netxlite.DNSDecoderMiekg + RoundTripper = netxlite.DNSTransport + SerialResolver = netxlite.SerialResolver + Dialer = netxlite.Dialer + DialContextFunc = netxlite.DialContextFunc ) diff --git a/internal/engine/netx/tlsdialer/saver_test.go b/internal/engine/netx/tlsdialer/saver_test.go index bc7449e..7af6d0d 100644 --- a/internal/engine/netx/tlsdialer/saver_test.go +++ b/internal/engine/netx/tlsdialer/saver_test.go @@ -12,7 +12,6 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "github.com/ooni/probe-cli/v3/internal/netxlite" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) { @@ -71,7 +70,7 @@ func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) { t.Fatal("unexpected NumBytes") } switch ev[idx].Name { - case errorsx.ReadOperation, errorsx.WriteOperation: + case netxlite.ReadOperation, netxlite.WriteOperation: default: t.Fatal("unexpected Name") } diff --git a/internal/engine/probeservices/collector_test.go b/internal/engine/probeservices/collector_test.go index 4a1c0fa..71f6bfa 100644 --- a/internal/engine/probeservices/collector_test.go +++ b/internal/engine/probeservices/collector_test.go @@ -15,7 +15,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/probeservices" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type fakeTestKeys struct { @@ -234,7 +234,7 @@ func TestEndToEnd(t *testing.T) { return } if r.RequestURI == "/report/_id" { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { panic(err) } diff --git a/internal/engine/probeservices/probeservices_test.go b/internal/engine/probeservices/probeservices_test.go index 140afc9..9551dfb 100644 --- a/internal/engine/probeservices/probeservices_test.go +++ b/internal/engine/probeservices/probeservices_test.go @@ -16,7 +16,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/probeservices" "github.com/ooni/probe-cli/v3/internal/engine/probeservices/testorchestra" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func newclient() *probeservices.Client { @@ -165,7 +165,7 @@ func TestCloudfront(t *testing.T) { if resp.StatusCode != 200 { t.Fatal("unexpected status code") } - data, err := iox.ReadAllContext(req.Context(), resp.Body) + data, err := netxlite.ReadAllContext(req.Context(), resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/engine/session_integration_test.go b/internal/engine/session_integration_test.go index 49ba4b4..d1472dd 100644 --- a/internal/engine/session_integration_test.go +++ b/internal/engine/session_integration_test.go @@ -16,7 +16,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/geolocate" "github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/probeservices" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/version" ) @@ -32,7 +32,7 @@ func TestSessionByteCounter(t *testing.T) { } defer resp.Body.Close() ctx := context.Background() - if _, err := iox.CopyContext(ctx, io.Discard, resp.Body); err != nil { + if _, err := netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil { t.Fatal(err) } if s.KibiBytesSent() <= 0 || s.KibiBytesReceived() <= 0 { diff --git a/internal/fsx/example_test.go b/internal/fsx/example_test.go index 2c86687..037807a 100644 --- a/internal/fsx/example_test.go +++ b/internal/fsx/example_test.go @@ -9,7 +9,7 @@ import ( "syscall" "github.com/ooni/probe-cli/v3/internal/fsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) func ExampleOpenFile_openingDir() { @@ -27,7 +27,7 @@ func ExampleOpenFile_openingFile() { if err != nil { log.Fatal("unexpected error", err) } - data, err := iox.ReadAllContext(context.Background(), filep) + data, err := netxlite.ReadAllContext(context.Background(), filep) if err != nil { log.Fatal("unexpected error", err) } diff --git a/internal/mlablocate/mlablocate.go b/internal/mlablocate/mlablocate.go index 4d077f8..e8b6708 100644 --- a/internal/mlablocate/mlablocate.go +++ b/internal/mlablocate/mlablocate.go @@ -12,7 +12,7 @@ import ( "net/http" "net/url" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // Logger is the logger expected by this package. @@ -93,7 +93,7 @@ func (c *Client) Query(ctx context.Context, tool string) (Result, error) { if resp.StatusCode != 200 { return Result{}, fmt.Errorf("mlablocate: non-200 status code: %d", resp.StatusCode) } - data, err := iox.ReadAllContext(ctx, resp.Body) + data, err := netxlite.ReadAllContext(ctx, resp.Body) if err != nil { return Result{}, err } diff --git a/internal/mlablocatev2/fake_test.go b/internal/mlablocatev2/fake_test.go index 9605b2d..3b59383 100644 --- a/internal/mlablocatev2/fake_test.go +++ b/internal/mlablocatev2/fake_test.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeTransport struct { @@ -19,7 +19,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { return txp.Func(req) } if req.Body != nil { - iox.ReadAllContext(req.Context(), req.Body) + netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if txp.Err != nil { diff --git a/internal/mlablocatev2/mlablocatev2.go b/internal/mlablocatev2/mlablocatev2.go index 8947b95..f3fe937 100644 --- a/internal/mlablocatev2/mlablocatev2.go +++ b/internal/mlablocatev2/mlablocatev2.go @@ -12,7 +12,7 @@ import ( "net/url" "regexp" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) const ( @@ -128,7 +128,7 @@ func (c Client) query(ctx context.Context, path string) (resultRecord, error) { if resp.StatusCode != 200 { return resultRecord{}, fmt.Errorf("%w: %d", ErrRequestFailed, resp.StatusCode) } - data, err := iox.ReadAllContext(ctx, resp.Body) + data, err := netxlite.ReadAllContext(ctx, resp.Body) if err != nil { return resultRecord{}, err } diff --git a/internal/netxlite/certifi.go b/internal/netxlite/certifi.go index 3252d9b..d2b5af9 100644 --- a/internal/netxlite/certifi.go +++ b/internal/netxlite/certifi.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-27 15:57:57.877144 +0200 CEST m=+1.353309960 +// 2021-09-28 12:05:19.526032 +0200 CEST m=+0.405934084 // https://curl.haxx.se/ca/cacert.pem package netxlite diff --git a/internal/netxlite/errorsx/classify.go b/internal/netxlite/classify.go similarity index 99% rename from internal/netxlite/errorsx/classify.go rename to internal/netxlite/classify.go index 2e0a707..0b61daa 100644 --- a/internal/netxlite/errorsx/classify.go +++ b/internal/netxlite/classify.go @@ -1,4 +1,4 @@ -package errorsx +package netxlite import ( "context" diff --git a/internal/netxlite/errorsx/classify_test.go b/internal/netxlite/classify_test.go similarity index 99% rename from internal/netxlite/errorsx/classify_test.go rename to internal/netxlite/classify_test.go index cde789d..21f05b5 100644 --- a/internal/netxlite/errorsx/classify_test.go +++ b/internal/netxlite/classify_test.go @@ -1,4 +1,4 @@ -package errorsx +package netxlite import ( "context" diff --git a/internal/netxlite/dialer.go b/internal/netxlite/dialer.go index d143b92..9ba9afa 100644 --- a/internal/netxlite/dialer.go +++ b/internal/netxlite/dialer.go @@ -6,8 +6,6 @@ import ( "net" "sync" "time" - - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) // Dialer establishes network connections. @@ -229,8 +227,7 @@ var _ Dialer = &dialerErrWrapper{} func (d *dialerErrWrapper) DialContext(ctx context.Context, network, address string) (net.Conn, error) { conn, err := d.Dialer.DialContext(ctx, network, address) if err != nil { - return nil, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.ConnectOperation, err) + return nil, NewErrWrapper(ClassifyGenericError, ConnectOperation, err) } return &dialerErrWrapperConn{Conn: conn}, nil } @@ -245,8 +242,7 @@ var _ net.Conn = &dialerErrWrapperConn{} func (c *dialerErrWrapperConn) Read(b []byte) (int, error) { count, err := c.Conn.Read(b) if err != nil { - return 0, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.ReadOperation, err) + return 0, NewErrWrapper(ClassifyGenericError, ReadOperation, err) } return count, nil } @@ -254,8 +250,7 @@ func (c *dialerErrWrapperConn) Read(b []byte) (int, error) { func (c *dialerErrWrapperConn) Write(b []byte) (int, error) { count, err := c.Conn.Write(b) if err != nil { - return 0, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.WriteOperation, err) + return 0, NewErrWrapper(ClassifyGenericError, WriteOperation, err) } return count, nil } @@ -263,8 +258,7 @@ func (c *dialerErrWrapperConn) Write(b []byte) (int, error) { func (c *dialerErrWrapperConn) Close() error { err := c.Conn.Close() if err != nil { - return errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.CloseOperation, err) + return NewErrWrapper(ClassifyGenericError, CloseOperation, err) } return nil } diff --git a/internal/netxlite/dialer_test.go b/internal/netxlite/dialer_test.go index d340b4a..67cbafb 100644 --- a/internal/netxlite/dialer_test.go +++ b/internal/netxlite/dialer_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -254,9 +253,9 @@ func TestDialerResolver(t *testing.T) { mu := &sync.Mutex{} errorsList := []error{ errors.New("a mocked error"), - errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, - errorsx.CloseOperation, + NewErrWrapper( + ClassifyGenericError, + CloseOperation, io.EOF, ), } @@ -282,7 +281,7 @@ func TestDialerResolver(t *testing.T) { }, } conn, err := d.DialContext(context.Background(), "tcp", "dot.dns:853") - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if conn != nil { @@ -296,9 +295,9 @@ func TestDialerResolver(t *testing.T) { mu := &sync.Mutex{} errorsList := []error{ errors.New("a mocked error"), - errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, - errorsx.CloseOperation, + NewErrWrapper( + ClassifyGenericError, + CloseOperation, errors.New("antani"), ), } @@ -529,7 +528,7 @@ func TestDialerErrWrapper(t *testing.T) { } ctx := context.Background() conn, err := d.DialContext(ctx, "", "") - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if conn != nil { @@ -585,7 +584,7 @@ func TestDialerErrWrapperConn(t *testing.T) { }, } count, err := conn.Read(b) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if count != 0 { @@ -624,7 +623,7 @@ func TestDialerErrWrapperConn(t *testing.T) { }, } count, err := conn.Write(b) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if count != 0 { @@ -658,7 +657,7 @@ func TestDialerErrWrapperConn(t *testing.T) { }, } err := conn.Close() - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } }) diff --git a/internal/netxlite/dnsx/dnsdecoder.go b/internal/netxlite/dnsdecoder.go similarity index 82% rename from internal/netxlite/dnsx/dnsdecoder.go rename to internal/netxlite/dnsdecoder.go index 067f3f5..5976d74 100644 --- a/internal/netxlite/dnsx/dnsdecoder.go +++ b/internal/netxlite/dnsdecoder.go @@ -1,13 +1,6 @@ -package dnsx +package netxlite -import ( - "github.com/miekg/dns" - "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx/model" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" -) - -// HTTPSSvc is an HTTPSSvc reply. -type HTTPSSvc = model.HTTPSSvc +import "github.com/miekg/dns" // The DNSDecoder decodes DNS replies. type DNSDecoder interface { @@ -32,11 +25,11 @@ func (d *DNSDecoderMiekg) parseReply(data []byte) (*dns.Msg, error) { case dns.RcodeSuccess: return reply, nil case dns.RcodeNameError: - return nil, errorsx.ErrOODNSNoSuchHost + return nil, ErrOODNSNoSuchHost case dns.RcodeRefused: - return nil, errorsx.ErrOODNSRefused + return nil, ErrOODNSRefused default: - return nil, errorsx.ErrOODNSMisbehaving + return nil, ErrOODNSMisbehaving } } @@ -66,7 +59,7 @@ func (d *DNSDecoderMiekg) DecodeHTTPS(data []byte) (*HTTPSSvc, error) { } } if len(out.ALPN) <= 0 { - return nil, errorsx.ErrOODNSNoAnswer + return nil, ErrOODNSNoAnswer } return out, nil } @@ -92,7 +85,7 @@ func (d *DNSDecoderMiekg) DecodeLookupHost(qtype uint16, data []byte) ([]string, } } if len(addrs) <= 0 { - return nil, errorsx.ErrOODNSNoAnswer + return nil, ErrOODNSNoAnswer } return addrs, nil } diff --git a/internal/netxlite/dnsx/dnsdecoder_test.go b/internal/netxlite/dnsdecoder_test.go similarity index 95% rename from internal/netxlite/dnsx/dnsdecoder_test.go rename to internal/netxlite/dnsdecoder_test.go index a15e15f..c3e1289 100644 --- a/internal/netxlite/dnsx/dnsdecoder_test.go +++ b/internal/netxlite/dnsdecoder_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "errors" @@ -8,7 +8,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/miekg/dns" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) func TestDNSDecoder(t *testing.T) { @@ -40,7 +39,7 @@ func TestDNSDecoder(t *testing.T) { d := &DNSDecoderMiekg{} data, err := d.DecodeLookupHost( dns.TypeA, dnsGenReplyWithError(t, dns.TypeA, dns.RcodeRefused)) - if !errors.Is(err, errorsx.ErrOODNSRefused) { + if !errors.Is(err, ErrOODNSRefused) { t.Fatal("not the error we expected", err) } if data != nil { @@ -51,7 +50,7 @@ func TestDNSDecoder(t *testing.T) { t.Run("no address", func(t *testing.T) { d := &DNSDecoderMiekg{} data, err := d.DecodeLookupHost(dns.TypeA, dnsGenLookupHostReplySuccess(t, dns.TypeA)) - if !errors.Is(err, errorsx.ErrOODNSNoAnswer) { + if !errors.Is(err, ErrOODNSNoAnswer) { t.Fatal("not the error we expected", err) } if data != nil { @@ -99,7 +98,7 @@ func TestDNSDecoder(t *testing.T) { d := &DNSDecoderMiekg{} data, err := d.DecodeLookupHost( dns.TypeA, dnsGenLookupHostReplySuccess(t, dns.TypeAAAA, "::1", "fe80::1")) - if !errors.Is(err, errorsx.ErrOODNSNoAnswer) { + if !errors.Is(err, ErrOODNSNoAnswer) { t.Fatal("not the error we expected", err) } if data != nil { @@ -111,7 +110,7 @@ func TestDNSDecoder(t *testing.T) { d := &DNSDecoderMiekg{} data, err := d.DecodeLookupHost( dns.TypeAAAA, dnsGenLookupHostReplySuccess(t, dns.TypeA, "1.1.1.1", "8.8.4.4.")) - if !errors.Is(err, errorsx.ErrOODNSNoAnswer) { + if !errors.Is(err, ErrOODNSNoAnswer) { t.Fatal("not the error we expected", err) } if data != nil { @@ -129,7 +128,7 @@ func TestDNSDecoder(t *testing.T) { t.Fatal(err) } reply, err := d.parseReply(data) - if !errors.Is(err, errorsx.ErrOODNSMisbehaving) { // catch all error + if !errors.Is(err, ErrOODNSMisbehaving) { // catch all error t.Fatal("not the error we expected", err) } if reply != nil { @@ -153,7 +152,7 @@ func TestDNSDecoder(t *testing.T) { data := dnsGenHTTPSReplySuccess(t, nil, nil, nil) d := &DNSDecoderMiekg{} reply, err := d.DecodeHTTPS(data) - if !errors.Is(err, errorsx.ErrOODNSNoAnswer) { + if !errors.Is(err, ErrOODNSNoAnswer) { t.Fatal("unexpected err", err) } if reply != nil { diff --git a/internal/netxlite/dnsx/dnsencoder.go b/internal/netxlite/dnsencoder.go similarity index 99% rename from internal/netxlite/dnsx/dnsencoder.go rename to internal/netxlite/dnsencoder.go index d238308..6a96ab5 100644 --- a/internal/netxlite/dnsx/dnsencoder.go +++ b/internal/netxlite/dnsencoder.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import "github.com/miekg/dns" diff --git a/internal/netxlite/dnsx/dnsencoder_test.go b/internal/netxlite/dnsencoder_test.go similarity index 99% rename from internal/netxlite/dnsx/dnsencoder_test.go rename to internal/netxlite/dnsencoder_test.go index 99edad8..10257f0 100644 --- a/internal/netxlite/dnsx/dnsencoder_test.go +++ b/internal/netxlite/dnsencoder_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "strings" diff --git a/internal/netxlite/dnsx/dnsoverhttps.go b/internal/netxlite/dnsoverhttps.go similarity index 95% rename from internal/netxlite/dnsx/dnsoverhttps.go rename to internal/netxlite/dnsoverhttps.go index 30f9804..f63b9b1 100644 --- a/internal/netxlite/dnsx/dnsoverhttps.go +++ b/internal/netxlite/dnsoverhttps.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "bytes" @@ -8,7 +8,6 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/httpheader" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" ) // HTTPClient is the HTTP client expected by DNSOverHTTPS. @@ -63,7 +62,7 @@ func (t *DNSOverHTTPS) RoundTrip(ctx context.Context, query []byte) ([]byte, err if resp.Header.Get("content-type") != "application/dns-message" { return nil, errors.New("doh: invalid content-type") } - return iox.ReadAllContext(ctx, resp.Body) + return ReadAllContext(ctx, resp.Body) } // RequiresPadding returns true for DoH according to RFC8467 diff --git a/internal/netxlite/dnsx/dnsoverhttps_test.go b/internal/netxlite/dnsoverhttps_test.go similarity index 99% rename from internal/netxlite/dnsx/dnsoverhttps_test.go rename to internal/netxlite/dnsoverhttps_test.go index 1c88fb3..c21b924 100644 --- a/internal/netxlite/dnsx/dnsoverhttps_test.go +++ b/internal/netxlite/dnsoverhttps_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "bytes" diff --git a/internal/netxlite/dnsx/dnsovertcp.go b/internal/netxlite/dnsovertcp.go similarity index 99% rename from internal/netxlite/dnsx/dnsovertcp.go rename to internal/netxlite/dnsovertcp.go index 2e9cd2b..77f9c7c 100644 --- a/internal/netxlite/dnsx/dnsovertcp.go +++ b/internal/netxlite/dnsovertcp.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "context" diff --git a/internal/netxlite/dnsx/dnsovertcp_test.go b/internal/netxlite/dnsovertcp_test.go similarity index 99% rename from internal/netxlite/dnsx/dnsovertcp_test.go rename to internal/netxlite/dnsovertcp_test.go index 803d97d..9c9c296 100644 --- a/internal/netxlite/dnsx/dnsovertcp_test.go +++ b/internal/netxlite/dnsovertcp_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "bytes" diff --git a/internal/netxlite/dnsx/dnsoverudp.go b/internal/netxlite/dnsoverudp.go similarity index 88% rename from internal/netxlite/dnsx/dnsoverudp.go rename to internal/netxlite/dnsoverudp.go index 08b95f0..5eae24e 100644 --- a/internal/netxlite/dnsx/dnsoverudp.go +++ b/internal/netxlite/dnsoverudp.go @@ -1,16 +1,10 @@ -package dnsx +package netxlite import ( "context" - "net" "time" ) -// Dialer is the network dialer interface assumed by this package. -type Dialer interface { - DialContext(ctx context.Context, network, address string) (net.Conn, error) -} - // DNSOverUDP is a DNS over UDP RoundTripper. type DNSOverUDP struct { dialer Dialer diff --git a/internal/netxlite/dnsx/dnsoverudp_test.go b/internal/netxlite/dnsoverudp_test.go similarity index 97% rename from internal/netxlite/dnsx/dnsoverudp_test.go rename to internal/netxlite/dnsoverudp_test.go index fab0a92..ee3ca3b 100644 --- a/internal/netxlite/dnsx/dnsoverudp_test.go +++ b/internal/netxlite/dnsoverudp_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "bytes" @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -147,7 +148,7 @@ func TestDNSOverUDP(t *testing.T) { t.Run("other functions okay", func(t *testing.T) { const address = "9.9.9.9:53" - txp := NewDNSOverUDP(&net.Dialer{}, address) + txp := NewDNSOverUDP(NewDialerWithoutResolver(log.Log), address) if txp.RequiresPadding() != false { t.Fatal("invalid RequiresPadding") } diff --git a/internal/netxlite/dnsx/dnstransport.go b/internal/netxlite/dnstransport.go similarity index 97% rename from internal/netxlite/dnsx/dnstransport.go rename to internal/netxlite/dnstransport.go index 95fe571..a9cc144 100644 --- a/internal/netxlite/dnsx/dnstransport.go +++ b/internal/netxlite/dnstransport.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import "context" diff --git a/internal/netxlite/dnsx/model/model.go b/internal/netxlite/dnsx/dnsx.go similarity index 80% rename from internal/netxlite/dnsx/model/model.go rename to internal/netxlite/dnsx/dnsx.go index 75e9055..25d2640 100644 --- a/internal/netxlite/dnsx/model/model.go +++ b/internal/netxlite/dnsx/dnsx.go @@ -1,5 +1,5 @@ -// Package model contains the dnsx model. -package model +// Package dnsx contains the dnsx model. +package dnsx // HTTPSSvc is an HTTPSSvc reply. type HTTPSSvc struct { diff --git a/internal/netxlite/dnsx/mocks/doc.go b/internal/netxlite/dnsx/mocks/doc.go deleted file mode 100644 index e594bf9..0000000 --- a/internal/netxlite/dnsx/mocks/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package mocks contains mocks for dnsx. -package mocks diff --git a/internal/netxlite/errorsx/errno.go b/internal/netxlite/errno.go similarity index 98% rename from internal/netxlite/errorsx/errno.go rename to internal/netxlite/errno.go index 631d766..e5f9249 100644 --- a/internal/netxlite/errorsx/errno.go +++ b/internal/netxlite/errno.go @@ -1,7 +1,7 @@ // Code generated by go generate; DO NOT EDIT. -// Generated: 2021-09-27 15:57:58.500515 +0200 CEST m=+0.304199251 +// Generated: 2021-09-28 12:05:19.868647 +0200 CEST m=+0.105301959 -package errorsx +package netxlite //go:generate go run ./internal/generrno/ diff --git a/internal/netxlite/errorsx/errno_test.go b/internal/netxlite/errno_test.go similarity index 98% rename from internal/netxlite/errorsx/errno_test.go rename to internal/netxlite/errno_test.go index 42bb3d3..b60b35a 100644 --- a/internal/netxlite/errorsx/errno_test.go +++ b/internal/netxlite/errno_test.go @@ -1,7 +1,7 @@ // Code generated by go generate; DO NOT EDIT. -// Generated: 2021-09-27 15:57:58.553101 +0200 CEST m=+0.356786917 +// Generated: 2021-09-28 12:05:19.918073 +0200 CEST m=+0.154728959 -package errorsx +package netxlite import ( "io" diff --git a/internal/netxlite/errorsx/errno_unix.go b/internal/netxlite/errno_unix.go similarity index 92% rename from internal/netxlite/errorsx/errno_unix.go rename to internal/netxlite/errno_unix.go index 619f15c..82f3004 100644 --- a/internal/netxlite/errorsx/errno_unix.go +++ b/internal/netxlite/errno_unix.go @@ -1,7 +1,7 @@ // Code generated by go generate; DO NOT EDIT. -// Generated: 2021-09-27 15:57:58.197535 +0200 CEST m=+0.001212709 +// Generated: 2021-09-28 12:05:19.763535 +0200 CEST m=+0.000187668 -package errorsx +package netxlite import "golang.org/x/sys/unix" diff --git a/internal/netxlite/errorsx/errno_windows.go b/internal/netxlite/errno_windows.go similarity index 93% rename from internal/netxlite/errorsx/errno_windows.go rename to internal/netxlite/errno_windows.go index a59f6ff..a20a9bd 100644 --- a/internal/netxlite/errorsx/errno_windows.go +++ b/internal/netxlite/errno_windows.go @@ -1,7 +1,7 @@ // Code generated by go generate; DO NOT EDIT. -// Generated: 2021-09-27 15:57:58.455744 +0200 CEST m=+0.259427834 +// Generated: 2021-09-28 12:05:19.843209 +0200 CEST m=+0.079863168 -package errorsx +package netxlite import "golang.org/x/sys/windows" diff --git a/internal/netxlite/errorsx/doc.go b/internal/netxlite/errorsx/doc.go deleted file mode 100644 index 851116f..0000000 --- a/internal/netxlite/errorsx/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -// Package errorsx contains code to classify errors. -// -// We define the ErrWrapper type, that should wrap any error -// and map it to the corresponding OONI failure. -// -// See https://github.com/ooni/spec/blob/master/data-formats/df-007-errors.md -// for a list of OONI failure strings. -// -// We define ClassifyXXX functions that map an `error` type to -// the corresponding OONI failure. -// -// When we cannot map an error to an OONI failure we return -// an "unknown_failure: XXX" string where the XXX part has -// been scrubbed so to remove any network endpoints. -// -// The general approach we have been following for this -// package has been to return the same strings that we used -// with the previous measurement engine, Measurement Kit -// available at https://github.com/measurement-kit/measurement-kit. -package errorsx diff --git a/internal/netxlite/errorsx/errwrapper.go b/internal/netxlite/errwrapper.go similarity index 99% rename from internal/netxlite/errorsx/errwrapper.go rename to internal/netxlite/errwrapper.go index a814b6e..e9b4c5c 100644 --- a/internal/netxlite/errorsx/errwrapper.go +++ b/internal/netxlite/errwrapper.go @@ -1,4 +1,4 @@ -package errorsx +package netxlite import "encoding/json" diff --git a/internal/netxlite/errorsx/errwrapper_test.go b/internal/netxlite/errwrapper_test.go similarity index 99% rename from internal/netxlite/errorsx/errwrapper_test.go rename to internal/netxlite/errwrapper_test.go index 68a6437..1fe8aa4 100644 --- a/internal/netxlite/errorsx/errwrapper_test.go +++ b/internal/netxlite/errwrapper_test.go @@ -1,4 +1,4 @@ -package errorsx +package netxlite import ( "encoding/json" diff --git a/internal/netxlite/http_test.go b/internal/netxlite/http_test.go index bf4966c..9045fc3 100644 --- a/internal/netxlite/http_test.go +++ b/internal/netxlite/http_test.go @@ -13,7 +13,6 @@ import ( "github.com/apex/log" oohttp "github.com/ooni/oohttp" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -84,7 +83,7 @@ func TestHTTPTransportLogger(t *testing.T) { if err != nil { t.Fatal(err) } - iox.ReadAllContext(context.Background(), resp.Body) + ReadAllContext(context.Background(), resp.Body) resp.Body.Close() if count < 1 { t.Fatal("no logs?!") diff --git a/internal/netxlite/internal/gencertifi/main.go b/internal/netxlite/internal/gencertifi/main.go index 344f912..a7c9dae 100644 --- a/internal/netxlite/internal/gencertifi/main.go +++ b/internal/netxlite/internal/gencertifi/main.go @@ -19,7 +19,7 @@ import ( "text/template" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) var tmpl = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT. @@ -50,7 +50,7 @@ func main() { } defer resp.Body.Close() - bundle, err := iox.ReadAllContext(context.Background(), resp.Body) + bundle, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { log.Fatal(err) } diff --git a/internal/netxlite/errorsx/internal/generrno/main.go b/internal/netxlite/internal/generrno/main.go similarity index 98% rename from internal/netxlite/errorsx/internal/generrno/main.go rename to internal/netxlite/internal/generrno/main.go index dce774f..a93ab33 100644 --- a/internal/netxlite/errorsx/internal/generrno/main.go +++ b/internal/netxlite/internal/generrno/main.go @@ -143,7 +143,7 @@ func writeSystemSpecificFile(kind string) { filep := fileCreate(filename) fileWrite(filep, "// Code generated by go generate; DO NOT EDIT.\n") filePrintf(filep, "// Generated: %+v\n\n", time.Now()) - fileWrite(filep, "package errorsx\n\n") + fileWrite(filep, "package netxlite\n\n") filePrintf(filep, "import \"golang.org/x/sys/%s\"\n\n", kind) fileWrite(filep, "const (\n") for _, spec := range Specs { @@ -163,7 +163,7 @@ func writeGenericFile() { filep := fileCreate(filename) fileWrite(filep, "// Code generated by go generate; DO NOT EDIT.\n") filePrintf(filep, "// Generated: %+v\n\n", time.Now()) - fileWrite(filep, "package errorsx\n\n") + fileWrite(filep, "package netxlite\n\n") fileWrite(filep, "//go:generate go run ./internal/generrno/\n\n") fileWrite(filep, "import (\n") fileWrite(filep, "\t\"errors\"\n") @@ -237,7 +237,7 @@ func writeGenericTestFile() { fileWrite(filep, "// Code generated by go generate; DO NOT EDIT.\n") filePrintf(filep, "// Generated: %+v\n\n", time.Now()) - fileWrite(filep, "package errorsx\n\n") + fileWrite(filep, "package netxlite\n\n") fileWrite(filep, "import (\n") fileWrite(filep, "\t\"io\"\n") fileWrite(filep, "\t\"syscall\"\n") diff --git a/internal/netxlite/iox/iox.go b/internal/netxlite/iox.go similarity index 96% rename from internal/netxlite/iox/iox.go rename to internal/netxlite/iox.go index 9101187..a9b8f58 100644 --- a/internal/netxlite/iox/iox.go +++ b/internal/netxlite/iox.go @@ -1,5 +1,4 @@ -// Package iox contains io extensions. -package iox +package netxlite import ( "context" diff --git a/internal/netxlite/iox/example_test.go b/internal/netxlite/iox/example_test.go deleted file mode 100644 index 90f60c1..0000000 --- a/internal/netxlite/iox/example_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package iox_test - -import ( - "context" - "fmt" - "log" - "strings" - - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" -) - -func ExampleReadAllContext() { - r := strings.NewReader("deadbeef") - ctx := context.Background() - out, err := iox.ReadAllContext(ctx, r) - if err != nil { - log.Fatal(err) - } - fmt.Printf("%d\n", len(out)) - // Output: 8 -} diff --git a/internal/netxlite/iox/iox_test.go b/internal/netxlite/iox_test.go similarity index 99% rename from internal/netxlite/iox/iox_test.go rename to internal/netxlite/iox_test.go index eae09f0..d36d173 100644 --- a/internal/netxlite/iox/iox_test.go +++ b/internal/netxlite/iox_test.go @@ -1,4 +1,4 @@ -package iox +package netxlite import ( "context" diff --git a/internal/netxlite/dnsx/mocks/dnsdecoder.go b/internal/netxlite/mocks/dnsdecoder.go similarity index 85% rename from internal/netxlite/dnsx/mocks/dnsdecoder.go rename to internal/netxlite/mocks/dnsdecoder.go index a04858d..6e06916 100644 --- a/internal/netxlite/dnsx/mocks/dnsdecoder.go +++ b/internal/netxlite/mocks/dnsdecoder.go @@ -1,9 +1,9 @@ package mocks -import "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx/model" +import "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx" // HTTPSSvc is the result of HTTPS queries. -type HTTPSSvc = model.HTTPSSvc +type HTTPSSvc = dnsx.HTTPSSvc // DNSDecoder allows mocking dnsx.DNSDecoder. type DNSDecoder struct { diff --git a/internal/netxlite/dnsx/mocks/dnsdecoder_test.go b/internal/netxlite/mocks/dnsdecoder_test.go similarity index 100% rename from internal/netxlite/dnsx/mocks/dnsdecoder_test.go rename to internal/netxlite/mocks/dnsdecoder_test.go diff --git a/internal/netxlite/dnsx/mocks/dnsencoder.go b/internal/netxlite/mocks/dnsencoder.go similarity index 100% rename from internal/netxlite/dnsx/mocks/dnsencoder.go rename to internal/netxlite/mocks/dnsencoder.go diff --git a/internal/netxlite/dnsx/mocks/dnsencoder_test.go b/internal/netxlite/mocks/dnsencoder_test.go similarity index 100% rename from internal/netxlite/dnsx/mocks/dnsencoder_test.go rename to internal/netxlite/mocks/dnsencoder_test.go diff --git a/internal/netxlite/dnsx/mocks/dnstransport.go b/internal/netxlite/mocks/dnstransport.go similarity index 100% rename from internal/netxlite/dnsx/mocks/dnstransport.go rename to internal/netxlite/mocks/dnstransport.go diff --git a/internal/netxlite/dnsx/mocks/dnstransport_test.go b/internal/netxlite/mocks/dnstransport_test.go similarity index 100% rename from internal/netxlite/dnsx/mocks/dnstransport_test.go rename to internal/netxlite/mocks/dnstransport_test.go diff --git a/internal/netxlite/mocks/resolver.go b/internal/netxlite/mocks/resolver.go index d75fbd4..592a26a 100644 --- a/internal/netxlite/mocks/resolver.go +++ b/internal/netxlite/mocks/resolver.go @@ -2,8 +2,6 @@ package mocks import ( "context" - - "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx/model" ) // Resolver is a mockable Resolver. @@ -35,9 +33,6 @@ func (r *Resolver) CloseIdleConnections() { r.MockCloseIdleConnections() } -// HTTPSSvc is an HTTPSSvc reply. -type HTTPSSvc = model.HTTPSSvc - // LookupHTTPS calls MockLookupHTTPS. func (r *Resolver) LookupHTTPS(ctx context.Context, domain string) (*HTTPSSvc, error) { return r.MockLookupHTTPS(ctx, domain) diff --git a/internal/netxlite/errorsx/operations.go b/internal/netxlite/operations.go similarity index 98% rename from internal/netxlite/errorsx/operations.go rename to internal/netxlite/operations.go index 2f0bc36..256fc03 100644 --- a/internal/netxlite/errorsx/operations.go +++ b/internal/netxlite/operations.go @@ -1,4 +1,4 @@ -package errorsx +package netxlite // Operations that we measure. They are the possibly values of // the ErrWrapper.Operation field. diff --git a/internal/netxlite/quic.go b/internal/netxlite/quic.go index 7193ecb..710cd91 100644 --- a/internal/netxlite/quic.go +++ b/internal/netxlite/quic.go @@ -9,7 +9,6 @@ import ( "sync" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -360,8 +359,7 @@ var _ QUICListener = &quicListenerErrWrapper{} func (qls *quicListenerErrWrapper) Listen(addr *net.UDPAddr) (quicx.UDPLikeConn, error) { pconn, err := qls.QUICListener.Listen(addr) if err != nil { - return nil, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.QUICListenOperation, err) + return nil, NewErrWrapper(ClassifyGenericError, QUICListenOperation, err) } return &quicErrWrapperUDPLikeConn{pconn}, nil } @@ -378,8 +376,7 @@ var _ quicx.UDPLikeConn = &quicErrWrapperUDPLikeConn{} func (c *quicErrWrapperUDPLikeConn) WriteTo(p []byte, addr net.Addr) (int, error) { count, err := c.UDPLikeConn.WriteTo(p, addr) if err != nil { - return 0, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.WriteToOperation, err) + return 0, NewErrWrapper(ClassifyGenericError, WriteToOperation, err) } return count, nil } @@ -388,8 +385,7 @@ func (c *quicErrWrapperUDPLikeConn) WriteTo(p []byte, addr net.Addr) (int, error func (c *quicErrWrapperUDPLikeConn) ReadFrom(b []byte) (int, net.Addr, error) { n, addr, err := c.UDPLikeConn.ReadFrom(b) if err != nil { - return 0, nil, errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.ReadFromOperation, err) + return 0, nil, NewErrWrapper(ClassifyGenericError, ReadFromOperation, err) } return n, addr, nil } @@ -398,8 +394,7 @@ func (c *quicErrWrapperUDPLikeConn) ReadFrom(b []byte) (int, net.Addr, error) { func (c *quicErrWrapperUDPLikeConn) Close() error { err := c.UDPLikeConn.Close() if err != nil { - return errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, errorsx.ReadFromOperation, err) + return NewErrWrapper(ClassifyGenericError, ReadFromOperation, err) } return nil } @@ -415,8 +410,8 @@ func (d *quicDialerErrWrapper) DialContext( tlsCfg *tls.Config, cfg *quic.Config) (quic.EarlySession, error) { sess, err := d.QUICDialer.DialContext(ctx, network, host, tlsCfg, cfg) if err != nil { - return nil, errorsx.NewErrWrapper( - errorsx.ClassifyQUICHandshakeError, errorsx.QUICHandshakeOperation, err) + return nil, NewErrWrapper( + ClassifyQUICHandshakeError, QUICHandshakeOperation, err) } return sess, nil } diff --git a/internal/netxlite/quic_test.go b/internal/netxlite/quic_test.go index a7848b1..8ed70c0 100644 --- a/internal/netxlite/quic_test.go +++ b/internal/netxlite/quic_test.go @@ -12,7 +12,6 @@ import ( "github.com/apex/log" "github.com/google/go-cmp/cmp" "github.com/lucas-clemente/quic-go" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx" ) @@ -524,7 +523,7 @@ func TestQUICListenerErrWrapper(t *testing.T) { }, } conn, err := ql.Listen(&net.UDPAddr{}) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if conn != nil { @@ -569,7 +568,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) { }, } count, addr, err := conn.ReadFrom(p) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if count != 0 { @@ -611,7 +610,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) { }, } count, err := conn.WriteTo(p, &net.UDPAddr{}) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if count != 0 { @@ -645,7 +644,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) { }, } err := conn.Close() - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } }) @@ -699,7 +698,7 @@ func TestQUICDialerErrWrapper(t *testing.T) { } ctx := context.Background() sess, err := d.DialContext(ctx, "", "", &tls.Config{}, &quic.Config{}) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if sess != nil { diff --git a/internal/netxlite/quirks.go b/internal/netxlite/quirks.go index 6774c1e..ae0cb72 100644 --- a/internal/netxlite/quirks.go +++ b/internal/netxlite/quirks.go @@ -3,8 +3,6 @@ package netxlite import ( "errors" "strings" - - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) // This file contains weird stuff that we carried over from @@ -36,7 +34,7 @@ func quirkReduceErrors(errorslist []error) error { return nil } for _, err := range errorslist { - var wrapper *errorsx.ErrWrapper + var wrapper *ErrWrapper if errors.As(err, &wrapper) && !strings.HasPrefix( err.Error(), "unknown_failure", ) { diff --git a/internal/netxlite/quirks_test.go b/internal/netxlite/quirks_test.go index 189c6a8..182ae1a 100644 --- a/internal/netxlite/quirks_test.go +++ b/internal/netxlite/quirks_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) func TestQuirkReduceErrors(t *testing.T) { @@ -35,19 +34,19 @@ func TestQuirkReduceErrors(t *testing.T) { t.Run("multiple errors with meaningful ones", func(t *testing.T) { err1 := errors.New("mocked error #1") - err2 := errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, - errorsx.CloseOperation, + err2 := NewErrWrapper( + ClassifyGenericError, + CloseOperation, errors.New("antani"), ) - err3 := errorsx.NewErrWrapper( - errorsx.ClassifyGenericError, - errorsx.CloseOperation, - errorsx.ECONNREFUSED, + err3 := NewErrWrapper( + ClassifyGenericError, + CloseOperation, + ECONNREFUSED, ) err4 := errors.New("mocked error #3") result := quirkReduceErrors([]error{err1, err2, err3, err4}) - if result.Error() != errorsx.FailureConnectionRefused { + if result.Error() != FailureConnectionRefused { t.Fatal("wrong result") } }) diff --git a/internal/netxlite/resolver.go b/internal/netxlite/resolver.go index c915a18..179e98a 100644 --- a/internal/netxlite/resolver.go +++ b/internal/netxlite/resolver.go @@ -8,7 +8,6 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "golang.org/x/net/idna" ) @@ -253,8 +252,7 @@ var _ Resolver = &resolverErrWrapper{} func (r *resolverErrWrapper) LookupHost(ctx context.Context, hostname string) ([]string, error) { addrs, err := r.Resolver.LookupHost(ctx, hostname) if err != nil { - return nil, errorsx.NewErrWrapper( - errorsx.ClassifyResolverError, errorsx.ResolveOperation, err) + return nil, NewErrWrapper(ClassifyResolverError, ResolveOperation, err) } return addrs, nil } @@ -263,8 +261,7 @@ func (r *resolverErrWrapper) LookupHTTPS( ctx context.Context, domain string) (*HTTPSSvc, error) { out, err := r.Resolver.LookupHTTPS(ctx, domain) if err != nil { - return nil, errorsx.NewErrWrapper( - errorsx.ClassifyResolverError, errorsx.ResolveOperation, err) + return nil, NewErrWrapper(ClassifyResolverError, ResolveOperation, err) } return out, nil } diff --git a/internal/netxlite/resolver_test.go b/internal/netxlite/resolver_test.go index b0b3569..1351465 100644 --- a/internal/netxlite/resolver_test.go +++ b/internal/netxlite/resolver_test.go @@ -11,7 +11,6 @@ import ( "github.com/apex/log" "github.com/google/go-cmp/cmp" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -493,7 +492,7 @@ func TestResolverErrWrapper(t *testing.T) { } ctx := context.Background() addrs, err := reso.LookupHost(ctx, "") - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if addrs != nil { @@ -578,7 +577,7 @@ func TestResolverErrWrapper(t *testing.T) { } ctx := context.Background() https, err := reso.LookupHTTPS(ctx, "") - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if https != nil { diff --git a/internal/netxlite/dnsx/serialresolver.go b/internal/netxlite/serialresolver.go similarity index 99% rename from internal/netxlite/dnsx/serialresolver.go rename to internal/netxlite/serialresolver.go index 2ef0db6..5b8cab2 100644 --- a/internal/netxlite/dnsx/serialresolver.go +++ b/internal/netxlite/serialresolver.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "context" diff --git a/internal/netxlite/dnsx/serialresolver_test.go b/internal/netxlite/serialresolver_test.go similarity index 95% rename from internal/netxlite/dnsx/serialresolver_test.go rename to internal/netxlite/serialresolver_test.go index 4ac2e29..f621487 100644 --- a/internal/netxlite/dnsx/serialresolver_test.go +++ b/internal/netxlite/serialresolver_test.go @@ -1,4 +1,4 @@ -package dnsx +package netxlite import ( "context" @@ -9,8 +9,7 @@ import ( "github.com/miekg/dns" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx/mocks" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" + "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) func TestSerialResolver(t *testing.T) { @@ -81,7 +80,7 @@ func TestSerialResolver(t *testing.T) { } r := NewSerialResolver(txp) addrs, err := r.LookupHost(context.Background(), "www.gogle.com") - if !errors.Is(err, errorsx.ErrOODNSNoAnswer) { + if !errors.Is(err, ErrOODNSNoAnswer) { t.Fatal("not the error we expected", err) } if addrs != nil { @@ -130,7 +129,7 @@ func TestSerialResolver(t *testing.T) { t.Run("with timeout", func(t *testing.T) { txp := &mocks.DNSTransport{ MockRoundTrip: func(ctx context.Context, query []byte) (reply []byte, err error) { - return nil, &net.OpError{Err: errorsx.ETIMEDOUT, Op: "dial"} + return nil, &net.OpError{Err: ETIMEDOUT, Op: "dial"} }, MockRequiresPadding: func() bool { return true @@ -138,7 +137,7 @@ func TestSerialResolver(t *testing.T) { } r := NewSerialResolver(txp) addrs, err := r.LookupHost(context.Background(), "www.gogle.com") - if !errors.Is(err, errorsx.ETIMEDOUT) { + if !errors.Is(err, ETIMEDOUT) { t.Fatal("not the error we expected") } if addrs != nil { diff --git a/internal/netxlite/tls.go b/internal/netxlite/tls.go index c002909..f3deab6 100644 --- a/internal/netxlite/tls.go +++ b/internal/netxlite/tls.go @@ -10,7 +10,6 @@ import ( "time" oohttp "github.com/ooni/oohttp" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" ) var ( @@ -346,8 +345,8 @@ func (h *tlsHandshakerErrWrapper) Handshake( ) (net.Conn, tls.ConnectionState, error) { tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config) if err != nil { - return nil, tls.ConnectionState{}, errorsx.NewErrWrapper( - errorsx.ClassifyTLSHandshakeError, errorsx.TLSHandshakeOperation, err) + return nil, tls.ConnectionState{}, NewErrWrapper( + ClassifyTLSHandshakeError, TLSHandshakeOperation, err) } return tlsconn, state, nil } diff --git a/internal/netxlite/tls_test.go b/internal/netxlite/tls_test.go index cec398d..17ee0f5 100644 --- a/internal/netxlite/tls_test.go +++ b/internal/netxlite/tls_test.go @@ -16,7 +16,6 @@ import ( "github.com/apex/log" "github.com/google/go-cmp/cmp" - "github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -544,7 +543,7 @@ func TestTLSHandshakerErrWrapper(t *testing.T) { } ctx := context.Background() conn, _, err := th.Handshake(ctx, &mocks.Conn{}, &tls.Config{}) - if err == nil || err.Error() != errorsx.FailureEOFError { + if err == nil || err.Error() != FailureEOFError { t.Fatal("unexpected err", err) } if conn != nil { diff --git a/internal/ooapi/apis.go b/internal/ooapi/apis.go index 6de5d76..2a0bfa6 100644 --- a/internal/ooapi/apis.go +++ b/internal/ooapi/apis.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:18.962287 +0200 CEST m=+0.000333710 +// 2021-09-28 12:05:20.164257 +0200 CEST m=+0.000193834 package ooapi diff --git a/internal/ooapi/apis_test.go b/internal/ooapi/apis_test.go index 0eb4ba9..bf264fe 100644 --- a/internal/ooapi/apis_test.go +++ b/internal/ooapi/apis_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:19.316964 +0200 CEST m=+0.000287376 +// 2021-09-28 12:05:20.537692 +0200 CEST m=+0.000164918 package ooapi @@ -17,7 +17,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/ooapi/apimodel" ) @@ -177,7 +177,7 @@ func (h *handleCheckReportID) ServeHTTP(w http.ResponseWriter, r *http.Request) } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -440,7 +440,7 @@ func (h *handleCheckIn) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -685,7 +685,7 @@ func (h *handleLogin) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -912,7 +912,7 @@ func (h *handleMeasurementMeta) ServeHTTP(w http.ResponseWriter, r *http.Request } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -1175,7 +1175,7 @@ func (h *handleRegister) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -1402,7 +1402,7 @@ func (h *handleTestHelpers) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -1671,7 +1671,7 @@ func (h *handlePsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -1942,7 +1942,7 @@ func (h *handleTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -2192,7 +2192,7 @@ func (h *handleURLs) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -2437,7 +2437,7 @@ func (h *handleOpenReport) ServeHTTP(w http.ResponseWriter, r *http.Request) { } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -2682,7 +2682,7 @@ func (h *handleSubmitMeasurement) ServeHTTP(w http.ResponseWriter, r *http.Reque } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return diff --git a/internal/ooapi/caching.go b/internal/ooapi/caching.go index 164bc4a..70d0aad 100644 --- a/internal/ooapi/caching.go +++ b/internal/ooapi/caching.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:19.664951 +0200 CEST m=+0.000206417 +// 2021-09-28 12:05:20.806737 +0200 CEST m=+0.000196043 package ooapi diff --git a/internal/ooapi/caching_test.go b/internal/ooapi/caching_test.go index 3954001..0165aee 100644 --- a/internal/ooapi/caching_test.go +++ b/internal/ooapi/caching_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:19.945161 +0200 CEST m=+0.000190709 +// 2021-09-28 12:05:21.094817 +0200 CEST m=+0.000177376 package ooapi diff --git a/internal/ooapi/callers.go b/internal/ooapi/callers.go index c18b747..ce4ffee 100644 --- a/internal/ooapi/callers.go +++ b/internal/ooapi/callers.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:20.211832 +0200 CEST m=+0.000215876 +// 2021-09-28 12:05:21.383065 +0200 CEST m=+0.000204043 package ooapi diff --git a/internal/ooapi/clientcall.go b/internal/ooapi/clientcall.go index 0962e8a..d46f7b6 100644 --- a/internal/ooapi/clientcall.go +++ b/internal/ooapi/clientcall.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:20.571825 +0200 CEST m=+0.000210710 +// 2021-09-28 12:05:21.649124 +0200 CEST m=+0.000178126 package ooapi diff --git a/internal/ooapi/clientcall_test.go b/internal/ooapi/clientcall_test.go index e30e6d1..f5c9c7e 100644 --- a/internal/ooapi/clientcall_test.go +++ b/internal/ooapi/clientcall_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:20.84233 +0200 CEST m=+0.000203459 +// 2021-09-28 12:05:21.914519 +0200 CEST m=+0.000179917 package ooapi @@ -16,7 +16,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/ooni/probe-cli/v3/internal/kvstore" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/ooapi/apimodel" ) @@ -42,7 +42,7 @@ func (h *handleClientCallCheckReportID) ServeHTTP(w http.ResponseWriter, r *http } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -135,7 +135,7 @@ func (h *handleClientCallCheckIn) ServeHTTP(w http.ResponseWriter, r *http.Reque } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -227,7 +227,7 @@ func (h *handleClientCallMeasurementMeta) ServeHTTP(w http.ResponseWriter, r *ht } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -320,7 +320,7 @@ func (h *handleClientCallTestHelpers) ServeHTTP(w http.ResponseWriter, r *http.R } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -435,7 +435,7 @@ func (h *handleClientCallPsiphonConfig) ServeHTTP(w http.ResponseWriter, r *http } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -550,7 +550,7 @@ func (h *handleClientCallTorTargets) ServeHTTP(w http.ResponseWriter, r *http.Re } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -643,7 +643,7 @@ func (h *handleClientCallURLs) ServeHTTP(w http.ResponseWriter, r *http.Request) } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -736,7 +736,7 @@ func (h *handleClientCallOpenReport) ServeHTTP(w http.ResponseWriter, r *http.Re } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -828,7 +828,7 @@ func (h *handleClientCallSubmitMeasurement) ServeHTTP(w http.ResponseWriter, r * } h.count++ if r.Body != nil { - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return diff --git a/internal/ooapi/cloners.go b/internal/ooapi/cloners.go index d13c17e..dc15c55 100644 --- a/internal/ooapi/cloners.go +++ b/internal/ooapi/cloners.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:21.153077 +0200 CEST m=+0.000199334 +// 2021-09-28 12:05:22.176937 +0200 CEST m=+0.000169251 package ooapi diff --git a/internal/ooapi/fake_test.go b/internal/ooapi/fake_test.go index 5e9f225..e664621 100644 --- a/internal/ooapi/fake_test.go +++ b/internal/ooapi/fake_test.go @@ -6,7 +6,7 @@ import ( "net/http" "time" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) type FakeCodec struct { @@ -31,7 +31,7 @@ type FakeHTTPClient struct { func (c *FakeHTTPClient) Do(req *http.Request) (*http.Response, error) { time.Sleep(10 * time.Microsecond) if req.Body != nil { - _, _ = iox.ReadAllContext(req.Context(), req.Body) + _, _ = netxlite.ReadAllContext(req.Context(), req.Body) req.Body.Close() } if c.Err != nil { diff --git a/internal/ooapi/fakeapi_test.go b/internal/ooapi/fakeapi_test.go index 13b23fd..f9c7c77 100644 --- a/internal/ooapi/fakeapi_test.go +++ b/internal/ooapi/fakeapi_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:21.412036 +0200 CEST m=+0.000169751 +// 2021-09-28 12:05:22.411961 +0200 CEST m=+0.000187918 package ooapi diff --git a/internal/ooapi/internal/generator/apistest.go b/internal/ooapi/internal/generator/apistest.go index 66b8a9f..c39fef4 100644 --- a/internal/ooapi/internal/generator/apistest.go +++ b/internal/ooapi/internal/generator/apistest.go @@ -231,7 +231,7 @@ func (d *Descriptor) genTestRoundTrip(sb *strings.Builder) { fmt.Fprint(sb, "\t}\n") fmt.Fprint(sb, "\th.count++\n") fmt.Fprint(sb, "\tif r.Body != nil {\n") - fmt.Fprint(sb, "\t\tdata, err := iox.ReadAllContext(r.Context(), r.Body)\n") + fmt.Fprint(sb, "\t\tdata, err := netxlite.ReadAllContext(r.Context(), r.Body)\n") fmt.Fprint(sb, "\t\tif err != nil {\n") fmt.Fprintf(sb, "\t\t\tw.WriteHeader(400)\n") fmt.Fprintf(sb, "\t\t\treturn\n") @@ -451,7 +451,7 @@ func GenAPIsTestGo(file string) { fmt.Fprint(&sb, "\t\"sync\"\n") fmt.Fprint(&sb, "\n") fmt.Fprint(&sb, "\t\"github.com/google/go-cmp/cmp\"\n") - fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite/iox\"\n") + fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite\"\n") fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/ooapi/apimodel\"\n") fmt.Fprint(&sb, ")\n") for _, desc := range Descriptors { diff --git a/internal/ooapi/internal/generator/clientcalltest.go b/internal/ooapi/internal/generator/clientcalltest.go index 9e4f0a7..0e0a166 100644 --- a/internal/ooapi/internal/generator/clientcalltest.go +++ b/internal/ooapi/internal/generator/clientcalltest.go @@ -57,7 +57,7 @@ func (d *Descriptor) genTestClientCallRoundTrip(sb *strings.Builder) { fmt.Fprint(sb, "\t}\n") fmt.Fprint(sb, "\th.count++\n") fmt.Fprint(sb, "\tif r.Body != nil {\n") - fmt.Fprint(sb, "\t\tdata, err := iox.ReadAllContext(r.Context(), r.Body)\n") + fmt.Fprint(sb, "\t\tdata, err := netxlite.ReadAllContext(r.Context(), r.Body)\n") fmt.Fprint(sb, "\t\tif err != nil {\n") fmt.Fprintf(sb, "\t\t\tw.WriteHeader(400)\n") fmt.Fprintf(sb, "\t\t\treturn\n") @@ -168,7 +168,7 @@ func GenClientCallTestGo(file string) { fmt.Fprint(&sb, "\t\"sync\"\n") fmt.Fprint(&sb, "\n") fmt.Fprint(&sb, "\t\"github.com/google/go-cmp/cmp\"\n") - fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite/iox\"\n") + fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite\"\n") fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/kvstore\"\n") fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/ooapi/apimodel\"\n") fmt.Fprint(&sb, ")\n") diff --git a/internal/ooapi/internal/generator/responses.go b/internal/ooapi/internal/generator/responses.go index 3b0da9a..821bae6 100644 --- a/internal/ooapi/internal/generator/responses.go +++ b/internal/ooapi/internal/generator/responses.go @@ -23,7 +23,7 @@ func (d *Descriptor) genNewResponse(sb *strings.Builder) { fmt.Fprint(sb, "\t}\n") fmt.Fprint(sb, "\tdefer resp.Body.Close()\n") fmt.Fprint(sb, "\treader := io.LimitReader(resp.Body, 4<<20)\n") - fmt.Fprint(sb, "\tdata, err := iox.ReadAllContext(ctx, reader)\n") + fmt.Fprint(sb, "\tdata, err := netxlite.ReadAllContext(ctx, reader)\n") fmt.Fprint(sb, "\tif err != nil {\n") fmt.Fprint(sb, "\t\treturn nil, err\n") fmt.Fprint(sb, "\t}\n") @@ -71,7 +71,7 @@ func GenResponsesGo(file string) { fmt.Fprint(&sb, "\t\"io\"\n") fmt.Fprint(&sb, "\t\"net/http\"\n") fmt.Fprint(&sb, "\n") - fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite/iox\"\n") + fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/netxlite\"\n") fmt.Fprint(&sb, "\t\"github.com/ooni/probe-cli/v3/internal/ooapi/apimodel\"\n") fmt.Fprint(&sb, ")\n\n") for _, desc := range Descriptors { diff --git a/internal/ooapi/login.go b/internal/ooapi/login.go index 5a9adfb..a459d3f 100644 --- a/internal/ooapi/login.go +++ b/internal/ooapi/login.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:21.648163 +0200 CEST m=+0.000177959 +// 2021-09-28 12:05:22.674011 +0200 CEST m=+0.000198918 package ooapi diff --git a/internal/ooapi/login_test.go b/internal/ooapi/login_test.go index 55dd369..19ee4d8 100644 --- a/internal/ooapi/login_test.go +++ b/internal/ooapi/login_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:21.967872 +0200 CEST m=+0.000174460 +// 2021-09-28 12:05:22.959095 +0200 CEST m=+0.000193418 package ooapi diff --git a/internal/ooapi/loginhandler_test.go b/internal/ooapi/loginhandler_test.go index 5d75968..7f68270 100644 --- a/internal/ooapi/loginhandler_test.go +++ b/internal/ooapi/loginhandler_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/ooapi/apimodel" ) @@ -72,7 +72,7 @@ func (lh *LoginHandler) register(w http.ResponseWriter, r *http.Request) { w.WriteHeader(400) return } - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return @@ -113,7 +113,7 @@ func (lh *LoginHandler) login(w http.ResponseWriter, r *http.Request) { w.WriteHeader(400) return } - data, err := iox.ReadAllContext(r.Context(), r.Body) + data, err := netxlite.ReadAllContext(r.Context(), r.Body) if err != nil { w.WriteHeader(400) return diff --git a/internal/ooapi/requests.go b/internal/ooapi/requests.go index 400cea7..60bcc4f 100644 --- a/internal/ooapi/requests.go +++ b/internal/ooapi/requests.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:22.226116 +0200 CEST m=+0.000176793 +// 2021-09-28 12:05:23.239796 +0200 CEST m=+0.000205959 package ooapi diff --git a/internal/ooapi/responses.go b/internal/ooapi/responses.go index 5bdd963..7047e2e 100644 --- a/internal/ooapi/responses.go +++ b/internal/ooapi/responses.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:22.556115 +0200 CEST m=+0.000158543 +// 2021-09-28 12:05:23.599657 +0200 CEST m=+0.000196001 package ooapi @@ -10,7 +10,7 @@ import ( "io" "net/http" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/ooapi/apimodel" ) @@ -26,7 +26,7 @@ func (api *simpleCheckReportIDAPI) newResponse(ctx context.Context, resp *http.R } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -49,7 +49,7 @@ func (api *simpleCheckInAPI) newResponse(ctx context.Context, resp *http.Respons } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -72,7 +72,7 @@ func (api *simpleLoginAPI) newResponse(ctx context.Context, resp *http.Response, } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (api *simpleMeasurementMetaAPI) newResponse(ctx context.Context, resp *http } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func (api *simpleRegisterAPI) newResponse(ctx context.Context, resp *http.Respon } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -141,7 +141,7 @@ func (api *simpleTestHelpersAPI) newResponse(ctx context.Context, resp *http.Res } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -167,7 +167,7 @@ func (api *simplePsiphonConfigAPI) newResponse(ctx context.Context, resp *http.R } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -193,7 +193,7 @@ func (api *simpleTorTargetsAPI) newResponse(ctx context.Context, resp *http.Resp } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -219,7 +219,7 @@ func (api *simpleURLsAPI) newResponse(ctx context.Context, resp *http.Response, } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -242,7 +242,7 @@ func (api *simpleOpenReportAPI) newResponse(ctx context.Context, resp *http.Resp } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } @@ -265,7 +265,7 @@ func (api *simpleSubmitMeasurementAPI) newResponse(ctx context.Context, resp *ht } defer resp.Body.Close() reader := io.LimitReader(resp.Body, 4<<20) - data, err := iox.ReadAllContext(ctx, reader) + data, err := netxlite.ReadAllContext(ctx, reader) if err != nil { return nil, err } diff --git a/internal/ooapi/swagger_test.go b/internal/ooapi/swagger_test.go index 0d7980d..2bfe53f 100644 --- a/internal/ooapi/swagger_test.go +++ b/internal/ooapi/swagger_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2021-09-05 13:54:22.884854 +0200 CEST m=+0.000556501 +// 2021-09-28 12:05:23.978512 +0200 CEST m=+0.000565751 package ooapi @@ -9,7 +9,7 @@ const swagger = `{ "swagger": "2.0", "info": { "title": "OONI API specification", - "version": "0.20210905.9115422" + "version": "0.20210928.9100523" }, "host": "api.ooni.io", "basePath": "/", diff --git a/internal/ooapi/swaggerdiff_test.go b/internal/ooapi/swaggerdiff_test.go index faaf6be..d612be6 100644 --- a/internal/ooapi/swaggerdiff_test.go +++ b/internal/ooapi/swaggerdiff_test.go @@ -13,7 +13,7 @@ import ( "github.com/hexops/gotextdiff" "github.com/hexops/gotextdiff/myers" "github.com/hexops/gotextdiff/span" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/ooapi/internal/openapi" ) @@ -37,7 +37,7 @@ func getServerModel(serverURL string) *openapi.Swagger { log.Fatal(err) } defer resp.Body.Close() - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { log.Fatal(err) } diff --git a/internal/ptx/ptx.go b/internal/ptx/ptx.go index d39ae6a..736c39d 100644 --- a/internal/ptx/ptx.go +++ b/internal/ptx/ptx.go @@ -45,7 +45,7 @@ import ( "sync" pt "git.torproject.org/pluggable-transports/goptlib.git" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" ) // PTDialer is a generic pluggable transports dialer. @@ -110,11 +110,11 @@ func (lst *Listener) forward(ctx context.Context, left, right net.Conn, done cha wg.Add(2) go func() { defer wg.Done() - iox.CopyContext(ctx, left, right) + netxlite.CopyContext(ctx, left, right) }() go func() { defer wg.Done() - iox.CopyContext(ctx, right, left) + netxlite.CopyContext(ctx, right, left) }() wg.Wait() } diff --git a/internal/ptx/ptx_test.go b/internal/ptx/ptx_test.go index 32f90c5..40c6048 100644 --- a/internal/ptx/ptx_test.go +++ b/internal/ptx/ptx_test.go @@ -13,7 +13,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/netxlite/iox" + "github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks" ) @@ -57,7 +57,7 @@ func TestListenerWorksWithFakeDialer(t *testing.T) { if err != nil { t.Fatal(err) } - data, err := iox.ReadAllContext(context.Background(), resp.Body) + data, err := netxlite.ReadAllContext(context.Background(), resp.Body) if err != nil { t.Fatal(err) }