From 5182a7e38fda780e294978cef8a2c0bcdbe6220b Mon Sep 17 00:00:00 2001 From: Matthew Scheffel Date: Tue, 16 Jul 2024 21:19:03 -0300 Subject: [PATCH] Set age dynamically #504 --- src/core/pdu/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/pdu/mod.rs b/src/core/pdu/mod.rs index 0c54812e..a4254b08 100644 --- a/src/core/pdu/mod.rs +++ b/src/core/pdu/mod.rs @@ -116,7 +116,11 @@ impl PduEvent { .map_or_else(|| Ok(BTreeMap::new()), |u| serde_json::from_str(u.get())) .map_err(|_| Error::bad_database("Invalid unsigned in pdu event"))?; - unsigned.insert("age".to_owned(), to_raw_value(&1).unwrap()); + let now: u64 = MilliSecondsSinceUnixEpoch::now().get().into(); + let then: u64 = self.origin_server_ts.into(); + let this_age: u64 = now - then; + + unsigned.insert("age".to_owned(), to_raw_value(&this_age).unwrap()); self.unsigned = Some(to_raw_value(&unsigned).expect("unsigned is valid")); Ok(())