geolocate

package
v0.0.0-...-11a4145 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 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).

type Geolocator

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

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

func NewDefaultGeolocator

func NewDefaultGeolocator() *Geolocator

func NewGeolocator

func NewGeolocator(apiUrl string) *Geolocator

func (*Geolocator) FindCurrentHostGeolocationWithSTUN

func (g *Geolocator) FindCurrentHostGeolocationWithSTUN(stunServers []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

func (*Geolocator) Geolocate

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

Source Files

  • doc.go
  • geolocate.go
  • https.go
  • stun.go

Jump to

Keyboard shortcuts

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