From f25906d44eb32bdbf25df594f7cbf105a0a2830e Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 25 Sep 2021 11:27:43 +0200 Subject: [PATCH] Improved path utility output --- RNS/Reticulum.py | 24 ++++++++++++++++++++++++ RNS/Utilities/__init__.py | 5 +++++ RNS/Utilities/rnpath.py | 4 ++-- RNS/Utilities/rnstatus.py | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 RNS/Utilities/__init__.py diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 7b505d4..f44b567 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -504,6 +504,12 @@ class Reticulum: if path == "interface_stats": rpc_connection.send(self.get_interface_stats()) + if path == "next_hop_if_name": + rpc_connection.send(self.get_next_hop_if_name(call["destination_hash"])) + + if path == "next_hop": + rpc_connection.send(self.get_next_hop(call["destination_hash"])) + rpc_connection.close() except Exception as e: RNS.log("An error ocurred while handling RPC call from local client: "+str(e), RNS.LOG_ERROR) @@ -532,6 +538,24 @@ class Reticulum: return stats + def get_next_hop_if_name(self, destination): + if self.is_connected_to_shared_instance: + rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) + rpc_connection.send({"get": "next_hop_if_name", "destination_hash": destination}) + response = rpc_connection.recv() + return response + else: + return str(RNS.Transport.next_hop_interface(destination)) + + def get_next_hop(self, destination): + if self.is_connected_to_shared_instance: + rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) + rpc_connection.send({"get": "next_hop", "destination_hash": destination}) + response = rpc_connection.recv() + return response + else: + return RNS.Transport.next_hop(destination) + @staticmethod def should_use_implicit_proof(): diff --git a/RNS/Utilities/__init__.py b/RNS/Utilities/__init__.py new file mode 100644 index 0000000..e3164b0 --- /dev/null +++ b/RNS/Utilities/__init__.py @@ -0,0 +1,5 @@ +import os +import glob + +modules = glob.glob(os.path.dirname(__file__)+"/*.py") +__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')] diff --git a/RNS/Utilities/rnpath.py b/RNS/Utilities/rnpath.py index ba91e5b..3bbafc5 100644 --- a/RNS/Utilities/rnpath.py +++ b/RNS/Utilities/rnpath.py @@ -37,8 +37,8 @@ def program_setup(configdir, destination_hexhash, verbosity): i = (i+1)%len(syms) hops = RNS.Transport.hops_to(destination_hash) - next_hop = RNS.prettyhexrep(RNS.Transport.next_hop(destination_hash)) - next_hop_interface = str(RNS.Transport.next_hop_interface(destination_hash)) + next_hop = RNS.prettyhexrep(reticulum.get_next_hop(destination_hash)) + next_hop_interface = reticulum.get_next_hop_if_name(destination_hash) if hops > 1: ms = "s" diff --git a/RNS/Utilities/rnstatus.py b/RNS/Utilities/rnstatus.py index c897a21..03f2cb1 100644 --- a/RNS/Utilities/rnstatus.py +++ b/RNS/Utilities/rnstatus.py @@ -32,6 +32,7 @@ def program_setup(configdir, dispall=False, verbosity = 0): for ifstat in ifstats: name = ifstat["name"] + print("") if dispall or not (name.startswith("LocalInterface[") or name.startswith("TCPInterface[Client")): if ifstat["status"]: ss = "Up" @@ -53,7 +54,7 @@ def program_setup(configdir, dispall=False, verbosity = 0): if clients != None: print("\t"+clients_string) print("\tRX: {rxb}\n\tTX: {txb}".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"]))) - print("") + else: print("Could not get RNS status")