From b50a97378649ca2467b5e02eda17c76b99e22d23 Mon Sep 17 00:00:00 2001 From: dawn Date: Fri, 16 Oct 2026 20:45:59 +0300 Subject: [PATCH] knot-config: add how long a member's read lease lasts Signed-off-by: dawn --- knot2/crates/knot-config/src/lib.rs | 23 +++++++++++++++++++++++ knot2/example.toml | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/knot2/crates/knot-config/src/lib.rs b/knot2/crates/knot-config/src/lib.rs index 8d808836e..8032ff1ef 100644 --- a/knot2/crates/knot-config/src/lib.rs +++ b/knot2/crates/knot-config/src/lib.rs @@ -46,6 +46,8 @@ pub struct KnotConfig { #[config(nested)] pub keyfill: KeyfillConfig, #[config(nested)] + pub leases: LeasesConfig, + #[config(nested)] pub resources: ResourcesConfig, #[config(nested)] pub homepage: HomepageConfig, @@ -477,6 +479,12 @@ pub struct KeyfillConfig { pub reprieve_budget_secs: u64, } +#[derive(Debug, Config)] +pub struct LeasesConfig { + #[config(env = "KNOT_LEASES_TTL_DAYS", default = 3)] + pub ttl_days: u32, +} + #[derive(Debug, Config)] pub struct ResourcesConfig { #[config(env = "KNOT_MAX_THREADS", default = 0)] @@ -806,6 +814,10 @@ impl KnotConfig { self.keyfill.reprieve_budget_secs >= self.keyfill.reprieve_retry_secs, "keyfill.reprieve_budget_secs must be at least keyfill.reprieve_retry_secs", ), + check( + (1..=MAX_SPAN_SECS / 86_400).contains(&u64::from(self.leases.ttl_days)), + "leases.ttl_days must be between one day and one year", + ), check( self.maintenance.interval_secs > 0, "maintenance.interval_secs must be greater than zero", @@ -1387,6 +1399,7 @@ mod tests { reprieve_retry_secs: 300, reprieve_budget_secs: 21_600, }, + leases: LeasesConfig { ttl_days: 3 }, resources: ResourcesConfig { max_threads: 0, max_memory_bytes: 0, @@ -1732,6 +1745,16 @@ mod tests { }, "keyfill.reprieve_budget_secs must be at least", ), + ( + "a_lease_ttl_of_zero_days", + |config| config.leases.ttl_days = 0, + "leases.ttl_days", + ), + ( + "a_lease_ttl_past_a_year", + |config| config.leases.ttl_days = 366, + "leases.ttl_days", + ), ( "a_non_https_plc_directory", |config| { diff --git a/knot2/example.toml b/knot2/example.toml index 5f6bcb1bc..cffbb0dea 100644 --- a/knot2/example.toml +++ b/knot2/example.toml @@ -461,6 +461,11 @@ # Default value: 21600 #reprieve_budget_secs = 21600 +[leases] +# Can also be specified via environment variable `KNOT_LEASES_TTL_DAYS`. +# Default value: 3 +#ttl_days = 3 + [resources] # Can also be specified via environment variable `KNOT_MAX_THREADS`. # Default value: 0 -- 2.54.0