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/netxlite/iox.ReadAllContext` instead of `io.ReadAll`
and `./internal/netxlite/iox.CopyContext` instead of `io.Copy`
- use `./internal/netxlite.ReadAllContext` instead of `io.ReadAll`
and `./internal/netxlite.CopyContext` instead of `io.Copy`
## Code testing requirements

View File

@ -8,7 +8,7 @@ import (
"os"
"testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func getShasum(path string) (string, error) {
@ -19,7 +19,7 @@ func getShasum(path string) (string, error) {
return "", err
}
defer f.Close()
if _, err := iox.CopyContext(context.Background(), hasher, f); err != nil {
if _, err := netxlite.CopyContext(context.Background(), hasher, f); err != nil {
return "", err
}
return hex.EncodeToString(hasher.Sum(nil)), nil

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ import (
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/version"
)
@ -130,7 +130,7 @@ func (oo OOClient) Do(ctx context.Context, config OOConfig) (*CtrlResponse, erro
if resp.StatusCode != 200 {
return nil, ErrHTTPStatusCode
}
data, err = iox.ReadAllContext(ctx, resp.Body)
data, err = netxlite.ReadAllContext(ctx, resp.Body)
if err != nil {
return nil, err
}

View File

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

View File

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

View File

@ -8,7 +8,7 @@ import (
"sync"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// CtrlHTTPResponse is the result of the HTTP check performed by
@ -62,7 +62,7 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) {
headers[k] = resp.Header.Get(k)
}
reader := &io.LimitedReader{R: resp.Body, N: config.MaxAcceptableBody}
data, err := iox.ReadAllContext(ctx, reader)
data, err := netxlite.ReadAllContext(ctx, reader)
config.Out <- CtrlHTTPResponse{
BodyLength: int64(len(data)),
Failure: newfailure(err),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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/trace"
"github.com/ooni/probe-cli/v3/internal/humanize"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
const (
@ -87,7 +86,7 @@ func (r runner) NewHTTPRequest(meth, url string, body io.Reader) (*http.Request,
}
func (r runner) ReadAllContext(ctx context.Context, reader io.Reader) ([]byte, error) {
return iox.ReadAllContext(ctx, reader)
return netxlite.ReadAllContext(ctx, reader)
}
func (r runner) Scheme() string {
@ -172,7 +171,7 @@ func (r runner) measure(
// of the latest connect time. We should have one sample in most
// cases, because the connection should be persistent.
for _, ev := range r.saver.Read() {
if ev.Name == errorsx.ConnectOperation {
if ev.Name == netxlite.ConnectOperation {
connectTime = ev.Duration.Seconds()
}
}

View File

@ -14,7 +14,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestRunnerLoopLocateFailure(t *testing.T) {
@ -108,7 +108,7 @@ func TestRunnerLoopMeasureFailure(t *testing.T) {
func TestRunnerLoopCollectFailure(t *testing.T) {
expected := errors.New("mocked error")
saver := new(trace.Saver)
saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond})
saver.Write(trace.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond})
r := runner{
callbacks: model.NewPrinterCallbacks(log.Log),
httpClient: &http.Client{
@ -152,7 +152,7 @@ func TestRunnerLoopCollectFailure(t *testing.T) {
func TestRunnerLoopSuccess(t *testing.T) {
saver := new(trace.Saver)
saver.Write(trace.Event{Name: errorsx.ConnectOperation, Duration: 150 * time.Millisecond})
saver.Write(trace.Event{Name: netxlite.ConnectOperation, Duration: 150 * time.Millisecond})
r := runner{
callbacks: model.NewPrinterCallbacks(log.Log),
httpClient: &http.Client{

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

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

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

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

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

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

View File

@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/tunnel"
)
@ -57,7 +57,7 @@ func (g Getter) Get(ctx context.Context) (TestKeys, error) {
// hitting our httptransport that does error wrapping.
err = legacyerrorsx.SafeErrWrapperBuilder{
Error: err,
Operation: errorsx.TopLevelOperation,
Operation: netxlite.TopLevelOperation,
}.MaybeBuild()
tk.FailedOperation = archival.NewFailedOperation(err)
tk.Failure = archival.NewFailure(err)

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"net"
"net/url"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// DNSAnalysisResult contains the results of analysing comparing
@ -44,7 +44,7 @@ func DNSAnalysis(URL *url.URL, measurement DNSLookupResult,
switch *control.DNS.Failure {
case DNSNameError: // the control returns this on NXDOMAIN error
switch *measurement.Failure {
case errorsx.FailureDNSNXDOMAINError:
case netxlite.FailureDNSNXDOMAINError:
out.DNSConsistency = &DNSConsistent
}
}

View File

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

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

View File

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

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ import (
"net/http"
"net/url"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// Logger is the definition of Logger used by this package.
@ -101,7 +101,7 @@ func (c Client) Do(request *http.Request) ([]byte, error) {
if response.StatusCode >= 400 {
return nil, fmt.Errorf("httpx: request failed: %s", response.Status)
}
return iox.ReadAllContext(request.Context(), response.Body)
return netxlite.ReadAllContext(request.Context(), response.Body)
}
// DoJSON performs the provided request and unmarshals the JSON response body

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package errorsx
import (
"context"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// Resolver is a DNS resolver. The *net.Resolver used by Go implements
@ -24,9 +24,9 @@ var _ Resolver = &ErrorWrapperResolver{}
func (r *ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
addrs, err := r.Resolver.LookupHost(ctx, hostname)
err = SafeErrWrapperBuilder{
Classifier: errorsx.ClassifyResolverError,
Classifier: netxlite.ClassifyResolverError,
Error: err,
Operation: errorsx.ResolveOperation,
Operation: netxlite.ResolveOperation,
}.MaybeBuild()
return addrs, err
}

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

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

View File

@ -11,7 +11,7 @@ import (
goptlib "git.torproject.org/pluggable-transports/goptlib.git"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"gitlab.com/yawning/obfs4.git/transports"
obfs4base "gitlab.com/yawning/obfs4.git/transports/base"
)
@ -55,7 +55,7 @@ func TestDNSLookupCancellation(t *testing.T) {
if results.Error == nil {
t.Fatal("expected an error here")
}
if results.Error.Error() != errorsx.FailureGenericTimeoutError {
if results.Error.Error() != netxlite.FailureGenericTimeoutError {
t.Fatal("not the error we expected")
}
if len(results.Addresses) > 0 {
@ -170,7 +170,7 @@ func TestTLSConnectCancellation(t *testing.T) {
if results.Error == nil {
t.Fatal("expected an error here")
}
if results.Error.Error() != errorsx.FailureGenericTimeoutError {
if results.Error.Error() != netxlite.FailureGenericTimeoutError {
t.Fatal("not the error we expected")
}
}

View File

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

View File

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

View File

@ -9,7 +9,7 @@ import (
"testing"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
)
@ -27,7 +27,7 @@ func dorequest(ctx context.Context, url string) error {
if err != nil {
return err
}
if _, err := iox.CopyContext(ctx, io.Discard, resp.Body); err != nil {
if _, err := netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil {
return err
}
return resp.Body.Close()

View File

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

View File

@ -9,7 +9,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
)
@ -44,7 +44,7 @@ func TestSaverDialerFailure(t *testing.T) {
if !errors.Is(ev[0].Err, expected) {
t.Fatal("unexpected Err")
}
if ev[0].Name != errorsx.ConnectOperation {
if ev[0].Name != netxlite.ConnectOperation {
t.Fatal("unexpected Name")
}
if ev[0].Proto != "tcp" {

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// SaverPerformanceHTTPTransport is a RoundTripper that saves
@ -172,7 +172,7 @@ func ignoreExpectedEOF(err error, resp *http.Response) error {
}
func saverSnapRead(ctx context.Context, r io.ReadCloser, snapsize int) ([]byte, error) {
return iox.ReadAllContext(ctx, io.LimitReader(r, int64(snapsize)))
return netxlite.ReadAllContext(ctx, io.LimitReader(r, int64(snapsize)))
}
func saverCompose(data []byte, r io.ReadCloser) io.ReadCloser {

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

View File

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

View File

@ -354,7 +354,8 @@ func NewDNSClientWithOverrides(config Config, URL, hostOverride, SNIOverride,
if err != nil {
return c, err
}
var txp resolver.RoundTripper = resolver.NewDNSOverUDP(dialer, endpoint)
var txp resolver.RoundTripper = resolver.NewDNSOverUDP(
netxlite.NewDialerLegacyAdapter(dialer), endpoint)
if config.ResolveSaver != nil {
txp = resolver.SaverDNSTransport{
RoundTripper: txp,

View File

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

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

View File

@ -4,7 +4,7 @@ import (
"context"
"net"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@ -65,7 +65,7 @@ func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]strin
addrs, err := r.Resolver.LookupHost(ctx, hostname)
for _, addr := range addrs {
if IsBogon(addr) {
return nil, errorsx.ErrDNSBogon
return nil, netxlite.ErrDNSBogon
}
}
return addrs, err

View File

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

View File

@ -70,14 +70,14 @@ func TestNewResolverSystem(t *testing.T) {
func TestNewResolverUDPAddress(t *testing.T) {
reso := resolver.NewSerialResolver(
resolver.NewDNSOverUDP(new(net.Dialer), "8.8.8.8:53"))
resolver.NewDNSOverUDP(netxlite.NewDialerLegacyAdapter(&net.Dialer{}), "8.8.8.8:53"))
testresolverquick(t, reso)
testresolverquickidna(t, reso)
}
func TestNewResolverUDPDomain(t *testing.T) {
reso := resolver.NewSerialResolver(
resolver.NewDNSOverUDP(new(net.Dialer), "dns.google.com:53"))
resolver.NewDNSOverUDP(netxlite.NewDialerLegacyAdapter(&net.Dialer{}), "dns.google.com:53"))
testresolverquick(t, reso)
testresolverquickidna(t, reso)
}

View File

@ -1,28 +1,28 @@
package resolver
import "github.com/ooni/probe-cli/v3/internal/netxlite/dnsx"
import "github.com/ooni/probe-cli/v3/internal/netxlite"
// Variables that other packages expect to find here but have been
// moved into the internal/netxlite/dnsx package.
var (
NewSerialResolver = dnsx.NewSerialResolver
NewDNSOverUDP = dnsx.NewDNSOverUDP
NewDNSOverTCP = dnsx.NewDNSOverTCP
NewDNSOverTLS = dnsx.NewDNSOverTLS
NewDNSOverHTTPS = dnsx.NewDNSOverHTTPS
NewDNSOverHTTPSWithHostOverride = dnsx.NewDNSOverHTTPSWithHostOverride
NewSerialResolver = netxlite.NewSerialResolver
NewDNSOverUDP = netxlite.NewDNSOverUDP
NewDNSOverTCP = netxlite.NewDNSOverTCP
NewDNSOverTLS = netxlite.NewDNSOverTLS
NewDNSOverHTTPS = netxlite.NewDNSOverHTTPS
NewDNSOverHTTPSWithHostOverride = netxlite.NewDNSOverHTTPSWithHostOverride
)
// Types that other packages expect to find here but have been
// moved into the internal/netxlite/dnsx package.
type (
DNSOverHTTPS = dnsx.DNSOverHTTPS
DNSOverTCP = dnsx.DNSOverTCP
DNSOverUDP = dnsx.DNSOverUDP
MiekgEncoder = dnsx.DNSEncoderMiekg
MiekgDecoder = dnsx.DNSDecoderMiekg
RoundTripper = dnsx.DNSTransport
SerialResolver = dnsx.SerialResolver
Dialer = dnsx.Dialer
DialContextFunc = dnsx.DialContextFunc
DNSOverHTTPS = netxlite.DNSOverHTTPS
DNSOverTCP = netxlite.DNSOverTCP
DNSOverUDP = netxlite.DNSOverUDP
MiekgEncoder = netxlite.DNSEncoderMiekg
MiekgDecoder = netxlite.DNSDecoderMiekg
RoundTripper = netxlite.DNSTransport
SerialResolver = netxlite.SerialResolver
Dialer = netxlite.Dialer
DialContextFunc = netxlite.DialContextFunc
)

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/version"
)
@ -32,7 +32,7 @@ func TestSessionByteCounter(t *testing.T) {
}
defer resp.Body.Close()
ctx := context.Background()
if _, err := iox.CopyContext(ctx, io.Discard, resp.Body); err != nil {
if _, err := netxlite.CopyContext(ctx, io.Discard, resp.Body); err != nil {
t.Fatal(err)
}
if s.KibiBytesSent() <= 0 || s.KibiBytesReceived() <= 0 {

View File

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

View File

@ -12,7 +12,7 @@ import (
"net/http"
"net/url"
"github.com/ooni/probe-cli/v3/internal/netxlite/iox"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// Logger is the logger expected by this package.
@ -93,7 +93,7 @@ func (c *Client) Query(ctx context.Context, tool string) (Result, error) {
if resp.StatusCode != 200 {
return Result{}, fmt.Errorf("mlablocate: non-200 status code: %d", resp.StatusCode)
}
data, err := iox.ReadAllContext(ctx, resp.Body)
data, err := netxlite.ReadAllContext(ctx, resp.Body)
if err != nil {
return Result{}, err
}

View File

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

View File

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

View File

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2021-09-27 15:57:57.877144 +0200 CEST m=+1.353309960
// 2021-09-28 12:05:19.526032 +0200 CEST m=+0.405934084
// https://curl.haxx.se/ca/cacert.pem
package netxlite

View File

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

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