2021-11-02 12:04:40 +01:00
|
|
|
package netxlite
|
|
|
|
|
2022-05-15 19:25:27 +02:00
|
|
|
//
|
|
|
|
// Transparent proxy (for integration testing)
|
|
|
|
//
|
|
|
|
|
2021-11-02 12:04:40 +01:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-11-02 12:04:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TProxy is the fundamental variable controlling how netxlite creates
|
2022-01-03 13:53:23 +01:00
|
|
|
// net.Conn and model.UDPLikeConn, as well as how it uses the stdlib
|
2021-11-02 12:04:40 +01:00
|
|
|
// 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.
|
2022-01-03 13:53:23 +01:00
|
|
|
var TProxy model.UnderlyingNetworkLibrary = &TProxyStdlib{}
|
2021-11-02 12:04:40 +01:00
|
|
|
|
2022-01-03 13:53:23 +01:00
|
|
|
// TProxyStdlib is the default model.UnderlyingNetworkLibrary using
|
2021-11-02 12:04:40 +01:00
|
|
|
// the stdlib in the most obvious way for every functionality.
|
|
|
|
type TProxyStdlib struct{}
|
|
|
|
|
|
|
|
// ListenUDP calls net.ListenUDP.
|
2022-01-03 13:53:23 +01:00
|
|
|
func (*TProxyStdlib) ListenUDP(network string, laddr *net.UDPAddr) (model.UDPLikeConn, error) {
|
2021-11-02 12:04:40 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-03 13:53:23 +01:00
|
|
|
// NewSimpleDialer returns a &net.Dialer{Timeout: timeout} instance.
|
|
|
|
func (*TProxyStdlib) NewSimpleDialer(timeout time.Duration) model.SimpleDialer {
|
2021-11-02 12:04:40 +01:00
|
|
|
return &net.Dialer{Timeout: timeout}
|
|
|
|
}
|