refactor: interfaces and data types into the model package (#642)

## Checklist

- [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md)
- [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885
- [x] related ooni/spec pull request: N/A

Location of the issue tracker: https://github.com/ooni/probe

## Description

This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package.

The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity.

An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other.

This is what I want to move in `internal/model`:

- [x] most important interfaces from `internal/netxlite`
- [x] everything that was previously part of `internal/engine/model`
- [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
This commit is contained in:
Simone Basso
2022-01-03 13:53:23 +01:00
committed by GitHub
parent 69aca619ea
commit 273b70bacc
275 changed files with 1281 additions and 1375 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"net/http"
"net/url"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type collectDeps interface {
+1 -1
View File
@@ -14,10 +14,10 @@ import (
"time"
"github.com/montanaflynn/stats"
"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/trace"
"github.com/ooni/probe-cli/v3/internal/humanize"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
+1 -1
View File
@@ -12,8 +12,8 @@ import (
"github.com/apex/log"
"github.com/montanaflynn/stats"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"time"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type FakeDeps struct {
+1 -1
View File
@@ -4,8 +4,8 @@ import (
"context"
"net/http"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/mlablocate"
"github.com/ooni/probe-cli/v3/internal/model"
)
type locateDeps interface {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"net/http"
"net/url"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type negotiateDeps interface {
@@ -15,10 +15,10 @@ import (
"github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"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/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -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/model"
)
func TestHTTPHostWithOverride(t *testing.T) {
@@ -9,7 +9,7 @@ import (
"errors"
"time"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
const testVersion = "0.1.0"
@@ -9,7 +9,7 @@ import (
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/example"
"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/model"
)
func TestSuccess(t *testing.T) {
@@ -10,7 +10,7 @@ import (
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -10,8 +10,8 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/fbmessenger"
"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/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -222,7 +222,7 @@ func TestComputeEndpointStatsDNSIsLying(t *testing.T) {
func newsession(t *testing.T) model.ExperimentSession {
sess, err := engine.NewSession(context.Background(), engine.SessionConfig{
AvailableProbeServices: []model.Service{{
AvailableProbeServices: []model.OOAPIService{{
Address: "https://ams-pg-test.ooni.org",
Type: "https",
}},
+1 -1
View File
@@ -17,9 +17,9 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
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/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/randx"
)
+7 -7
View File
@@ -16,8 +16,8 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/hhfm"
"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/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -36,7 +36,7 @@ func TestSuccess(t *testing.T) {
ctx := context.Background()
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": {{
Address: "http://37.218.241.94:80",
Type: "legacy",
@@ -144,7 +144,7 @@ func TestCancelledContext(t *testing.T) {
cancel()
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": {{
Address: "http://37.218.241.94:80",
Type: "legacy",
@@ -303,7 +303,7 @@ func TestNoActualHelpersInList(t *testing.T) {
measurer := hhfm.NewExperimentMeasurer(hhfm.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": nil,
},
}
@@ -353,7 +353,7 @@ func TestWrongTestHelperType(t *testing.T) {
measurer := hhfm.NewExperimentMeasurer(hhfm.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": {{
Address: "http://127.0.0.1",
Type: "antani",
@@ -406,7 +406,7 @@ func TestNewRequestFailure(t *testing.T) {
measurer := hhfm.NewExperimentMeasurer(hhfm.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": {{
Address: "http://127.0.0.1\t\t\t", // invalid
Type: "legacy",
@@ -463,7 +463,7 @@ func TestInvalidJSONBody(t *testing.T) {
measurer := hhfm.NewExperimentMeasurer(hhfm.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"http-return-json-headers": {{
Address: server.URL,
Type: "legacy",
+1 -1
View File
@@ -11,9 +11,9 @@ import (
"strings"
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/randx"
)
+11 -11
View File
@@ -9,9 +9,9 @@ import (
"github.com/apex/log"
"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/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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -30,7 +30,7 @@ func TestSuccess(t *testing.T) {
ctx := context.Background()
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -79,7 +79,7 @@ func TestCancelledContext(t *testing.T) {
cancel()
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -178,7 +178,7 @@ func TestWithFakeMethods(t *testing.T) {
}
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "127.0.0.1",
Type: "legacy",
@@ -239,7 +239,7 @@ func TestWithNoMethods(t *testing.T) {
}
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "127.0.0.1",
Type: "legacy",
@@ -302,7 +302,7 @@ func TestNoActualHelperInList(t *testing.T) {
measurer := hirl.NewExperimentMeasurer(hirl.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": nil,
},
}
@@ -334,7 +334,7 @@ func TestWrongTestHelperType(t *testing.T) {
measurer := hirl.NewExperimentMeasurer(hirl.Config{})
ctx := context.Background()
sess := &mockable.Session{
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "127.0.0.1",
Type: "antani",
@@ -368,7 +368,7 @@ func TestWrongTestHelperType(t *testing.T) {
func TestRunMethodDialFailure(t *testing.T) {
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -415,7 +415,7 @@ func TestRunMethodDialFailure(t *testing.T) {
func TestRunMethodSetDeadlineFailure(t *testing.T) {
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -464,7 +464,7 @@ func TestRunMethodSetDeadlineFailure(t *testing.T) {
func TestRunMethodWriteFailure(t *testing.T) {
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -513,7 +513,7 @@ func TestRunMethodWriteFailure(t *testing.T) {
func TestRunMethodReadEOFWithWrongData(t *testing.T) {
sess := &mockable.Session{
MockableLogger: log.Log,
MockableTestHelpers: map[string][]model.Service{
MockableTestHelpers: map[string][]model.OOAPIService{
"tcp-echo": {{
Address: "37.218.241.93",
Type: "legacy",
@@ -10,7 +10,7 @@ import (
"fmt"
"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/model"
)
const (
@@ -8,7 +8,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/model"
)
const (
+1 -1
View File
@@ -7,9 +7,9 @@ import (
"net/url"
"github.com/gorilla/websocket"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
+1 -1
View File
@@ -11,10 +11,10 @@ import (
"net/http"
"time"
"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/humanize"
"github.com/ooni/probe-cli/v3/internal/mlablocatev2"
"github.com/ooni/probe-cli/v3/internal/model"
)
const (
+1 -1
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/model"
)
func TestNewExperimentMeasurer(t *testing.T) {
@@ -11,7 +11,7 @@ import (
"time"
"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/model"
)
const (
@@ -12,7 +12,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/psiphon"
"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/model"
)
// Implementation note: integration test performed by
@@ -10,8 +10,8 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -15,8 +15,8 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/riseupvpn"
"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/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"sync"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/dnscheck"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type dnsCheckMain struct {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/dnscheck"
"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/model"
)
// Config contains settings.
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/run"
"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/model"
)
func TestExperimentNameAndVersion(t *testing.T) {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/dnscheck"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
type experimentMain interface {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"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/model"
)
type urlGetterMain struct{}
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -8,7 +8,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/signal"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -14,7 +14,7 @@ import (
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -8,7 +8,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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -6,7 +6,7 @@ import (
"time"
)
// TODO(bassosimone): we should use internal/netxlite/mocks rather
// TODO(bassosimone): we should use internal/model/mocks rather
// than rolling out a custom type private to this package.
type FakeConn struct {
@@ -12,11 +12,11 @@ import (
"time"
"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"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/pion/stun"
)
@@ -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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/pion/stun"
)
@@ -10,7 +10,7 @@ import (
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -11,7 +11,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/telegram"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -16,9 +16,9 @@ import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/tlstool/internal"
"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/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -7,7 +7,7 @@ import (
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/tlstool"
"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/model"
)
func TestMeasurerExperimentNameVersion(t *testing.T) {
+7 -7
View File
@@ -17,7 +17,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netxlogger"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/scrubber"
@@ -144,14 +144,14 @@ func (tk *TestKeys) fillToplevelKeys() {
// Measurer performs the measurement.
type Measurer struct {
config Config
fetchTorTargets func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.TorTarget, error)
fetchTorTargets func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error)
}
// NewMeasurer creates a new Measurer
func NewMeasurer(config Config) *Measurer {
return &Measurer{
config: config,
fetchTorTargets: func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.TorTarget, error) {
fetchTorTargets: func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
return sess.FetchTorTargets(ctx, cc)
},
}
@@ -189,7 +189,7 @@ func (m *Measurer) Run(
func (m *Measurer) gimmeTargets(
ctx context.Context, sess model.ExperimentSession,
) (map[string]model.TorTarget, error) {
) (map[string]model.OOAPITorTarget, error) {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
return m.fetchTorTargets(ctx, sess, sess.ProbeCC())
@@ -198,7 +198,7 @@ func (m *Measurer) gimmeTargets(
// keytarget contains a key and the related target
type keytarget struct {
key string
target model.TorTarget
target model.OOAPITorTarget
}
// private returns whether a target is private. We consider private
@@ -222,7 +222,7 @@ func (m *Measurer) measureTargets(
sess model.ExperimentSession,
measurement *model.Measurement,
callbacks model.ExperimentCallbacks,
targets map[string]model.TorTarget,
targets map[string]model.OOAPITorTarget,
) {
// run measurements in parallel
var waitgroup sync.WaitGroup
@@ -327,7 +327,7 @@ func maybeScrubbingLogger(input model.Logger, kt keytarget) model.Logger {
if !kt.private() {
return input
}
return &scrubber.Logger{UnderlyingLogger: input}
return &scrubber.Logger{Logger: input}
}
func (rc *resultsCollector) defaultFlexibleConnect(
+13 -13
View File
@@ -16,7 +16,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/mockable"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/scrubber"
)
@@ -34,7 +34,7 @@ func TestNewExperimentMeasurer(t *testing.T) {
func TestMeasurerMeasureFetchTorTargetsError(t *testing.T) {
measurer := NewMeasurer(Config{})
expected := errors.New("mocked error")
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.TorTarget, error) {
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
return nil, expected
}
err := measurer.Run(
@@ -52,7 +52,7 @@ func TestMeasurerMeasureFetchTorTargetsError(t *testing.T) {
func TestMeasurerMeasureFetchTorTargetsEmptyList(t *testing.T) {
measurer := NewMeasurer(Config{})
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.TorTarget, error) {
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
return nil, nil
}
measurement := new(model.Measurement)
@@ -77,7 +77,7 @@ func TestMeasurerMeasureGoodWithMockedOrchestra(t *testing.T) {
// This test mocks orchestra to return a nil list of targets, so the code runs
// but we don't perform any actual network actions.
measurer := NewMeasurer(Config{})
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.TorTarget, error) {
measurer.fetchTorTargets = func(ctx context.Context, sess model.ExperimentSession, cc string) (map[string]model.OOAPITorTarget, error) {
return nil, nil
}
err := measurer.Run(
@@ -120,7 +120,7 @@ func TestMeasurerMeasureGood(t *testing.T) {
var staticPrivateTestingTargetEndpoint = "192.95.36.142:443"
var staticPrivateTestingTarget = model.TorTarget{
var staticPrivateTestingTarget = model.OOAPITorTarget{
Address: staticPrivateTestingTargetEndpoint,
Params: map[string][]string{
"cert": {
@@ -139,7 +139,7 @@ func TestMeasurerMeasureSanitiseOutput(t *testing.T) {
measurer := NewMeasurer(Config{})
sess := newsession()
key := "xyz-xyz-xyz-theCh2ju-ahG4chei-Ai2eka0a"
sess.MockableFetchTorTargetsResult = map[string]model.TorTarget{
sess.MockableFetchTorTargetsResult = map[string]model.OOAPITorTarget{
key: staticPrivateTestingTarget,
}
measurement := new(model.Measurement)
@@ -172,7 +172,7 @@ func TestMeasurerMeasureSanitiseOutput(t *testing.T) {
}
}
var staticTestingTargets = []model.TorTarget{
var staticTestingTargets = []model.OOAPITorTarget{
{
Address: "192.95.36.142:443",
Params: map[string][]string{
@@ -226,7 +226,7 @@ func TestMeasurerMeasureTargetsCanceledContext(t *testing.T) {
},
&measurement,
model.NewPrinterCallbacks(log.Log),
map[string]model.TorTarget{
map[string]model.OOAPITorTarget{
"xx": staticTestingTargets[0],
},
)
@@ -243,7 +243,7 @@ func TestMeasurerMeasureTargetsCanceledContext(t *testing.T) {
}
}
func wrapTestingTarget(tt model.TorTarget) keytarget {
func wrapTestingTarget(tt model.OOAPITorTarget) keytarget {
return keytarget{
key: "xx", // using an super simple key; should work anyway
target: tt,
@@ -683,7 +683,7 @@ func TestMaybeSanitize(t *testing.T) {
t.Fatal(err)
}
t.Run("nothing to do", func(t *testing.T) {
out := maybeSanitize(input, keytarget{target: model.TorTarget{Source: ""}})
out := maybeSanitize(input, keytarget{target: model.OOAPITorTarget{Source: ""}})
diff := cmp.Diff(input, out)
if diff != "" {
t.Fatal(diff)
@@ -694,7 +694,7 @@ func TestMaybeSanitize(t *testing.T) {
if err := json.Unmarshal(scrubbedTargetResult, &expected); err != nil {
t.Fatal(err)
}
out := maybeSanitize(input, keytarget{target: model.TorTarget{
out := maybeSanitize(input, keytarget{target: model.OOAPITorTarget{
Address: "85.31.186.98:443",
Source: "bridgedb",
}})
@@ -709,7 +709,7 @@ func TestMaybeScrubbingLogger(t *testing.T) {
var input model.Logger = log.Log
t.Run("for when we don't need to save", func(t *testing.T) {
kt := keytarget{target: model.TorTarget{
kt := keytarget{target: model.OOAPITorTarget{
Source: "",
}}
out := maybeScrubbingLogger(input, kt)
@@ -722,7 +722,7 @@ func TestMaybeScrubbingLogger(t *testing.T) {
})
t.Run("for when we need to save", func(t *testing.T) {
kt := keytarget{target: model.TorTarget{
kt := keytarget{target: model.OOAPITorTarget{
Source: "bridgedb",
}}
out := maybeScrubbingLogger(input, kt)
@@ -8,7 +8,7 @@ import (
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/experiment/torsf"
"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/model"
"golang.org/x/sys/execabs"
)
+1 -1
View File
@@ -9,8 +9,8 @@ import (
"path"
"time"
"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/model"
"github.com/ooni/probe-cli/v3/internal/ptx"
"github.com/ooni/probe-cli/v3/internal/tunnel"
)
@@ -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/model"
"github.com/ooni/probe-cli/v3/internal/tunnel"
)
@@ -8,9 +8,9 @@ import (
"regexp"
"strings"
"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/trace"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -7,9 +7,9 @@ import (
"time"
legacyerrorsx "github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/tunnel"
)
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
// MultiInput is the input for Multi.Run().
@@ -13,7 +13,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/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestMultiIntegration(t *testing.T) {
@@ -8,8 +8,8 @@ import (
"crypto/x509"
"time"
"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/model"
)
const (
@@ -8,7 +8,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/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
)
func TestMeasurer(t *testing.T) {
@@ -6,7 +6,7 @@ import (
"time"
"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/model"
)
// ConnectsConfig contains the config for Connects
@@ -6,7 +6,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -8,7 +8,7 @@ import (
"time"
"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/model"
)
// DNSLookupConfig contains settings for the DNS lookup.
@@ -7,7 +7,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"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/model"
)
// HTTPAnalysisResult contains the results of the analysis performed on the
@@ -9,7 +9,7 @@ import (
"time"
"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/model"
)
// HTTPGetConfig contains the config for HTTPGet
@@ -4,7 +4,7 @@ import (
"strings"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -13,8 +13,8 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity/internal"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"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/model"
)
const (
@@ -149,7 +149,7 @@ func (m Measurer) Run(
}
// 1. find test helper
testhelpers, _ := sess.GetTestHelpersByName("web-connectivity")
var testhelper *model.Service
var testhelper *model.OOAPIService
for _, th := range testhelpers {
if th.Type == "https" {
testhelper = &th
@@ -11,8 +11,8 @@ import (
"github.com/google/go-cmp/cmp"
engine "github.com/ooni/probe-cli/v3/internal/engine"
"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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -202,7 +202,7 @@ func TestMeasureWithNoAvailableTestHelpers(t *testing.T) {
func newsession(t *testing.T, lookupBackends bool) model.ExperimentSession {
sess, err := engine.NewSession(context.Background(), engine.SessionConfig{
AvailableProbeServices: []model.Service{{
AvailableProbeServices: []model.OOAPIService{{
Address: "https://ams-pg-test.ooni.org",
Type: "https",
}},
@@ -5,7 +5,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/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -14,6 +14,7 @@ import (
oohttp "github.com/ooni/oohttp"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -80,7 +81,7 @@ func NewSingleTransport(conn net.Conn) http.RoundTripper {
}
// NewSingleTransport creates a new HTTP transport with a custom dialer and handshaker.
func NewTransportWithDialer(dialer netxlite.DialerLegacy, tlsConfig *tls.Config, handshaker netxlite.TLSHandshaker) http.RoundTripper {
func NewTransportWithDialer(dialer netxlite.DialerLegacy, tlsConfig *tls.Config, handshaker model.TLSHandshaker) http.RoundTripper {
transport := newBaseTransport()
transport.DialContext = dialer.DialContext
transport.DialTLSContext = (&netxlite.TLSDialerLegacy{
@@ -24,8 +24,8 @@ import (
"github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"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/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -111,7 +111,7 @@ func (m Measurer) Run(
// 3. Find the testhelper
// TODO(kelmenhorst,bassosimone): this is not used at the moment, but the hardcoded local address
testhelpers, _ := sess.GetTestHelpersByName("web-connectivity")
var testhelper *model.Service
var testhelper *model.OOAPIService
for _, th := range testhelpers {
if th.Type == "https" {
testhelper = &th
@@ -13,9 +13,9 @@ import (
"net/url"
"time"
"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/measurex"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@@ -85,7 +85,7 @@ func (mx *Measurer) RunAsync(
}
// 2. Find the testhelper
testhelpers, _ := sess.GetTestHelpersByName("web-connectivity")
var testhelper *model.Service
var testhelper *model.OOAPIService
for _, th := range testhelpers {
if th.Type == "https" {
testhelper = &th
@@ -110,7 +110,7 @@ var measurerResolvers = []*measurex.ResolverInfo{{
}}
func (mx *Measurer) runAsync(ctx context.Context, sess model.ExperimentSession,
URL string, th *model.Service, out chan<- *model.ExperimentAsyncTestKeys) {
URL string, th *model.OOAPIService, out chan<- *model.ExperimentAsyncTestKeys) {
defer close(out)
helper := &measurerMeasureURLHelper{
Clnt: sess.DefaultHTTPClient(),
@@ -14,7 +14,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
"github.com/ooni/probe-cli/v3/internal/engine/internal/httpfailure"
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
@@ -14,7 +14,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/whatsapp"
"github.com/ooni/probe-cli/v3/internal/engine/internal/httpfailure"
"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/model"
)
func TestNewExperimentMeasurer(t *testing.T) {