geo
geo
¶
NIP-66 geolocation metadata container with GeoIP lookup capabilities.
Resolves a relay's hostname to an IP address and performs a GeoIP City database lookup to determine geographic location, including country, city, coordinates, and a computed geohash as part of NIP-66 monitoring. Clearnet relays only.
Note
Hostname resolution uses resolve_host,
preferring IPv4 over IPv6 for the GeoIP lookup. The GeoIP City database
(GeoLite2-City) must be provided as an open geoip2.database.Reader
-- the caller is responsible for database lifecycle management.
The geohash is computed at precision 9 (approximately 5-meter accuracy)
using the geohash2 library and is useful for spatial proximity
queries.
See Also
bigbrotr.nips.nip66.data.Nip66GeoData: Data model for geolocation fields. bigbrotr.nips.nip66.logs.Nip66GeoLogs: Log model for geolocation lookup results. bigbrotr.nips.nip66.net.Nip66NetMetadata: Network/ASN test that also uses resolve_host for IP resolution. bigbrotr.utils.dns.resolve_host: DNS resolution utility used to obtain IP addresses.
Classes¶
GeoExtractor
¶
Extracts structured geolocation fields from a GeoIP2 City response.
See Also
Nip66GeoMetadata: Container that uses this extractor during geolocation lookup. bigbrotr.nips.nip66.data.Nip66GeoData: Data model populated by the extracted fields.
Functions¶
extract_country
staticmethod
¶
Extract country code, name, and EU membership status.
Source code in src/bigbrotr/nips/nip66/geo.py
extract_administrative
staticmethod
¶
Extract continent, city, region, postal code, and geoname ID.
Source code in src/bigbrotr/nips/nip66/geo.py
extract_location
staticmethod
¶
Extract latitude, longitude, accuracy radius, timezone, and geohash.
Source code in src/bigbrotr/nips/nip66/geo.py
extract_all
classmethod
¶
Extract all geolocation fields from a GeoIP2 City response.
Source code in src/bigbrotr/nips/nip66/geo.py
Nip66GeoMetadata
¶
Bases: BaseNipMetadata
Container for geolocation data and lookup logs.
Provides the execute() class method that resolves the relay hostname,
performs a GeoIP City lookup, and extracts location fields.
See Also
bigbrotr.nips.nip66.nip66.Nip66:
Top-level model that orchestrates this alongside other tests.
bigbrotr.models.metadata.MetadataType:
The NIP66_GEO variant used when storing these results.
bigbrotr.nips.nip66.net.Nip66NetMetadata:
Network/ASN test that shares the IP resolution step.
Functions¶
execute
async
classmethod
¶
execute(
relay: Relay,
city_reader: Reader,
geohash_precision: int = 9,
) -> Self
Perform a geolocation lookup for a clearnet relay.
Resolves the relay hostname to an IP (preferring IPv4), then queries the GeoIP City database in a thread pool.
Parameters:
-
relay(Relay) –Clearnet relay to geolocate.
-
city_reader(Reader) –Open GeoLite2-City database reader.
Returns:
-
Self–An
Nip66GeoMetadatainstance with location data and logs.