geolocate

package
v0.0.0-...-09ee25e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package geolocate has utils to obtain geolocate metadata about the vantage point.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttemptFetchingPublicIP

func AttemptFetchingPublicIP() (string, error)

AttemptFetchingPublicIP will attempt to get our public IP by exhausting all the available sources; the order is stun > https. It will return an error if all the sources are used and we still don't have a result.

func FetchIPFromHTTPSAPICall

func FetchIPFromHTTPSAPICall(provider string) (string, error)

FetchIPFromHTTPSAPICall tries to get the public IP via the passed HTTPS provider label.

func FetchIPFromSTUNCall

func FetchIPFromSTUNCall(uri string) (string, error)

FetchIPFromSTUNCall tries to get our public IP using the passed stun uri. It returns an error of the operation does not succeed.

Types

type GeoInfo

type GeoInfo struct {
	ASName string `json:"as_name"`
	ASN    int    `json:"asn"`
	CC     string `json:"cc"`
}

GeoInfo contains the minimal metadata that we need for annotating reports.

func FindCurrentHostGeolocation

func FindCurrentHostGeolocation() (*GeoInfo, error)

FindCurrentHostGeolocation will make a best-effor attempt at discovering the public IP of the vantage point where the software is running, and obtain geolocation metadata for it. This function currently uses a single endpoint for geolocation (in the OONI API).

type Geolocator

type Geolocator struct {
	API    string
	Client *http.Client
}

A Geolocator is able to geolocate IPs, using a specific http.Client.

func NewGeolocator

func NewGeolocator() *Geolocator

TODO: add NewGeolocationWithHTTPClient

func (*Geolocator) Geolocate

func (g *Geolocator) Geolocate(ip string) (*GeoInfo, error)

Jump to

Keyboard shortcuts

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