forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtproxy.go
39 lines (31 loc) · 1.19 KB
/
tproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
}