forked from ooni/probe-cli
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(netxlite): implement hooks for transparent proxy (ooni#561)
- Loading branch information
1 parent
c123d83
commit 0091c57
Showing
5 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package netxlite | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"time" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/netxlite/quicx" | ||
) | ||
|
||
// TProxable is the fundamental type used by the netxlite package to perform | ||
// low-level network operations for which, by default, we use the stdlib. | ||
// | ||
// The t stands for transparent. By using this type as the fundamental type, | ||
// we can transparently intercept connections and implement censorship | ||
// policies. The implementation of this functionality is not part of netxlite: | ||
// here we only have the basic mechanism to make this possible. | ||
type TProxable interface { | ||
// ListenUDP creates a new quicx.UDPLikeConn conn. | ||
ListenUDP(network string, laddr *net.UDPAddr) (quicx.UDPLikeConn, error) | ||
|
||
// LookupHost lookups a domain using the stdlib resolver. | ||
LookupHost(ctx context.Context, domain string) ([]string, error) | ||
|
||
// NewTProxyDialer returns a new TProxyDialer. | ||
NewTProxyDialer(timeout time.Duration) TProxyDialer | ||
} | ||
|
||
// TProxyDialer is the dialer type returned by TProxable.NewDialer. | ||
type TProxyDialer interface { | ||
// DialContext behaves like net.Dialer.DialContext. | ||
DialContext(ctx context.Context, network, address string) (net.Conn, error) | ||
} | ||
|
||
// TProxy is the fundamental variable controlling how netxlite creates | ||
// net.Conn and quicx.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 TProxable = &TProxyStdlib{} | ||
|
||
// TProxyStdlib is the default TProxable implementation that uses | ||
// 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) (quicx.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) | ||
} | ||
|
||
// NewTProxyDialer returns a &net.Dialer{Timeout: timeout} instance. | ||
func (*TProxyStdlib) NewTProxyDialer(timeout time.Duration) TProxyDialer { | ||
return &net.Dialer{Timeout: timeout} | ||
} |