geolocate

package
v0.0.0-...-7328bb5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: GPL-3.0 Imports: 9 Imported by: 1

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).

func FindCurrentHostGeolocationWithSTUN

func FindCurrentHostGeolocationWithSTUN(stunServers []string, countryCodeLookupURL string) (*GeoInfo, error)

FindCurrentHostGeolocationWithSTUN first trys to get the current public ip address by using the given STUN servers. It then uses countryCodeLookupURL to convert the ip address into a country code. If countryCodeLookupURL is empty, then defaultGeolocationAPI (OONI) is used

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