pub struct GeoipDb {
pub(crate) map_v4: DenseRangeMap<u32, CountryCode, NonZeroU32>,
pub(crate) map_v6: DenseRangeMap<u128, CountryCode, NonZeroU32>,
}Expand description
A database of IP addresses to country codes.
Fields§
§map_v4: DenseRangeMap<u32, CountryCode, NonZeroU32>The IPv4 subset of the database, with v4 addresses stored as 32-bit integers.
map_v6: DenseRangeMap<u128, CountryCode, NonZeroU32>The IPv6 subset of the database, with v6 addresses stored as 128-bit integers.
Implementations§
Source§impl GeoipDb
impl GeoipDb
Sourcepub fn new_embedded() -> Arc<Self>
pub fn new_embedded() -> Arc<Self>
Make a new GeoipDb using a compiled-in copy of the GeoIP database.
The returned instance of the database is shared with Arc across all invocations of this
function in the same program.
Sourcepub fn new_from_legacy_format(
db_v4: &str,
db_v6: &str,
include_asn: bool,
) -> Result<Self, Error>
pub fn new_from_legacy_format( db_v4: &str, db_v6: &str, include_asn: bool, ) -> Result<Self, Error>
Make a new GeoipDb using provided copies of the v4 and v6 database, in Tor legacy format.
Sourcepub fn export_raw(&self) -> RawGeoipDbExport<'_>
pub fn export_raw(&self) -> RawGeoipDbExport<'_>
Return the database in a raw format suitable for embedding.
This method and the format it returns are unstable. This method should only be used for maintaining the database.
Sourcepub fn lookup_country_code(&self, ip: IpAddr) -> Option<&CountryCode>
pub fn lookup_country_code(&self, ip: IpAddr) -> Option<&CountryCode>
Get a 2-letter country code for the given IP address, if this data is available.
Sourcepub fn lookup_country_code_multi<I>(&self, ips: I) -> Option<&CountryCode>where
I: IntoIterator<Item = IpAddr>,
pub fn lookup_country_code_multi<I>(&self, ips: I) -> Option<&CountryCode>where
I: IntoIterator<Item = IpAddr>,
Determine a 2-letter country code for a host with multiple IP addresses.
This looks up all of the IP addresses with lookup_country_code. If the lookups
return different countries, None is returned. IP addresses that fail to resolve
into a country are ignored if some of the other addresses do resolve successfully.
Sourcepub fn lookup_asn(&self, ip: IpAddr) -> Option<u32>
pub fn lookup_asn(&self, ip: IpAddr) -> Option<u32>
Return the ASN the IP address is in, if this data is available.