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. // OOClient is a client for the OONI Web Connectivity test helper.
type OOClient struct { type OOClient struct {
// HTTPClient is the HTTP client to use. // HTTPClient is the HTTP client to use.
HTTPClient *http.Client HTTPClient model.HTTPClient
// Resolver is the resolver to user. // Resolver is the resolver to user.
Resolver Resolver Resolver Resolver

View File

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

View File

@ -332,6 +332,11 @@ func NewHTTPTransportStdlib(logger model.DebugLogger) model.HTTPTransport {
// standard library for TLS and DNS resolutions. // standard library for TLS and DNS resolutions.
func NewHTTPClientStdlib(logger model.DebugLogger) model.HTTPClient { func NewHTTPClientStdlib(logger model.DebugLogger) model.HTTPClient {
txp := NewHTTPTransportStdlib(logger) 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}) return WrapHTTPClient(&http.Client{Transport: txp})
} }