Skip to content

Commit

Permalink
cleanup(geolocate): use netxlite rather than netx (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone authored May 25, 2022
1 parent d922bd9 commit 09523f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions internal/engine/geolocate/geolocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{},
Expand Down
11 changes: 6 additions & 5 deletions internal/engine/geolocate/iplookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions internal/engine/geolocate/iplookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 09523f8

Please sign in to comment.