From 124cc1ca6bf5d80e54ef8da5318dce737d2989a4 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:35:10 -0700 Subject: [PATCH] runtime: mark shared-medium interfaces as upstream does --- crates/rns-runtime/src/interface_factory.rs | 42 ++++++++++++++++++++ crates/rns-runtime/src/interface_registry.rs | 22 ++++++++++ crates/rns-runtime/src/reticulum.rs | 3 ++ 3 files changed, 67 insertions(+) diff --git a/crates/rns-runtime/src/interface_factory.rs b/crates/rns-runtime/src/interface_factory.rs index d9cad38..45fb47b 100644 --- a/crates/rns-runtime/src/interface_factory.rs +++ b/crates/rns-runtime/src/interface_factory.rs @@ -2009,6 +2009,9 @@ pub struct InterfacePostInit { /// Serial, KISS, AX.25 KISS, RNode and RNodeMulti interfaces never hold /// announces in Python; they override `should_ingress_limit`. pub announce_ingress_exempt: bool, + /// The interface classes Python marks `shared_medium`: Serial, KISS, + /// AX.25 KISS, RNode (every port), RNodeMulti, UDP and Pipe. + pub shared_medium: bool, /// Per-interface ingress/egress overrides parsed from `ic_*`, `ec_pr_freq` /// and `egress_control` settings. pub ingress_overrides: rns_transport::ingress::IngressOverrides, @@ -2112,6 +2115,18 @@ impl InterfacePostInit { | "RNodeMultiInterface" ) ), + shared_medium: matches!( + section.get("type"), + Some( + "SerialInterface" + | "KISSInterface" + | "AX25KISSInterface" + | "RNodeInterface" + | "RNodeMultiInterface" + | "UDPInterface" + | "PipeInterface" + ) + ), ingress_overrides, recursive_prs, announces_from_internal, @@ -2170,6 +2185,33 @@ pub fn default_ifac_size_for(config: &InterfaceConfig) -> usize { #[cfg(test)] mod tests { + /// The classes that set `shared_medium = True` in Python 1.6.1 + /// (`RNS/Interfaces/*.py`); the base class leaves it false. + #[test] + fn shared_medium_follows_the_python_interface_class() { + for (kind, shared) in [ + ("SerialInterface", true), + ("KISSInterface", true), + ("AX25KISSInterface", true), + ("RNodeInterface", true), + ("RNodeMultiInterface", true), + ("UDPInterface", true), + ("PipeInterface", true), + ("TCPClientInterface", false), + ("TCPServerInterface", false), + ("BackboneInterface", false), + ("BackboneClientInterface", false), + ("AutoInterface", false), + ("LocalInterface", false), + ("I2PInterface", false), + ] { + let mut section = ConfigSection::new(); + section.set("type", kind); + let post_init = InterfacePostInit::try_from_section(§ion).unwrap(); + assert_eq!(post_init.shared_medium, shared, "{kind}"); + } + } + #[cfg(feature = "serial")] #[test] fn android_usb_serial_ports_are_refused_off_android() { diff --git a/crates/rns-runtime/src/interface_registry.rs b/crates/rns-runtime/src/interface_registry.rs index dac31dd..720ebf6 100644 --- a/crates/rns-runtime/src/interface_registry.rs +++ b/crates/rns-runtime/src/interface_registry.rs @@ -53,6 +53,13 @@ impl InterfaceKind { } } + /// Runtime-spawned radios and the BLE peer mesh share their medium; every + /// other directly registered interface (TCP, Backbone, I2P, Local and + /// Auto peers, listener children) does not (Python `shared_medium`). + pub(crate) fn shared_medium(self) -> bool { + self != Self::Standard + } + fn requires_exact_driver(self) -> bool { match self { #[cfg(feature = "ble")] @@ -1691,4 +1698,19 @@ mod tests { InterfaceShutdownStrategy::ExactRNodeDriver ); } + + /// The BLE peer mesh is one interface whose peers cannot hear each other, + /// so it must keep rebroadcasting what one of them sent. + #[test] + fn only_standard_registrations_are_off_a_shared_medium() { + assert!(!InterfaceKind::Standard.shared_medium()); + #[cfg(feature = "ble")] + assert!(InterfaceKind::BlePeer.shared_medium() && InterfaceKind::BleRNode.shared_medium()); + #[cfg(any(feature = "serial", feature = "rnode-tcp"))] + assert!(InterfaceKind::RNode.shared_medium()); + #[cfg(feature = "serial")] + assert!(InterfaceKind::RNodeMulti.shared_medium()); + #[cfg(target_os = "android")] + assert!(InterfaceKind::AndroidUsbRNode.shared_medium()); + } } diff --git a/crates/rns-runtime/src/reticulum.rs b/crates/rns-runtime/src/reticulum.rs index 8234c73..1db9bb2 100644 --- a/crates/rns-runtime/src/reticulum.rs +++ b/crates/rns-runtime/src/reticulum.rs @@ -5952,6 +5952,7 @@ async fn prepare_interface_with_role_and_overrides( entry.inspection = handle.inspection; entry.ingress = ingress; entry.multipoint = multipoint; + entry.shared_medium = kind.shared_medium(); if let Some(parent) = inherited.as_ref() { entry.announce_cap = parent.announce_cap; entry.announce_rate_target = parent.announce_rate_target; @@ -6095,6 +6096,7 @@ fn clone_interface_post_init( default_ifac_size: post_init.default_ifac_size, ingress_control: post_init.ingress_control, announce_ingress_exempt: post_init.announce_ingress_exempt, + shared_medium: post_init.shared_medium, ingress_overrides: post_init.ingress_overrides.clone(), recursive_prs: post_init.recursive_prs, announces_from_internal: post_init.announces_from_internal, @@ -6296,6 +6298,7 @@ async fn prepare_interface_with_post_init( entry.announces_from_internal = post_init.announces_from_internal; entry.announces_to_internal = post_init.announces_to_internal; entry.gravity = post_init.gravity.unwrap_or(0); + entry.shared_medium = post_init.shared_medium; entry.destination_cost = post_init.destination_cost; entry.pr_cost = post_init.pr_cost; Ok(PreparedInterfaceRegistration {