cleanup: remove unnecessary legacy interfaces (#656)

This diff addresses another point of https://github.com/ooni/probe/issues/1956:

> - [ ] observe that we're still using a bunch of private interfaces for common interfaces such as the `Dialer`, so we can get rid of these private interfaces and always use the ones in `model`, which allows us to remove a bunch of legacy wrappers

Additional cleanups may still be possible. The more I cleanup, the more I see
there's extra legacy code we can dispose of (which seems good?).
This commit is contained in:
Simone Basso
2022-01-07 18:33:37 +01:00
committed by GitHub
parent 1c057d322d
commit 566c6b246a
76 changed files with 328 additions and 736 deletions
@@ -5,14 +5,14 @@ import (
"net"
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/model"
)
// Dialer creates net.Conn instances where (1) we delay writes if
// a delay is configured and (2) we split outgoing buffers if there
// is a configured splitter function.
type Dialer struct {
netx.Dialer
model.Dialer
Delay time.Duration
Splitter func([]byte) [][]byte
}
@@ -17,6 +17,8 @@ func (d FakeDialer) DialContext(ctx context.Context, network, address string) (n
return d.Conn, d.Err
}
func (d FakeDialer) CloseIdleConnections() {}
type FakeConn struct {
ReadError error
ReadData []byte
@@ -4,12 +4,12 @@ package internal
import (
"time"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/model"
)
// DialerConfig contains the config for creating a dialer
type DialerConfig struct {
Dialer netx.Dialer
Dialer model.Dialer
Delay time.Duration
SNI string
}
@@ -6,6 +6,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/experiment/tlstool/internal"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/model"
)
var config = internal.DialerConfig{
@@ -14,7 +15,7 @@ var config = internal.DialerConfig{
SNI: "dns.google",
}
func dial(t *testing.T, d netx.Dialer) {
func dial(t *testing.T, d model.Dialer) {
td := netx.NewTLSDialer(netx.Config{Dialer: d})
conn, err := td.DialTLSContext(context.Background(), "tcp", "dns.google:853")
if err != nil {
@@ -107,7 +107,7 @@ func (m Measurer) Run(
return nil // return nil so we always submit the measurement
}
func (m Measurer) newDialer(logger model.Logger) netx.Dialer {
func (m Measurer) newDialer(logger model.Logger) model.Dialer {
// TODO(bassosimone): this is a resolver that should hopefully work
// in many places. Maybe allow to configure it?
resolver, err := netx.NewDNSClientWithOverrides(netx.Config{Logger: logger},