Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/oohelper/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 10 additions & 17 deletions internal/cmd/oohelper/oohelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions internal/netxlite/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}

Expand Down