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
@@ -10,7 +10,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func dorequest(ctx context.Context, url string) error {
+4 -12
View File
@@ -7,6 +7,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/legacy/errorsx"
"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"
)
@@ -22,15 +23,6 @@ type Resolver interface {
LookupHost(ctx context.Context, hostname string) (addrs []string, err error)
}
// Logger is the interface we expect from a logger.
type Logger interface {
// Debugf formats and emits a debug message.
Debugf(format string, v ...interface{})
// Debug emits a debug message.
Debug(msg string)
}
// Config contains the settings for New.
type Config struct {
// ContextByteCounting optionally configures context-based
@@ -58,7 +50,7 @@ type Config struct {
// Logger is the optional logger. If not set, there
// will be no logging from the new dialer.
Logger Logger
Logger model.DebugLogger
// ProxyURL is the optional proxy URL.
ProxyURL *url.URL
@@ -73,8 +65,8 @@ func New(config *Config, resolver Resolver) Dialer {
d = &errorsx.ErrorWrapperDialer{Dialer: d}
if config.Logger != nil {
d = &netxlite.DialerLogger{
Dialer: netxlite.NewDialerLegacyAdapter(d),
Logger: config.Logger,
Dialer: netxlite.NewDialerLegacyAdapter(d),
DebugLogger: config.Logger,
}
}
if config.DialSaver != nil {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"net/url"
"testing"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestProxyDialerDialContextNoProxyURL(t *testing.T) {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"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/mocks"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestSaverDialerFailure(t *testing.T) {