diff --git a/internal/measurexlite/dialer.go b/internal/measurexlite/dialer.go index 663b88915f..e0837a6b66 100644 --- a/internal/measurexlite/dialer.go +++ b/internal/measurexlite/dialer.go @@ -18,7 +18,10 @@ import ( // NewDialerWithoutResolver is equivalent to netxlite.NewDialerWithoutResolver // except that it returns a model.Dialer that uses this trace. -func (tx *Trace) NewDialerWithoutResolver(dl model.DebugLogger) model.Dialer { +// +// Caveat: the dialer wrappers are there to implement the [model.MeasuringNetwork] +// interface, but they're not used by this function. +func (tx *Trace) NewDialerWithoutResolver(dl model.DebugLogger, wrappers ...model.DialerWrapper) model.Dialer { return &dialerTrace{ d: tx.Netx.NewDialerWithoutResolver(dl), tx: tx, diff --git a/internal/measurexlite/dns.go b/internal/measurexlite/dns.go index 4d214a3d52..8c72544426 100644 --- a/internal/measurexlite/dns.go +++ b/internal/measurexlite/dns.go @@ -92,17 +92,17 @@ func (r *resolverTrace) LookupNS(ctx context.Context, domain string) ([]*net.NS, } // NewStdlibResolver returns a trace-ware system resolver -func (tx *Trace) NewStdlibResolver(logger model.Logger) model.Resolver { +func (tx *Trace) NewStdlibResolver(logger model.DebugLogger) model.Resolver { return tx.wrapResolver(tx.Netx.NewStdlibResolver(logger)) } // NewParallelUDPResolver returns a trace-ware parallel UDP resolver -func (tx *Trace) NewParallelUDPResolver(logger model.Logger, dialer model.Dialer, address string) model.Resolver { +func (tx *Trace) NewParallelUDPResolver(logger model.DebugLogger, dialer model.Dialer, address string) model.Resolver { return tx.wrapResolver(tx.Netx.NewParallelUDPResolver(logger, dialer, address)) } // NewParallelDNSOverHTTPSResolver returns a trace-aware parallel DoH resolver -func (tx *Trace) NewParallelDNSOverHTTPSResolver(logger model.Logger, URL string) model.Resolver { +func (tx *Trace) NewParallelDNSOverHTTPSResolver(logger model.DebugLogger, URL string) model.Resolver { return tx.wrapResolver(tx.Netx.NewParallelDNSOverHTTPSResolver(logger, URL)) } diff --git a/internal/measurexlite/quic.go b/internal/measurexlite/quic.go index fa21d05b27..949068f505 100644 --- a/internal/measurexlite/quic.go +++ b/internal/measurexlite/quic.go @@ -16,7 +16,11 @@ import ( // NewQUICDialerWithoutResolver is equivalent to netxlite.NewQUICDialerWithoutResolver // except that it returns a model.QUICDialer that uses this trace. -func (tx *Trace) NewQUICDialerWithoutResolver(listener model.UDPListener, dl model.DebugLogger) model.QUICDialer { +// +// Caveat: the dialer wrappers are there to implement the [model.MeasuringNetwork] +// interface, but they're not used by this function. +func (tx *Trace) NewQUICDialerWithoutResolver( + listener model.UDPListener, dl model.DebugLogger, wrappers ...model.QUICDialerWrapper) model.QUICDialer { return &quicDialerTrace{ qd: tx.Netx.NewQUICDialerWithoutResolver(listener, dl), tx: tx, diff --git a/internal/measurexlite/trace.go b/internal/measurexlite/trace.go index 84bf672632..7a7e79a6f8 100644 --- a/internal/measurexlite/trace.go +++ b/internal/measurexlite/trace.go @@ -75,6 +75,8 @@ type Trace struct { ZeroTime time.Time } +var _ model.MeasuringNetwork = &Trace{} + // NetworkEventBufferSize is the [*Trace] buffer size for network I/O events. const NetworkEventBufferSize = 64 diff --git a/internal/measurexlite/udp.go b/internal/measurexlite/udp.go new file mode 100644 index 0000000000..ee9d1aaf05 --- /dev/null +++ b/internal/measurexlite/udp.go @@ -0,0 +1,7 @@ +package measurexlite + +import "github.com/ooni/probe-cli/v3/internal/model" + +func (tx *Trace) NewUDPListener() model.UDPListener { + return tx.Netx.NewUDPListener() +} diff --git a/internal/measurexlite/udp_test.go b/internal/measurexlite/udp_test.go new file mode 100644 index 0000000000..a5ee8d617a --- /dev/null +++ b/internal/measurexlite/udp_test.go @@ -0,0 +1,24 @@ +package measurexlite + +import ( + "testing" + "time" + + "github.com/ooni/probe-cli/v3/internal/mocks" + "github.com/ooni/probe-cli/v3/internal/model" +) + +func TestNewUDPListener(t *testing.T) { + // Make sure that we're forwarding the call to the measuring network. + expectListener := &mocks.UDPListener{} + trace := NewTrace(0, time.Now()) + trace.Netx = &mocks.MeasuringNetwork{ + MockNewUDPListener: func() model.UDPListener { + return expectListener + }, + } + listener := trace.NewUDPListener() + if listener != expectListener { + t.Fatal("unexpected listener") + } +}