tools: wait for a path of their own before linking, as upstream's do

This commit is contained in:
DeFiDude committed 2026-11-18 15:19:58 -07:00
1 parent 4c4418ca93
commit 65d683404b
6 files changed
+24 -19

No files matched your search

+1 -1
View File
@@ -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
+2 -2
View File
@@ -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) {
+2 -12
View File
@@ -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
+2 -2
View File
@@ -593,7 +593,7 @@ impl Session {
) -> Result<Option<(Value, Option<Value>, Option<Value>)>, 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 {
+2 -2
View File
@@ -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;
+15
View File
@@ -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.