From 692260e79bbe642d073103391a2d737219fa8fb3 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Sun, 25 Oct 2026 07:11:57 -0600 Subject: [PATCH] status: name the network an auto-connected interface came from --- CHANGELOG.md | 1 + api/snapshots/rns-runtime.txt | 1 + api/stability.json | 4 +- crates/rns-runtime/src/reticulum.rs | 26 ++++++++-- .../src/reticulum/tests/autoconnect.rs | 47 +++++++++++++++++++ crates/rns-runtime/src/rpc.rs | 10 +++- crates/rns-runtime/src/rpc_server.rs | 2 + 7 files changed, 85 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d7dadf..7329997 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - `rnpath -R` filters the remote path and rate tables as Python Reticulum compares them: a destination hash of another length matches nothing, and the hop limit compares as a number instead of wrapping above 255. - Remote management Links refuse Resources other than requests and responses, as Python Reticulum's do. - `rnsd-rs` never auto-connects a discovered interface at an onion address, at 127.0.0.1 or 0.0.0.0, or at a host and port that an interface already connects to, as in Python Reticulum. +- Interface stats name the network an auto-connected interface was discovered through (`autoconnect_source`), as in Python Reticulum. ## 1.4.0 - 2026-10-12 diff --git a/api/snapshots/rns-runtime.txt b/api/snapshots/rns-runtime.txt index d12f141..155549a 100644 --- a/api/snapshots/rns-runtime.txt +++ b/api/snapshots/rns-runtime.txt @@ -2031,6 +2031,7 @@ pub rns_runtime::rpc::InterfaceStatEntry::announce_rate_penalty: core::option::O pub rns_runtime::rpc::InterfaceStatEntry::announce_rate_target: core::option::Option pub rns_runtime::rpc::InterfaceStatEntry::announces_received: u64 pub rns_runtime::rpc::InterfaceStatEntry::announces_sent: u64 +pub rns_runtime::rpc::InterfaceStatEntry::autoconnect_source: core::option::Option pub rns_runtime::rpc::InterfaceStatEntry::bitrate: u64 pub rns_runtime::rpc::InterfaceStatEntry::blocked_ips: core::option::Option pub rns_runtime::rpc::InterfaceStatEntry::burst_activated: f64 diff --git a/api/stability.json b/api/stability.json index e720361..411a8b7 100644 --- a/api/stability.json +++ b/api/stability.json @@ -87,8 +87,8 @@ "tier": "provisional", "compatibility": "reviewed-snapshot", "snapshot": "api/snapshots/rns-runtime.txt", - "itemCount": 2142, - "sha256": "a318326e7ce8e7bace2e2bcb3299e96cd18a8eb89d3f0703921ea12712fb3bc0" + "itemCount": 2143, + "sha256": "bbc823bcc6673a564785b135ee2f73404bcdaa4a231b2b112589e422e7b19654" }, { "name": "rns-tools", diff --git a/crates/rns-runtime/src/reticulum.rs b/crates/rns-runtime/src/reticulum.rs index 8092de4..a6880b4 100644 --- a/crates/rns-runtime/src/reticulum.rs +++ b/crates/rns-runtime/src/reticulum.rs @@ -67,12 +67,16 @@ struct InterfaceControlMetadata { /// The host and port a client interface connects to (Python /// `target_ip`, `target_port`), which auto-connect checks. client_target: Option<(String, u16)>, + /// The network identity, in hex, that announced an auto-connected + /// interface (Python `autoconnect_source`, Discovery.py:865). + autoconnect_source: Option, } type InterfaceControlMap = Arc>>; -/// IFAC fields of Python's interface stats, from the runtime's registration -/// records: all `None` for an interface without IFAC. +/// The fields of Python's interface stats that come from the runtime's +/// registration records: IFAC, all `None` for an interface without it, and +/// the auto-connect source. #[derive(Clone)] pub(crate) struct InterfaceIfacStats(InterfaceControlMap); @@ -106,6 +110,14 @@ impl InterfaceIfacStats { netname, } } + + pub(crate) fn autoconnect_source(&self, id: u64) -> Option { + self.0 + .lock() + .expect("interface_controls mutex poisoned") + .get(&id) + .and_then(|control| control.autoconnect_source.clone()) + } } #[derive(Default)] @@ -4629,6 +4641,7 @@ async fn prepare_interface_with_role_and_overrides( ifac_size, ifac_netname, client_target: None, + autoconnect_source: None, }, ); } @@ -4935,6 +4948,7 @@ async fn prepare_interface_with_post_init( ifac_size: post_init.ifac_size.unwrap_or(post_init.default_ifac_size), ifac_netname: ifac_key.and(post_init.ifac_network_name.clone()), client_target: None, + autoconnect_source: None, }, ); let entry = rns_transport::messages::InterfaceEntry { @@ -6608,7 +6622,10 @@ async fn spawn_discovered_backbone_client( ) .await .map_err(|error| format!("Backbone client registration failed: {error}"))?; - record_client_target(&handle.interface_controls, id, host, port); + update_interface_control(&handle.interface_controls, id, |control| { + control.client_target = Some((host.to_string(), port)); + control.autoconnect_source = Some(hex::encode(record.network_id)); + }); tracing::info!(name = %name, id, endpoint = %format!("{host}:{port}"), "auto-connected discovered interface"); Ok(id) } @@ -8774,6 +8791,7 @@ mod tests { ifac_size: 0, ifac_netname: None, client_target: None, + autoconnect_source: None, }, ); @@ -8920,6 +8938,7 @@ mod tests { ifac_size: 0, ifac_netname: None, client_target: None, + autoconnect_source: None, }, ); drop(registration); @@ -14186,6 +14205,7 @@ egress_control = Yes ifac_size: 0, ifac_netname: None, client_target: None, + autoconnect_source: None, }, ); diff --git a/crates/rns-runtime/src/reticulum/tests/autoconnect.rs b/crates/rns-runtime/src/reticulum/tests/autoconnect.rs index 3ebde89..5198b5a 100644 --- a/crates/rns-runtime/src/reticulum/tests/autoconnect.rs +++ b/crates/rns-runtime/src/reticulum/tests/autoconnect.rs @@ -121,3 +121,50 @@ async fn autoconnect_connects_once_per_endpoint() { handle.shutdown_and_wait().await; let _ = std::fs::remove_dir_all(dir); } + +/// Python names the network that announced an auto-connected interface in +/// its stats, as the announcer's identity hash in hex (Discovery.py:865, +/// Reticulum.py:1611-1612), and `rnstatus` prints it (rnstatus.py:525-526). +#[tokio::test] +async fn an_autoconnected_interface_names_its_source() { + let (uplink_port, port) = (unused_port().await, unused_port().await); + let dir = config_dir("source", &hub_config(uplink_port)); + let handle = start(&dir).await; + maybe_autoconnect_discovered(&handle, discovered("sourced", "localhost", port)).await; + let id = *handle + .discovery + .autoconnected + .lock() + .await + .values() + .next() + .expect("the interface auto-connected"); + + let Some(TransportQueryResponse::InterfaceStats(entries)) = handle + .query_transport(TransportQuery::GetInterfaceStats) + .await + else { + panic!("no interface stats"); + }; + let records = InterfaceIfacStats(handle.interface_controls.clone()); + let stats = crate::rpc_server::stat_entries(entries, Some(&records)); + let source = |name: &str| { + stats + .iter() + .find(|entry| entry.name == name) + .unwrap_or_else(|| panic!("{name} is listed")) + .autoconnect_source + .clone() + }; + let autoconnected_name = stats + .iter() + .find(|entry| entry.id == id) + .expect("the auto-connected interface is listed") + .name + .clone(); + assert_eq!(source(&autoconnected_name), Some(hex::encode([0x5a; 16]))); + assert_eq!(source("Uplink"), None); + + handle.shutdown_and_wait().await; + let _ = std::fs::remove_dir_all(dir); +} diff --git a/crates/rns-runtime/src/rpc.rs b/crates/rns-runtime/src/rpc.rs index 7849cb2..31cdb6a 100644 --- a/crates/rns-runtime/src/rpc.rs +++ b/crates/rns-runtime/src/rpc.rs @@ -205,6 +205,10 @@ pub struct InterfaceStatEntry { /// Name of the listener that accepted this interface. #[serde(default)] pub parent_interface_name: Option, + /// The network identity, in hex, that announced an auto-connected + /// interface (Python `autoconnect_source`). + #[serde(default)] + pub autoconnect_source: Option, } /// What a transport instance adds to its interface stats @@ -751,7 +755,10 @@ fn interface_stat_value(e: &InterfaceStatEntry) -> PyValue { "ifac_netname", optional(e.ifac_netname.clone().map(PyValue::String)), ), - ("autoconnect_source", PyValue::None), + ( + "autoconnect_source", + optional(e.autoconnect_source.clone().map(PyValue::String)), + ), ("announce_queue", optional(e.announce_queue.map(int))), ("held_announces", int(e.held_announces)), ( @@ -1043,6 +1050,7 @@ fn parse_interface_stats(value: &PyValue) -> Result, Rpc .and_then(py_u64) .unwrap_or(0), parent_interface_name: dict_get(m, "parent_interface_name").and_then(py_string), + autoconnect_source: dict_get(m, "autoconnect_source").and_then(py_string), }) }) .collect() diff --git a/crates/rns-runtime/src/rpc_server.rs b/crates/rns-runtime/src/rpc_server.rs index ffcc0a8..6c7c133 100644 --- a/crates/rns-runtime/src/rpc_server.rs +++ b/crates/rns-runtime/src/rpc_server.rs @@ -94,8 +94,10 @@ pub(crate) fn stat_entries( entries .into_iter() .map(|e| { + let autoconnect_source = ifac.and_then(|records| records.autoconnect_source(e.id)); let ifac = ifac.map(|ifac| ifac.lookup(e.id)).unwrap_or_default(); rpc::InterfaceStatEntry { + autoconnect_source, parent_interface_name: e.parent_id.and_then(|id| names.get(&id).cloned()), id: e.id, name: e.name,