cleanup(geolocate): use netxlite rather than netx (#756)
See https://github.com/ooni/probe/issues/2114
This commit is contained in:
parent
d922bd9afc
commit
09523f8efb
|
@ -5,8 +5,8 @@ import (
|
|||
"context"
|
||||
"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/netxlite"
|
||||
"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)
|
||||
}
|
||||
if config.Resolver == nil {
|
||||
config.Resolver = netx.NewResolver(
|
||||
netx.Config{Logger: config.Logger})
|
||||
config.Resolver = netxlite.NewResolverStdlib(config.Logger)
|
||||
}
|
||||
return &Task{
|
||||
countryLookupper: mmdbLookupper{},
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"net/http"
|
||||
"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/multierror"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -86,10 +86,11 @@ func (c ipLookupClient) doWithCustomFunc(
|
|||
// Implementation note: we MUST use an HTTP client that we're
|
||||
// sure IS NOT using any proxy. To this end, we construct a
|
||||
// client ourself that we know is not proxied.
|
||||
clnt := &http.Client{Transport: netx.NewHTTPTransport(netx.Config{
|
||||
Logger: c.Logger,
|
||||
FullResolver: c.Resolver,
|
||||
})}
|
||||
dialer := netxlite.NewDialerWithResolver(c.Logger, c.Resolver)
|
||||
handshaker := netxlite.NewTLSHandshakerStdlib(c.Logger)
|
||||
tlsDialer := netxlite.NewTLSDialer(dialer, handshaker)
|
||||
txp := netxlite.NewHTTPTransport(c.Logger, dialer, tlsDialer)
|
||||
clnt := &http.Client{Transport: txp}
|
||||
defer clnt.CloseIdleConnections()
|
||||
ip, err := fn(ctx, clnt, c.Logger, c.UserAgent)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,11 +7,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"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) {
|
||||
ip, err := (ipLookupClient{
|
||||
Logger: log.Log,
|
||||
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
|
||||
UserAgent: "ooniprobe-engine/0.1.0",
|
||||
}).LookupProbeIP(context.Background())
|
||||
if err != nil {
|
||||
|
@ -27,6 +30,7 @@ func TestIPLookupAllFailed(t *testing.T) {
|
|||
cancel() // immediately cancel to cause Do() to fail
|
||||
ip, err := (ipLookupClient{
|
||||
Logger: log.Log,
|
||||
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
|
||||
UserAgent: "ooniprobe-engine/0.1.0",
|
||||
}).LookupProbeIP(ctx)
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
|
@ -41,6 +45,7 @@ func TestIPLookupInvalidIP(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
ip, err := (ipLookupClient{
|
||||
Logger: log.Log,
|
||||
Resolver: netxlite.NewResolverStdlib(model.DiscardLogger),
|
||||
UserAgent: "ooniprobe-engine/0.1.0",
|
||||
}).doWithCustomFunc(ctx, invalidIPLookup)
|
||||
if !errors.Is(err, ErrInvalidIPAddress) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user