geolocate

package
v0.20.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2020 License: BSD-3-Clause Imports: 16 Imported by: 0

README

Package github.com/ooni/probe-engine/geolocate

Package geolocate implements IP lookup, resolver lookup, and GeoIP location of an OONI Probe instance.

Documentation

Overview

Package geolocate implements IP lookup, resolver lookup, and GeoIP location an OONI Probe instance.

Index

Constants

This section is empty.

Variables

View Source
var ErrAllIPLookuppersFailed = errors.New("all IP lookuppers failed")

ErrAllIPLookuppersFailed indicates that we failed with looking up the probe IP for with all the lookuppers that we tried.

Functions

func AvastIPLookup

func AvastIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

AvastIPLookup performs the IP lookup using Avast services.

func IPConfigIPLookup added in v0.20.0

func IPConfigIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

IPConfigIPLookup performs the IP lookup using ipconfig.io.

func IPInfoIPLookup added in v0.20.0

func IPInfoIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

IPInfoIPLookup performs the IP lookup using ipinfo.io

func LookupASN

func LookupASN(path, ip string) (asn uint, org string, err error)

LookupASN maps the ip to the probe ASN and org using the MMDB database located at path, or returns an error. In case the IP is not valid, this function will fail with an error complaining that geoip2 was passed a nil IP.

func LookupAllResolverIPs

func LookupAllResolverIPs(ctx context.Context, resolver HostLookupper) (ips []string, err error)

LookupAllResolverIPs returns all resolver IPs

func LookupCC

func LookupCC(path, ip string) (cc string, err error)

LookupCC is like LookupASN but for the country code.

func LookupFirstResolverIP

func LookupFirstResolverIP(ctx context.Context, resolver HostLookupper) (ip string, err error)

LookupFirstResolverIP returns the first resolver IP

func STUNEkigaIPLookup added in v0.20.0

func STUNEkigaIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

STUNEkigaIPLookup performs the IP lookup using ekiga.net.

func STUNGoogleIPLookup added in v0.20.0

func STUNGoogleIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

STUNGoogleIPLookup performs the IP lookup using google.com.

func STUNIPLookup added in v0.20.0

func STUNIPLookup(ctx context.Context, config STUNConfig) (string, error)

STUNIPLookup performs the IP lookup using STUN.

func UbuntuIPLookup

func UbuntuIPLookup(
	ctx context.Context,
	httpClient *http.Client,
	logger model.Logger,
	userAgent string,
) (string, error)

UbuntuIPLookup performs the IP lookup using Ubuntu services.

Types

type AvastResponse

type AvastResponse struct {
	IP string `json:"ip"`
}

AvastResponse is the response returned by Avast IP lookup services.

type HostLookupper

type HostLookupper interface {
	LookupHost(ctx context.Context, host string) (addrs []string, err error)
}

HostLookupper is an interface that looks up the name of a host.

type IPInfoResponse added in v0.20.0

type IPInfoResponse struct {
	IP string `json:"ip"`
}

IPInfoResponse is the response returned by ipinfo.io

type IPLookupClient

type IPLookupClient struct {
	// HTTPClient is the HTTP client to use
	HTTPClient *http.Client

	// Logger is the logger to use
	Logger model.Logger

	// UserAgent is the user agent to use
	UserAgent string
}

IPLookupClient is an iplookup client

func (IPLookupClient) Do

func (c IPLookupClient) Do(ctx context.Context) (string, error)

Do performs the IP lookup.

func (IPLookupClient) DoWithCustomFunc

func (c IPLookupClient) DoWithCustomFunc(
	ctx context.Context, fn LookupFunc,
) (string, error)

DoWithCustomFunc performs the IP lookup with a custom function.

type LookupFunc

type LookupFunc func(
	ctx context.Context, client *http.Client,
	logger model.Logger, userAgent string,
) (string, error)

LookupFunc is a function for performing the IP lookup.

type STUNClient added in v0.20.0

type STUNClient interface {
	Close() error
	Start(m *stun.Message, h stun.Handler) error
}

STUNClient is the STUN client expected by this package

type STUNConfig added in v0.20.0

type STUNConfig struct {
	Dial     func(network string, address string) (STUNClient, error)
	Endpoint string
	Logger   model.Logger
}

STUNConfig contains configuration for STUNIPLookup

type UbuntuResponse

type UbuntuResponse struct {
	XMLName xml.Name `xml:"Response"`
	IP      string   `xml:"Ip"`
}

UbuntuResponse is the response by Ubuntu IP lookup services.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL