transport: do not rebroadcast an announce that only replaces an unresponsive path

This commit is contained in:
DeFiDude committed 2026-11-18 12:33:10 -07:00
1 parent 20ed5a07b1
commit ad8c98cd0d
3 files changed
+54 -2

No files matched your search

+7 -2
View File
@@ -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
+1
View File
@@ -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;
@@ -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, &current, 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());
}