refactor(netx): merge archival, trace, and the savers (#772)

This diff creates a new package under netx called tracex that
contains everything we need to perform measurements using events
tracing and postprocessing (which is the technique with which
we implement most network experiments).

The general idea here is to (1) create a unique package out of
all of these packages; (2) clean up the code a bit (improve tests,
docs, apply more recent code patterns); (3) move the resulting
code as a toplevel package inside of internal.

Once this is done, netx can be further refactored to avoid
subpackages and we can search for more code to salvage/refactor.

See https://github.com/ooni/probe/issues/2121
This commit is contained in:
Simone Basso
2022-05-31 21:53:01 +02:00
committed by GitHub
parent dd5655eaee
commit bbcd2e2280
53 changed files with 869 additions and 865 deletions
+8 -8
View File
@@ -12,7 +12,7 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/tracex"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/randx"
@@ -29,11 +29,11 @@ type Config struct{}
// TestKeys contains the experiment test keys.
type TestKeys struct {
FailureList []*string `json:"failure_list"`
Received []archival.MaybeBinaryValue `json:"received"`
Sent []string `json:"sent"`
TamperingList []bool `json:"tampering_list"`
Tampering bool `json:"tampering"`
FailureList []*string `json:"failure_list"`
Received []tracex.MaybeBinaryValue `json:"received"`
Sent []string `json:"sent"`
TamperingList []bool `json:"tampering_list"`
Tampering bool `json:"tampering"`
}
// NewExperimentMeasurer creates a new ExperimentMeasurer.
@@ -123,7 +123,7 @@ func (m Measurer) Run(
}
continue
}
failure := archival.NewFailure(result.Err)
failure := tracex.NewFailure(result.Err)
tk.FailureList = append(tk.FailureList, failure)
tk.Received = append(tk.Received, result.Received)
tk.Sent = append(tk.Sent, result.Sent)
@@ -150,7 +150,7 @@ type MethodConfig struct {
type MethodResult struct {
Err error
Name string
Received archival.MaybeBinaryValue
Received tracex.MaybeBinaryValue
Sent string
Tampering bool
}
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/hirl"
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/tracex"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -149,7 +149,7 @@ func (FakeMethodSuccessful) Name() string {
func (meth FakeMethodSuccessful) Run(ctx context.Context, config hirl.MethodConfig) {
config.Out <- hirl.MethodResult{
Name: meth.Name(),
Received: archival.MaybeBinaryValue{Value: "antani"},
Received: tracex.MaybeBinaryValue{Value: "antani"},
Sent: "antani",
Tampering: false,
}
@@ -164,7 +164,7 @@ func (FakeMethodFailure) Name() string {
func (meth FakeMethodFailure) Run(ctx context.Context, config hirl.MethodConfig) {
config.Out <- hirl.MethodResult{
Name: meth.Name(),
Received: archival.MaybeBinaryValue{Value: "antani"},
Received: tracex.MaybeBinaryValue{Value: "antani"},
Sent: "melandri",
Tampering: true,
}