feat: reintroduce the tproxy functionality (#975)
We originally removed the TProxy in https://github.com/ooni/probe/issues/2224. Nevertheless, in https://github.com/ooni/probe-cli/pull/969, we determined that something like the previous TProxy, with small changes, was required to support https://github.com/ooni/probe/issues/2340. So, this pull request reintroduces a slightly-modified TProxy functionality that better adapts to the `--remote=REMOTE` use case.
This commit is contained in:
parent
46233802ab
commit
86ffd6a0c4
10 changed files with 262 additions and 55 deletions
39
internal/netxlite/tproxy.go
Normal file
39
internal/netxlite/tproxy.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package netxlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
// TProxy refers to the UnderlyingNetwork implementation. By overriding this
|
||||
// variable you can force netxlite to use alternative network primitives.
|
||||
var TProxy model.UnderlyingNetwork = &DefaultTProxy{}
|
||||
|
||||
// defaultTProxy is the default UnderlyingNetwork implementation.
|
||||
type DefaultTProxy struct{}
|
||||
|
||||
// DialContext implements UnderlyingNetwork.
|
||||
func (tp *DefaultTProxy) DialContext(ctx context.Context, timeout time.Duration, network, address string) (net.Conn, error) {
|
||||
d := &net.Dialer{
|
||||
Timeout: timeout,
|
||||
}
|
||||
return d.DialContext(ctx, network, address)
|
||||
}
|
||||
|
||||
// ListenUDP implements UnderlyingNetwork.
|
||||
func (tp *DefaultTProxy) ListenUDP(network string, addr *net.UDPAddr) (model.UDPLikeConn, error) {
|
||||
return net.ListenUDP(network, addr)
|
||||
}
|
||||
|
||||
// GetaddrinfoLookupANY implements UnderlyingNetwork.
|
||||
func (tp *DefaultTProxy) GetaddrinfoLookupANY(ctx context.Context, domain string) ([]string, string, error) {
|
||||
return getaddrinfoLookupANY(ctx, domain)
|
||||
}
|
||||
|
||||
// GetaddrinfoResolverNetwork implements UnderlyingNetwork.
|
||||
func (tp *DefaultTProxy) GetaddrinfoResolverNetwork() string {
|
||||
return getaddrinfoResolverNetwork()
|
||||
}
|
||||
Loading…
Reference in a new issue