status: name the network an auto-connected interface came from

This commit is contained in:
DeFiDude committed 2026-10-25 07:11:57 -06:00
1 parent 48e355a943
commit 692260e79b
7 files changed
+85 -6

No files matched your search

+1
View File
@@ -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
+1
View File
@@ -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<f64>
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<alloc::string::String>
pub rns_runtime::rpc::InterfaceStatEntry::bitrate: u64
pub rns_runtime::rpc::InterfaceStatEntry::blocked_ips: core::option::Option<u64>
pub rns_runtime::rpc::InterfaceStatEntry::burst_activated: f64
+2 -2
View File
@@ -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",
+23 -3
View File
@@ -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<String>,
}
type InterfaceControlMap = Arc<std::sync::Mutex<HashMap<u64, InterfaceControlMetadata>>>;
/// 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<String> {
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,
},
);
@@ -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);
}
+9 -1
View File
@@ -205,6 +205,10 @@ pub struct InterfaceStatEntry {
/// Name of the listener that accepted this interface.
#[serde(default)]
pub parent_interface_name: Option<String>,
/// The network identity, in hex, that announced an auto-connected
/// interface (Python `autoconnect_source`).
#[serde(default)]
pub autoconnect_source: Option<String>,
}
/// 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<Vec<InterfaceStatEntry>, 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()
+2
View File
@@ -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,