mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-17 15:07:43 +02:00
Don't download BGP Ris dumps if they were checked recently. (#279)
This commit is contained in:
@@ -41,7 +41,7 @@ impl BgpAnalyser {
|
||||
pub async fn update(&self) -> Result<bool, BgpAnalyserError> {
|
||||
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]
|
||||
|
||||
@@ -172,6 +172,7 @@ impl AsRef<TypedPrefix> for Announcement {
|
||||
pub struct Announcements {
|
||||
seen: TypedPrefixTree<Announcement>,
|
||||
last_updated: Option<Time>,
|
||||
last_checked: Option<Time>,
|
||||
}
|
||||
|
||||
impl Announcements {
|
||||
@@ -182,7 +183,13 @@ impl Announcements {
|
||||
}
|
||||
let tree = builder.build();
|
||||
self.seen = tree;
|
||||
self.last_updated = Some(Time::now());
|
||||
let now = Time::now();
|
||||
self.last_updated = Some(now);
|
||||
self.last_checked = Some(now);
|
||||
}
|
||||
|
||||
pub fn update_checked(&mut self) {
|
||||
self.last_checked = Some(Time::now())
|
||||
}
|
||||
|
||||
pub fn equivalent(&self, announcements: &[Announcement]) -> bool {
|
||||
@@ -207,6 +214,10 @@ impl Announcements {
|
||||
self.size() == 0
|
||||
}
|
||||
|
||||
pub fn last_checked(&self) -> Option<Time> {
|
||||
self.last_checked
|
||||
}
|
||||
|
||||
pub fn last_updated(&self) -> Option<Time> {
|
||||
self.last_updated
|
||||
}
|
||||
@@ -217,6 +228,7 @@ impl Default for Announcements {
|
||||
Announcements {
|
||||
seen: TypedPrefixTreeBuilder::default().build(),
|
||||
last_updated: None,
|
||||
last_checked: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user