From 9bd2b80fba65cfc1477ee9c8deec168cd193ded9 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:51:06 -0700 Subject: [PATCH] transport: a repeated path request keeps its queued answer's time --- CHANGELOG.md | 2 +- crates/rns-transport/src/actor/mod.rs | 58 ++++++++++++++++++++++ crates/rns-transport/src/actor/outbound.rs | 25 ++++++++-- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c11a6..1509f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ - Interface start-up code is compiled once instead of again in every crate that starts the runtime, which makes `rnsd-rs` about 1.5 MB smaller. - Bluetooth RNodes report battery, temperature, and channel load in the interface stats, as USB RNodes already do (`battery_state`, `battery_percent`, `cpu_temp`, `noise_floor`). - Bluetooth Peer: on Android, a link the app closes after a failed write reports `Disconnected`, so the peer no longer stays listed as connected. On Linux, disconnecting a peer reports it too, and the Central role keeps looking for a Bluetooth adapter that appears after start-up instead of giving up until restart. -- Path requests are handled as in Python Reticulum 1.6.0. A node that knows a path but can't read its cached announce ignores the request instead of searching the network and blocking later requests for 45 seconds. A queued path response is dropped once other nodes are heard answering. Requests that arrive during a path-request burst are counted and checked before they wait, so duplicates no longer crowd out real ones. A search answer now also reaches a requester on the roaming interface it arrived on. +- Path requests are handled as in Python Reticulum 1.6.0. A node that knows a path but can't read its cached announce ignores the request instead of searching the network and blocking later requests for 45 seconds. A queued path response is dropped once other nodes are heard answering. Requests that arrive during a path-request burst are counted and checked before they wait, so duplicates no longer crowd out real ones. A search answer now also reaches a requester on the roaming interface it arrived on. A node asked again for a path it's about to answer keeps the answer's time, so a requester that repeats quickly is no longer left waiting forever. - 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 diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 7063d68..2386e7a 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -12424,6 +12424,64 @@ mod tests { } } + /// A requester repeating faster than the grace still gets an answer: the + /// queued answer keeps its time instead of restarting the grace. + #[test] + fn repeated_path_requests_do_not_postpone_the_answer() { + let dir = std::env::temp_dir().join("rns_path_response_repeat"); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + + let (mut actor, _tx) = TransportActor::new(); + actor.is_transport_enabled = true; + actor.transport_identity_hash = Some([0x44; 16]); + actor.storage_dir = Some(dir.clone()); + actor.kd.attach_storage(&dir); + let (mut requestor, mut requestor_rx) = make_test_interface("requestor"); + requestor.ingress = crate::ingress::IngressController::disabled(); + actor.interfaces.insert(1, requestor); + let (next_hop_iface, _rx2) = make_test_interface("next_hop_iface"); + actor.interfaces.insert(2, next_hop_iface); + + let (raw, dest) = make_valid_announce("test.path.response.repeat", 1); + let ph = rns_wire::hash::packet_hash(&raw, rns_wire::flags::HeaderType::Header1); + crate::store::seed_cached_announce(&dir, &ph, &raw, None).unwrap(); + let mut path_entry = + crate::path_table::PathEntry::new(Some([0xAB; 16]), 2, 2, InterfaceMode::Gateway); + path_entry.packet_hash = Some(ph); + actor.path_table.insert(dest, path_entry); + + // Requests every 0.5 s, ticks every 0.25 s: no tick falls inside a + // restarted 0.4 s grace. + let start = now_f64(); + let clock = crate::test_clock::Clock::at(start); + actor.last_announces_check = start; + let mut answered = false; + for step in 0..=80u8 { + clock.set(start + f64::from(step) * 0.05); + if step % 10 == 0 { + let tag = [step.wrapping_add(1); 16]; + actor.handle_inbound_path_request( + &make_path_request_payload_with_tag(dest, None, tag), + 1, + ); + } + if step % 5 == 0 { + actor.on_tick(); + } + while let Ok(sent) = requestor_rx.try_recv() { + let (header, _) = rns_wire::header::PacketHeader::unpack(&sent).unwrap(); + answered |= header.destination_hash == dest + && header.context == rns_wire::context::PacketContext::PathResponse; + } + if answered { + break; + } + } + assert!(answered, "a path response reaches the requester"); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] fn known_path_response_restores_displaced_announce() { let dir = std::env::temp_dir().join("rns_path_request_held"); diff --git a/crates/rns-transport/src/actor/outbound.rs b/crates/rns-transport/src/actor/outbound.rs index 7b1eb95..21c0497 100644 --- a/crates/rns-transport/src/actor/outbound.rs +++ b/crates/rns-transport/src/actor/outbound.rs @@ -889,14 +889,29 @@ impl TransportActor { }; PATH_REQUEST_GRACE + roaming_extra }; - if let Some(held_entry) = self.announce_table.remove(&requested_dest) { - self.held_announces.insert(requested_dest, held_entry); - } + // A repeat request keeps the time of an answer already queued to the + // same interface; Transport.py restarts the grace, so a requester + // repeating faster than grace plus the announce check is never answered. + let queued = self.announce_table.get(&requested_dest).filter(|entry| { + entry.block_rebroadcast && entry.attached_interface == Some(interface_id) + }); + let (timestamp, retransmit_timeout) = match queued { + Some(entry) => ( + entry.timestamp, + entry.retransmit_timeout.min(now + response_delay), + ), + None => { + if let Some(held_entry) = self.announce_table.remove(&requested_dest) { + self.held_announces.insert(requested_dest, held_entry); + } + (now, now + response_delay) + } + }; self.announce_table.insert( requested_dest, crate::announce::AnnounceEntry { - timestamp: now, - retransmit_timeout: now + response_delay, + timestamp, + retransmit_timeout, // Transport.py: lets an overheard answer cancel this one. retries: PATHFINDER_R, hops,