From 5fab2cb712e3b56017d99d3fa5cfbe1c76c8a9cd Mon Sep 17 00:00:00 2001 From: Tim Bruijnzeels Date: Mon, 6 Jul 2020 12:19:58 +0200 Subject: [PATCH] Don't download BGP Ris dumps if they were checked recently. (#279) --- src/commons/bgp/analyser.rs | 9 +++++---- src/commons/bgp/announcements.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/commons/bgp/analyser.rs b/src/commons/bgp/analyser.rs index cffe2573..7f0ff21d 100644 --- a/src/commons/bgp/analyser.rs +++ b/src/commons/bgp/analyser.rs @@ -41,7 +41,7 @@ impl BgpAnalyser { pub async fn update(&self) -> Result { if let Some(loader) = &self.dumploader { let mut seen = self.seen.write().unwrap(); - if let Some(last_time) = seen.last_updated() { + if let Some(last_time) = seen.last_checked() { if (last_time + Duration::minutes(BGP_RIS_REFRESH_MINUTES)) > Time::now() { trace!("Will not check BGP Ris Dumps until the refresh interval has passed"); return Ok(false); // no need to update yet @@ -50,6 +50,7 @@ impl BgpAnalyser { let announcements = loader.download_updates().await?; if seen.equivalent(&announcements) { debug!("BGP Ris Dumps unchanged"); + seen.update_checked(); Ok(false) } else { info!( @@ -68,7 +69,7 @@ impl BgpAnalyser { let seen = self.seen.read().unwrap(); let mut entries = vec![]; - if seen.last_updated().is_none() { + if seen.last_checked().is_none() { // nothing to analyse, just push all ROAs as 'no announcement info' for roa in roas { entries.push(BgpAnalysisEntry::roa_no_announcement_info(*roa)); @@ -222,10 +223,10 @@ mod tests { let analyser = BgpAnalyser::new(true, bgp_risdump_v4_uri, bgp_risdump_v6_uri); assert!(analyser.seen.read().unwrap().is_empty()); - assert!(analyser.seen.read().unwrap().last_updated().is_none()); + assert!(analyser.seen.read().unwrap().last_checked().is_none()); analyser.update().await.unwrap(); assert!(!analyser.seen.read().unwrap().is_empty()); - assert!(analyser.seen.read().unwrap().last_updated().is_some()); + assert!(analyser.seen.read().unwrap().last_checked().is_some()); } #[test] diff --git a/src/commons/bgp/announcements.rs b/src/commons/bgp/announcements.rs index 8a45cf89..296fa69f 100644 --- a/src/commons/bgp/announcements.rs +++ b/src/commons/bgp/announcements.rs @@ -172,6 +172,7 @@ impl AsRef for Announcement { pub struct Announcements { seen: TypedPrefixTree, last_updated: Option