refactor: merge dnsx and errorsx into netxlite (#517)

When preparing a tutorial for netxlite, I figured it is easier
to tell people "hey, this is the package you should use for all
low-level networking stuff" rather than introducing people to
a set of packages working together where some piece of functionality
is here and some other piece is there.

Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-28 12:42:01 +02:00 committed by GitHub
parent de130d249c
commit 6d3a4f1db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
169 changed files with 575 additions and 671 deletions

View File

@ -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/fsx.OpenFile` when you need to open a file
- use `./internal/netxlite/iox.ReadAllContext` instead of `io.ReadAll` - use `./internal/netxlite.ReadAllContext` instead of `io.ReadAll`
and `./internal/netxlite/iox.CopyContext` instead of `io.Copy` and `./internal/netxlite.CopyContext` instead of `io.Copy`
## Code testing requirements ## Code testing requirements

View File

@ -8,7 +8,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func getShasum(path string) (string, error) { func getShasum(path string) (string, error) {
@ -19,7 +19,7 @@ func getShasum(path string) (string, error) {
return "", err return "", err
} }
defer f.Close() 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 "", err
} }
return hex.EncodeToString(hasher.Sum(nil)), nil return hex.EncodeToString(hasher.Sum(nil)), nil

View File

@ -6,7 +6,7 @@ import (
"embed" "embed"
"github.com/apex/log" "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" migrate "github.com/rubenv/sql-migrate"
"upper.io/db.v3/lib/sqlbuilder" "upper.io/db.v3/lib/sqlbuilder"
"upper.io/db.v3/sqlite" "upper.io/db.v3/sqlite"
@ -20,7 +20,7 @@ func readAsset(path string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return iox.ReadAllContext(context.Background(), filep) return netxlite.ReadAllContext(context.Background(), filep)
} }
func readAssetDir(path string) ([]string, error) { func readAssetDir(path string) ([]string, error) {

View File

@ -16,7 +16,7 @@ import (
"time" "time"
"github.com/google/martian/v3/mitm" "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. // CensoringProxy is a proxy that does not behave correctly.
@ -57,7 +57,7 @@ func (p *CensoringProxy) serve(conn net.Conn) {
} else { } else {
const maxread = 1 << 17 const maxread = 1 << 17
reader := io.LimitReader(conn, maxread) reader := io.LimitReader(conn, maxread)
iox.ReadAllContext(context.Background(), reader) netxlite.ReadAllContext(context.Background(), reader)
} }
conn.Close() conn.Close()
} }

View File

@ -8,7 +8,7 @@ import (
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/cmd/jafar/uncensored" "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) { func TestPass(t *testing.T) {
@ -102,7 +102,7 @@ func checkrequest(
if !foundProduct && expectVia { if !foundProduct && expectVia {
t.Fatal("Via header not found") 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -120,7 +120,7 @@ func checkbody(t *testing.T, proxiedData []byte, host string) {
t.Fatal("unexpected status code") t.Fatal("unexpected status code")
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := iox.ReadAllContext(context.Background(), resp.Body) data, err := netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -7,7 +7,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestGood(t *testing.T) { func TestGood(t *testing.T) {
@ -56,7 +56,7 @@ func TestGood(t *testing.T) {
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
t.Fatal("invalid status-code") t.Fatal("invalid status-code")
} }
data, err := iox.ReadAllContext(context.Background(), resp.Body) data, err := netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -13,7 +13,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "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/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/runtimex"
"github.com/ooni/probe-cli/v3/internal/version" "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 { if resp.StatusCode != 200 {
return nil, ErrHTTPStatusCode return nil, ErrHTTPStatusCode
} }
data, err = iox.ReadAllContext(ctx, resp.Body) data, err = netxlite.ReadAllContext(ctx, resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "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 { type FakeResolver struct {
@ -63,7 +63,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -9,7 +9,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "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 { type FakeResolver struct {
@ -63,7 +63,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -8,7 +8,7 @@ import (
"sync" "sync"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "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 // 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) headers[k] = resp.Header.Get(k)
} }
reader := &io.LimitedReader{R: resp.Body, N: config.MaxAcceptableBody} reader := &io.LimitedReader{R: resp.Body, N: config.MaxAcceptableBody}
data, err := iox.ReadAllContext(ctx, reader) data, err := netxlite.ReadAllContext(ctx, reader)
config.Out <- CtrlHTTPResponse{ config.Out <- CtrlHTTPResponse{
BodyLength: int64(len(data)), BodyLength: int64(len(data)),
Failure: newfailure(err), Failure: newfailure(err),

View File

@ -7,7 +7,7 @@ import (
"net/http" "net/http"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "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/runtimex"
"github.com/ooni/probe-cli/v3/internal/version" "github.com/ooni/probe-cli/v3/internal/version"
) )
@ -29,7 +29,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
reader := &io.LimitedReader{R: req.Body, N: h.MaxAcceptableBody} 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 { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)
return return

View File

@ -11,7 +11,6 @@ import (
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
) )
const simplerequest = `{ const simplerequest = `{
@ -126,7 +125,7 @@ func TestWorkingAsIntended(t *testing.T) {
if v := resp.Header.Get("content-type"); v != expect.respContentType { if v := resp.Header.Get("content-type"); v != expect.respContentType {
t.Fatalf("unexpected content-type: %s", v) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -11,7 +11,7 @@ import (
"testing" "testing"
"github.com/lucas-clemente/quic-go" "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" "github.com/ooni/probe-cli/v3/internal/runtimex"
) )
@ -68,7 +68,7 @@ func TestGenerateDNSFailure(t *testing.T) {
if urlMeasurements[0].DNS == nil { if urlMeasurements[0].DNS == nil {
t.Fatal("DNS should not be 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") t.Fatal("unexpected DNS failure type")
} }
} }

View File

@ -6,7 +6,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestMeasureSuccess(t *testing.T) { func TestMeasureSuccess(t *testing.T) {
@ -79,7 +79,7 @@ func TestMeasureInitialChecksFailWithNXDOMAIN(t *testing.T) {
if resp.URLs[0].DNS == nil { if resp.URLs[0].DNS == nil {
t.Fatal("DNS entry should not be 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") t.Fatal("unexpected failure")
} }
} }

View File

@ -13,7 +13,7 @@ import (
"net/http" "net/http"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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/runtimex"
"github.com/ooni/probe-cli/v3/internal/version" "github.com/ooni/probe-cli/v3/internal/version"
) )
@ -42,7 +42,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return return
} }
reader := &io.LimitedReader{R: req.Body, N: maxAcceptableBody} 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 { if err != nil {
w.WriteHeader(400) w.WriteHeader(400)
return return

View File

@ -10,7 +10,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const requestnoredirect = `{ const requestnoredirect = `{
@ -188,7 +188,7 @@ func TestWorkingAsIntended(t *testing.T) {
if resp.StatusCode != expect.respStatusCode { if resp.StatusCode != expect.respStatusCode {
t.Fatalf("unexpected status code: %+v", resp.StatusCode) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -220,7 +220,7 @@ func TestHandlerWithInternalServerError(t *testing.T) {
if resp.StatusCode != 500 { if resp.StatusCode != 500 {
t.Fatalf("unexpected status code: %+v", resp.StatusCode) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,8 +18,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/netx" "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/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/humanize" "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"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
) )
const ( 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) { 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 { 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 // of the latest connect time. We should have one sample in most
// cases, because the connection should be persistent. // cases, because the connection should be persistent.
for _, ev := range r.saver.Read() { for _, ev := range r.saver.Read() {
if ev.Name == errorsx.ConnectOperation { if ev.Name == netxlite.ConnectOperation {
connectTime = ev.Duration.Seconds() connectTime = ev.Duration.Seconds()
} }
} }

View File

@ -14,7 +14,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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) { func TestRunnerLoopLocateFailure(t *testing.T) {
@ -108,7 +108,7 @@ func TestRunnerLoopMeasureFailure(t *testing.T) {
func TestRunnerLoopCollectFailure(t *testing.T) { func TestRunnerLoopCollectFailure(t *testing.T) {
expected := errors.New("mocked error") expected := errors.New("mocked error")
saver := new(trace.Saver) 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{ r := runner{
callbacks: model.NewPrinterCallbacks(log.Log), callbacks: model.NewPrinterCallbacks(log.Log),
httpClient: &http.Client{ httpClient: &http.Client{
@ -152,7 +152,7 @@ func TestRunnerLoopCollectFailure(t *testing.T) {
func TestRunnerLoopSuccess(t *testing.T) { func TestRunnerLoopSuccess(t *testing.T) {
saver := new(trace.Saver) 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{ r := runner{
callbacks: model.NewPrinterCallbacks(log.Log), callbacks: model.NewPrinterCallbacks(log.Log),
httpClient: &http.Client{ httpClient: &http.Client{

View File

@ -11,7 +11,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/engine/model"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const ( const (
@ -111,7 +111,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo
// start where all is unknown // start where all is unknown
*dns, *tcp = nil, nil *dns, *tcp = nil, nil
// process DNS first // 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 tk.FacebookDNSBlocking = &trueValue
*dns = &falseValue *dns = &falseValue
return // we know that the DNS has failed return // we know that the DNS has failed
@ -127,7 +127,7 @@ func (tk *TestKeys) ComputeEndpointStatus(v urlgetter.MultiOutput, dns, tcp **bo
} }
*dns = &trueValue *dns = &trueValue
// now process connect // 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 tk.FacebookTCPBlocking = &trueValue
*tcp = &falseValue *tcp = &falseValue
return // because connect failed return // because connect failed

View File

@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -162,7 +162,7 @@ func TestWithCancelledContext(t *testing.T) {
func TestComputeEndpointStatsTCPBlocking(t *testing.T) { func TestComputeEndpointStatsTCPBlocking(t *testing.T) {
failure := io.EOF.Error() failure := io.EOF.Error()
operation := errorsx.ConnectOperation operation := netxlite.ConnectOperation
tk := fbmessenger.TestKeys{} tk := fbmessenger.TestKeys{}
tk.Update(urlgetter.MultiOutput{ tk.Update(urlgetter.MultiOutput{
Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge},
@ -192,7 +192,7 @@ func TestComputeEndpointStatsTCPBlocking(t *testing.T) {
func TestComputeEndpointStatsDNSIsLying(t *testing.T) { func TestComputeEndpointStatsDNSIsLying(t *testing.T) {
failure := io.EOF.Error() failure := io.EOF.Error()
operation := errorsx.ConnectOperation operation := netxlite.ConnectOperation
tk := fbmessenger.TestKeys{} tk := fbmessenger.TestKeys{}
tk.Update(urlgetter.MultiOutput{ tk.Update(urlgetter.MultiOutput{
Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge}, Input: urlgetter.MultiInput{Target: fbmessenger.ServiceEdge},

View File

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeDialer struct { type FakeDialer struct {
@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -20,8 +20,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" "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"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/randx" "github.com/ooni/probe-cli/v3/internal/randx"
) )
@ -165,7 +164,7 @@ func (m Measurer) Run(
// parse response body // parse response body
var jsonHeaders JSONHeaders var jsonHeaders JSONHeaders
if err := json.Unmarshal(data, &jsonHeaders); err != nil { if err := json.Unmarshal(data, &jsonHeaders); err != nil {
failure := errorsx.FailureJSONParseError failure := netxlite.FailureJSONParseError
tk.Failure = &failure tk.Failure = &failure
tk.Tampering.Total = true tk.Tampering.Total = true
return nil // measurement did not fail, we measured tampering 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 // make sure that we return a wrapped error here
resp, data, err := transact(txp, req, callbacks) resp, data, err := transact(txp, req, callbacks)
err = errorsxlegacy.SafeErrWrapperBuilder{ err = errorsxlegacy.SafeErrWrapperBuilder{
Error: err, Operation: errorsx.TopLevelOperation}.MaybeBuild() Error: err, Operation: netxlite.TopLevelOperation}.MaybeBuild()
return resp, data, err return resp, data, err
} }
@ -199,7 +198,7 @@ func transact(txp Transport, req *http.Request,
return nil, nil, urlgetter.ErrHTTPRequestFailed return nil, nil, urlgetter.ErrHTTPRequestFailed
} }
callbacks.OnProgress(0.75, "reading response body...") 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)) callbacks.OnProgress(1.00, fmt.Sprintf("got reseponse body... %+v", err))
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -18,7 +18,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -161,14 +161,14 @@ func TestCancelledContext(t *testing.T) {
if tk.Agent != "agent" { if tk.Agent != "agent" {
t.Fatal("invalid Agent") t.Fatal("invalid Agent")
} }
if *tk.Failure != errorsx.FailureInterrupted { if *tk.Failure != netxlite.FailureInterrupted {
t.Fatal("invalid Failure") t.Fatal("invalid Failure")
} }
if len(tk.Requests) != 1 { if len(tk.Requests) != 1 {
t.Fatal("invalid Requests") t.Fatal("invalid Requests")
} }
request := tk.Requests[0] request := tk.Requests[0]
if *request.Failure != errorsx.FailureInterrupted { if *request.Failure != netxlite.FailureInterrupted {
t.Fatal("invalid Requests[0].Failure") t.Fatal("invalid Requests[0].Failure")
} }
if request.Request.Body.Value != "" { if request.Request.Body.Value != "" {
@ -480,7 +480,7 @@ func TestInvalidJSONBody(t *testing.T) {
if tk.Agent != "agent" { if tk.Agent != "agent" {
t.Fatal("invalid Agent") t.Fatal("invalid Agent")
} }
if *tk.Failure != errorsx.FailureJSONParseError { if *tk.Failure != netxlite.FailureJSONParseError {
t.Fatal("invalid Failure") t.Fatal("invalid Failure")
} }
if len(tk.Requests) != 1 { if len(tk.Requests) != 1 {

View File

@ -14,7 +14,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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" "github.com/ooni/probe-cli/v3/internal/randx"
) )
@ -293,7 +293,7 @@ func RunMethod(ctx context.Context, config RunMethodConfig) {
count, err := conn.Read(data) count, err := conn.Read(data)
if err != nil { if err != nil {
// We expect this method to terminate w/ timeout // We expect this method to terminate w/ timeout
if err.Error() == errorsx.FailureGenericTimeoutError { if err.Error() == netxlite.FailureGenericTimeoutError {
err = nil err = nil
} }
result.Err = err result.Err = err

View File

@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -97,7 +97,7 @@ func TestCancelledContext(t *testing.T) {
t.Fatal("unexpected FailureList length") t.Fatal("unexpected FailureList length")
} }
for _, failure := range tk.FailureList { for _, failure := range tk.FailureList {
if *failure != errorsx.FailureInterrupted { if *failure != netxlite.FailureInterrupted {
t.Fatal("unexpected failure") t.Fatal("unexpected failure")
} }
} }

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type downloadManager struct { 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 // we used to return `nil` on context errors, this function is
// here to keep the previous behavior by filtering the error // here to keep the previous behavior by filtering the error
// returned when reading messages, given that now reading messages // 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 { func (mgr downloadManager) reduceErr(err error) error {
if errors.Is(err, context.Canceled) { if errors.Is(err, context.Canceled) {
return nil return nil
@ -72,7 +72,7 @@ func (mgr downloadManager) doRun(ctx context.Context) error {
return err return err
} }
if kind == websocket.TextMessage { if kind == websocket.TextMessage {
data, err := iox.ReadAllContext(ctx, reader) data, err := netxlite.ReadAllContext(ctx, reader)
if err != nil { if err != nil {
return err return err
} }
@ -82,7 +82,7 @@ func (mgr downloadManager) doRun(ctx context.Context) error {
} }
continue continue
} }
n, err := iox.CopyContext(ctx, io.Discard, reader) n, err := netxlite.CopyContext(ctx, io.Discard, reader)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,7 +17,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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 ( const (
@ -270,11 +270,11 @@ func TestUpdateWithMixedResults(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.HTTPRoundTripOperation s := netxlite.HTTPRoundTripOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -291,7 +291,7 @@ func TestUpdateWithMixedResults(t *testing.T) {
if tk.APIStatus != "blocked" { if tk.APIStatus != "blocked" {
t.Fatal("ApiStatus should be blocked") t.Fatal("ApiStatus should be blocked")
} }
if *tk.APIFailure != errorsx.FailureEOFError { if *tk.APIFailure != netxlite.FailureEOFError {
t.Fatal("invalid ApiFailure") t.Fatal("invalid ApiFailure")
} }
if tk.FailingGateways != nil { if tk.FailingGateways != nil {
@ -730,7 +730,7 @@ func generateMockGetter(requestResponse map[string]string, responseStatus map[st
responseBody = "" responseBody = ""
eofError := io.EOF.Error() eofError := io.EOF.Error()
failure = &eofError failure = &eofError
connectOperation := errorsx.ConnectOperation connectOperation := netxlite.ConnectOperation
failedOperation = &connectOperation failedOperation = &connectOperation
responseStatus = 0 responseStatus = 0
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -85,7 +85,7 @@ func TestUpdate(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -93,7 +93,7 @@ func TestUpdate(t *testing.T) {
if tk.SignalBackendStatus != "blocked" { if tk.SignalBackendStatus != "blocked" {
t.Fatal("SignalBackendStatus should be blocked") t.Fatal("SignalBackendStatus should be blocked")
} }
if *tk.SignalBackendFailure != errorsx.FailureEOFError { if *tk.SignalBackendFailure != netxlite.FailureEOFError {
t.Fatal("invalid SignalBackendError") t.Fatal("invalid SignalBackendError")
} }
} }

View File

@ -15,7 +15,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/engine/model"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const ( const (
@ -64,24 +64,24 @@ func (tk *TestKeys) classify() string {
return classSuccessGotServerHello return classSuccessGotServerHello
} }
switch *tk.Target.Failure { switch *tk.Target.Failure {
case errorsx.FailureConnectionRefused: case netxlite.FailureConnectionRefused:
return classAnomalyTestHelperUnreachable return classAnomalyTestHelperUnreachable
case errorsx.FailureConnectionReset: case netxlite.FailureConnectionReset:
return classInterferenceReset return classInterferenceReset
case errorsx.FailureDNSNXDOMAINError: case netxlite.FailureDNSNXDOMAINError:
return classAnomalyTestHelperUnreachable return classAnomalyTestHelperUnreachable
case errorsx.FailureEOFError: case netxlite.FailureEOFError:
return classInterferenceClosed return classInterferenceClosed
case errorsx.FailureGenericTimeoutError: case netxlite.FailureGenericTimeoutError:
if tk.Control.Failure != nil { if tk.Control.Failure != nil {
return classAnomalyTestHelperUnreachable return classAnomalyTestHelperUnreachable
} }
return classAnomalyTimeout return classAnomalyTimeout
case errorsx.FailureSSLInvalidCertificate: case netxlite.FailureSSLInvalidCertificate:
return classInterferenceInvalidCertificate return classInterferenceInvalidCertificate
case errorsx.FailureSSLInvalidHostname: case netxlite.FailureSSLInvalidHostname:
return classSuccessGotServerHello return classSuccessGotServerHello
case errorsx.FailureSSLUnknownAuthority: case netxlite.FailureSSLUnknownAuthority:
return classInterferenceUnknownAuthority return classInterferenceUnknownAuthority
} }
return classAnomalyUnexpectedFailure return classAnomalyUnexpectedFailure
@ -117,8 +117,8 @@ func (m *Measurer) measureone(
select { select {
case <-time.After(sleeptime): case <-time.After(sleeptime):
case <-ctx.Done(): case <-ctx.Done():
s := errorsx.FailureInterrupted s := netxlite.FailureInterrupted
failedop := errorsx.TopLevelOperation failedop := netxlite.TopLevelOperation
return Subresult{ return Subresult{
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: &failedop, FailedOperation: &failedop,

View File

@ -9,7 +9,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/mockable" "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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const ( const (
@ -29,64 +29,64 @@ func TestTestKeysClassify(t *testing.T) {
}) })
t.Run("with tk.Target.Failure == connection_refused", func(t *testing.T) { t.Run("with tk.Target.Failure == connection_refused", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureConnectionRefused) tk.Target.Failure = asStringPtr(netxlite.FailureConnectionRefused)
if tk.classify() != classAnomalyTestHelperUnreachable { if tk.classify() != classAnomalyTestHelperUnreachable {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == dns_nxdomain_error", func(t *testing.T) { t.Run("with tk.Target.Failure == dns_nxdomain_error", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureDNSNXDOMAINError) tk.Target.Failure = asStringPtr(netxlite.FailureDNSNXDOMAINError)
if tk.classify() != classAnomalyTestHelperUnreachable { if tk.classify() != classAnomalyTestHelperUnreachable {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == connection_reset", func(t *testing.T) { t.Run("with tk.Target.Failure == connection_reset", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureConnectionReset) tk.Target.Failure = asStringPtr(netxlite.FailureConnectionReset)
if tk.classify() != classInterferenceReset { if tk.classify() != classInterferenceReset {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == eof_error", func(t *testing.T) { t.Run("with tk.Target.Failure == eof_error", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureEOFError) tk.Target.Failure = asStringPtr(netxlite.FailureEOFError)
if tk.classify() != classInterferenceClosed { if tk.classify() != classInterferenceClosed {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == ssl_invalid_hostname", func(t *testing.T) { t.Run("with tk.Target.Failure == ssl_invalid_hostname", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidHostname) tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidHostname)
if tk.classify() != classSuccessGotServerHello { if tk.classify() != classSuccessGotServerHello {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == ssl_unknown_authority", func(t *testing.T) { t.Run("with tk.Target.Failure == ssl_unknown_authority", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureSSLUnknownAuthority) tk.Target.Failure = asStringPtr(netxlite.FailureSSLUnknownAuthority)
if tk.classify() != classInterferenceUnknownAuthority { if tk.classify() != classInterferenceUnknownAuthority {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == ssl_invalid_certificate", func(t *testing.T) { t.Run("with tk.Target.Failure == ssl_invalid_certificate", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidCertificate) tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidCertificate)
if tk.classify() != classInterferenceInvalidCertificate { if tk.classify() != classInterferenceInvalidCertificate {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == generic_timeout_error #1", func(t *testing.T) { t.Run("with tk.Target.Failure == generic_timeout_error #1", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
if tk.classify() != classAnomalyTimeout { if tk.classify() != classAnomalyTimeout {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("with tk.Target.Failure == generic_timeout_error #2", func(t *testing.T) { t.Run("with tk.Target.Failure == generic_timeout_error #2", func(t *testing.T) {
tk := new(TestKeys) tk := new(TestKeys)
tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
tk.Control.Failure = asStringPtr(errorsx.FailureGenericTimeoutError) tk.Control.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
if tk.classify() != classAnomalyTestHelperUnreachable { if tk.classify() != classAnomalyTestHelperUnreachable {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
@ -191,10 +191,10 @@ func TestMeasureoneCancelledContext(t *testing.T) {
if result.DNSCache != nil { if result.DNSCache != nil {
t.Fatal("not the expected DNSCache") 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") 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") t.Fatal("not the expected failure")
} }
if result.NetworkEvents != nil { if result.NetworkEvents != nil {
@ -295,10 +295,10 @@ func TestMeasureoneSuccess(t *testing.T) {
if result.DNSCache != nil { if result.DNSCache != nil {
t.Fatal("not the expected DNSCache") 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") 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") t.Fatal("unexpected failure")
} }
if len(result.NetworkEvents) < 1 { if len(result.NetworkEvents) < 1 {
@ -348,7 +348,7 @@ func TestMeasureonewithcacheWorks(t *testing.T) {
if result.Cached != expected { if result.Cached != expected {
t.Fatal("unexpected cached") t.Fatal("unexpected cached")
} }
if *result.Failure != errorsx.FailureSSLInvalidHostname { if *result.Failure != netxlite.FailureSSLInvalidHostname {
t.Fatal("unexpected failure") t.Fatal("unexpected failure")
} }
if result.SNI != "kernel.org" { if result.SNI != "kernel.org" {

View File

@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/stunreachability" "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/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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" "github.com/pion/stun"
) )
@ -213,7 +213,7 @@ func TestReadFailure(t *testing.T) {
t.Fatal("not the error we expected") t.Fatal("not the error we expected")
} }
tk := measurement.TestKeys.(*stunreachability.TestKeys) tk := measurement.TestKeys.(*stunreachability.TestKeys)
if *tk.Failure != errorsx.FailureGenericTimeoutError { if *tk.Failure != netxlite.FailureGenericTimeoutError {
t.Fatal("expected different failure here") t.Fatal("expected different failure here")
} }
if tk.Endpoint != "stun.l.google.com:19302" { if tk.Endpoint != "stun.l.google.com:19302" {

View File

@ -11,7 +11,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/engine/model"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const ( const (
@ -56,7 +56,7 @@ func (tk *TestKeys) Update(v urlgetter.MultiOutput) {
tk.TelegramTCPBlocking = false tk.TelegramTCPBlocking = false
return // found successful access point connection 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 tk.TelegramTCPBlocking = false
} }
return return

View File

@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -94,7 +94,7 @@ func TestUpdateWithNoAccessPointsBlocking(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -125,7 +125,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -137,7 +137,7 @@ func TestUpdateWithNilFailedOperation(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -159,11 +159,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.ConnectOperation s := netxlite.ConnectOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -175,11 +175,11 @@ func TestUpdateWithNonConnectFailedOperation(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.HTTPRoundTripOperation s := netxlite.HTTPRoundTripOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -201,11 +201,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.ConnectOperation s := netxlite.ConnectOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -217,11 +217,11 @@ func TestUpdateWithAllConnectsFailed(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.ConnectOperation s := netxlite.ConnectOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -243,11 +243,11 @@ func TestUpdateWebWithMixedResults(t *testing.T) {
}, },
TestKeys: urlgetter.TestKeys{ TestKeys: urlgetter.TestKeys{
FailedOperation: (func() *string { FailedOperation: (func() *string {
s := errorsx.HTTPRoundTripOperation s := netxlite.HTTPRoundTripOperation
return &s return &s
})(), })(),
Failure: (func() *string { Failure: (func() *string {
s := errorsx.FailureEOFError s := netxlite.FailureEOFError
return &s return &s
})(), })(),
}, },
@ -265,7 +265,7 @@ func TestUpdateWebWithMixedResults(t *testing.T) {
if tk.TelegramWebStatus != "blocked" { if tk.TelegramWebStatus != "blocked" {
t.Fatal("TelegramWebStatus should be blocked") t.Fatal("TelegramWebStatus should be blocked")
} }
if *tk.TelegramWebFailure != errorsx.FailureEOFError { if *tk.TelegramWebFailure != netxlite.FailureEOFError {
t.Fatal("invalid TelegramWebFailure") t.Fatal("invalid TelegramWebFailure")
} }
} }

View File

@ -18,7 +18,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonidatamodel" "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/legacy/oonitemplates"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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/runtimex"
"github.com/ooni/probe-cli/v3/internal/scrubber" "github.com/ooni/probe-cli/v3/internal/scrubber"
) )
@ -77,7 +77,7 @@ func (tr *TargetResults) fillSummary() {
if len(tr.TCPConnect) < 1 { if len(tr.TCPConnect) < 1 {
return return
} }
tr.Summary[errorsx.ConnectOperation] = Summary{ tr.Summary[netxlite.ConnectOperation] = Summary{
Failure: tr.TCPConnect[0].Status.Failure, Failure: tr.TCPConnect[0].Status.Failure,
} }
switch tr.TargetProtocol { switch tr.TargetProtocol {

View File

@ -17,7 +17,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "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/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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" "github.com/ooni/probe-cli/v3/internal/scrubber"
) )
@ -446,7 +446,7 @@ func TestSummary(t *testing.T) {
if len(tr.Summary) != 1 { if len(tr.Summary) != 1 {
t.Fatal("cannot find expected entry") t.Fatal("cannot find expected entry")
} }
if *tr.Summary[errorsx.ConnectOperation].Failure != failure { if *tr.Summary[netxlite.ConnectOperation].Failure != failure {
t.Fatal("invalid failure") t.Fatal("invalid failure")
} }
}) })
@ -465,7 +465,7 @@ func TestSummary(t *testing.T) {
if len(tr.Summary) != 2 { if len(tr.Summary) != 2 {
t.Fatal("cannot find expected entry") t.Fatal("cannot find expected entry")
} }
if tr.Summary[errorsx.ConnectOperation].Failure != nil { if tr.Summary[netxlite.ConnectOperation].Failure != nil {
t.Fatal("invalid failure") t.Fatal("invalid failure")
} }
if *tr.Summary["handshake"].Failure != failure { if *tr.Summary["handshake"].Failure != failure {
@ -489,7 +489,7 @@ func TestSummary(t *testing.T) {
if len(tr.Summary) < 1 { if len(tr.Summary) < 1 {
t.Fatal("cannot find expected entry") t.Fatal("cannot find expected entry")
} }
if tr.Summary[errorsx.ConnectOperation].Failure != nil { if tr.Summary[netxlite.ConnectOperation].Failure != nil {
t.Fatal("invalid failure") t.Fatal("invalid failure")
} }
if handshake == nil { if handshake == nil {

View File

@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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" "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. // hitting our httptransport that does error wrapping.
err = legacyerrorsx.SafeErrWrapperBuilder{ err = legacyerrorsx.SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.TopLevelOperation, Operation: netxlite.TopLevelOperation,
}.MaybeBuild() }.MaybeBuild()
tk.FailedOperation = archival.NewFailedOperation(err) tk.FailedOperation = archival.NewFailedOperation(err)
tk.Failure = archival.NewFailure(err) tk.Failure = archival.NewFailure(err)

View File

@ -10,7 +10,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter" "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/mockable"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestGetterWithVeryShortTimeout(t *testing.T) { func TestGetterWithVeryShortTimeout(t *testing.T) {
@ -31,7 +31,7 @@ func TestGetterWithVeryShortTimeout(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || *tk.Failure != "generic_timeout_error" { if tk.Failure == nil || *tk.Failure != "generic_timeout_error" {
@ -98,7 +98,7 @@ func TestGetterWithCancelledContextVanilla(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") {
@ -166,7 +166,7 @@ func TestGetterWithCancelledContextAndMethod(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") {
@ -236,7 +236,7 @@ func TestGetterWithCancelledContextNoFollowRedirects(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") { if tk.Failure == nil || !strings.HasSuffix(*tk.Failure, "interrupted") {
@ -306,7 +306,7 @@ func TestGetterWithCancelledContextCannotStartTunnel(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || *tk.Failure != "interrupted" { if tk.Failure == nil || *tk.Failure != "interrupted" {
@ -361,7 +361,7 @@ func TestGetterWithCancelledContextUnknownResolverURL(t *testing.T) {
if tk.BootstrapTime != 0 { if tk.BootstrapTime != 0 {
t.Fatal("not the BootstrapTime we expected") 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") t.Fatal("not the FailedOperation we expected")
} }
if tk.Failure == nil || *tk.Failure != "unknown_failure: unsupported resolver scheme" { if tk.Failure == nil || *tk.Failure != "unknown_failure: unsupported resolver scheme" {
@ -446,7 +446,7 @@ func TestGetterIntegrationHTTPS(t *testing.T) {
resolveStart = true resolveStart = true
case "resolve_done": case "resolve_done":
resolveDone = true resolveDone = true
case errorsx.ConnectOperation: case netxlite.ConnectOperation:
connect = true connect = true
case "tls_handshake_start": case "tls_handshake_start":
tlsHandshakeStart = true tlsHandshakeStart = true
@ -587,7 +587,7 @@ func TestGetterIntegrationTLSHandshake(t *testing.T) {
resolveStart = true resolveStart = true
case "resolve_done": case "resolve_done":
resolveDone = true resolveDone = true
case errorsx.ConnectOperation: case netxlite.ConnectOperation:
connect = true connect = true
case "tls_handshake_start": case "tls_handshake_start":
tlsHandshakeStart = true tlsHandshakeStart = true
@ -705,7 +705,7 @@ func TestGetterHTTPSWithTunnel(t *testing.T) {
resolveStart = true resolveStart = true
case "resolve_done": case "resolve_done":
resolveDone = true resolveDone = true
case errorsx.ConnectOperation: case netxlite.ConnectOperation:
connect = true connect = true
case "tls_handshake_start": case "tls_handshake_start":
tlsHandshakeStart = true tlsHandshakeStart = true

View File

@ -11,17 +11,16 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/httpheader" "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/engine/netx"
"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/iox"
"github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/runtimex"
) )
const httpRequestFailed = "http_request_failed" const httpRequestFailed = "http_request_failed"
// ErrHTTPRequestFailed indicates that the HTTP request failed. // ErrHTTPRequestFailed indicates that the HTTP request failed.
var ErrHTTPRequestFailed = &errorsx.ErrWrapper{ var ErrHTTPRequestFailed = &netxlite.ErrWrapper{
Failure: httpRequestFailed, Failure: httpRequestFailed,
Operation: errorsx.TopLevelOperation, Operation: netxlite.TopLevelOperation,
WrappedErr: errors.New(httpRequestFailed), WrappedErr: errors.New(httpRequestFailed),
} }
@ -92,7 +91,7 @@ func (r Runner) httpGet(ctx context.Context, url string) error {
return err return err
} }
defer resp.Body.Close() 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 return err
} }
// Implementation note: we shall check for this error once we have read the // Implementation note: we shall check for this error once we have read the

View File

@ -7,7 +7,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/httpx" "github.com/ooni/probe-cli/v3/internal/engine/httpx"
legacyerrorsx "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" 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/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 // ControlRequest is the request that we send to the control
@ -62,7 +62,7 @@ func Control(
// make sure error is wrapped // make sure error is wrapped
err = legacyerrorsx.SafeErrWrapperBuilder{ err = legacyerrorsx.SafeErrWrapperBuilder{
Error: clnt.PostJSON(ctx, "/", creq, &out), Error: clnt.PostJSON(ctx, "/", creq, &out),
Operation: errorsx.TopLevelOperation, Operation: netxlite.TopLevelOperation,
}.MaybeBuild() }.MaybeBuild()
sess.Logger().Infof("control for %s... %+v", creq.HTTPRequest, err) sess.Logger().Infof("control for %s... %+v", creq.HTTPRequest, err)
(&out.DNS).FillASNs(sess) (&out.DNS).FillASNs(sess)

View File

@ -4,7 +4,7 @@ import (
"net" "net"
"net/url" "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 // DNSAnalysisResult contains the results of analysing comparing
@ -44,7 +44,7 @@ func DNSAnalysis(URL *url.URL, measurement DNSLookupResult,
switch *control.DNS.Failure { switch *control.DNS.Failure {
case DNSNameError: // the control returns this on NXDOMAIN error case DNSNameError: // the control returns this on NXDOMAIN error
switch *measurement.Failure { switch *measurement.Failure {
case errorsx.FailureDNSNXDOMAINError: case netxlite.FailureDNSNXDOMAINError:
out.DNSConsistency = &DNSConsistent out.DNSConsistency = &DNSConsistent
} }
} }

View File

@ -7,11 +7,11 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "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) { func TestDNSAnalysis(t *testing.T) {
measurementFailure := errorsx.FailureDNSNXDOMAINError measurementFailure := netxlite.FailureDNSNXDOMAINError
controlFailure := webconnectivity.DNSNameError controlFailure := webconnectivity.DNSNameError
eofFailure := io.EOF.Error() eofFailure := io.EOF.Error()
type args struct { type args struct {

View File

@ -5,7 +5,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity/internal" "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/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 // 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 // If DNS failed with NXDOMAIN and the control DNS is consistent, then it
// means this website does not exist anymore. // means this website does not exist anymore.
if tk.DNSExperimentFailure != nil && if tk.DNSExperimentFailure != nil &&
*tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError && *tk.DNSExperimentFailure == netxlite.FailureDNSNXDOMAINError &&
tk.DNSConsistency != nil && *tk.DNSConsistency == DNSConsistent { tk.DNSConsistency != nil && *tk.DNSConsistency == DNSConsistent {
// TODO(bassosimone): MK flags this as accessible. This result is debatable. We // 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. // 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. // Otherwise, if DNS failed with NXDOMAIN, it's DNS based blocking.
// TODO(bassosimone): do we wanna include other errors here? Like timeout? // TODO(bassosimone): do we wanna include other errors here? Like timeout?
if tk.DNSExperimentFailure != nil && if tk.DNSExperimentFailure != nil &&
*tk.DNSExperimentFailure == errorsx.FailureDNSNXDOMAINError { *tk.DNSExperimentFailure == netxlite.FailureDNSNXDOMAINError {
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.BlockingReason = &dns out.BlockingReason = &dns
out.Status |= StatusAnomalyDNS | StatusExperimentDNS out.Status |= StatusAnomalyDNS | StatusExperimentDNS
@ -184,41 +184,41 @@ func Summarize(tk *TestKeys) (out Summary) {
if tk.Requests[0].Failure != nil { if tk.Requests[0].Failure != nil {
out.Status |= StatusExperimentHTTP out.Status |= StatusExperimentHTTP
switch *tk.Requests[0].Failure { switch *tk.Requests[0].Failure {
case errorsx.FailureConnectionRefused: case netxlite.FailureConnectionRefused:
// This is possibly because a subsequent connection to some // This is possibly because a subsequent connection to some
// other endpoint has been blocked. We call this http-failure // other endpoint has been blocked. We call this http-failure
// because this is what MK would actually do. // because this is what MK would actually do.
out.BlockingReason = &httpFailure out.BlockingReason = &httpFailure
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.Status |= StatusAnomalyConnect out.Status |= StatusAnomalyConnect
case errorsx.FailureConnectionReset: case netxlite.FailureConnectionReset:
// We don't currently support TLS failures and we don't have a // 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 // way to know if it was during TLS or later. So, for now we are
// going to call this error condition an http-failure. // going to call this error condition an http-failure.
out.BlockingReason = &httpFailure out.BlockingReason = &httpFailure
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.Status |= StatusAnomalyReadWrite out.Status |= StatusAnomalyReadWrite
case errorsx.FailureDNSNXDOMAINError: case netxlite.FailureDNSNXDOMAINError:
// This is possibly because a subsequent resolution to // This is possibly because a subsequent resolution to
// some other domain name has been blocked. // some other domain name has been blocked.
out.BlockingReason = &dns out.BlockingReason = &dns
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.Status |= StatusAnomalyDNS out.Status |= StatusAnomalyDNS
case errorsx.FailureEOFError: case netxlite.FailureEOFError:
// We have seen this happening with TLS handshakes as well as // We have seen this happening with TLS handshakes as well as
// sometimes with HTTP blocking. So http-failure. // sometimes with HTTP blocking. So http-failure.
out.BlockingReason = &httpFailure out.BlockingReason = &httpFailure
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.Status |= StatusAnomalyReadWrite out.Status |= StatusAnomalyReadWrite
case errorsx.FailureGenericTimeoutError: case netxlite.FailureGenericTimeoutError:
// Alas, here we don't know whether it's connect or whether it's // 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. // perhaps the TLS handshake. So use the same classification used by MK.
out.BlockingReason = &httpFailure out.BlockingReason = &httpFailure
out.Accessible = &inaccessible out.Accessible = &inaccessible
out.Status |= StatusAnomalyUnknown out.Status |= StatusAnomalyUnknown
case errorsx.FailureSSLInvalidHostname, case netxlite.FailureSSLInvalidHostname,
errorsx.FailureSSLInvalidCertificate, netxlite.FailureSSLInvalidCertificate,
errorsx.FailureSSLUnknownAuthority: netxlite.FailureSSLUnknownAuthority:
// We treat these three cases equally. Misconfiguration is a bit // We treat these three cases equally. Misconfiguration is a bit
// less likely since we also checked with the control. Since there // less likely since we also checked with the control. Since there
// is no TLS, for now we're going to call this http-failure. // is no TLS, for now we're going to call this http-failure.

View File

@ -7,7 +7,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "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/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) { func TestSummarize(t *testing.T) {
@ -18,14 +18,14 @@ func TestSummarize(t *testing.T) {
httpDiff = "http-diff" httpDiff = "http-diff"
httpFailure = "http-failure" httpFailure = "http-failure"
nilstring *string nilstring *string
probeConnectionRefused = errorsx.FailureConnectionRefused probeConnectionRefused = netxlite.FailureConnectionRefused
probeConnectionReset = errorsx.FailureConnectionReset probeConnectionReset = netxlite.FailureConnectionReset
probeEOFError = errorsx.FailureEOFError probeEOFError = netxlite.FailureEOFError
probeNXDOMAIN = errorsx.FailureDNSNXDOMAINError probeNXDOMAIN = netxlite.FailureDNSNXDOMAINError
probeTimeout = errorsx.FailureGenericTimeoutError probeTimeout = netxlite.FailureGenericTimeoutError
probeSSLInvalidHost = errorsx.FailureSSLInvalidHostname probeSSLInvalidHost = netxlite.FailureSSLInvalidHostname
probeSSLInvalidCert = errorsx.FailureSSLInvalidCertificate probeSSLInvalidCert = netxlite.FailureSSLInvalidCertificate
probeSSLUnknownAuth = errorsx.FailureSSLUnknownAuthority probeSSLUnknownAuth = netxlite.FailureSSLUnknownAuthority
tcpIP = "tcp_ip" tcpIP = "tcp_ip"
trueValue = true trueValue = true
) )

View File

@ -13,7 +13,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival" "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) { func TestNewExperimentMeasurer(t *testing.T) {
@ -69,10 +69,10 @@ func TestMeasureWithCancelledContext(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
tk := measurement.TestKeys.(*webconnectivity.TestKeys) tk := measurement.TestKeys.(*webconnectivity.TestKeys)
if *tk.ControlFailure != errorsx.FailureInterrupted { if *tk.ControlFailure != netxlite.FailureInterrupted {
t.Fatal("unexpected control_failure") t.Fatal("unexpected control_failure")
} }
if *tk.DNSExperimentFailure != errorsx.FailureInterrupted { if *tk.DNSExperimentFailure != netxlite.FailureInterrupted {
t.Fatal("unexpected dns_experiment_failure") t.Fatal("unexpected dns_experiment_failure")
} }
if tk.HTTPExperimentFailure != nil { if tk.HTTPExperimentFailure != nil {

View File

@ -6,7 +6,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/httpx" "github.com/ooni/probe-cli/v3/internal/engine/httpx"
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" 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/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. // Control performs the control request and returns the response.
@ -21,7 +21,7 @@ func Control(
// make sure error is wrapped // make sure error is wrapped
err = errorsxlegacy.SafeErrWrapperBuilder{ err = errorsxlegacy.SafeErrWrapperBuilder{
Error: clnt.PostJSON(ctx, resourcePath, creq, &out), Error: clnt.PostJSON(ctx, resourcePath, creq, &out),
Operation: errorsx.TopLevelOperation, Operation: netxlite.TopLevelOperation,
}.MaybeBuild() }.MaybeBuild()
return return
} }

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeTransport struct { type FakeTransport struct {
@ -15,7 +15,7 @@ type FakeTransport struct {
func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) { func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Microsecond)
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeTransport struct { type FakeTransport struct {
@ -19,7 +19,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -10,7 +10,7 @@ import (
"net/http" "net/http"
"net/url" "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. // 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 { if response.StatusCode >= 400 {
return nil, fmt.Errorf("httpx: request failed: %s", response.Status) 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 // DoJSON performs the provided request and unmarshals the JSON response body

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"net" "net"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
// Dialer establishes network connections. // 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) conn, err := d.Dialer.DialContext(ctx, network, address)
if err != nil { if err != nil {
return nil, SafeErrWrapperBuilder{ return nil, SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyGenericError, Classifier: netxlite.ClassifyGenericError,
Operation: errorsx.ConnectOperation, Operation: netxlite.ConnectOperation,
Error: err, Error: err,
}.MaybeBuild() }.MaybeBuild()
} }
@ -44,8 +44,8 @@ func (c *errorWrapperConn) Read(b []byte) (int, error) {
count, err := c.Conn.Read(b) count, err := c.Conn.Read(b)
if err != nil { if err != nil {
return 0, SafeErrWrapperBuilder{ return 0, SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyGenericError, Classifier: netxlite.ClassifyGenericError,
Operation: errorsx.ReadOperation, Operation: netxlite.ReadOperation,
Error: err, Error: err,
}.MaybeBuild() }.MaybeBuild()
} }
@ -57,8 +57,8 @@ func (c *errorWrapperConn) Write(b []byte) (int, error) {
count, err := c.Conn.Write(b) count, err := c.Conn.Write(b)
if err != nil { if err != nil {
return 0, SafeErrWrapperBuilder{ return 0, SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyGenericError, Classifier: netxlite.ClassifyGenericError,
Operation: errorsx.WriteOperation, Operation: netxlite.WriteOperation,
Error: err, Error: err,
}.MaybeBuild() }.MaybeBuild()
} }
@ -70,8 +70,8 @@ func (c *errorWrapperConn) Close() error {
err := c.Conn.Close() err := c.Conn.Close()
if err != nil { if err != nil {
return SafeErrWrapperBuilder{ return SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyGenericError, Classifier: netxlite.ClassifyGenericError,
Operation: errorsx.CloseOperation, Operation: netxlite.CloseOperation,
Error: err, Error: err,
}.MaybeBuild() }.MaybeBuild()
} }

View File

@ -7,7 +7,7 @@ import (
"net" "net"
"testing" "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" "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") conn, err := d.DialContext(ctx, "tcp", "www.google.com:443")
var ew *errorsx.ErrWrapper var ew *netxlite.ErrWrapper
if !errors.As(err, &ew) { if !errors.As(err, &ew) {
t.Fatal("cannot convert to ErrWrapper") t.Fatal("cannot convert to ErrWrapper")
} }
if ew.Operation != errorsx.ConnectOperation { if ew.Operation != netxlite.ConnectOperation {
t.Fatal("unexpected operation", ew.Operation) t.Fatal("unexpected operation", ew.Operation)
} }
if ew.Failure != errorsx.FailureEOFError { if ew.Failure != netxlite.FailureEOFError {
t.Fatal("unexpected failure", ew.Failure) t.Fatal("unexpected failure", ew.Failure)
} }
if !errors.Is(ew.WrappedErr, io.EOF) { if !errors.Is(ew.WrappedErr, io.EOF) {
@ -68,14 +68,14 @@ func TestErrorWrapperConnReadFailure(t *testing.T) {
} }
buf := make([]byte, 1024) buf := make([]byte, 1024)
cnt, err := c.Read(buf) cnt, err := c.Read(buf)
var ew *errorsx.ErrWrapper var ew *netxlite.ErrWrapper
if !errors.As(err, &ew) { if !errors.As(err, &ew) {
t.Fatal("cannot cast error to ErrWrapper") t.Fatal("cannot cast error to ErrWrapper")
} }
if ew.Operation != errorsx.ReadOperation { if ew.Operation != netxlite.ReadOperation {
t.Fatal("invalid operation", ew.Operation) t.Fatal("invalid operation", ew.Operation)
} }
if ew.Failure != errorsx.FailureEOFError { if ew.Failure != netxlite.FailureEOFError {
t.Fatal("invalid failure", ew.Failure) t.Fatal("invalid failure", ew.Failure)
} }
if !errors.Is(ew.WrappedErr, io.EOF) { if !errors.Is(ew.WrappedErr, io.EOF) {
@ -114,14 +114,14 @@ func TestErrorWrapperConnWriteFailure(t *testing.T) {
} }
buf := make([]byte, 1024) buf := make([]byte, 1024)
cnt, err := c.Write(buf) cnt, err := c.Write(buf)
var ew *errorsx.ErrWrapper var ew *netxlite.ErrWrapper
if !errors.As(err, &ew) { if !errors.As(err, &ew) {
t.Fatal("cannot cast error to ErrWrapper") t.Fatal("cannot cast error to ErrWrapper")
} }
if ew.Operation != errorsx.WriteOperation { if ew.Operation != netxlite.WriteOperation {
t.Fatal("invalid operation", ew.Operation) t.Fatal("invalid operation", ew.Operation)
} }
if ew.Failure != errorsx.FailureEOFError { if ew.Failure != netxlite.FailureEOFError {
t.Fatal("invalid failure", ew.Failure) t.Fatal("invalid failure", ew.Failure)
} }
if !errors.Is(ew.WrappedErr, io.EOF) { if !errors.Is(ew.WrappedErr, io.EOF) {
@ -159,14 +159,14 @@ func TestErrorWrapperConnCloseFailure(t *testing.T) {
}, },
} }
err := c.Close() err := c.Close()
var ew *errorsx.ErrWrapper var ew *netxlite.ErrWrapper
if !errors.As(err, &ew) { if !errors.As(err, &ew) {
t.Fatal("cannot cast error to ErrWrapper") t.Fatal("cannot cast error to ErrWrapper")
} }
if ew.Operation != errorsx.CloseOperation { if ew.Operation != netxlite.CloseOperation {
t.Fatal("invalid operation", ew.Operation) t.Fatal("invalid operation", ew.Operation)
} }
if ew.Failure != errorsx.FailureEOFError { if ew.Failure != netxlite.FailureEOFError {
t.Fatal("invalid failure", ew.Failure) t.Fatal("invalid failure", ew.Failure)
} }
if !errors.Is(ew.WrappedErr, io.EOF) { if !errors.Is(ew.WrappedErr, io.EOF) {

View File

@ -4,7 +4,7 @@ package errorsx
import ( import (
"errors" "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 // SafeErrWrapperBuilder contains a builder for ErrWrapper that
@ -27,9 +27,9 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) {
if b.Error != nil { if b.Error != nil {
classifier := b.Classifier classifier := b.Classifier
if classifier == nil { if classifier == nil {
classifier = errorsx.ClassifyGenericError classifier = netxlite.ClassifyGenericError
} }
err = &errorsx.ErrWrapper{ err = &netxlite.ErrWrapper{
Failure: classifier(b.Error), Failure: classifier(b.Error),
Operation: toOperationString(b.Error, b.Operation), Operation: toOperationString(b.Error, b.Operation),
WrappedErr: b.Error, WrappedErr: b.Error,
@ -39,30 +39,30 @@ func (b SafeErrWrapperBuilder) MaybeBuild() (err error) {
} }
func toOperationString(err error, operation string) string { func toOperationString(err error, operation string) string {
var errwrapper *errorsx.ErrWrapper var errwrapper *netxlite.ErrWrapper
if errors.As(err, &errwrapper) { if errors.As(err, &errwrapper) {
// Basically, as explained in ErrWrapper docs, let's // Basically, as explained in ErrWrapper docs, let's
// keep the child major operation, if any. // keep the child major operation, if any.
if errwrapper.Operation == errorsx.ConnectOperation { if errwrapper.Operation == netxlite.ConnectOperation {
return errwrapper.Operation return errwrapper.Operation
} }
if errwrapper.Operation == errorsx.HTTPRoundTripOperation { if errwrapper.Operation == netxlite.HTTPRoundTripOperation {
return errwrapper.Operation return errwrapper.Operation
} }
if errwrapper.Operation == errorsx.ResolveOperation { if errwrapper.Operation == netxlite.ResolveOperation {
return errwrapper.Operation return errwrapper.Operation
} }
if errwrapper.Operation == errorsx.TLSHandshakeOperation { if errwrapper.Operation == netxlite.TLSHandshakeOperation {
return errwrapper.Operation return errwrapper.Operation
} }
if errwrapper.Operation == errorsx.QUICHandshakeOperation { if errwrapper.Operation == netxlite.QUICHandshakeOperation {
return errwrapper.Operation return errwrapper.Operation
} }
if errwrapper.Operation == "quic_handshake_start" { if errwrapper.Operation == "quic_handshake_start" {
return errorsx.QUICHandshakeOperation return netxlite.QUICHandshakeOperation
} }
if errwrapper.Operation == "quic_handshake_done" { if errwrapper.Operation == "quic_handshake_done" {
return errorsx.QUICHandshakeOperation return netxlite.QUICHandshakeOperation
} }
// FALLTHROUGH // FALLTHROUGH
} }

View File

@ -4,14 +4,14 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestMaybeBuildFactory(t *testing.T) { func TestMaybeBuildFactory(t *testing.T) {
err := SafeErrWrapperBuilder{ err := SafeErrWrapperBuilder{
Error: errors.New("mocked error"), Error: errors.New("mocked error"),
}.MaybeBuild() }.MaybeBuild()
var target *errorsx.ErrWrapper var target *netxlite.ErrWrapper
if errors.As(err, &target) == false { if errors.As(err, &target) == false {
t.Fatal("not the expected error type") t.Fatal("not the expected error type")
} }
@ -27,32 +27,32 @@ func TestToOperationString(t *testing.T) {
t.Run("for connect", func(t *testing.T) { t.Run("for connect", func(t *testing.T) {
// You're doing HTTP and connect fails. You want to know // You're doing HTTP and connect fails. You want to know
// that connect failed not that HTTP failed. // that connect failed not that HTTP failed.
err := &errorsx.ErrWrapper{Operation: errorsx.ConnectOperation} err := &netxlite.ErrWrapper{Operation: netxlite.ConnectOperation}
if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.ConnectOperation { if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.ConnectOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("for http_round_trip", func(t *testing.T) { t.Run("for http_round_trip", func(t *testing.T) {
// You're doing DoH and something fails inside HTTP. You want // You're doing DoH and something fails inside HTTP. You want
// to know about the internal HTTP error, not resolve. // to know about the internal HTTP error, not resolve.
err := &errorsx.ErrWrapper{Operation: errorsx.HTTPRoundTripOperation} err := &netxlite.ErrWrapper{Operation: netxlite.HTTPRoundTripOperation}
if toOperationString(err, errorsx.ResolveOperation) != errorsx.HTTPRoundTripOperation { if toOperationString(err, netxlite.ResolveOperation) != netxlite.HTTPRoundTripOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("for resolve", func(t *testing.T) { t.Run("for resolve", func(t *testing.T) {
// You're doing HTTP and the DNS fails. You want to // You're doing HTTP and the DNS fails. You want to
// know that resolve failed. // know that resolve failed.
err := &errorsx.ErrWrapper{Operation: errorsx.ResolveOperation} err := &netxlite.ErrWrapper{Operation: netxlite.ResolveOperation}
if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.ResolveOperation { if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.ResolveOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("for tls_handshake", func(t *testing.T) { t.Run("for tls_handshake", func(t *testing.T) {
// You're doing HTTP and the TLS handshake fails. You want // You're doing HTTP and the TLS handshake fails. You want
// to know about a TLS handshake error. // to know about a TLS handshake error.
err := &errorsx.ErrWrapper{Operation: errorsx.TLSHandshakeOperation} err := &netxlite.ErrWrapper{Operation: netxlite.TLSHandshakeOperation}
if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.TLSHandshakeOperation { if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.TLSHandshakeOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
@ -60,16 +60,16 @@ func TestToOperationString(t *testing.T) {
// You just noticed that TLS handshake failed and you // You just noticed that TLS handshake failed and you
// have a child error telling you that read failed. Here // have a child error telling you that read failed. Here
// you want to know about a TLS handshake error. // you want to know about a TLS handshake error.
err := &errorsx.ErrWrapper{Operation: errorsx.ReadOperation} err := &netxlite.ErrWrapper{Operation: netxlite.ReadOperation}
if toOperationString(err, errorsx.TLSHandshakeOperation) != errorsx.TLSHandshakeOperation { if toOperationString(err, netxlite.TLSHandshakeOperation) != netxlite.TLSHandshakeOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })
t.Run("for quic_handshake", func(t *testing.T) { t.Run("for quic_handshake", func(t *testing.T) {
// You're doing HTTP and the TLS handshake fails. You want // You're doing HTTP and the TLS handshake fails. You want
// to know about a TLS handshake error. // to know about a TLS handshake error.
err := &errorsx.ErrWrapper{Operation: errorsx.QUICHandshakeOperation} err := &netxlite.ErrWrapper{Operation: netxlite.QUICHandshakeOperation}
if toOperationString(err, errorsx.HTTPRoundTripOperation) != errorsx.QUICHandshakeOperation { if toOperationString(err, netxlite.HTTPRoundTripOperation) != netxlite.QUICHandshakeOperation {
t.Fatal("unexpected result") t.Fatal("unexpected result")
} }
}) })

View File

@ -8,7 +8,6 @@ import (
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" 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"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
) )
func TestErrorWrapperQUICDialerInvalidCertificate(t *testing.T) { func TestErrorWrapperQUICDialerInvalidCertificate(t *testing.T) {
@ -31,7 +30,7 @@ func TestErrorWrapperQUICDialerInvalidCertificate(t *testing.T) {
if sess != nil { if sess != nil {
t.Fatal("expected nil sess here") t.Fatal("expected nil sess here")
} }
if err.Error() != errorsx.FailureSSLInvalidCertificate { if err.Error() != netxlite.FailureSSLInvalidCertificate {
t.Fatal("unexpected failure") t.Fatal("unexpected failure")
} }
} }

View File

@ -6,7 +6,7 @@ import (
"net" "net"
"github.com/lucas-clemente/quic-go" "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" "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 { if err != nil {
return nil, SafeErrWrapperBuilder{ return nil, SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.QUICListenOperation, Operation: netxlite.QUICListenOperation,
}.MaybeBuild() }.MaybeBuild()
} }
return &errorWrapperUDPConn{pconn}, nil return &errorWrapperUDPConn{pconn}, nil
@ -59,7 +59,7 @@ func (c *errorWrapperUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) {
if err != nil { if err != nil {
return 0, SafeErrWrapperBuilder{ return 0, SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.WriteToOperation, Operation: netxlite.WriteToOperation,
}.MaybeBuild() }.MaybeBuild()
} }
return count, nil return count, nil
@ -71,7 +71,7 @@ func (c *errorWrapperUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
if err != nil { if err != nil {
return 0, nil, SafeErrWrapperBuilder{ return 0, nil, SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.ReadFromOperation, Operation: netxlite.ReadFromOperation,
}.MaybeBuild() }.MaybeBuild()
} }
return n, addr, nil return n, addr, nil
@ -89,9 +89,9 @@ func (d *ErrorWrapperQUICDialer) DialContext(
sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg) sess, err := d.Dialer.DialContext(ctx, network, host, tlsCfg, cfg)
if err != nil { if err != nil {
return nil, SafeErrWrapperBuilder{ return nil, SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyQUICHandshakeError, Classifier: netxlite.ClassifyQUICHandshakeError,
Error: err, Error: err,
Operation: errorsx.QUICHandshakeOperation, Operation: netxlite.QUICHandshakeOperation,
}.MaybeBuild() }.MaybeBuild()
} }
return sess, nil return sess, nil

View File

@ -9,7 +9,7 @@ import (
"testing" "testing"
"github.com/lucas-clemente/quic-go" "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/mocks"
"github.com/ooni/probe-cli/v3/internal/netxlite/quicx" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx"
) )
@ -143,14 +143,14 @@ func TestErrorWrapperQUICDialerFailure(t *testing.T) {
if !errors.Is(err, io.EOF) { if !errors.Is(err, io.EOF) {
t.Fatal("expected another error here") t.Fatal("expected another error here")
} }
var errWrapper *errorsx.ErrWrapper var errWrapper *netxlite.ErrWrapper
if !errors.As(err, &errWrapper) { if !errors.As(err, &errWrapper) {
t.Fatal("cannot cast to ErrWrapper") t.Fatal("cannot cast to ErrWrapper")
} }
if errWrapper.Operation != errorsx.QUICHandshakeOperation { if errWrapper.Operation != netxlite.QUICHandshakeOperation {
t.Fatal("unexpected Operation") t.Fatal("unexpected Operation")
} }
if errWrapper.Failure != errorsx.FailureEOFError { if errWrapper.Failure != netxlite.FailureEOFError {
t.Fatal("unexpected failure") t.Fatal("unexpected failure")
} }
} }

View File

@ -3,7 +3,7 @@ package errorsx
import ( import (
"context" "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 // 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) { func (r *ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
addrs, err := r.Resolver.LookupHost(ctx, hostname) addrs, err := r.Resolver.LookupHost(ctx, hostname)
err = SafeErrWrapperBuilder{ err = SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyResolverError, Classifier: netxlite.ClassifyResolverError,
Error: err, Error: err,
Operation: errorsx.ResolveOperation, Operation: netxlite.ResolveOperation,
}.MaybeBuild() }.MaybeBuild()
return addrs, err return addrs, err
} }

View File

@ -6,7 +6,7 @@ import (
"net" "net"
"testing" "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" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
) )
@ -41,14 +41,14 @@ func TestErrorWrapperResolverFailure(t *testing.T) {
if addrs != nil { if addrs != nil {
t.Fatal("expected nil addr here") t.Fatal("expected nil addr here")
} }
var errWrapper *errorsx.ErrWrapper var errWrapper *netxlite.ErrWrapper
if !errors.As(err, &errWrapper) { if !errors.As(err, &errWrapper) {
t.Fatal("cannot properly cast the returned error") t.Fatal("cannot properly cast the returned error")
} }
if errWrapper.Failure != errorsx.FailureDNSNXDOMAINError { if errWrapper.Failure != netxlite.FailureDNSNXDOMAINError {
t.Fatal("unexpected failure") t.Fatal("unexpected failure")
} }
if errWrapper.Operation != errorsx.ResolveOperation { if errWrapper.Operation != netxlite.ResolveOperation {
t.Fatal("unexpected Operation") t.Fatal("unexpected Operation")
} }
} }

View File

@ -5,7 +5,7 @@ import (
"crypto/tls" "crypto/tls"
"net" "net"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
// TLSHandshaker is the generic TLS handshaker // TLSHandshaker is the generic TLS handshaker
@ -25,9 +25,9 @@ func (h *ErrorWrapperTLSHandshaker) Handshake(
) (net.Conn, tls.ConnectionState, error) { ) (net.Conn, tls.ConnectionState, error) {
tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config) tlsconn, state, err := h.TLSHandshaker.Handshake(ctx, conn, config)
err = SafeErrWrapperBuilder{ err = SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyTLSHandshakeError, Classifier: netxlite.ClassifyTLSHandshakeError,
Error: err, Error: err,
Operation: errorsx.TLSHandshakeOperation, Operation: netxlite.TLSHandshakeOperation,
}.MaybeBuild() }.MaybeBuild()
return tlsconn, state, err return tlsconn, state, err
} }

View File

@ -8,7 +8,7 @@ import (
"net" "net"
"testing" "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" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
) )
@ -30,14 +30,14 @@ func TestErrorWrapperTLSHandshakerFailure(t *testing.T) {
if conn != nil { if conn != nil {
t.Fatal("expected nil con here") t.Fatal("expected nil con here")
} }
var errWrapper *errorsx.ErrWrapper var errWrapper *netxlite.ErrWrapper
if !errors.As(err, &errWrapper) { if !errors.As(err, &errWrapper) {
t.Fatal("cannot cast to ErrWrapper") t.Fatal("cannot cast to ErrWrapper")
} }
if errWrapper.Failure != errorsx.FailureEOFError { if errWrapper.Failure != netxlite.FailureEOFError {
t.Fatal("unexpected Failure") t.Fatal("unexpected Failure")
} }
if errWrapper.Operation != errorsx.TLSHandshakeOperation { if errWrapper.Operation != netxlite.TLSHandshakeOperation {
t.Fatal("unexpected Operation") t.Fatal("unexpected Operation")
} }
} }

View File

@ -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/handlers"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" "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/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" "golang.org/x/net/http2"
) )
@ -82,10 +82,10 @@ func (t *HTTPTransport) RoundTrip(
resp, err = t.roundTripper.RoundTrip(req) resp, err = t.roundTripper.RoundTrip(req)
// For safety wrap the error as modelx.HTTPRoundTripOperation but this // For safety wrap the error as modelx.HTTPRoundTripOperation but this
// will only be used if the error chain does not contain any // 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{ err = errorsxlegacy.SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.HTTPRoundTripOperation, Operation: netxlite.HTTPRoundTripOperation,
}.MaybeBuild() }.MaybeBuild()
return resp, err return resp, err
} }

View File

@ -13,8 +13,7 @@ import (
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx" "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"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
) )
func dowithclient(t *testing.T, client *netx.HTTPClient) { func dowithclient(t *testing.T, client *netx.HTTPClient) {
@ -24,7 +23,7 @@ func dowithclient(t *testing.T, client *netx.HTTPClient) {
t.Fatal(err) t.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -126,7 +125,7 @@ func httpProxyTestMain(t *testing.T, client *http.Client, expect int) {
t.Fatal(err) t.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -148,7 +147,7 @@ func TestHTTPTransportTimeout(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("expected an error here") 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") t.Fatal("not the error we expected")
} }
if resp != nil { if resp != nil {

View File

@ -8,7 +8,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestNewTLSConnectionState(t *testing.T) { func TestNewTLSConnectionState(t *testing.T) {
@ -61,7 +61,7 @@ func TestMeasurementRootWithMeasurementRootPanic(t *testing.T) {
func TestErrWrapperPublicAPI(t *testing.T) { func TestErrWrapperPublicAPI(t *testing.T) {
child := errors.New("mocked error") child := errors.New("mocked error")
wrapper := &errorsx.ErrWrapper{ wrapper := &netxlite.ErrWrapper{
Failure: "moobar", Failure: "moobar",
WrappedErr: child, WrappedErr: child,
} }

View File

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestBodyTracerSuccess(t *testing.T) { func TestBodyTracerSuccess(t *testing.T) {
@ -17,7 +17,7 @@ func TestBodyTracerSuccess(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestGood(t *testing.T) { func TestGood(t *testing.T) {
@ -17,7 +17,7 @@ func TestGood(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -13,8 +13,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/atomicx"
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" 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/engine/legacy/netx/modelx"
"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/iox"
) )
// TraceTripper performs single HTTP transactions. // TraceTripper performs single HTTP transactions.
@ -28,7 +27,7 @@ type TraceTripper struct {
func NewTraceTripper(roundTripper http.RoundTripper) *TraceTripper { func NewTraceTripper(roundTripper http.RoundTripper) *TraceTripper {
return &TraceTripper{ return &TraceTripper{
readAllErrs: &atomicx.Int64{}, readAllErrs: &atomicx.Int64{},
readAllContext: iox.ReadAllContext, readAllContext: netxlite.ReadAllContext,
roundTripper: roundTripper, roundTripper: roundTripper,
} }
} }
@ -84,7 +83,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
var ( var (
err error err error
majorOp = errorsx.HTTPRoundTripOperation majorOp = netxlite.HTTPRoundTripOperation
majorOpMu sync.Mutex majorOpMu sync.Mutex
requestBody []byte requestBody []byte
requestHeaders = http.Header{} requestHeaders = http.Header{}
@ -104,7 +103,7 @@ func (t *TraceTripper) RoundTrip(req *http.Request) (*http.Response, error) {
tracer := &httptrace.ClientTrace{ tracer := &httptrace.ClientTrace{
TLSHandshakeStart: func() { TLSHandshakeStart: func() {
majorOpMu.Lock() majorOpMu.Lock()
majorOp = errorsx.TLSHandshakeOperation majorOp = netxlite.TLSHandshakeOperation
majorOpMu.Unlock() majorOpMu.Unlock()
// Event emitted by net/http when DialTLS is not // Event emitted by net/http when DialTLS is not
// configured in the http.Transport // 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 // less confusing to users to see the wrapped name
err = errorsxlegacy.SafeErrWrapperBuilder{ err = errorsxlegacy.SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.TLSHandshakeOperation, Operation: netxlite.TLSHandshakeOperation,
}.MaybeBuild() }.MaybeBuild()
durationSinceBeginning := time.Since(root.Beginning) durationSinceBeginning := time.Since(root.Beginning)
// Event emitted by net/http when DialTLS is not // 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) { GotConn: func(info httptrace.GotConnInfo) {
majorOpMu.Lock() majorOpMu.Lock()
majorOp = errorsx.HTTPRoundTripOperation majorOp = netxlite.HTTPRoundTripOperation
majorOpMu.Unlock() majorOpMu.Unlock()
root.Handler.OnMeasurement(modelx.Measurement{ root.Handler.OnMeasurement(modelx.Measurement{
HTTPConnectionReady: &modelx.HTTPConnectionReadyEvent{ 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 // less confusing to users to see the wrapped name
err := errorsxlegacy.SafeErrWrapperBuilder{ err := errorsxlegacy.SafeErrWrapperBuilder{
Error: info.Err, Error: info.Err,
Operation: errorsx.HTTPRoundTripOperation, Operation: netxlite.HTTPRoundTripOperation,
}.MaybeBuild() }.MaybeBuild()
root.Handler.OnMeasurement(modelx.Measurement{ root.Handler.OnMeasurement(modelx.Measurement{
HTTPRequestDone: &modelx.HTTPRequestDoneEvent{ HTTPRequestDone: &modelx.HTTPRequestDoneEvent{

View File

@ -13,7 +13,7 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" "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) { func TestTraceTripperSuccess(t *testing.T) {
@ -25,7 +25,7 @@ func TestTraceTripperSuccess(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -156,7 +156,7 @@ func TestTraceTripperWithCorrectSnaps(t *testing.T) {
// Read the whole response body, parse it as valid DNS // Read the whole response body, parse it as valid DNS
// reply and verify we obtained what we expected // 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -118,7 +118,8 @@ func newResolver(
if network == "udp" { if network == "udp" {
// Same rationale as above: avoid possible endless loop // Same rationale as above: avoid possible endless loop
return newResolverWrapper(beginning, handler, newResolverUDP( return newResolverWrapper(beginning, handler, newResolverUDP(
newDialer(beginning, handler), withPort(address, "53"), netxlite.NewDialerLegacyAdapter(newDialer(beginning, handler)),
withPort(address, "53"),
)), nil )), nil
} }
return nil, errors.New("resolver.New: unsupported network value") return nil, errors.New("resolver.New: unsupported network value")

View File

@ -10,7 +10,7 @@ import (
"github.com/apex/log/handlers/discard" "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"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" "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) { func TestGood(t *testing.T) {
@ -33,7 +33,7 @@ func TestGood(t *testing.T) {
t.Fatal("expected non-nil resp here") t.Fatal("expected non-nil resp here")
} }
defer resp.Body.Close() defer resp.Body.Close()
_, err = iox.ReadAllContext(context.Background(), resp.Body) _, err = netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -20,7 +20,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "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/engine/model"
"github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
) )
// ExtSpec describes a data format extension // ExtSpec describes a data format extension
@ -418,7 +417,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
out = append(out, &NetworkEvent{ out = append(out, &NetworkEvent{
Address: in.Connect.RemoteAddress, Address: in.Connect.RemoteAddress,
Failure: makeFailure(in.Connect.Error), Failure: makeFailure(in.Connect.Error),
Operation: errorsx.ConnectOperation, Operation: netxlite.ConnectOperation,
T: in.Connect.DurationSinceBeginning.Seconds(), T: in.Connect.DurationSinceBeginning.Seconds(),
}) })
// fallthrough // fallthrough
@ -426,7 +425,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
if in.Read != nil { if in.Read != nil {
out = append(out, &NetworkEvent{ out = append(out, &NetworkEvent{
Failure: makeFailure(in.Read.Error), Failure: makeFailure(in.Read.Error),
Operation: errorsx.ReadOperation, Operation: netxlite.ReadOperation,
NumBytes: in.Read.NumBytes, NumBytes: in.Read.NumBytes,
T: in.Read.DurationSinceBeginning.Seconds(), T: in.Read.DurationSinceBeginning.Seconds(),
}) })
@ -435,7 +434,7 @@ func NewNetworkEventsList(results oonitemplates.Results) NetworkEventsList {
if in.Write != nil { if in.Write != nil {
out = append(out, &NetworkEvent{ out = append(out, &NetworkEvent{
Failure: makeFailure(in.Write.Error), Failure: makeFailure(in.Write.Error),
Operation: errorsx.WriteOperation, Operation: netxlite.WriteOperation,
NumBytes: in.Write.NumBytes, NumBytes: in.Write.NumBytes,
T: in.Write.DurationSinceBeginning.Seconds(), T: in.Write.DurationSinceBeginning.Seconds(),
}) })

View File

@ -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/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/oonitemplates" "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) { func TestNewTCPConnectListEmpty(t *testing.T) {
@ -67,7 +67,7 @@ func TestNewTCPConnectListFailure(t *testing.T) {
Connects: []*modelx.ConnectEvent{ Connects: []*modelx.ConnectEvent{
{ {
RemoteAddress: "8.8.8.8:53", 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 { if out[0].Port != 53 {
t.Fatal("unexpected out[0].Port") 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") t.Fatal("unexpected out[0].Failure")
} }
if out[0].Status.Success != false { if out[0].Status.Success != false {
@ -93,7 +93,7 @@ func TestNewTCPConnectListInvalidInput(t *testing.T) {
Connects: []*modelx.ConnectEvent{ Connects: []*modelx.ConnectEvent{
{ {
RemoteAddress: "8.8.8.8", 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 { if out[0].Port != 0 {
t.Fatal("unexpected out[0].Port") 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") t.Fatal("unexpected out[0].Failure")
} }
if out[0].Status.Success != false { if out[0].Status.Success != false {
@ -649,7 +649,7 @@ func TestNewDNSQueriesListSuccess(t *testing.T) {
TransportNetwork: "system", TransportNetwork: "system",
}, },
{ {
Error: errors.New(errorsx.FailureDNSNXDOMAINError), Error: errors.New(netxlite.FailureDNSNXDOMAINError),
Hostname: "dns.googlex", Hostname: "dns.googlex",
TransportNetwork: "system", TransportNetwork: "system",
}, },
@ -768,7 +768,7 @@ func dnscheckbad(e DNSQueryEntry) error {
if e.Engine != "system" { if e.Engine != "system" {
return errors.New("invalid engine") return errors.New("invalid engine")
} }
if *e.Failure != errorsx.FailureDNSNXDOMAINError { if *e.Failure != netxlite.FailureDNSNXDOMAINError {
return errors.New("invalid failure") return errors.New("invalid failure")
} }
if e.Hostname != "dns.googlex" { if e.Hostname != "dns.googlex" {
@ -854,7 +854,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[0].NumBytes != 0 { if out[0].NumBytes != 0 {
t.Fatal("wrong out[0].NumBytes") t.Fatal("wrong out[0].NumBytes")
} }
if out[0].Operation != errorsx.ConnectOperation { if out[0].Operation != netxlite.ConnectOperation {
t.Fatal("wrong out[0].Operation") t.Fatal("wrong out[0].Operation")
} }
if !floatEquals(out[0].T, 0.010) { if !floatEquals(out[0].T, 0.010) {
@ -870,7 +870,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[1].NumBytes != 1789 { if out[1].NumBytes != 1789 {
t.Fatal("wrong out[1].NumBytes") t.Fatal("wrong out[1].NumBytes")
} }
if out[1].Operation != errorsx.ReadOperation { if out[1].Operation != netxlite.ReadOperation {
t.Fatal("wrong out[1].Operation") t.Fatal("wrong out[1].Operation")
} }
if !floatEquals(out[1].T, 0.020) { if !floatEquals(out[1].T, 0.020) {
@ -886,7 +886,7 @@ func TestNewNetworkEventsListGood(t *testing.T) {
if out[2].NumBytes != 17714 { if out[2].NumBytes != 17714 {
t.Fatal("wrong out[2].NumBytes") t.Fatal("wrong out[2].NumBytes")
} }
if out[2].Operation != errorsx.WriteOperation { if out[2].Operation != netxlite.WriteOperation {
t.Fatal("wrong out[2].Operation") t.Fatal("wrong out[2].Operation")
} }
if !floatEquals(out[2].T, 0.030) { if !floatEquals(out[2].T, 0.030) {
@ -933,7 +933,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[0].NumBytes != 0 { if out[0].NumBytes != 0 {
t.Fatal("wrong out[0].NumBytes") t.Fatal("wrong out[0].NumBytes")
} }
if out[0].Operation != errorsx.ConnectOperation { if out[0].Operation != netxlite.ConnectOperation {
t.Fatal("wrong out[0].Operation") t.Fatal("wrong out[0].Operation")
} }
if !floatEquals(out[0].T, 0.010) { if !floatEquals(out[0].T, 0.010) {
@ -949,7 +949,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[1].NumBytes != 1789 { if out[1].NumBytes != 1789 {
t.Fatal("wrong out[1].NumBytes") t.Fatal("wrong out[1].NumBytes")
} }
if out[1].Operation != errorsx.ReadOperation { if out[1].Operation != netxlite.ReadOperation {
t.Fatal("wrong out[1].Operation") t.Fatal("wrong out[1].Operation")
} }
if !floatEquals(out[1].T, 0.020) { if !floatEquals(out[1].T, 0.020) {
@ -965,7 +965,7 @@ func TestNewNetworkEventsListGoodUDPAndErrors(t *testing.T) {
if out[2].NumBytes != 17714 { if out[2].NumBytes != 17714 {
t.Fatal("wrong out[2].NumBytes") t.Fatal("wrong out[2].NumBytes")
} }
if out[2].Operation != errorsx.WriteOperation { if out[2].Operation != netxlite.WriteOperation {
t.Fatal("wrong out[2].Operation") t.Fatal("wrong out[2].Operation")
} }
if !floatEquals(out[2].T, 0.030) { if !floatEquals(out[2].T, 0.030) {

View File

@ -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"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers" "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/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" "github.com/ooni/probe-cli/v3/internal/runtimex"
"gitlab.com/yawning/obfs4.git/transports" "gitlab.com/yawning/obfs4.git/transports"
obfs4base "gitlab.com/yawning/obfs4.git/transports/base" obfs4base "gitlab.com/yawning/obfs4.git/transports/base"
@ -327,7 +327,7 @@ func HTTPDo(
config.MaxResponseBodySnapSize, config.MaxResponseBodySnapSize,
), ),
) )
data, err := iox.ReadAllContext(ctx, reader) data, err := netxlite.ReadAllContext(ctx, reader)
mu.Lock() mu.Lock()
results.BodySnap, results.Error = data, err results.BodySnap, results.Error = data, err
mu.Unlock() mu.Unlock()

View File

@ -11,7 +11,7 @@ import (
goptlib "git.torproject.org/pluggable-transports/goptlib.git" 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/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" "gitlab.com/yawning/obfs4.git/transports"
obfs4base "gitlab.com/yawning/obfs4.git/transports/base" obfs4base "gitlab.com/yawning/obfs4.git/transports/base"
) )
@ -55,7 +55,7 @@ func TestDNSLookupCancellation(t *testing.T) {
if results.Error == nil { if results.Error == nil {
t.Fatal("expected an error here") 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") t.Fatal("not the error we expected")
} }
if len(results.Addresses) > 0 { if len(results.Addresses) > 0 {
@ -170,7 +170,7 @@ func TestTLSConnectCancellation(t *testing.T) {
if results.Error == nil { if results.Error == nil {
t.Fatal("expected an error here") 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") t.Fatal("not the error we expected")
} }
} }

View File

@ -20,7 +20,7 @@ import (
errorsxlegacy "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx" 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/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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 // ExtSpec describes a data format extension
@ -81,7 +81,7 @@ type TCPConnectEntry struct {
func NewTCPConnectList(begin time.Time, events []trace.Event) []TCPConnectEntry { func NewTCPConnectList(begin time.Time, events []trace.Event) []TCPConnectEntry {
var out []TCPConnectEntry var out []TCPConnectEntry
for _, event := range events { for _, event := range events {
if event.Name != errorsx.ConnectOperation { if event.Name != netxlite.ConnectOperation {
continue continue
} }
if event.Proto != "tcp" { if event.Proto != "tcp" {
@ -113,9 +113,9 @@ func NewFailure(err error) *string {
// in which this happen is with context deadline for HTTP. // in which this happen is with context deadline for HTTP.
err = errorsxlegacy.SafeErrWrapperBuilder{ err = errorsxlegacy.SafeErrWrapperBuilder{
Error: err, Error: err,
Operation: errorsx.TopLevelOperation, Operation: netxlite.TopLevelOperation,
}.MaybeBuild() }.MaybeBuild()
errWrapper := err.(*errorsx.ErrWrapper) errWrapper := err.(*netxlite.ErrWrapper)
s := errWrapper.Failure s := errWrapper.Failure
if s == "" { if s == "" {
s = "unknown_failure: errWrapper.Failure is empty" s = "unknown_failure: errWrapper.Failure is empty"
@ -129,8 +129,8 @@ func NewFailedOperation(err error) *string {
return nil return nil
} }
var ( var (
errWrapper *errorsx.ErrWrapper errWrapper *netxlite.ErrWrapper
s = errorsx.UnknownOperation s = netxlite.UnknownOperation
) )
if errors.As(err, &errWrapper) && errWrapper.Operation != "" { if errors.As(err, &errWrapper) && errWrapper.Operation != "" {
s = errWrapper.Operation s = errWrapper.Operation
@ -475,7 +475,7 @@ type NetworkEvent struct {
func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent { func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent {
var out []NetworkEvent var out []NetworkEvent
for _, ev := range events { for _, ev := range events {
if ev.Name == errorsx.ConnectOperation { if ev.Name == netxlite.ConnectOperation {
out = append(out, NetworkEvent{ out = append(out, NetworkEvent{
Address: ev.Address, Address: ev.Address,
Failure: NewFailure(ev.Err), Failure: NewFailure(ev.Err),
@ -485,7 +485,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent
}) })
continue continue
} }
if ev.Name == errorsx.ReadOperation { if ev.Name == netxlite.ReadOperation {
out = append(out, NetworkEvent{ out = append(out, NetworkEvent{
Failure: NewFailure(ev.Err), Failure: NewFailure(ev.Err),
Operation: ev.Name, Operation: ev.Name,
@ -494,7 +494,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent
}) })
continue continue
} }
if ev.Name == errorsx.WriteOperation { if ev.Name == netxlite.WriteOperation {
out = append(out, NetworkEvent{ out = append(out, NetworkEvent{
Failure: NewFailure(ev.Err), Failure: NewFailure(ev.Err),
Operation: ev.Name, Operation: ev.Name,
@ -503,7 +503,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent
}) })
continue continue
} }
if ev.Name == errorsx.ReadFromOperation { if ev.Name == netxlite.ReadFromOperation {
out = append(out, NetworkEvent{ out = append(out, NetworkEvent{
Address: ev.Address, Address: ev.Address,
Failure: NewFailure(ev.Err), Failure: NewFailure(ev.Err),
@ -513,7 +513,7 @@ func NewNetworkEventsList(begin time.Time, events []trace.Event) []NetworkEvent
}) })
continue continue
} }
if ev.Name == errorsx.WriteToOperation { if ev.Name == netxlite.WriteToOperation {
out = append(out, NetworkEvent{ out = append(out, NetworkEvent{
Address: ev.Address, Address: ev.Address,
Failure: NewFailure(ev.Err), Failure: NewFailure(ev.Err),

View File

@ -15,7 +15,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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) { func TestNewTCPConnectList(t *testing.T) {
@ -47,20 +47,20 @@ func TestNewTCPConnectList(t *testing.T) {
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Duration: 30 * time.Millisecond, Duration: 30 * time.Millisecond,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: "tcp", Proto: "tcp",
Time: begin.Add(130 * time.Millisecond), Time: begin.Add(130 * time.Millisecond),
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Duration: 55 * time.Millisecond, Duration: 55 * time.Millisecond,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: "udp", Proto: "udp",
Time: begin.Add(130 * time.Millisecond), Time: begin.Add(130 * time.Millisecond),
}, { }, {
Address: "8.8.4.4:53", Address: "8.8.4.4:53",
Duration: 50 * time.Millisecond, Duration: 50 * time.Millisecond,
Err: io.EOF, Err: io.EOF,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: "tcp", Proto: "tcp",
Time: begin.Add(180 * time.Millisecond), Time: begin.Add(180 * time.Millisecond),
}}, }},
@ -314,14 +314,14 @@ func TestNewDNSQueriesList(t *testing.T) {
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Duration: 30 * time.Millisecond, Duration: 30 * time.Millisecond,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: "tcp", Proto: "tcp",
Time: begin.Add(130 * time.Millisecond), Time: begin.Add(130 * time.Millisecond),
}, { }, {
Address: "8.8.4.4:53", Address: "8.8.4.4:53",
Duration: 50 * time.Millisecond, Duration: 50 * time.Millisecond,
Err: io.EOF, Err: io.EOF,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: "tcp", Proto: "tcp",
Time: begin.Add(180 * time.Millisecond), Time: begin.Add(180 * time.Millisecond),
}}, }},
@ -371,7 +371,7 @@ func TestNewDNSQueriesList(t *testing.T) {
args: args{ args: args{
begin: begin, begin: begin,
events: []trace.Event{{ events: []trace.Event{{
Err: &errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}, Err: &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError},
Hostname: "dns.google.com", Hostname: "dns.google.com",
Name: "resolve_done", Name: "resolve_done",
Time: begin.Add(200 * time.Millisecond), Time: begin.Add(200 * time.Millisecond),
@ -380,14 +380,14 @@ func TestNewDNSQueriesList(t *testing.T) {
want: []archival.DNSQueryEntry{{ want: []archival.DNSQueryEntry{{
Answers: nil, Answers: nil,
Failure: archival.NewFailure( Failure: archival.NewFailure(
&errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError}),
Hostname: "dns.google.com", Hostname: "dns.google.com",
QueryType: "A", QueryType: "A",
T: 0.2, T: 0.2,
}, { }, {
Answers: nil, Answers: nil,
Failure: archival.NewFailure( Failure: archival.NewFailure(
&errorsx.ErrWrapper{Failure: errorsx.FailureDNSNXDOMAINError}), &netxlite.ErrWrapper{Failure: netxlite.FailureDNSNXDOMAINError}),
Hostname: "dns.google.com", Hostname: "dns.google.com",
QueryType: "AAAA", QueryType: "AAAA",
T: 0.2, T: 0.2,
@ -425,35 +425,35 @@ func TestNewNetworkEventsList(t *testing.T) {
args: args{ args: args{
begin: begin, begin: begin,
events: []trace.Event{{ events: []trace.Event{{
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Err: io.EOF, Err: io.EOF,
Proto: "tcp", Proto: "tcp",
Time: begin.Add(7 * time.Millisecond), Time: begin.Add(7 * time.Millisecond),
}, { }, {
Name: errorsx.ReadOperation, Name: netxlite.ReadOperation,
Err: context.Canceled, Err: context.Canceled,
NumBytes: 7117, NumBytes: 7117,
Time: begin.Add(11 * time.Millisecond), Time: begin.Add(11 * time.Millisecond),
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Name: errorsx.ReadFromOperation, Name: netxlite.ReadFromOperation,
Err: context.Canceled, Err: context.Canceled,
NumBytes: 7117, NumBytes: 7117,
Time: begin.Add(11 * time.Millisecond), Time: begin.Add(11 * time.Millisecond),
}, { }, {
Name: errorsx.WriteOperation, Name: netxlite.WriteOperation,
Err: websocket.ErrBadHandshake, Err: websocket.ErrBadHandshake,
NumBytes: 4114, NumBytes: 4114,
Time: begin.Add(14 * time.Millisecond), Time: begin.Add(14 * time.Millisecond),
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Name: errorsx.WriteToOperation, Name: netxlite.WriteToOperation,
Err: websocket.ErrBadHandshake, Err: websocket.ErrBadHandshake,
NumBytes: 4114, NumBytes: 4114,
Time: begin.Add(14 * time.Millisecond), Time: begin.Add(14 * time.Millisecond),
}, { }, {
Name: errorsx.CloseOperation, Name: netxlite.CloseOperation,
Err: websocket.ErrReadLimit, Err: websocket.ErrReadLimit,
Time: begin.Add(17 * time.Millisecond), Time: begin.Add(17 * time.Millisecond),
}}, }},
@ -461,34 +461,34 @@ func TestNewNetworkEventsList(t *testing.T) {
want: []archival.NetworkEvent{{ want: []archival.NetworkEvent{{
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Failure: archival.NewFailure(io.EOF), Failure: archival.NewFailure(io.EOF),
Operation: errorsx.ConnectOperation, Operation: netxlite.ConnectOperation,
Proto: "tcp", Proto: "tcp",
T: 0.007, T: 0.007,
}, { }, {
Failure: archival.NewFailure(context.Canceled), Failure: archival.NewFailure(context.Canceled),
NumBytes: 7117, NumBytes: 7117,
Operation: errorsx.ReadOperation, Operation: netxlite.ReadOperation,
T: 0.011, T: 0.011,
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Failure: archival.NewFailure(context.Canceled), Failure: archival.NewFailure(context.Canceled),
NumBytes: 7117, NumBytes: 7117,
Operation: errorsx.ReadFromOperation, Operation: netxlite.ReadFromOperation,
T: 0.011, T: 0.011,
}, { }, {
Failure: archival.NewFailure(websocket.ErrBadHandshake), Failure: archival.NewFailure(websocket.ErrBadHandshake),
NumBytes: 4114, NumBytes: 4114,
Operation: errorsx.WriteOperation, Operation: netxlite.WriteOperation,
T: 0.014, T: 0.014,
}, { }, {
Address: "8.8.8.8:853", Address: "8.8.8.8:853",
Failure: archival.NewFailure(websocket.ErrBadHandshake), Failure: archival.NewFailure(websocket.ErrBadHandshake),
NumBytes: 4114, NumBytes: 4114,
Operation: errorsx.WriteToOperation, Operation: netxlite.WriteToOperation,
T: 0.014, T: 0.014,
}, { }, {
Failure: archival.NewFailure(websocket.ErrReadLimit), Failure: archival.NewFailure(websocket.ErrReadLimit),
Operation: errorsx.CloseOperation, Operation: netxlite.CloseOperation,
T: 0.017, T: 0.017,
}}, }},
}} }}
@ -523,7 +523,7 @@ func TestNewTLSHandshakesList(t *testing.T) {
args: args{ args: args{
begin: begin, begin: begin,
events: []trace.Event{{ events: []trace.Event{{
Name: errorsx.CloseOperation, Name: netxlite.CloseOperation,
Err: websocket.ErrReadLimit, Err: websocket.ErrReadLimit,
Time: begin.Add(17 * time.Millisecond), Time: begin.Add(17 * time.Millisecond),
}, { }, {
@ -929,18 +929,18 @@ func TestNewFailure(t *testing.T) {
}, { }, {
name: "when error is wrapped and failure meaningful", name: "when error is wrapped and failure meaningful",
args: args{ args: args{
err: &errorsx.ErrWrapper{ err: &netxlite.ErrWrapper{
Failure: errorsx.FailureConnectionRefused, Failure: netxlite.FailureConnectionRefused,
}, },
}, },
want: func() *string { want: func() *string {
s := errorsx.FailureConnectionRefused s := netxlite.FailureConnectionRefused
return &s return &s
}(), }(),
}, { }, {
name: "when error is wrapped and failure is not meaningful", name: "when error is wrapped and failure is not meaningful",
args: args{ args: args{
err: &errorsx.ErrWrapper{}, err: &netxlite.ErrWrapper{},
}, },
want: func() *string { want: func() *string {
s := "unknown_failure: errWrapper.Failure is empty" s := "unknown_failure: errWrapper.Failure is empty"
@ -1002,24 +1002,24 @@ func TestNewFailedOperation(t *testing.T) {
}, { }, {
name: "With wrapped error and non-empty operation", name: "With wrapped error and non-empty operation",
args: args{ args: args{
err: &errorsx.ErrWrapper{ err: &netxlite.ErrWrapper{
Failure: errorsx.FailureConnectionRefused, Failure: netxlite.FailureConnectionRefused,
Operation: errorsx.ConnectOperation, Operation: netxlite.ConnectOperation,
}, },
}, },
want: (func() *string { want: (func() *string {
s := errorsx.ConnectOperation s := netxlite.ConnectOperation
return &s return &s
})(), })(),
}, { }, {
name: "With wrapped error and empty operation", name: "With wrapped error and empty operation",
args: args{ args: args{
err: &errorsx.ErrWrapper{ err: &netxlite.ErrWrapper{
Failure: errorsx.FailureConnectionRefused, Failure: netxlite.FailureConnectionRefused,
}, },
}, },
want: (func() *string { want: (func() *string {
s := errorsx.UnknownOperation s := netxlite.UnknownOperation
return &s return &s
})(), })(),
}, { }, {
@ -1028,7 +1028,7 @@ func TestNewFailedOperation(t *testing.T) {
err: io.EOF, err: io.EOF,
}, },
want: (func() *string { want: (func() *string {
s := errorsx.UnknownOperation s := netxlite.UnknownOperation
return &s return &s
})(), })(),
}} }}

View File

@ -9,7 +9,7 @@ import (
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/bytecounter" "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" "github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
) )
@ -27,7 +27,7 @@ func dorequest(ctx context.Context, url string) error {
if err != nil { if err != nil {
return err 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 err
} }
return resp.Body.Close() return resp.Body.Close()

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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 // saverDialer saves events occurring during the dial
@ -24,7 +24,7 @@ func (d *saverDialer) DialContext(ctx context.Context, network, address string)
Address: address, Address: address,
Duration: stop.Sub(start), Duration: stop.Sub(start),
Err: err, Err: err,
Name: errorsx.ConnectOperation, Name: netxlite.ConnectOperation,
Proto: network, Proto: network,
Time: stop, Time: stop,
}) })
@ -61,7 +61,7 @@ func (c *saverConn) Read(p []byte) (int, error) {
Duration: stop.Sub(start), Duration: stop.Sub(start),
Err: err, Err: err,
NumBytes: count, NumBytes: count,
Name: errorsx.ReadOperation, Name: netxlite.ReadOperation,
Time: stop, Time: stop,
}) })
return count, err return count, err
@ -76,7 +76,7 @@ func (c *saverConn) Write(p []byte) (int, error) {
Duration: stop.Sub(start), Duration: stop.Sub(start),
Err: err, Err: err,
NumBytes: count, NumBytes: count,
Name: errorsx.WriteOperation, Name: netxlite.WriteOperation,
Time: stop, Time: stop,
}) })
return count, err return count, err

View File

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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" "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) { if !errors.Is(ev[0].Err, expected) {
t.Fatal("unexpected Err") t.Fatal("unexpected Err")
} }
if ev[0].Name != errorsx.ConnectOperation { if ev[0].Name != netxlite.ConnectOperation {
t.Fatal("unexpected Name") t.Fatal("unexpected Name")
} }
if ev[0].Proto != "tcp" { if ev[0].Proto != "tcp" {

View File

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeDialer struct { type FakeDialer struct {
@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/bytecounter" "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/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) { func TestByteCounterFailure(t *testing.T) {
@ -69,7 +69,7 @@ func TestByteCounterSuccess(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
data, err := iox.ReadAllContext(context.Background(), resp.Body) data, err := netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -105,7 +105,7 @@ func TestByteCounterSuccessWithEOF(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
data, err := iox.ReadAllContext(context.Background(), resp.Body) data, err := netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeDialer struct { type FakeDialer struct {
@ -31,7 +31,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -10,7 +10,7 @@ import (
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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 // 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) { 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 { func saverCompose(data []byte, r io.ReadCloser) io.ReadCloser {

View File

@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "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/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) { func TestSaverPerformanceNoMultipleEvents(t *testing.T) {
@ -248,7 +248,7 @@ func TestSaverBodySuccess(t *testing.T) {
txp := httptransport.SaverBodyHTTPTransport{ txp := httptransport.SaverBodyHTTPTransport{
RoundTripper: httptransport.FakeTransport{ RoundTripper: httptransport.FakeTransport{
Func: func(req *http.Request) (*http.Response, error) { 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -277,7 +277,7 @@ func TestSaverBodySuccess(t *testing.T) {
t.Fatal("unexpected status code") t.Fatal("unexpected status code")
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := iox.ReadAllContext(context.Background(), resp.Body) data, err := netxlite.ReadAllContext(context.Background(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -10,8 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/bytecounter" "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"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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/iox"
) )
func TestSuccess(t *testing.T) { func TestSuccess(t *testing.T) {
@ -38,7 +37,7 @@ func TestSuccess(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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) t.Fatal(err)
} }
if err = resp.Body.Close(); err != nil { if err = resp.Body.Close(); err != nil {
@ -78,10 +77,10 @@ func TestBogonResolutionNotBroken(t *testing.T) {
Logger: log.Log, Logger: log.Log,
}) })
addrs, err := r.LookupHost(context.Background(), "www.google.com") 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") t.Fatal("not the error we expected")
} }
if err.Error() != errorsx.FailureDNSBogonError { if err.Error() != netxlite.FailureDNSBogonError {
t.Fatal("error not correctly wrapped") t.Fatal("error not correctly wrapped")
} }
if len(addrs) > 0 { if len(addrs) > 0 {

View File

@ -354,7 +354,8 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
if err != nil { if err != nil {
return c, err 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 { if config.ResolveSaver != nil {
txp = resolver.SaverDNSTransport{ txp = resolver.SaverDNSTransport{
RoundTripper: txp, RoundTripper: txp,

View File

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "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" "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), Duration: stop.Sub(start),
Err: err, Err: err,
NumBytes: count, NumBytes: count,
Name: errorsx.WriteToOperation, Name: netxlite.WriteToOperation,
Time: stop, Time: stop,
}) })
return count, err return count, err
@ -73,7 +73,7 @@ func (c *saverUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
Duration: stop.Sub(start), Duration: stop.Sub(start),
Err: err, Err: err,
NumBytes: n, NumBytes: n,
Name: errorsx.ReadFromOperation, Name: netxlite.ReadFromOperation,
Time: stop, Time: stop,
}) })
return n, addr, err return n, addr, err

View File

@ -11,7 +11,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer" "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/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite" "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/mocks"
"github.com/ooni/probe-cli/v3/internal/netxlite/quicx" "github.com/ooni/probe-cli/v3/internal/netxlite/quicx"
) )
@ -76,7 +75,7 @@ func TestSystemDialerSuccessWithReadWrite(t *testing.T) {
t.Fatal("unexpected NumBytes") t.Fatal("unexpected NumBytes")
} }
switch ev[idx].Name { switch ev[idx].Name {
case errorsx.ReadFromOperation, errorsx.WriteToOperation: case netxlite.ReadFromOperation, netxlite.WriteToOperation:
default: default:
t.Fatal("unexpected Name") t.Fatal("unexpected Name")
} }

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"net" "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" "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) addrs, err := r.Resolver.LookupHost(ctx, hostname)
for _, addr := range addrs { for _, addr := range addrs {
if IsBogon(addr) { if IsBogon(addr) {
return nil, errorsx.ErrDNSBogon return nil, netxlite.ErrDNSBogon
} }
} }
return addrs, err return addrs, err

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver" "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) { func TestResolverIsBogon(t *testing.T) {
@ -29,7 +29,7 @@ func TestBogonAwareResolverWithBogon(t *testing.T) {
Resolver: resolver.NewFakeResolverWithResult([]string{"127.0.0.1"}), Resolver: resolver.NewFakeResolverWithResult([]string{"127.0.0.1"}),
} }
addrs, err := r.LookupHost(context.Background(), "dns.google.com") 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") t.Fatal("not the error we expected")
} }
if len(addrs) > 0 { if len(addrs) > 0 {

View File

@ -70,14 +70,14 @@ func TestNewResolverSystem(t *testing.T) {
func TestNewResolverUDPAddress(t *testing.T) { func TestNewResolverUDPAddress(t *testing.T) {
reso := resolver.NewSerialResolver( 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) testresolverquick(t, reso)
testresolverquickidna(t, reso) testresolverquickidna(t, reso)
} }
func TestNewResolverUDPDomain(t *testing.T) { func TestNewResolverUDPDomain(t *testing.T) {
reso := resolver.NewSerialResolver( 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) testresolverquick(t, reso)
testresolverquickidna(t, reso) testresolverquickidna(t, reso)
} }

View File

@ -1,28 +1,28 @@
package resolver 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 // Variables that other packages expect to find here but have been
// moved into the internal/netxlite/dnsx package. // moved into the internal/netxlite/dnsx package.
var ( var (
NewSerialResolver = dnsx.NewSerialResolver NewSerialResolver = netxlite.NewSerialResolver
NewDNSOverUDP = dnsx.NewDNSOverUDP NewDNSOverUDP = netxlite.NewDNSOverUDP
NewDNSOverTCP = dnsx.NewDNSOverTCP NewDNSOverTCP = netxlite.NewDNSOverTCP
NewDNSOverTLS = dnsx.NewDNSOverTLS NewDNSOverTLS = netxlite.NewDNSOverTLS
NewDNSOverHTTPS = dnsx.NewDNSOverHTTPS NewDNSOverHTTPS = netxlite.NewDNSOverHTTPS
NewDNSOverHTTPSWithHostOverride = dnsx.NewDNSOverHTTPSWithHostOverride NewDNSOverHTTPSWithHostOverride = netxlite.NewDNSOverHTTPSWithHostOverride
) )
// Types that other packages expect to find here but have been // Types that other packages expect to find here but have been
// moved into the internal/netxlite/dnsx package. // moved into the internal/netxlite/dnsx package.
type ( type (
DNSOverHTTPS = dnsx.DNSOverHTTPS DNSOverHTTPS = netxlite.DNSOverHTTPS
DNSOverTCP = dnsx.DNSOverTCP DNSOverTCP = netxlite.DNSOverTCP
DNSOverUDP = dnsx.DNSOverUDP DNSOverUDP = netxlite.DNSOverUDP
MiekgEncoder = dnsx.DNSEncoderMiekg MiekgEncoder = netxlite.DNSEncoderMiekg
MiekgDecoder = dnsx.DNSDecoderMiekg MiekgDecoder = netxlite.DNSDecoderMiekg
RoundTripper = dnsx.DNSTransport RoundTripper = netxlite.DNSTransport
SerialResolver = dnsx.SerialResolver SerialResolver = netxlite.SerialResolver
Dialer = dnsx.Dialer Dialer = netxlite.Dialer
DialContextFunc = dnsx.DialContextFunc DialContextFunc = netxlite.DialContextFunc
) )

View File

@ -12,7 +12,6 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer" "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/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite" "github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
) )
func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) { func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) {
@ -71,7 +70,7 @@ func TestSaverTLSHandshakerSuccessWithReadWrite(t *testing.T) {
t.Fatal("unexpected NumBytes") t.Fatal("unexpected NumBytes")
} }
switch ev[idx].Name { switch ev[idx].Name {
case errorsx.ReadOperation, errorsx.WriteOperation: case netxlite.ReadOperation, netxlite.WriteOperation:
default: default:
t.Fatal("unexpected Name") t.Fatal("unexpected Name")
} }

View File

@ -15,7 +15,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/engine/model" "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"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type fakeTestKeys struct { type fakeTestKeys struct {
@ -234,7 +234,7 @@ func TestEndToEnd(t *testing.T) {
return return
} }
if r.RequestURI == "/report/_id" { if r.RequestURI == "/report/_id" {
data, err := iox.ReadAllContext(r.Context(), r.Body) data, err := netxlite.ReadAllContext(r.Context(), r.Body)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -16,7 +16,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model" "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"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices/testorchestra" "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 { func newclient() *probeservices.Client {
@ -165,7 +165,7 @@ func TestCloudfront(t *testing.T) {
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
t.Fatal("unexpected status code") t.Fatal("unexpected status code")
} }
data, err := iox.ReadAllContext(req.Context(), resp.Body) data, err := netxlite.ReadAllContext(req.Context(), resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -16,7 +16,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/geolocate" "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/model"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices" "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" "github.com/ooni/probe-cli/v3/internal/version"
) )
@ -32,7 +32,7 @@ func TestSessionByteCounter(t *testing.T) {
} }
defer resp.Body.Close() defer resp.Body.Close()
ctx := context.Background() 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) t.Fatal(err)
} }
if s.KibiBytesSent() <= 0 || s.KibiBytesReceived() <= 0 { if s.KibiBytesSent() <= 0 || s.KibiBytesReceived() <= 0 {

View File

@ -9,7 +9,7 @@ import (
"syscall" "syscall"
"github.com/ooni/probe-cli/v3/internal/fsx" "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() { func ExampleOpenFile_openingDir() {
@ -27,7 +27,7 @@ func ExampleOpenFile_openingFile() {
if err != nil { if err != nil {
log.Fatal("unexpected error", err) log.Fatal("unexpected error", err)
} }
data, err := iox.ReadAllContext(context.Background(), filep) data, err := netxlite.ReadAllContext(context.Background(), filep)
if err != nil { if err != nil {
log.Fatal("unexpected error", err) log.Fatal("unexpected error", err)
} }

View File

@ -12,7 +12,7 @@ import (
"net/http" "net/http"
"net/url" "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. // 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 { if resp.StatusCode != 200 {
return Result{}, fmt.Errorf("mlablocate: non-200 status code: %d", resp.StatusCode) 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 { if err != nil {
return Result{}, err return Result{}, err
} }

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
type FakeTransport struct { type FakeTransport struct {
@ -19,7 +19,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return txp.Func(req) return txp.Func(req)
} }
if req.Body != nil { if req.Body != nil {
iox.ReadAllContext(req.Context(), req.Body) netxlite.ReadAllContext(req.Context(), req.Body)
req.Body.Close() req.Body.Close()
} }
if txp.Err != nil { if txp.Err != nil {

View File

@ -12,7 +12,7 @@ import (
"net/url" "net/url"
"regexp" "regexp"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox" "github.com/ooni/probe-cli/v3/internal/netxlite"
) )
const ( const (
@ -128,7 +128,7 @@ func (c Client) query(ctx context.Context, path string) (resultRecord, error) {
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return resultRecord{}, fmt.Errorf("%w: %d", ErrRequestFailed, resp.StatusCode) 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 { if err != nil {
return resultRecord{}, err return resultRecord{}, err
} }

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT. // 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 // https://curl.haxx.se/ca/cacert.pem
package netxlite package netxlite

View File

@ -1,4 +1,4 @@
package errorsx package netxlite
import ( import (
"context" "context"

Some files were not shown because too many files have changed in this diff Show More