From 65d683404b0ad8e6f40e7ed2d6ac9a7b1bfd5e01 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:43:18 -0700 Subject: [PATCH] tools: wait for a path of their own before linking, as upstream's do --- crates/rns-tools/src/commands/rncp.rs | 2 +- crates/rns-tools/src/commands/rnpath.rs | 4 ++-- crates/rns-tools/src/commands/rnprobe.rs | 14 ++------------ crates/rns-tools/src/commands/rnstatus.rs | 4 ++-- crates/rns-tools/src/commands/rnx.rs | 4 ++-- crates/rns-tools/src/lib.rs | 15 +++++++++++++++ 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/crates/rns-tools/src/commands/rncp.rs b/crates/rns-tools/src/commands/rncp.rs index a08f93d..639a045 100644 --- a/crates/rns-tools/src/commands/rncp.rs +++ b/crates/rns-tools/src/commands/rncp.rs @@ -508,7 +508,7 @@ async fn wait_for_path( ) -> Duration { let deadline = Instant::now() + path_timeout(handle, timeout).await; let h = pretty_hex_rep(&dest_hash); - let has_path = || async { handle.has_path(dest_hash).await.unwrap_or(false) }; + let has_path = || async { rns_tools::has_local_path(handle, dest_hash).await }; if !has_path().await { let _ = handle .transport_tx diff --git a/crates/rns-tools/src/commands/rnpath.rs b/crates/rns-tools/src/commands/rnpath.rs index 32a3a71..0a36995 100644 --- a/crates/rns-tools/src/commands/rnpath.rs +++ b/crates/rns-tools/src/commands/rnpath.rs @@ -1253,7 +1253,7 @@ async fn await_remote_path( .unwrap_or(0.0), _ => 0.0, }; - if handle.has_path(dest).await.unwrap_or(false) { + if rns_tools::has_local_path(handle, dest).await { return Ok(()); } print!("Path to {} requested ", pretty_hex_rep(&dest)); @@ -1263,7 +1263,7 @@ async fn await_remote_path( .await; let deadline = deadline_after(timeout.max(medium)); loop { - if handle.has_path(dest).await.unwrap_or(false) { + if rns_tools::has_local_path(handle, dest).await { return Ok(()); } if deadline.is_some_and(|d| Instant::now() >= d) { diff --git a/crates/rns-tools/src/commands/rnprobe.rs b/crates/rns-tools/src/commands/rnprobe.rs index 28e9a88..fa7c605 100644 --- a/crates/rns-tools/src/commands/rnprobe.rs +++ b/crates/rns-tools/src/commands/rnprobe.rs @@ -173,7 +173,7 @@ async fn run(args: &Args, handle: &ReticulumHandle, dest_hash: [u8; 16], full_na let timeout = args.timeout.filter(|t| *t != 0.0); // rnprobe.py. - if !local_has_path(handle, dest_hash).await { + if !rns_tools::has_local_path(handle, dest_hash).await { let _ = handle .request_path(dest_hash, PathRequestOptions::default()) .await; @@ -184,7 +184,7 @@ async fn run(args: &Args, handle: &ReticulumHandle, dest_hash: [u8; 16], full_na } let path_deadline = deadline_after(probe_timeout(handle, dest_hash, timeout).await); let mut i = 0; - while !local_has_path(handle, dest_hash).await && !passed(path_deadline) { + while !rns_tools::has_local_path(handle, dest_hash).await && !passed(path_deadline) { tokio::time::sleep(Duration::from_millis(100)).await; if !json { print!("\u{8}\u{8}{} ", SPINNER[i]); @@ -568,16 +568,6 @@ async fn medium_path_timeout(handle: &ReticulumHandle) -> f64 { .unwrap_or(0.0) } -/// `RNS.Transport.has_path`: this process's own path table. -async fn local_has_path(handle: &ReticulumHandle, dest: [u8; 16]) -> bool { - matches!( - handle - .query_transport(TransportQuery::HasPath { dest }) - .await, - Some(TransportQueryResponse::BoolResult(true)) - ) -} - /// `RNS.Transport.hops_to`: this process's own path table. async fn local_hops(handle: &ReticulumHandle, dest: [u8; 16]) -> u8 { match handle diff --git a/crates/rns-tools/src/commands/rnstatus.rs b/crates/rns-tools/src/commands/rnstatus.rs index 7298d09..199e530 100644 --- a/crates/rns-tools/src/commands/rnstatus.rs +++ b/crates/rns-tools/src/commands/rnstatus.rs @@ -593,7 +593,7 @@ impl Session { ) -> Result, Option)>, u8> { let no_output = args.json; let destination = Destination::hash_from_name_and_identity(MGMT_APP, Some(&identity_hash)); - if !self.handle.has_path(destination).await.unwrap_or(false) { + if !rns_tools::has_local_path(&self.handle, destination).await { if !no_output { outp!(out, "Path to {} requested ", pretty_hex(&destination)); out.flush_now(); @@ -603,7 +603,7 @@ impl Session { .request_path(destination, PathRequestOptions::default()) .await; let started = std::time::Instant::now(); - while !self.handle.has_path(destination).await.unwrap_or(false) { + while !rns_tools::has_local_path(&self.handle, destination).await { tokio::time::sleep(Duration::from_millis(100)).await; if started.elapsed().as_secs_f64() > args.timeout { if !no_output { diff --git a/crates/rns-tools/src/commands/rnx.rs b/crates/rns-tools/src/commands/rnx.rs index d428fb0..a8e58b8 100644 --- a/crates/rns-tools/src/commands/rnx.rs +++ b/crates/rns-tools/src/commands/rnx.rs @@ -498,7 +498,7 @@ impl Client<'_> { async fn ensure_path(&self, timeout: Timeout) -> bool { let handle = self.handle; let hash = self.destination_hash; - if handle.has_path(hash).await.unwrap_or(false) { + if rns_tools::has_local_path(handle, hash).await { return true; } let _ = handle @@ -510,7 +510,7 @@ impl Client<'_> { let msg = format!("Path to <{}> requested", hex::encode(hash)); let found = spin(&msg, async { loop { - if handle.has_path(hash).await.unwrap_or(false) { + if rns_tools::has_local_path(handle, hash).await { return true; } tokio::time::sleep(Duration::from_millis(100)).await; diff --git a/crates/rns-tools/src/lib.rs b/crates/rns-tools/src/lib.rs index 4ef16e6..7a1768e 100644 --- a/crates/rns-tools/src/lib.rs +++ b/crates/rns-tools/src/lib.rs @@ -335,6 +335,21 @@ impl RpcRegistration { } } +/// Python `RNS.Transport.has_path`: this process's own path table. A +/// shared-instance client fills it from the path responses it asks for and +/// sends to a destination only once it holds a path; `ReticulumHandle::has_path` +/// asks the shared instance instead. +pub async fn has_local_path(handle: &ReticulumHandle, destination: [u8; 16]) -> bool { + matches!( + handle + .query_transport(rns_transport::messages::TransportQuery::HasPath { dest: destination }) + .await, + Some(rns_transport::messages::TransportQueryResponse::BoolResult( + true + )) + ) +} + /// Reticulum.get_medium_path_timeout (Reticulum.py): ask the shared /// instance, or compute Transport.medium_path_timeout (Transport.py) /// from the lowest online interface bitrate. 0 when unknown or on error.