cleanup: remove UnderlyingNetworkLibrary and TProxy (#874)
* cleanup: remove UnderlyingNetworkLibrary and TProxy While there, replace mixture of mocking and real connections inside quicping with pure mocking of network connections. Closes https://github.com/ooni/probe/issues/2224 * cleanup: we don't need a SimpleResolver now This type was only used by UnderlyingNetworkLibrary and all the rest of the code uses Resolver. So, let's avoid complexity by zapping the SimpleResolver type and merging it inside Resolver.
This commit is contained in:
@@ -143,7 +143,7 @@ func NewDialerWithoutResolver(dl model.DebugLogger, w ...model.DialerWrapper) mo
|
||||
return NewDialerWithResolver(dl, &NullResolver{}, w...)
|
||||
}
|
||||
|
||||
// DialerSystem is a model.Dialer that uses TProxy.NewSimplerDialer
|
||||
// DialerSystem is a model.Dialer that uses the stdlib's net.Dialer
|
||||
// to construct the new SimpleDialer used for dialing. This dialer has
|
||||
// a fixed timeout for each connect operation equal to 15 seconds.
|
||||
type DialerSystem struct {
|
||||
@@ -160,7 +160,7 @@ func (d *DialerSystem) newUnderlyingDialer() model.SimpleDialer {
|
||||
if t <= 0 {
|
||||
t = dialerDefaultTimeout
|
||||
}
|
||||
return TProxy.NewSimpleDialer(t)
|
||||
return &net.Dialer{Timeout: t}
|
||||
}
|
||||
|
||||
func (d *DialerSystem) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
|
||||
@@ -81,7 +81,7 @@ func (txp *dnsOverGetaddrinfoTransport) lookupfn() func(ctx context.Context, dom
|
||||
if txp.testableLookupHost != nil {
|
||||
return txp.testableLookupHost
|
||||
}
|
||||
return TProxy.DefaultResolver().LookupHost
|
||||
return getaddrinfoLookupHost
|
||||
}
|
||||
|
||||
func (txp *dnsOverGetaddrinfoTransport) RequiresPadding() bool {
|
||||
@@ -89,7 +89,7 @@ func (txp *dnsOverGetaddrinfoTransport) RequiresPadding() bool {
|
||||
}
|
||||
|
||||
func (txp *dnsOverGetaddrinfoTransport) Network() string {
|
||||
return TProxy.DefaultResolver().Network()
|
||||
return getaddrinfoResolverNetwork()
|
||||
}
|
||||
|
||||
func (txp *dnsOverGetaddrinfoTransport) Address() string {
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestDNSOverGetaddrinfo(t *testing.T) {
|
||||
|
||||
t.Run("Network", func(t *testing.T) {
|
||||
txp := &dnsOverGetaddrinfoTransport{}
|
||||
if txp.Network() != TProxy.DefaultResolver().Network() {
|
||||
if txp.Network() != getaddrinfoResolverNetwork() {
|
||||
t.Fatal("unexpected Network")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ var _ model.QUICListener = &quicListenerStdlib{}
|
||||
|
||||
// Listen implements QUICListener.Listen.
|
||||
func (qls *quicListenerStdlib) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) {
|
||||
return TProxy.ListenUDP("udp", addr)
|
||||
return net.ListenUDP("udp", addr)
|
||||
}
|
||||
|
||||
// NewQUICDialerWithResolver is the WrapDialer equivalent for QUIC where
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package netxlite
|
||||
|
||||
//
|
||||
// Transparent proxy (for integration testing)
|
||||
//
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// TProxy is the fundamental variable controlling how netxlite creates
|
||||
// net.Conn and model.UDPLikeConn, as well as how it uses the stdlib
|
||||
// resolver. By modifying this variable, you can effectively transparently
|
||||
// proxy netxlite (and hence OONI) activities to other services. This is
|
||||
// quite convenient when performing quality assurance tests.
|
||||
var TProxy model.UnderlyingNetworkLibrary = &TProxyStdlib{}
|
||||
|
||||
// TProxyStdlib is the default model.UnderlyingNetworkLibrary using
|
||||
// the stdlib in the most obvious way for every functionality.
|
||||
type TProxyStdlib struct{}
|
||||
|
||||
// ListenUDP calls net.ListenUDP.
|
||||
func (*TProxyStdlib) ListenUDP(network string, laddr *net.UDPAddr) (model.UDPLikeConn, error) {
|
||||
return net.ListenUDP(network, laddr)
|
||||
}
|
||||
|
||||
// DefaultResolver returns the default resolver.
|
||||
func (*TProxyStdlib) DefaultResolver() model.SimpleResolver {
|
||||
return &tproxyDefaultResolver{}
|
||||
}
|
||||
|
||||
// NewSimpleDialer returns a &net.Dialer{Timeout: timeout} instance.
|
||||
func (*TProxyStdlib) NewSimpleDialer(timeout time.Duration) model.SimpleDialer {
|
||||
return &net.Dialer{Timeout: timeout}
|
||||
}
|
||||
|
||||
// tproxyDefaultResolver is the resolver we use by default.
|
||||
type tproxyDefaultResolver struct{}
|
||||
|
||||
// LookupHost implements model.SimpleResolver.LookupHost.
|
||||
func (r *tproxyDefaultResolver) LookupHost(ctx context.Context, domain string) ([]string, error) {
|
||||
return getaddrinfoLookupHost(ctx, domain)
|
||||
}
|
||||
|
||||
// Network implements model.SimpleResolver.Network.
|
||||
func (r *tproxyDefaultResolver) Network() string {
|
||||
return getaddrinfoResolverNetwork()
|
||||
}
|
||||
Reference in New Issue
Block a user