diff --git a/leader-stream/Cargo.lock b/leader-stream/Cargo.lock index 90f172c..f8abf2d 100644 --- a/leader-stream/Cargo.lock +++ b/leader-stream/Cargo.lock @@ -804,12 +804,9 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "ipnetwork" -version = "0.20.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" -dependencies = [ - "serde", -] +checksum = "cf370abdafd54d13e54a620e8c3e1145f28e46cc9d704bc6d94414559df41763" [[package]] name = "itoa" @@ -920,14 +917,15 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "maxminddb" -version = "0.24.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6087e5d8ea14861bb7c7f573afbc7be3798d3ef0fae87ec4fd9a4de9a127c3c" +checksum = "7ef0551fc3e7345a6c854c1026b0ddada1e443e51f4fb4cdcf86cc1a71d4b337" dependencies = [ "ipnetwork", "log", "memchr", "serde", + "thiserror 2.0.17", ] [[package]] @@ -1674,7 +1672,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl 2.0.17", ] [[package]] @@ -1688,6 +1695,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.9" @@ -1930,7 +1948,7 @@ dependencies = [ "rustls 0.23.35", "rustls-pki-types", "sha1", - "thiserror", + "thiserror 1.0.69", "utf-8", ] diff --git a/leader-stream/Cargo.toml b/leader-stream/Cargo.toml index 1a94d93..613039a 100644 --- a/leader-stream/Cargo.toml +++ b/leader-stream/Cargo.toml @@ -16,7 +16,7 @@ axum = { version = "0.7", features = ["macros"] } bytes = "1" flate2 = "1" futures-util = "0.3" -maxminddb = "0.24" +maxminddb = "0.27" reqwest = { version = "0.11", features = ["json", "rustls-tls", "stream"] } rustls = { version = "0.23", default-features = false, features = ["ring"] } serde_json = "1" diff --git a/leader-stream/src/geo.rs b/leader-stream/src/geo.rs index e4f5c1e..79077b2 100644 --- a/leader-stream/src/geo.rs +++ b/leader-stream/src/geo.rs @@ -10,7 +10,7 @@ use std::time::Duration; use anyhow::{anyhow, Context, Result}; use flate2::read::GzDecoder; use maxminddb::geoip2::City; -use maxminddb::{MaxMindDBError, Reader}; +use maxminddb::{MaxMindDbError, Reader}; use reqwest::Client; use tar::Archive; use tokio::sync::RwLock; @@ -79,12 +79,17 @@ impl GeoIpService { } }; - let result = match reader.lookup::(ip_addr) { - Ok(city) => extract_point(&city), - Err(err) => { - if !matches!(err, MaxMindDBError::AddressNotFoundError(_)) { + let result = match reader.lookup(ip_addr) { + Ok(lookup) => match lookup.decode::() { + Ok(Some(city)) => extract_point(&city), + Ok(None) => None, + Err(err) => { self.log_lookup_error_once(err); + None } + }, + Err(err) => { + self.log_lookup_error_once(err); None } }; @@ -97,7 +102,7 @@ impl GeoIpService { cache.insert(ip.to_string(), value); } - fn log_lookup_error_once(&self, err: MaxMindDBError) { + fn log_lookup_error_once(&self, err: MaxMindDbError) { if !self.lookup_error_logged.swap(true, Ordering::SeqCst) { warn!( ?err, @@ -257,21 +262,11 @@ async fn fetch_and_write(client: &Client, url: &str, target: &Path, raw_mmdb: bo } fn extract_point(city: &City) -> Option { - let location = city.location.as_ref()?; + let location = &city.location; let latitude = location.latitude?; let longitude = location.longitude?; - let city_name = city - .city - .as_ref() - .and_then(|record| record.names.as_ref()) - .and_then(|names| names.get("en")) - .map(|value| value.to_string()); - let country_name = city - .country - .as_ref() - .and_then(|record| record.names.as_ref()) - .and_then(|names| names.get("en")) - .map(|value| value.to_string()); + let city_name = city.city.names.english.map(|value| value.to_string()); + let country_name = city.country.names.english.map(|value| value.to_string()); Some(GeoPoint { latitude, longitude,