refactor(oohelper): use netxlite rather than netx (#805)

The oohelper does not need to use netx and it's enough to use
netxlite, hence let us apply this refactor.

The original code used DoT but the explanatory comment said we were
using DoT because of unclear issues inside GitHub actions.

We are now using DoH and this is fine as well. The comment implied
that any encrypted transport would do.

See https://github.com/ooni/probe/issues/2121
This commit is contained in:
Simone Basso 2022-06-08 09:52:47 +02:00 committed by GitHub
parent 4cf58380c3
commit 87d35f4225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 18 deletions

View File

@ -45,7 +45,7 @@ type Resolver interface {
// OOClient is a client for the OONI Web Connectivity test helper.
type OOClient struct {
// HTTPClient is the HTTP client to use.
HTTPClient *http.Client
HTTPClient model.HTTPClient
// Resolver is the resolver to user.
Resolver Resolver

View File

@ -7,40 +7,33 @@ import (
"encoding/json"
"flag"
"fmt"
"net/http"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/cmd/oohelper/internal"
"github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/runtimex"
)
var (
ctx, cancel = context.WithCancel(context.Background())
debug = flag.Bool("debug", false, "Toggle debug mode")
httpClient *http.Client
httpClient model.HTTPClient
resolver model.Resolver
server = flag.String("server", "", "URL of the test helper")
target = flag.String("target", "", "Target URL for the test helper")
)
func newhttpclient() *http.Client {
func init() {
// Use a nonstandard resolver, which is enough to work around the
// puzzling https://github.com/ooni/probe/issues/1409 issue.
childResolver, err := netx.NewDNSClient(
netx.Config{Logger: log.Log}, "dot://8.8.8.8:853")
runtimex.PanicOnError(err, "netx.NewDNSClient should not fail here")
txp := netx.NewHTTPTransport(netx.Config{
BaseResolver: childResolver,
Logger: log.Log,
})
return &http.Client{Transport: txp}
}
func init() {
httpClient = newhttpclient()
resolver = netx.NewResolver(netx.Config{Logger: log.Log})
const resolverURL = "https://8.8.8.8/dns-query"
resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, resolverURL)
thx := netxlite.NewTLSHandshakerStdlib(log.Log)
dialer := netxlite.NewDialerWithResolver(log.Log, resolver)
tlsDialer := netxlite.NewTLSDialer(dialer, thx)
txp := netxlite.NewHTTPTransport(log.Log, dialer, tlsDialer)
httpClient = netxlite.NewHTTPClient(txp)
}
func main() {

View File

@ -332,6 +332,11 @@ func NewHTTPTransportStdlib(logger model.DebugLogger) model.HTTPTransport {
// standard library for TLS and DNS resolutions.
func NewHTTPClientStdlib(logger model.DebugLogger) model.HTTPClient {
txp := NewHTTPTransportStdlib(logger)
return NewHTTPClient(txp)
}
// NewHTTPClient creates a new, wrapped HTTPClient using the given transport.
func NewHTTPClient(txp model.HTTPTransport) model.HTTPClient {
return WrapHTTPClient(&http.Client{Transport: txp})
}