pub struct MaxMindIntel { /* private fields */ }maxmind only.Expand description
Country and ASN lookups from MaxMind databases (GeoLite2-City / GeoLite2-Country /
GeoIP2-* for the country, GeoLite2-ASN for the network).
Databases are read into memory and can be swapped at runtime with reload
(for example after a geoipupdate run); lookups on the request path are lock-free. Unknown
addresses and lookup errors yield empty fields.
use session_guard::{Guard, GuardConfig, MaxMindIntel, MemoryStore};
let intel = MaxMindIntel::open(
"/var/lib/GeoIP/GeoLite2-Country.mmdb",
Some("/var/lib/GeoIP/GeoLite2-ASN.mmdb"),
)?;
let guard = Guard::builder(MemoryStore::new(), GuardConfig::default()).ip_intel(intel).build();Implementations§
Source§impl MaxMindIntel
impl MaxMindIntel
Sourcepub fn open(
country_db: impl AsRef<Path>,
asn_db: Option<impl AsRef<Path>>,
) -> Result<Self, MaxMindError>
pub fn open( country_db: impl AsRef<Path>, asn_db: Option<impl AsRef<Path>>, ) -> Result<Self, MaxMindError>
Reads the country database (City or Country edition) and, optionally, the ASN database.
§Errors
Fails when a file cannot be read, is not a valid MMDB file, or is the wrong kind of database.
Sourcepub fn from_bytes(
country_db: Vec<u8>,
asn_db: Option<Vec<u8>>,
) -> Result<Self, MaxMindError>
pub fn from_bytes( country_db: Vec<u8>, asn_db: Option<Vec<u8>>, ) -> Result<Self, MaxMindError>
Sourcepub fn reload(
&self,
country_db: impl AsRef<Path>,
asn_db: Option<impl AsRef<Path>>,
) -> Result<(), MaxMindError>
pub fn reload( &self, country_db: impl AsRef<Path>, asn_db: Option<impl AsRef<Path>>, ) -> Result<(), MaxMindError>
Replaces both databases with freshly read files. In-flight lookups finish on the old databases. On error the current databases stay in place.
To reload a source the guard uses, wrap it in an Arc, pass a clone to
GuardBuilder::ip_intel and keep the other.
§Errors
As for open.
Sourcepub fn reload_from_bytes(
&self,
country_db: Vec<u8>,
asn_db: Option<Vec<u8>>,
) -> Result<(), MaxMindError>
pub fn reload_from_bytes( &self, country_db: Vec<u8>, asn_db: Option<Vec<u8>>, ) -> Result<(), MaxMindError>
Trait Implementations§
Source§impl Debug for MaxMindIntel
impl Debug for MaxMindIntel
Auto Trait Implementations§
impl !Freeze for MaxMindIntel
impl RefUnwindSafe for MaxMindIntel
impl Send for MaxMindIntel
impl Sync for MaxMindIntel
impl Unpin for MaxMindIntel
impl UnsafeUnpin for MaxMindIntel
impl UnwindSafe for MaxMindIntel
Blanket Implementations§
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
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