From f6d0d698dd7e6edc180f9c3697ab1c873571f372 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:42:36 -0700 Subject: [PATCH] transport: a cached announce reports the emission time of the packet that last refreshed it --- api/snapshots/rns-transport.txt | 2 + api/stability.json | 4 +- crates/rns-transport/src/actor/inbound.rs | 5 +- crates/rns-transport/src/actor/maintenance.rs | 1 + crates/rns-transport/src/actor/mod.rs | 53 +++++++++++++++++++ crates/rns-transport/src/actor/persistence.rs | 3 ++ crates/rns-transport/src/actor/rpc.rs | 1 + .../rns-transport/src/actor/store_worker.rs | 2 + crates/rns-transport/src/messages.rs | 4 ++ crates/rns-transport/src/persistence.rs | 2 + 10 files changed, 73 insertions(+), 4 deletions(-) diff --git a/api/snapshots/rns-transport.txt b/api/snapshots/rns-transport.txt index 1f1c0c9..3cb444d 100644 --- a/api/snapshots/rns-transport.txt +++ b/api/snapshots/rns-transport.txt @@ -17,6 +17,7 @@ pub async fn rns_transport::actor::PersistenceTrigger::request(&self) -> bool pub struct rns_transport::actor::RecentAnnounce pub rns_transport::actor::RecentAnnounce::app_data: core::option::Option> pub rns_transport::actor::RecentAnnounce::dest_hash: [u8; 16] +pub rns_transport::actor::RecentAnnounce::emitted: core::option::Option pub rns_transport::actor::RecentAnnounce::facts_known: bool pub rns_transport::actor::RecentAnnounce::hops: u8 pub rns_transport::actor::RecentAnnounce::is_path_response: bool @@ -1363,6 +1364,7 @@ pub struct rns_transport::messages::AnnounceHandlerId(_) #[non_exhaustive] pub struct rns_transport::messages::AnnounceRpcEntry pub rns_transport::messages::AnnounceRpcEntry::app_data: core::option::Option> pub rns_transport::messages::AnnounceRpcEntry::dest_hash: [u8; 16] +pub rns_transport::messages::AnnounceRpcEntry::emitted: core::option::Option pub rns_transport::messages::AnnounceRpcEntry::facts_known: bool pub rns_transport::messages::AnnounceRpcEntry::hops: u8 pub rns_transport::messages::AnnounceRpcEntry::is_path_response: bool diff --git a/api/stability.json b/api/stability.json index b1bfbcc..2661c94 100644 --- a/api/stability.json +++ b/api/stability.json @@ -51,8 +51,8 @@ "tier": "provisional", "compatibility": "reviewed-snapshot", "snapshot": "api/snapshots/rns-transport.txt", - "itemCount": 2271, - "sha256": "ec003696e642b1b5696c04d65f885a0abce2888e820e8e88be121135af71706a" + "itemCount": 2273, + "sha256": "7894fdab76428a6fd8cd7097e60058409a6a593d8c4970c01c5d440e98613fa1" }, { "name": "rns-link", diff --git a/crates/rns-transport/src/actor/inbound.rs b/crates/rns-transport/src/actor/inbound.rs index ecf133a..e4ea8d9 100644 --- a/crates/rns-transport/src/actor/inbound.rs +++ b/crates/rns-transport/src/actor/inbound.rs @@ -845,6 +845,7 @@ impl TransportActor { let announce_identity_hash = Some(validated.identity_hash); let announce_random_hash = announce_data.random_hash; let announce_stamp_value = validated.stamp_value.unwrap_or(0.0); + let announce_emitted = announce_timebase(&announce_random_hash); // Python remembers every freshly validated announce, replays included, // before it decides whether the path changes; a validation-cache hit @@ -868,6 +869,7 @@ impl TransportActor { e.is_path_response = is_path_response; e.name_hash = announce_name_hash; e.facts_known = true; + e.emitted = Some(announce_emitted); self.kd.pending.mark_dirty(header.destination_hash); self.remember_received_ratchet(header.destination_hash, announce_ratchet); } @@ -891,6 +893,7 @@ impl TransportActor { stamp_value: announce_stamp_value, lr_cost: validated.lr_cost, facts_known: true, + emitted: Some(announce_emitted), }); self.state_dirty = true; self.kd.pending.mark_dirty(header.destination_hash); @@ -915,8 +918,6 @@ impl TransportActor { .map(|e| e.mode) .unwrap_or(InterfaceMode::Gateway); - let announce_emitted = announce_timebase(&announce_random_hash); - // Cancel our queued rebroadcast when a neighbor already carried it. // Same-hop neighbor rebroadcast counts toward the local cap; // strict hops+1 forward drops our queued copy outright. diff --git a/crates/rns-transport/src/actor/maintenance.rs b/crates/rns-transport/src/actor/maintenance.rs index 47e2cd4..6d4541f 100644 --- a/crates/rns-transport/src/actor/maintenance.rs +++ b/crates/rns-transport/src/actor/maintenance.rs @@ -762,6 +762,7 @@ mod cleanup_tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }; actor.recent_announces.insert(entry.dest_hash, entry); } diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index c96197f..d312725 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -391,6 +391,10 @@ pub struct RecentAnnounce { /// False for an entry restored from a row that carries no announce facts: /// `hops`, `name_hash`, and `is_path_response` are then unknown, not zero. pub facts_known: bool, + /// Emission time stamped into the random hash of the packet that last + /// refreshed this entry, which may be an older announce heard late; `None` + /// once restored from storage. + pub emitted: Option, } impl RecentAnnounce { @@ -3328,6 +3332,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -3401,6 +3406,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); } @@ -3500,6 +3506,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); } @@ -3526,6 +3533,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); let mut target_path = @@ -6349,6 +6357,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -6404,6 +6413,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); } @@ -8651,6 +8661,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); actor.blackhole_table.add_with_reason( @@ -9364,6 +9375,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }]; let dir = std::env::temp_dir().join("reticulum_rs_test_announce_cache"); @@ -9667,6 +9679,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -9931,6 +9944,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -11660,6 +11674,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -12308,6 +12323,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -12570,6 +12586,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -12661,6 +12678,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -12809,6 +12827,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); @@ -13291,6 +13310,39 @@ mod tests { assert_eq!(hrx.try_recv().unwrap().emitted, emitted); } + /// Once the path is gone an older announce is accepted again (Transport.py) + /// and refreshes the cache, so the entry carries its own, older emission. + #[test] + fn cached_announce_reports_the_emission_of_the_packet_that_refreshed_it() { + let (mut actor, _tx) = TransportActor::new(); + let (entry, _rx) = make_test_interface("test_iface"); + actor.interfaces.insert(1, entry); + let identity = rns_identity::identity::Identity::new(); + for (prefix, emitted) in [(0x41, 1_700_000_100), (0x42, 1_700_000_000)] { + let (raw, dest_hash) = make_announce_for_with_random_blob( + &identity, + "test.emitted", + 1, + random_blob(prefix, emitted), + ); + actor.on_inbound(crate::messages::InboundPacket { + raw, + interface_id: 1, + rssi: None, + snr: None, + q: None, + }); + let crate::messages::TransportQueryResponse::Announces(entries) = + actor.handle_query(crate::messages::TransportQuery::GetRecentAnnounces) + else { + panic!("expected Announces"); + }; + let cached = entries.iter().find(|e| e.dest_hash == dest_hash).unwrap(); + assert_eq!(cached.emitted, Some(emitted)); + actor.path_table.remove(&dest_hash); + } + } + #[test] fn path_response_bypasses_announce_rate_limit() { let (mut actor, _tx) = TransportActor::new(); @@ -13586,6 +13638,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); } diff --git a/crates/rns-transport/src/actor/persistence.rs b/crates/rns-transport/src/actor/persistence.rs index 12f7c9d..39cdcb7 100644 --- a/crates/rns-transport/src/actor/persistence.rs +++ b/crates/rns-transport/src/actor/persistence.rs @@ -43,6 +43,7 @@ fn recent_announce_from_cached_packet( stamp_value: 0.0, lr_cost: None, facts_known: false, + emitted: None, }; if let Ok((header, offset)) = rns_wire::header::PacketHeader::unpack(&raw_packet) @@ -1282,6 +1283,7 @@ mod announce_clean_tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); actor @@ -1527,6 +1529,7 @@ mod async_save_tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }, ); let now = crate::now_f64(); diff --git a/crates/rns-transport/src/actor/rpc.rs b/crates/rns-transport/src/actor/rpc.rs index d1ddeb2..d17b785 100644 --- a/crates/rns-transport/src/actor/rpc.rs +++ b/crates/rns-transport/src/actor/rpc.rs @@ -243,6 +243,7 @@ impl TransportActor { is_path_response, retained: a.retained, facts_known: a.facts_known, + emitted: a.emitted, } }) .collect(); diff --git a/crates/rns-transport/src/actor/store_worker.rs b/crates/rns-transport/src/actor/store_worker.rs index 6c3565d..aa61eb7 100644 --- a/crates/rns-transport/src/actor/store_worker.rs +++ b/crates/rns-transport/src/actor/store_worker.rs @@ -1289,6 +1289,7 @@ pub(super) fn recent_from_row(row: KnownDestinationRow) -> RecentAnnounce { stamp_value: row.stamp_value, lr_cost: row.lr_cost, facts_known: facts.is_some(), + emitted: None, } } @@ -1372,6 +1373,7 @@ mod tests { stamp_value: 0.0, lr_cost: Some(3.0), facts_known: true, + emitted: None, } } diff --git a/crates/rns-transport/src/messages.rs b/crates/rns-transport/src/messages.rs index 398d70f..30df399 100644 --- a/crates/rns-transport/src/messages.rs +++ b/crates/rns-transport/src/messages.rs @@ -1618,6 +1618,10 @@ pub struct AnnounceRpcEntry { /// `hops`, `name_hash`, and `is_path_response` are then unknown, and hold /// zero and `false` only as placeholders. pub facts_known: bool, + /// Unix seconds the announcer stamped into the cached announce's random + /// hash. A copy of an older announce accepted late carries its own, older + /// time; `None` for an entry restored from storage. + pub emitted: Option, } /// Identity-bearing metadata returned by [`TransportQuery::RecallDestination`]. diff --git a/crates/rns-transport/src/persistence.rs b/crates/rns-transport/src/persistence.rs index 862c43d..ad8ea71 100644 --- a/crates/rns-transport/src/persistence.rs +++ b/crates/rns-transport/src/persistence.rs @@ -2296,6 +2296,7 @@ mod tests { stamp_value: 0.0, lr_cost: None, facts_known: true, + emitted: None, }]; let dir = std::env::temp_dir().join("reticulum_rs_test_announce_persist"); @@ -2336,6 +2337,7 @@ mod tests { stamp_value: 25.5, lr_cost: Some(12.5), facts_known: true, + emitted: None, }; let dir = std::env::temp_dir().join(format!("rns_announce_stamp_fields_{}", std::process::id()));