cleanup(geolocate): use netxlite rather than netx (#756)

See https://github.com/ooni/probe/issues/2114
This commit is contained in:
Simone Basso 2022-05-25 09:12:02 +02:00 committed by GitHub
parent d922bd9afc
commit 09523f8efb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -5,8 +5,8 @@ import (
"context" "context"
"fmt" "fmt"
"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/version" "github.com/ooni/probe-cli/v3/internal/version"
) )
@ -114,8 +114,7 @@ func NewTask(config Config) *Task {
config.UserAgent = fmt.Sprintf("ooniprobe-engine/%s", version.Version) config.UserAgent = fmt.Sprintf("ooniprobe-engine/%s", version.Version)
} }
if config.Resolver == nil { if config.Resolver == nil {
config.Resolver = netx.NewResolver( config.Resolver = netxlite.NewResolverStdlib(config.Logger)
netx.Config{Logger: config.Logger})
} }
return &Task{ return &Task{
countryLookupper: mmdbLookupper{}, countryLookupper: mmdbLookupper{},

View File

@ -9,9 +9,9 @@ import (
"net/http" "net/http"
"time" "time"
"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/multierror" "github.com/ooni/probe-cli/v3/internal/multierror"
"github.com/ooni/probe-cli/v3/internal/netxlite"
) )
var ( var (
@ -86,10 +86,11 @@ func (c ipLookupClient) doWithCustomFunc(
// Implementation note: we MUST use an HTTP client that we're // Implementation note: we MUST use an HTTP client that we're
// sure IS NOT using any proxy. To this end, we construct a // sure IS NOT using any proxy. To this end, we construct a
// client ourself that we know is not proxied. // client ourself that we know is not proxied.
clnt := &http.Client{Transport: netx.NewHTTPTransport(netx.Config{ dialer := netxlite.NewDialerWithResolver(c.Logger, c.Resolver)
Logger: c.Logger, handshaker := netxlite.NewTLSHandshakerStdlib(c.Logger)
FullResolver: c.Resolver, tlsDialer := netxlite.NewTLSDialer(dialer, handshaker)
})} txp := netxlite.NewHTTPTransport(c.Logger, dialer, tlsDialer)
clnt := &http.Client{Transport: txp}
defer clnt.CloseIdleConnections() defer clnt.CloseIdleConnections()
ip, err := fn(ctx, clnt, c.Logger, c.UserAgent) ip, err := fn(ctx, clnt, c.Logger, c.UserAgent)
if err != nil { if err != nil {

View File

@ -7,11 +7,14 @@ import (
"testing" "testing"
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
) )
func TestIPLookupGood(t *testing.T) { func TestIPLookupGood(t *testing.T) {
ip, err := (ipLookupClient{ ip, err := (ipLookupClient{
Logger: log.Log, Logger: log.Log,
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
UserAgent: "ooniprobe-engine/0.1.0", UserAgent: "ooniprobe-engine/0.1.0",
}).LookupProbeIP(context.Background()) }).LookupProbeIP(context.Background())
if err != nil { if err != nil {
@ -27,6 +30,7 @@ func TestIPLookupAllFailed(t *testing.T) {
cancel() // immediately cancel to cause Do() to fail cancel() // immediately cancel to cause Do() to fail
ip, err := (ipLookupClient{ ip, err := (ipLookupClient{
Logger: log.Log, Logger: log.Log,
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
UserAgent: "ooniprobe-engine/0.1.0", UserAgent: "ooniprobe-engine/0.1.0",
}).LookupProbeIP(ctx) }).LookupProbeIP(ctx)
if !errors.Is(err, context.Canceled) { if !errors.Is(err, context.Canceled) {
@ -41,6 +45,7 @@ func TestIPLookupInvalidIP(t *testing.T) {
ctx := context.Background() ctx := context.Background()
ip, err := (ipLookupClient{ ip, err := (ipLookupClient{
Logger: log.Log, Logger: log.Log,
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
UserAgent: "ooniprobe-engine/0.1.0", UserAgent: "ooniprobe-engine/0.1.0",
}).doWithCustomFunc(ctx, invalidIPLookup) }).doWithCustomFunc(ctx, invalidIPLookup)
if !errors.Is(err, ErrInvalidIPAddress) { if !errors.Is(err, ErrInvalidIPAddress) {