diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock index eb95775e..e9e4a933 100644 --- a/src/rust/Cargo.lock +++ b/src/rust/Cargo.lock @@ -2078,6 +2078,7 @@ dependencies = [ "serde", "serde_cbor", "serde_json", + "sha256", "signal-hook", "strum", "surge-ping", @@ -3178,6 +3179,19 @@ dependencies = [ "digest", ] +[[package]] +name = "sha256" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18278f6a914fa3070aa316493f7d2ddfb9ac86ebc06fa3b83bffda487e9065b0" +dependencies = [ + "async-trait", + "bytes", + "hex", + "sha2", + "tokio", +] + [[package]] name = "sharded-slab" version = "0.1.7" diff --git a/src/rust/lqosd/Cargo.toml b/src/rust/lqosd/Cargo.toml index 6bf5dc40..3ed4da67 100644 --- a/src/rust/lqosd/Cargo.toml +++ b/src/rust/lqosd/Cargo.toml @@ -53,6 +53,7 @@ timerfd = { workspace = true } crossbeam-channel = { workspace = true } arc-swap = { workspace = true } crossbeam-queue = { workspace = true } +sha256 = "1.5.0" # For memory debugging allocative = { version = "0.3.3", features = [ "dashmap" ] } diff --git a/src/rust/lqosd/src/throughput_tracker/flow_data/flow_analysis/asn.rs b/src/rust/lqosd/src/throughput_tracker/flow_data/flow_analysis/asn.rs index 152b08ee..6f00b9fe 100644 --- a/src/rust/lqosd/src/throughput_tracker/flow_data/flow_analysis/asn.rs +++ b/src/rust/lqosd/src/throughput_tracker/flow_data/flow_analysis/asn.rs @@ -64,19 +64,38 @@ impl GeoTable { fn download() -> anyhow::Result<()> { tracing::warn!("Downloading ASN-IP Table"); let file_path = Self::file_path(); - let url = "https://stats.libreqos.io/geo2.bin"; + let url = "https://insight.libreqos.com/geo2.bin"; let response = reqwest::blocking::get(url)?; let content = response.bytes()?; let bytes = &content[0..]; std::fs::write(file_path, bytes)?; + tracing::info!("Downloaded geo2.bin"); Ok(()) } + fn is_file_uptodate() -> anyhow::Result { + let bytes = std::fs::read(&Self::file_path())?; // Vec + let hash = sha256::digest(&bytes); + + // Using blocking reqwest, retrieve the checksum as a string from https://insight.libreqos.com/geo/checksum + let checksum = reqwest::blocking::get("https://insight.libreqos.com/geo/checksum")?.text()?; + if checksum == hash { + return Ok(true) + } + + Ok(false) + } + pub fn load() -> anyhow::Result { let path = Self::file_path(); if !path.exists() { - info!("geo.bin not found - trying to download it"); + info!("geo2.bin not found - trying to download it"); Self::download()?; + } else { + if !Self::is_file_uptodate().unwrap_or(true) { + info!("geo2.bin is outdated - trying to download it"); + Self::download()?; + } } // Decompress and deserialize