From 82f204fb447b121da4764b72cf3e7f549ddbaee9 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 21 Sep 2023 18:48:08 +0200 Subject: [PATCH] Added ability to enable a built-in probe responder destination for Transport Instances --- RNS/Reticulum.py | 14 ++++++++++++++ RNS/Transport.py | 9 +++++++++ RNS/Utilities/rnstatus.py | 5 ++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 29587c8..da65187 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -201,6 +201,7 @@ class Reticulum: Reticulum.__transport_enabled = False Reticulum.__use_implicit_proof = True + Reticulum.__allow_probes = False Reticulum.panic_on_interface_error = False @@ -319,6 +320,7 @@ class Reticulum: self.is_standalone_instance = False self.is_connected_to_shared_instance = True Reticulum.__transport_enabled = False + Reticulum.__allow_probes = False RNS.log("Connected to locally available Reticulum instance via: "+str(interface), RNS.LOG_DEBUG) except Exception as e: RNS.log("Local shared instance appears to be running, but it could not be connected", RNS.LOG_ERROR) @@ -361,6 +363,10 @@ class Reticulum: v = self.config["reticulum"].as_bool(option) if v == True: Reticulum.__transport_enabled = True + if option == "respond_to_probes": + v = self.config["reticulum"].as_bool(option) + if v == True: + Reticulum.__allow_probes = True if option == "panic_on_interface_error": v = self.config["reticulum"].as_bool(option) if v == True: @@ -1147,6 +1153,10 @@ class Reticulum: if Reticulum.transport_enabled(): stats["transport_id"] = RNS.Transport.identity.hash stats["transport_uptime"] = time.time()-RNS.Transport.start_time + if Reticulum.probe_destination_enabled(): + stats["probe_responder"] = RNS.Transport.probe_destination.hash + else: + stats["probe_responder"] = None return stats @@ -1285,6 +1295,10 @@ class Reticulum: """ return Reticulum.__transport_enabled + @staticmethod + def probe_destination_enabled(): + return Reticulum.__allow_probes + # Default configuration file: __default_rns_config__ = '''# This is the default Reticulum config file. # You should probably edit it to include any additional, diff --git a/RNS/Transport.py b/RNS/Transport.py index 4870eaf..5cd4ed4 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -270,6 +270,15 @@ class Transport: except Exception as e: RNS.log("Could not load tunnel table from storage, the contained exception was: "+str(e), RNS.LOG_ERROR) + if RNS.Reticulum.probe_destination_enabled(): + Transport.probe_destination = RNS.Destination(Transport.identity, RNS.Destination.IN, RNS.Destination.SINGLE, Transport.APP_NAME, "probe") + Transport.probe_destination.accepts_links(False) + Transport.probe_destination.set_proof_strategy(RNS.Destination.PROVE_ALL) + Transport.probe_destination.announce() + RNS.log("Transport Instance will respond to probe requests on "+str(Transport.probe_destination), RNS.LOG_NOTICE) + else: + Transport.probe_destination = None + RNS.log("Transport instance "+str(Transport.identity)+" started", RNS.LOG_VERBOSE) Transport.start_time = time.time() diff --git a/RNS/Utilities/rnstatus.py b/RNS/Utilities/rnstatus.py index 45921c2..cd1d1c8 100644 --- a/RNS/Utilities/rnstatus.py +++ b/RNS/Utilities/rnstatus.py @@ -176,7 +176,10 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None,json=F print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"]))) if "transport_id" in stats and stats["transport_id"] != None: - print("\n Transport Instance "+RNS.prettyhexrep(stats["transport_id"])+" running\n Uptime is "+RNS.prettytime(stats["transport_uptime"])) + print("\n Transport Instance "+RNS.prettyhexrep(stats["transport_id"])+" running") + if "probe_responder" in stats and stats["probe_responder"] != None: + print(" Probe responder at "+RNS.prettyhexrep(stats["probe_responder"])) + print(" Uptime is "+RNS.prettytime(stats["transport_uptime"])) print("")