Update maxminddb dependency to 0.26 and adapt to breaking changes

This commit is contained in:
Slatian
2025-04-11 21:40:41 +02:00
parent 5c322f2611
commit 34e5e8f95c
3 changed files with 10 additions and 10 deletions

5
Cargo.lock generated
View File

@ -1403,14 +1403,15 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]] [[package]]
name = "maxminddb" name = "maxminddb"
version = "0.25.0" version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "144de2546bf4846c6c84b7f76be035f7ebbc1e7d40cfb05810ba45c129508321" checksum = "2a197e44322788858682406c74b0b59bf8d9b4954fe1f224d9a25147f1880bba"
dependencies = [ dependencies = [
"ipnetwork", "ipnetwork",
"log", "log",
"memchr", "memchr",
"serde", "serde",
"thiserror 2.0.12",
] ]
[[package]] [[package]]

View File

@ -20,7 +20,7 @@ hickory-resolver = { version = "0.25", features = ["tls-ring","https-ring","qui
http = "1.3" http = "1.3"
idna = "1.0" idna = "1.0"
log = "0.4" log = "0.4"
maxminddb = "0.25" maxminddb = "0.26"
mime = "0.3" mime = "0.3"
parking_lot = "0.12" parking_lot = "0.12"
regex = "1.11" regex = "1.11"

View File

@ -6,7 +6,6 @@
use log::{debug,info,warn,error}; use log::{debug,info,warn,error};
use maxminddb::geoip2; use maxminddb::geoip2;
use maxminddb::MaxMindDBError::AddressNotFoundError;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -130,13 +129,13 @@ impl QueryAsn for MMDBCarrier {
match &*mmdb { match &*mmdb {
Some(mmdb) => { Some(mmdb) => {
match mmdb.lookup::<geoip2::Asn>(*address) { match mmdb.lookup::<geoip2::Asn>(*address) {
Ok(res) => { Ok(Some(res)) => {
Some(AsnResult { Some(AsnResult {
asn: res.autonomous_system_number, asn: res.autonomous_system_number,
name: res.autonomous_system_organization.map(ToString::to_string), name: res.autonomous_system_organization.map(ToString::to_string),
}) })
}, },
Err(AddressNotFoundError(_)) => { Ok(None) => {
// Log to the debug channel. // Log to the debug channel.
// This isn't severe, and shouldn't be logged in production. // This isn't severe, and shouldn't be logged in production.
debug!("ASN not found in database for {address}."); debug!("ASN not found in database for {address}.");
@ -159,7 +158,7 @@ impl QueryLocation for MMDBCarrier {
match &*mmdb { match &*mmdb {
Some(mmdb) => { Some(mmdb) => {
match mmdb.lookup::<geoip2::City>(*address) { match mmdb.lookup::<geoip2::City>(*address) {
Ok(res) => { Ok(Some(res)) => {
Some(LocationResult { Some(LocationResult {
continent: continent:
res.continent.map(|c| geoip2_continent_to_named_location(c, languages)), res.continent.map(|c| geoip2_continent_to_named_location(c, languages)),
@ -210,7 +209,7 @@ impl QueryLocation for MMDBCarrier {
}, },
}) })
}, },
Err(AddressNotFoundError(_)) => { Ok(None) => {
// Log to the debug channel. // Log to the debug channel.
// This isn't severe, and shouldn't be logged in production. // This isn't severe, and shouldn't be logged in production.
debug!("IP location not found in database for {address}"); debug!("IP location not found in database for {address}");
@ -236,14 +235,14 @@ impl MMDBCarrier {
} }
} }
pub fn reload_database(&self) -> Result<(),maxminddb::MaxMindDBError> { pub fn reload_database(&self) -> Result<(),maxminddb::MaxMindDbError> {
match &self.path { match &self.path {
Some(path) => self.load_database_from_path(Path::new(&path)), Some(path) => self.load_database_from_path(Path::new(&path)),
None => Ok(()), None => Ok(()),
} }
} }
pub fn load_database_from_path(&self, path: &Path) -> Result<(),maxminddb::MaxMindDBError> { pub fn load_database_from_path(&self, path: &Path) -> Result<(),maxminddb::MaxMindDbError> {
let mut mmdb = self.mmdb.write(); let mut mmdb = self.mmdb.write();
info!("Loading {} from '{}' ...", &self.name, path.display()); info!("Loading {} from '{}' ...", &self.name, path.display());
match maxminddb::Reader::open_readfile(path) { match maxminddb::Reader::open_readfile(path) {