From ad8c98cd0d970b5f3f4c0014be786ecbfc257ead Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:33:10 -0700 Subject: [PATCH] transport: do not rebroadcast an announce that only replaces an unresponsive path --- crates/rns-transport/src/actor/inbound.rs | 9 +++- crates/rns-transport/src/actor/mod.rs | 1 + .../src/actor/tests/announce_rebroadcast.rs | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 crates/rns-transport/src/actor/tests/announce_rebroadcast.rs diff --git a/crates/rns-transport/src/actor/inbound.rs b/crates/rns-transport/src/actor/inbound.rs index c870ce9..1cfa971 100644 --- a/crates/rns-transport/src/actor/inbound.rs +++ b/crates/rns-transport/src/actor/inbound.rs @@ -900,6 +900,9 @@ impl TransportActor { .unwrap_or_default(); let suppressed = self.is_path_interface_suppressed(header.destination_hash, interface_id, now_f64()); + // Transport.py: an unresponsive path takes the same emission with more + // hops, but the announce is not rebroadcast. + let mut table_insertion_only = false; let should_add = if suppressed { false } else if let Some(existing) = self.path_table.get(&header.destination_hash) { @@ -922,8 +925,9 @@ impl TransportActor { } else if existing.is_expired() || announce_emitted > path_timebase { !random_seen } else if announce_emitted == path_timebase { - self.path_table.get_state(&header.destination_hash) - == crate::constants::PathState::Unresponsive + table_insertion_only = self.path_table.get_state(&header.destination_hash) + == crate::constants::PathState::Unresponsive; + table_insertion_only } else { false } @@ -966,6 +970,7 @@ impl TransportActor { // check above compares against our own queued copy. Non-transport // nodes never queue (would amplify the announce per hub). if !rate_blocked + && !table_insertion_only && (self.is_transport_enabled || is_from_local_client) && header.context != rns_wire::context::PacketContext::PathResponse && header.hops < PATHFINDER_M diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 9adb1fb..83be0db 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -2590,6 +2590,7 @@ mod tests { mod announce_admission; mod announce_identity; mod announce_ingress; + mod announce_rebroadcast; mod bitrate_timing; mod discovery_api; mod discovery_public_api; diff --git a/crates/rns-transport/src/actor/tests/announce_rebroadcast.rs b/crates/rns-transport/src/actor/tests/announce_rebroadcast.rs new file mode 100644 index 0000000..76feca7 --- /dev/null +++ b/crates/rns-transport/src/actor/tests/announce_rebroadcast.rs @@ -0,0 +1,46 @@ +//! Python 1.6.1 rebroadcast rules (Transport.py): an unresponsive path +//! replaced by the same emission is not rebroadcast (`table_insertion_only`). +use super::*; + +const APP: &str = "rebroadcast.test"; + +fn inbound(actor: &mut TransportActor, raw: &Bytes, interface_id: InterfaceId) { + actor.on_inbound(InboundPacket { + raw: raw.clone(), + interface_id, + rssi: None, + snr: None, + q: None, + }); +} + +/// Transport.py `table_insertion_only`: the same emission with more hops +/// replaces an unresponsive path but queues no rebroadcast. +#[test] +fn an_unresponsive_path_taken_by_the_same_emission_is_not_rebroadcast() { + let _clock = crate::test_clock::Clock::at(1_800_000_000.0); + let (mut actor, _) = TransportActor::new(); + actor.is_transport_enabled = true; + actor.transport_identity_hash = Some([0x42; 16]); + let mut rx = Vec::new(); + for id in [1, 2] { + let (entry, receiver) = make_test_interface(&format!("rebroadcast_{id}")); + actor.interfaces.insert(id, entry); + rx.push(receiver); + } + let identity = rns_identity::identity::Identity::new(); + let blob = random_blob(0xA4, 6000); + let (current, destination) = make_announce_for_with_random_blob(&identity, APP, 1, blob); + let (replay, _) = make_announce_for_with_random_blob(&identity, APP, 5, blob); + inbound(&mut actor, ¤t, 1); + actor.announce_table.remove(&destination); + actor + .path_table + .set_state(destination, crate::constants::PathState::Unresponsive); + + inbound(&mut actor, &replay, 2); + + let path = actor.path_table.get(&destination).unwrap(); + assert_eq!((path.hops, path.interface_id), (6, 2)); + assert!(actor.announce_table.get(&destination).is_none()); +}