mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-10-23 06:01:16 +00:00
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:
2 files changed
+24
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user