cleanup(geolocate): remove IP lookuppers blocked by sanctions (#747)
Closes https://github.com/ooni/probe/issues/2104
This commit is contained in:
parent
e5d59e834e
commit
6713fc6bc6
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user