Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(measurexlite): Trace now implements MeasuringNetwork #1262

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/measurexlite/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions internal/measurexlite/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
6 changes: 5 additions & 1 deletion internal/measurexlite/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions internal/measurexlite/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions internal/measurexlite/udp.go
Original file line number Diff line number Diff line change
@@ -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()
}
24 changes: 24 additions & 0 deletions internal/measurexlite/udp_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}