c1b06a2d09
This diff has been extracted and adapted from 8848c8c516
The reason to prefer composition over embedding is that we want the
build to break if we add new methods to interfaces we define. If the build
does not break, we may forget about wrapping methods we should
actually be wrapping. I noticed this issue inside netxlite when I was working
on websteps-illustrated and I added support for NS and PTR queries.
See https://github.com/ooni/probe/issues/2096
While there, perform comprehensive netxlite code review
and apply minor changes and improve the docs.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
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)
|
|
}
|
|
|
|
// LookupHost calls net.DefaultResolver.LookupHost.
|
|
func (*TProxyStdlib) LookupHost(ctx context.Context, domain string) ([]string, error) {
|
|
return net.DefaultResolver.LookupHost(ctx, domain)
|
|
}
|
|
|
|
// NewSimpleDialer returns a &net.Dialer{Timeout: timeout} instance.
|
|
func (*TProxyStdlib) NewSimpleDialer(timeout time.Duration) model.SimpleDialer {
|
|
return &net.Dialer{Timeout: timeout}
|
|
}
|