diff --git a/CHANGELOG.md b/CHANGELOG.md index 4499db3..56d9c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Announce handler events carry `emitted`, the time the announcer stamped into the announce, so an application can tell an older cached announce in a path response from a newer one. `AnnounceHandlerEvent` struct literals need the new field. + ## 1.5.0 - 2026-11-13 ### Added diff --git a/api/snapshots/rns-transport.txt b/api/snapshots/rns-transport.txt index ce92916..1b8d29d 100644 --- a/api/snapshots/rns-transport.txt +++ b/api/snapshots/rns-transport.txt @@ -1308,6 +1308,7 @@ pub struct rns_transport::messages::AnnounceHandlerEvent pub rns_transport::messages::AnnounceHandlerEvent::announce_packet_hash: [u8; 32] pub rns_transport::messages::AnnounceHandlerEvent::app_data: core::option::Option> pub rns_transport::messages::AnnounceHandlerEvent::destination_hash: [u8; 16] +pub rns_transport::messages::AnnounceHandlerEvent::emitted: u64 pub rns_transport::messages::AnnounceHandlerEvent::hops: u8 pub rns_transport::messages::AnnounceHandlerEvent::identity_hash: core::option::Option<[u8; 16]> pub rns_transport::messages::AnnounceHandlerEvent::is_path_response: bool diff --git a/api/stability.json b/api/stability.json index 9b1216f..1e3c9ec 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": 2160, - "sha256": "18a2a12e0f5ab6de901b7d439708e131e1756db23dafabd117153229067ca882" + "itemCount": 2161, + "sha256": "486f79c541ecec9e815cd082aec536dfd805acb4947498a7efde8c25632f56a2" }, { "name": "rns-link", diff --git a/crates/rns-transport/src/actor/inbound.rs b/crates/rns-transport/src/actor/inbound.rs index 4944a82..8289dce 100644 --- a/crates/rns-transport/src/actor/inbound.rs +++ b/crates/rns-transport/src/actor/inbound.rs @@ -1090,6 +1090,7 @@ impl TransportActor { announce_packet_hash, is_path_response, hops: header.hops, + emitted: announce_emitted, app_data: handler_app_data.clone(), public_key: announce_public_key, ratchet: announce_ratchet, diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 6fcbf2f..0a7777d 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -13006,6 +13006,7 @@ mod tests { rns_wire::context::PacketContext::PathResponse, ); let expected_hash = rns_wire::hash::packet_hash(&raw, rns_wire::flags::HeaderType::Header1); + let expected_emitted = announce_emitted_from_raw(&raw).unwrap(); actor.on_inbound(crate::messages::InboundPacket { raw, interface_id: 1, @@ -13024,6 +13025,43 @@ mod tests { assert_eq!(event.destination_hash, dest_hash); assert_eq!(event.announce_packet_hash, expected_hash); assert!(event.is_path_response); + assert_eq!(event.emitted, expected_emitted); + } + + #[test] + fn handler_event_carries_the_stamped_emission_time() { + let (mut actor, _tx) = TransportActor::new(); + let (entry, _rx) = make_test_interface("test_iface"); + actor.interfaces.insert(1, entry); + + let (htx, mut hrx) = mpsc::channel(8); + actor.announce_handlers.push(AnnounceHandlerRegistration { + id: crate::messages::AnnounceHandlerId(0), + ownership: AnnounceHandlerOwnership::Subscription, + aspect_filter: None, + receive_path_responses: false, + tx: htx, + dropped_events: Arc::new(AtomicU64::new(0)), + paused: Arc::new(AtomicBool::new(false)), + }); + + let emitted = 1_700_000_000; + let identity = rns_identity::identity::Identity::new(); + let (raw, _) = make_announce_for_with_random_blob( + &identity, + "test.emitted", + 1, + random_blob(0x33, emitted), + ); + actor.on_inbound(crate::messages::InboundPacket { + raw, + interface_id: 1, + rssi: None, + snr: None, + q: None, + }); + + assert_eq!(hrx.try_recv().unwrap().emitted, emitted); } #[test] diff --git a/crates/rns-transport/src/discovery/receiver.rs b/crates/rns-transport/src/discovery/receiver.rs index 89528b5..22386b3 100644 --- a/crates/rns-transport/src/discovery/receiver.rs +++ b/crates/rns-transport/src/discovery/receiver.rs @@ -845,6 +845,7 @@ mod tests { announce_packet_hash: [0x22; 32], is_path_response: false, hops: 3, + emitted: 0, app_data: Some(app_data), public_key: None, ratchet: None, @@ -921,6 +922,7 @@ mod tests { announce_packet_hash: [0; 32], is_path_response: false, hops: 0, + emitted: 0, app_data: None, public_key: None, ratchet: None, diff --git a/crates/rns-transport/src/messages.rs b/crates/rns-transport/src/messages.rs index 303a708..56a81fb 100644 --- a/crates/rns-transport/src/messages.rs +++ b/crates/rns-transport/src/messages.rs @@ -629,6 +629,8 @@ pub struct AnnounceHandlerEvent { pub announce_packet_hash: [u8; 32], pub is_path_response: bool, pub hops: u8, + /// Unix seconds the announcer stamped into the random hash (Python `Transport.announce_emitted`). + pub emitted: u64, pub app_data: Option>, /// X25519 || Ed25519 public key from the announce payload. pub public_key: Option<[u8; 64]>,