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:
@@ -5,8 +5,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ type CtrlDNSResult = webconnectivity.ControlDNSResult
|
||||
type DNSConfig struct {
|
||||
Domain string
|
||||
Out chan CtrlDNSResult
|
||||
Resolver netx.Resolver
|
||||
Resolver model.Resolver
|
||||
Wg *sync.WaitGroup
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ package webconnectivity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
@@ -49,7 +50,13 @@ func (c FakeResolver) Address() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
var _ netx.Resolver = FakeResolver{}
|
||||
func (c FakeResolver) CloseIdleConnections() {}
|
||||
|
||||
func (c FakeResolver) LookupHTTPS(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
var _ model.Resolver = FakeResolver{}
|
||||
|
||||
type FakeTransport struct {
|
||||
Err error
|
||||
@@ -75,7 +82,7 @@ func (txp FakeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
|
||||
func (txp FakeTransport) CloseIdleConnections() {}
|
||||
|
||||
var _ netx.HTTPRoundTripper = FakeTransport{}
|
||||
var _ model.HTTPTransport = FakeTransport{}
|
||||
|
||||
type FakeBody struct {
|
||||
Data []byte
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -22,9 +22,9 @@ type (
|
||||
// MeasureConfig contains configuration for Measure.
|
||||
type MeasureConfig struct {
|
||||
Client *http.Client
|
||||
Dialer netx.Dialer
|
||||
Dialer model.Dialer
|
||||
MaxAcceptableBody int64
|
||||
Resolver netx.Resolver
|
||||
Resolver model.Resolver
|
||||
}
|
||||
|
||||
// Measure performs the measurement described by the request and
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
@@ -20,7 +20,7 @@ type TCPResultPair struct {
|
||||
|
||||
// TCPConfig configures the TCP connect check.
|
||||
type TCPConfig struct {
|
||||
Dialer netx.Dialer
|
||||
Dialer model.Dialer
|
||||
Endpoint string
|
||||
Out chan TCPResultPair
|
||||
Wg *sync.WaitGroup
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"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/version"
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
// Handler implements the Web Connectivity test helper HTTP API.
|
||||
type Handler struct {
|
||||
Client *http.Client
|
||||
Dialer netx.Dialer
|
||||
Dialer model.Dialer
|
||||
MaxAcceptableBody int64
|
||||
Resolver netx.Resolver
|
||||
Resolver model.Resolver
|
||||
}
|
||||
|
||||
func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -52,7 +51,7 @@ const requestWithoutDomainName = `{
|
||||
func TestWorkingAsIntended(t *testing.T) {
|
||||
handler := Handler{
|
||||
Client: http.DefaultClient,
|
||||
Dialer: new(net.Dialer),
|
||||
Dialer: netxlite.DefaultDialer,
|
||||
MaxAcceptableBody: 1 << 24,
|
||||
Resolver: &netxlite.ResolverSystem{},
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/websteps"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
utls "gitlab.com/yawning/utls.git"
|
||||
@@ -28,7 +29,7 @@ type Explorer interface {
|
||||
|
||||
// DefaultExplorer is the default Explorer.
|
||||
type DefaultExplorer struct {
|
||||
resolver netxlite.ResolverLegacy
|
||||
resolver model.Resolver
|
||||
}
|
||||
|
||||
// Explore returns a list of round trips sorted so that the first
|
||||
@@ -138,8 +139,7 @@ func (e *DefaultExplorer) getH3(h3URL *h3URL, headers map[string][]string) (*htt
|
||||
}
|
||||
// Rationale for using log.Log here: we're already using log.Log
|
||||
// in this package, so it seems fair to use it also here
|
||||
transport := netxlite.NewHTTP3Transport(log.Log,
|
||||
netxlite.NewQUICDialerFromContextDialerAdapter(dialer), tlsConf)
|
||||
transport := netxlite.NewHTTP3Transport(log.Log, dialer, tlsConf)
|
||||
// TODO(bassosimone): here we should use runtimex.PanicOnError
|
||||
jarjar, _ := cookiejar.New(nil)
|
||||
clnt := &http.Client{
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/websteps"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// Generate is the third step of the algorithm. Given the
|
||||
@@ -22,9 +22,9 @@ type Generator interface {
|
||||
|
||||
// DefaultGenerator is the default Generator.
|
||||
type DefaultGenerator struct {
|
||||
dialer netxlite.DialerLegacy
|
||||
quicDialer netxlite.QUICContextDialer
|
||||
resolver netxlite.ResolverLegacy
|
||||
dialer model.Dialer
|
||||
quicDialer model.QUICDialer
|
||||
resolver model.Resolver
|
||||
transport http.RoundTripper
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ func (d fakeQUICDialer) DialContext(ctx context.Context, network, address string
|
||||
return nil, d.err
|
||||
}
|
||||
|
||||
func (d fakeQUICDialer) CloseIdleConnections() {}
|
||||
|
||||
type fakeDialer struct {
|
||||
err error
|
||||
}
|
||||
@@ -44,6 +46,8 @@ func (d fakeDialer) DialContext(ctx context.Context, network, address string) (n
|
||||
return nil, d.err
|
||||
}
|
||||
|
||||
func (d fakeDialer) CloseIdleConnections() {}
|
||||
|
||||
func TestGenerateDNSFailure(t *testing.T) {
|
||||
u, err := url.Parse("https://www.google.google")
|
||||
runtimex.PanicOnError(err, "url.Parse failed")
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// InitialChecks is the first step of the test helper algorithm. We
|
||||
@@ -31,7 +31,7 @@ type InitChecker interface {
|
||||
|
||||
// DefaultInitChecker is the default InitChecker.
|
||||
type DefaultInitChecker struct {
|
||||
resolver netxlite.ResolverLegacy
|
||||
resolver model.Resolver
|
||||
}
|
||||
|
||||
// InitialChecks checks whether the URL is valid and whether the
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/websteps"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
@@ -24,7 +25,7 @@ type Config struct {
|
||||
checker InitChecker
|
||||
explorer Explorer
|
||||
generator Generator
|
||||
resolver netxlite.ResolverLegacy
|
||||
resolver model.Resolver
|
||||
}
|
||||
|
||||
// Measure performs the three consecutive steps of the testhelper algorithm:
|
||||
@@ -90,12 +91,10 @@ func newDNSFailedResponse(err error, URL string) *ControlResponse {
|
||||
}
|
||||
|
||||
// newResolver creates a new DNS resolver instance
|
||||
func newResolver() netxlite.ResolverLegacy {
|
||||
func newResolver() model.Resolver {
|
||||
childResolver, err := netx.NewDNSClient(netx.Config{Logger: log.Log}, "doh://google")
|
||||
runtimex.PanicOnError(err, "NewDNSClient failed")
|
||||
var r netxlite.ResolverLegacy = childResolver
|
||||
r = &netxlite.ResolverIDNA{
|
||||
Resolver: netxlite.NewResolverLegacyAdapter(r),
|
||||
}
|
||||
var r model.Resolver = childResolver
|
||||
r = &netxlite.ResolverIDNA{Resolver: r}
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -13,16 +13,17 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/cmd/oohelperd/internal/websteps"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webstepsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
|
||||
const maxAcceptableBody = 1 << 24
|
||||
|
||||
var (
|
||||
dialer netx.Dialer
|
||||
dialer model.Dialer
|
||||
endpoint = flag.String("endpoint", ":8080", "Endpoint where to listen")
|
||||
httpx *http.Client
|
||||
resolver netx.Resolver
|
||||
resolver model.Resolver
|
||||
srvcancel context.CancelFunc
|
||||
srvctx context.Context
|
||||
srvwg = new(sync.WaitGroup)
|
||||
|
||||
Reference in New Issue
Block a user