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
Sourcefn rpc_lookup_countries(
&self,
request: GeoipLookupCountries,
) -> Result<GeoipLookupResult, AddrParseError>
fn rpc_lookup_countries( &self, request: GeoipLookupCountries, ) -> Result<GeoipLookupResult, AddrParseError>
Actually perform the geoip lookup for a given GeoipLookupCountries request.
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.
Trait Implementations§
impl Eq for GeoipDb
Source§impl Object for GeoipDb
impl Object for GeoipDb
Source§fn get_cast_table(&self) -> &CastTable
fn get_cast_table(&self) -> &CastTable
Source§fn expose_outside_of_session(&self) -> bool
fn expose_outside_of_session(&self) -> bool
impl StructuralPartialEq for GeoipDb
Auto Trait Implementations§
impl Forget for GeoipDb
impl Freeze for GeoipDb
impl Move for GeoipDb
impl RefUnwindSafe for GeoipDb
impl Send for GeoipDb
impl Sync for GeoipDb
impl Unpin for GeoipDb
impl UnsafeUnpin for GeoipDb
impl UnwindSafe for GeoipDb
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more