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:
Simone Basso 2022-08-23 11:43:44 +02:00 committed by GitHub
commit da1c13e312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 164 deletions

View file

@ -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()
}