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
169 changed files with 575 additions and 671 deletions
+2 -2
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 {
+4 -5
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
+4 -4
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 {