Make geotable only load once.

This commit is contained in:
Herbert Wolverson 2024-11-09 10:18:27 -06:00
parent 11c8a25c1c
commit 0ce2c9ba6d
2 changed files with 11 additions and 12 deletions

View File

@ -62,7 +62,7 @@ impl GeoTable {
}
fn download() -> anyhow::Result<()> {
debug!("Downloading ASN-IP Table");
tracing::warn!("Downloading ASN-IP Table");
let file_path = Self::file_path();
let url = "https://stats.libreqos.io/geo2.bin";
let response = reqwest::blocking::get(url)?;

View File

@ -26,19 +26,16 @@ pub struct FlowAnalysisSystem {
impl FlowAnalysisSystem {
pub fn new() -> Self {
// Periodically update the ASN table
// Moved from being periodically updated to being updated on startup
let _ = std::thread::Builder::new().name("GeoTable Updater".to_string()).spawn(|| {
loop {
let result = asn::GeoTable::load();
match result {
Ok(table) => {
ANALYSIS.asn_table.lock().unwrap().replace(table);
}
Err(e) => {
error!("Failed to update ASN table: {e}");
}
let result = asn::GeoTable::load();
match result {
Ok(table) => {
ANALYSIS.asn_table.lock().unwrap().replace(table);
}
Err(e) => {
error!("Failed to update ASN table: {e}");
}
std::thread::sleep(std::time::Duration::from_secs(60 * 60 * 24));
}
});
@ -61,6 +58,8 @@ impl FlowAnalysisSystem {
}
pub fn setup_flow_analysis() -> anyhow::Result<()> {
// This is locking the table, which triggers lazy-loading of the
// data. It's not actually doing nothing.
let e = ANALYSIS.asn_table.lock();
if e.is_err() {
anyhow::bail!("Failed to lock ASN table");