From c33b00fe32ed2e403406ba1389bfae8316a921d3 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 10 Dec 2023 16:29:52 -0500 Subject: [PATCH] clamp instead of reject max expiration time --- veilid-core/src/storage_manager/mod.rs | 15 +++++++++------ veilid-core/src/storage_manager/record_store.rs | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/veilid-core/src/storage_manager/mod.rs b/veilid-core/src/storage_manager/mod.rs index 31b5e48f..45749c24 100644 --- a/veilid-core/src/storage_manager/mod.rs +++ b/veilid-core/src/storage_manager/mod.rs @@ -642,14 +642,17 @@ impl StorageManager { expiration.as_u64() }; - // If the expiration time is less than our minimum expiration time or greater than the maximum time, consider this watch cancelled - if owvresult.expiration_ts.as_u64() < min_expiration_ts - || owvresult.expiration_ts.as_u64() > max_expiration_ts - { - // Don't set the watch so we ignore any stray valuechanged messages + // If the expiration time is less than our minimum expiration time consider this watch cancelled + let mut expiration_ts = owvresult.expiration_ts; + if expiration_ts.as_u64() < min_expiration_ts { return Ok(Timestamp::new(0)); } + // If the expiration time is greated than our maximum expiration time, clamp our local watch so we ignore extra valuechanged messages + if expiration_ts.as_u64() > max_expiration_ts { + expiration_ts = Timestamp::new(max_expiration_ts); + } + // If we requested a cancellation, then consider this watch cancelled if count == 0 { return Ok(Timestamp::new(0)); @@ -657,7 +660,7 @@ impl StorageManager { // Keep a record of the watch opened_record.set_active_watch(ActiveWatch { - expiration_ts: owvresult.expiration_ts, + expiration_ts, watch_node: owvresult.watch_node, opt_value_changed_route: owvresult.opt_value_changed_route, subkeys, diff --git a/veilid-core/src/storage_manager/record_store.rs b/veilid-core/src/storage_manager/record_store.rs index bca8266f..256107c4 100644 --- a/veilid-core/src/storage_manager/record_store.rs +++ b/veilid-core/src/storage_manager/record_store.rs @@ -760,9 +760,12 @@ where let cur_ts = get_timestamp(); let max_ts = cur_ts + self.limits.max_watch_expiration.as_u64(); let min_ts = cur_ts + self.limits.min_watch_expiration.as_u64(); - if expiration.as_u64() == 0 { + + if expiration.as_u64() == 0 || expiration.as_u64() > max_ts { + // Clamp expiration max time (or set zero expiration to max) expiration = Timestamp::new(max_ts); - } else if expiration.as_u64() < min_ts || expiration.as_u64() > max_ts { + } else if expiration.as_u64() < min_ts { + // Don't add watches with too low of an expiration time return Ok(None); }