Properly reset source key gc timers

After fixing #176 the source key garbage collection timers are not
updated if the source key is not adjusted. As a a result, in stable
networks source keys get garbage collected too frequently. Now we
properly reset them.

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet committed 2024-03-25 14:52:52 +01:00
1 parent 515f0470e8
commit a6fd2563d1
2 files changed
+24

No files matched your search

+4
View File
@@ -1245,6 +1245,10 @@ impl RouterInner {
self.expired_source_key_sink.clone(),
)
}
// We also reset the garbage collection timer (unless the update is a retraction)
else if !metric.is_infinite() {
source_table.reset_timer(source_key, self.expired_source_key_sink.clone());
}
}
// no entry for this source key, so insert it
else {
+20
View File
@@ -100,6 +100,26 @@ impl SourceTable {
};
}
/// Resets the garbage collection timer for a given source key.
///
/// Does nothing if the source key is not present.
pub fn reset_timer(&mut self, key: SourceKey, sink: mpsc::Sender<SourceKey>) {
self.table
.entry(key)
.and_modify(|(old_expiration_handle, _)| {
// First cancel the existing task
old_expiration_handle.abort();
// Then set the new one
*old_expiration_handle = tokio::spawn(async move {
tokio::time::sleep(SOURCE_HOLD_DURATION).await;
if let Err(e) = sink.send(key).await {
error!("Failed to notify router of expired source key {e}");
}
});
});
}
/// Get the [`FeasibilityDistance`] currently associated with the [`SourceKey`].
pub fn get(&self, key: &SourceKey) -> Option<&FeasibilityDistance> {
self.table.get(key).map(|(_, v)| v)