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:
@@ -3,6 +3,8 @@ package ptx
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// UnderlyingDialer is the underlying dialer used for dialing.
|
||||
@@ -11,29 +13,5 @@ type UnderlyingDialer interface {
|
||||
DialContext(ctx context.Context, network, address string) (net.Conn, error)
|
||||
}
|
||||
|
||||
// Logger allows us to log messages.
|
||||
type Logger interface {
|
||||
// Debugf formats and emits a debug message.
|
||||
Debugf(format string, v ...interface{})
|
||||
|
||||
// Infof formats and emits an informational message.
|
||||
Infof(format string, v ...interface{})
|
||||
|
||||
// Warnf formats and emits a warning message.
|
||||
Warnf(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// silentLogger implements Logger.
|
||||
type silentLogger struct{}
|
||||
|
||||
// Debugf implements Logger.Debugf.
|
||||
func (*silentLogger) Debugf(format string, v ...interface{}) {}
|
||||
|
||||
// Infof implements Logger.Infof.
|
||||
func (*silentLogger) Infof(format string, v ...interface{}) {}
|
||||
|
||||
// Warnf implements Logger.Warnf.
|
||||
func (*silentLogger) Warnf(format string, v ...interface{}) {}
|
||||
|
||||
// defaultLogger is the default silentLogger instance.
|
||||
var defaultLogger Logger = &silentLogger{}
|
||||
var defaultLogger model.Logger = model.DiscardLogger
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
)
|
||||
|
||||
func TestOBFS4DialerWorks(t *testing.T) {
|
||||
|
||||
+3
-2
@@ -45,6 +45,7 @@ import (
|
||||
"sync"
|
||||
|
||||
pt "git.torproject.org/pluggable-transports/goptlib.git"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
@@ -75,7 +76,7 @@ type Listener struct {
|
||||
// Logger is the optional logger. When not set, this library
|
||||
// will not emit logs. (But the underlying pluggable transport
|
||||
// may still emit its own log messages.)
|
||||
Logger Logger
|
||||
Logger model.Logger
|
||||
|
||||
// mu provides mutual exclusion for accessing internals.
|
||||
mu sync.Mutex
|
||||
@@ -94,7 +95,7 @@ type Listener struct {
|
||||
}
|
||||
|
||||
// logger returns the Logger, if set, or the defaultLogger.
|
||||
func (lst *Listener) logger() Logger {
|
||||
func (lst *Listener) logger() model.Logger {
|
||||
if lst.Logger != nil {
|
||||
return lst.Logger
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"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 TestListenerLoggerWorks(t *testing.T) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
|
||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
)
|
||||
|
||||
func TestSnowflakeDialerWorks(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user