diff --git a/internal/engine/geolocate/avast.go b/internal/engine/geolocate/avast.go deleted file mode 100644 index 99e037d..0000000 --- a/internal/engine/geolocate/avast.go +++ /dev/null @@ -1,32 +0,0 @@ -package geolocate - -import ( - "context" - "net/http" - - "github.com/ooni/probe-cli/v3/internal/httpx" - "github.com/ooni/probe-cli/v3/internal/model" -) - -type avastResponse struct { - IP string `json:"ip"` -} - -func avastIPLookup( - ctx context.Context, - httpClient *http.Client, - logger model.Logger, - userAgent string, -) (string, error) { - var v avastResponse - err := (&httpx.APIClientTemplate{ - BaseURL: "https://ip-info.ff.avast.com", - HTTPClient: httpClient, - Logger: logger, - UserAgent: userAgent, - }).WithBodyLogging().Build().GetJSON(ctx, "/v1/info", &v) - if err != nil { - return DefaultProbeIP, err - } - return v.IP, nil -} diff --git a/internal/engine/geolocate/avast_test.go b/internal/engine/geolocate/avast_test.go deleted file mode 100644 index 69c7f68..0000000 --- a/internal/engine/geolocate/avast_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package geolocate - -import ( - "context" - "net" - "net/http" - "testing" - - "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/engine/httpheader" -) - -func TestIPLookupWorksUsingAvast(t *testing.T) { - ip, err := avastIPLookup( - context.Background(), - http.DefaultClient, - log.Log, - httpheader.UserAgent(), - ) - if err != nil { - t.Fatal(err) - } - if net.ParseIP(ip) == nil { - t.Fatalf("not an IP address: '%s'", ip) - } -} diff --git a/internal/engine/geolocate/ipconfig.go b/internal/engine/geolocate/ipconfig.go deleted file mode 100644 index c21f258..0000000 --- a/internal/engine/geolocate/ipconfig.go +++ /dev/null @@ -1,31 +0,0 @@ -package geolocate - -import ( - "context" - "net/http" - "strings" - - "github.com/ooni/probe-cli/v3/internal/engine/httpheader" - "github.com/ooni/probe-cli/v3/internal/httpx" - "github.com/ooni/probe-cli/v3/internal/model" -) - -func ipConfigIPLookup( - ctx context.Context, - httpClient *http.Client, - logger model.Logger, - userAgent string, -) (string, error) { - data, err := (&httpx.APIClientTemplate{ - BaseURL: "https://ipconfig.io", - HTTPClient: httpClient, - Logger: logger, - UserAgent: httpheader.CLIUserAgent(), - }).WithBodyLogging().Build().FetchResource(ctx, "/") - if err != nil { - return DefaultProbeIP, err - } - ip := strings.Trim(string(data), "\r\n\t ") - logger.Debugf("ipconfig: body: %s", ip) - return ip, nil -} diff --git a/internal/engine/geolocate/ipconfig_test.go b/internal/engine/geolocate/ipconfig_test.go deleted file mode 100644 index ed9b262..0000000 --- a/internal/engine/geolocate/ipconfig_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package geolocate - -import ( - "context" - "net" - "net/http" - "testing" - - "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/engine/httpheader" -) - -func TestIPLookupWorksUsingIPConfig(t *testing.T) { - ip, err := ipConfigIPLookup( - context.Background(), - http.DefaultClient, - log.Log, - httpheader.UserAgent(), - ) - if err != nil { - t.Fatal(err) - } - if net.ParseIP(ip) == nil { - t.Fatalf("not an IP address: '%s'", ip) - } -} diff --git a/internal/engine/geolocate/ipinfo.go b/internal/engine/geolocate/ipinfo.go deleted file mode 100644 index bd75463..0000000 --- a/internal/engine/geolocate/ipinfo.go +++ /dev/null @@ -1,34 +0,0 @@ -package geolocate - -import ( - "context" - "net/http" - - "github.com/ooni/probe-cli/v3/internal/engine/httpheader" - "github.com/ooni/probe-cli/v3/internal/httpx" - "github.com/ooni/probe-cli/v3/internal/model" -) - -type ipInfoResponse struct { - IP string `json:"ip"` -} - -func ipInfoIPLookup( - ctx context.Context, - httpClient *http.Client, - logger model.Logger, - userAgent string, -) (string, error) { - var v ipInfoResponse - err := (&httpx.APIClientTemplate{ - Accept: "application/json", - BaseURL: "https://ipinfo.io", - HTTPClient: httpClient, - Logger: logger, - UserAgent: httpheader.CLIUserAgent(), // we must be a CLI client - }).WithBodyLogging().Build().GetJSON(ctx, "/", &v) - if err != nil { - return DefaultProbeIP, err - } - return v.IP, nil -} diff --git a/internal/engine/geolocate/ipinfo_test.go b/internal/engine/geolocate/ipinfo_test.go deleted file mode 100644 index 64f798d..0000000 --- a/internal/engine/geolocate/ipinfo_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package geolocate - -import ( - "context" - "net" - "net/http" - "testing" - - "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/engine/httpheader" -) - -func TestIPLookupWorksUsingIPInfo(t *testing.T) { - ip, err := ipInfoIPLookup( - context.Background(), - http.DefaultClient, - log.Log, - httpheader.UserAgent(), - ) - if err != nil { - t.Fatal(err) - } - if net.ParseIP(ip) == nil { - t.Fatalf("not an IP address: '%s'", ip) - } -} diff --git a/internal/engine/geolocate/iplookup.go b/internal/engine/geolocate/iplookup.go index 3d6d484..7a5cd10 100644 --- a/internal/engine/geolocate/iplookup.go +++ b/internal/engine/geolocate/iplookup.go @@ -36,22 +36,10 @@ type method struct { var ( methods = []method{ - { - name: "avast", - fn: avastIPLookup, - }, { name: "cloudflare", fn: cloudflareIPLookup, }, - { - name: "ipconfig", - fn: ipConfigIPLookup, - }, - { - name: "ipinfo", - fn: ipInfoIPLookup, - }, { name: "stun_ekiga", fn: stunEkigaIPLookup,