From 880db0a7b7776d407e44bb0a93541317a1f75487 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 21 Aug 2026 13:23:30 +0200 Subject: [PATCH] Added active links stat to rnstatus --- RNS/Reticulum.py | 13 ++++++++++++- RNS/Transport.py | 8 ++++++++ RNS/Utilities/rnstatus.py | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 7cf8ddd0..d183b9ec 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -1287,6 +1287,7 @@ class Reticulum: if path == "next_hop": self.rpc_return(conn, self.get_next_hop(call["destination_hash"])) if path == "first_hop_timeout": self.rpc_return(conn, self.get_first_hop_timeout(call["destination_hash"])) if path == "link_count": self.rpc_return(conn, self.get_link_count()) + if path == "active_link_count": self.rpc_return(conn, self.get_active_link_count()) if path == "packet_rssi": self.rpc_return(conn, self.get_packet_rssi(call["packet_hash"])) if path == "packet_snr": self.rpc_return(conn, self.get_packet_snr(call["packet_hash"])) if path == "packet_q": self.rpc_return(conn, self.get_packet_q(call["packet_hash"])) @@ -1738,7 +1739,17 @@ class Reticulum: return response else: - return len(RNS.Transport.link_table) + return RNS.Transport.link_count() + + def get_active_link_count(self): + if self.is_connected_to_shared_instance: + rpc_connection = self.get_rpc_client() + rpc_connection.send_bytes(mp.packb({"get": "active_link_count"})) + response = mp.unpackb(rpc_connection.recv_bytes()) + return response + + else: + return RNS.Transport.active_link_count() def get_packet_rssi(self, packet_hash): if self.is_connected_to_shared_instance: diff --git a/RNS/Transport.py b/RNS/Transport.py index b2e3ca83..4482a77b 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -3047,6 +3047,14 @@ class Transport: if interface != None and interface.bitrate: return ((1/interface.bitrate)*8)*RNS.Reticulum.MTU else: return 0 + @staticmethod + def link_count(): + return len(Transport.link_table) + + @staticmethod + def active_link_count(): + return sum(1 for e in (True for entry in Transport.link_table if entry[IDX_LT_VALIDATED])) + @staticmethod def expire_path(destination_hash): with Transport.path_table_lock: diff --git a/RNS/Utilities/rnstatus.py b/RNS/Utilities/rnstatus.py index 1f768ed9..b5f7015c 100644 --- a/RNS/Utilities/rnstatus.py +++ b/RNS/Utilities/rnstatus.py @@ -173,6 +173,7 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json= else: return link_count = None + active_link_count = None stats = None details = False @@ -339,6 +340,8 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json= if lstats: try: link_count = reticulum.get_link_count() except Exception as e: pass + try: active_link_count = reticulum.get_active_link_count() + except Exception as e: pass try: stats = reticulum.get_interface_stats() except Exception as e: pass @@ -677,6 +680,8 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json= else: lstr = f" {link_count} entr{ms} in link table" + if active_link_count: lstr = f"{lstr} ({active_link_count} active)" + if traffic_totals: rxb_str = "↓"+RNS.prettysize(stats["rxb"]) txb_str = "↑"+RNS.prettysize(stats["txb"])