Skip to content

Commit fd9af3b

Browse files
committed
Geo2.bin file checks with our server to see if its uptodate, and downloads a fresh one if it is old.
1 parent 97781e9 commit fd9af3b

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/rust/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/lqosd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ timerfd = { workspace = true }
5353
crossbeam-channel = { workspace = true }
5454
arc-swap = { workspace = true }
5555
crossbeam-queue = { workspace = true }
56+
sha256 = "1.5.0"
5657

5758
# For memory debugging
5859
allocative = { version = "0.3.3", features = [ "dashmap" ] }

src/rust/lqosd/src/throughput_tracker/flow_data/flow_analysis/asn.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,38 @@ impl GeoTable {
6464
fn download() -> anyhow::Result<()> {
6565
tracing::warn!("Downloading ASN-IP Table");
6666
let file_path = Self::file_path();
67-
let url = "https://stats.libreqos.io/geo2.bin";
67+
let url = "https://insight.libreqos.com/geo2.bin";
6868
let response = reqwest::blocking::get(url)?;
6969
let content = response.bytes()?;
7070
let bytes = &content[0..];
7171
std::fs::write(file_path, bytes)?;
72+
tracing::info!("Downloaded geo2.bin");
7273
Ok(())
7374
}
7475

76+
fn is_file_uptodate() -> anyhow::Result<bool> {
77+
let bytes = std::fs::read(&Self::file_path())?; // Vec<u8>
78+
let hash = sha256::digest(&bytes);
79+
80+
// Using blocking reqwest, retrieve the checksum as a string from https://insight.libreqos.com/geo/checksum
81+
let checksum = reqwest::blocking::get("https://insight.libreqos.com/geo/checksum")?.text()?;
82+
if checksum == hash {
83+
return Ok(true)
84+
}
85+
86+
Ok(false)
87+
}
88+
7589
pub fn load() -> anyhow::Result<Self> {
7690
let path = Self::file_path();
7791
if !path.exists() {
78-
info!("geo.bin not found - trying to download it");
92+
info!("geo2.bin not found - trying to download it");
7993
Self::download()?;
94+
} else {
95+
if !Self::is_file_uptodate().unwrap_or(true) {
96+
info!("geo2.bin is outdated - trying to download it");
97+
Self::download()?;
98+
}
8099
}
81100

82101
// Decompress and deserialize

0 commit comments

Comments
 (0)