From c71660a9c301b9e0292dc6531cfd769a89a6a297 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 24 Sep 2021 15:34:03 +0200 Subject: [PATCH] Added verbosity level to utilities --- RNS/Reticulum.py | 7 +++++++ RNS/Utilities/rnpath.py | 18 ++++++++++++------ RNS/Utilities/rnprobe.py | 20 ++++++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index af759f5..ab67414 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -104,6 +104,13 @@ class Reticulum: self.share_instance = True self.requested_loglevel = loglevel + if self.requested_loglevel != None: + if self.requested_loglevel > RNS.LOG_EXTREME: + self.requested_loglevel = RNS.LOG_EXTREME + if self.requested_loglevel < RNS.LOG_CRITICAL: + self.requested_loglevel = RNS.LOG_CRITICAL + + RNS.loglevel = self.requested_loglevel self.is_shared_instance = False self.is_connected_to_shared_instance = False diff --git a/RNS/Utilities/rnpath.py b/RNS/Utilities/rnpath.py index 8ea69cd..ba91e5b 100644 --- a/RNS/Utilities/rnpath.py +++ b/RNS/Utilities/rnpath.py @@ -8,7 +8,7 @@ import argparse from RNS._version import __version__ -def program_setup(configdir, destination_hexhash): +def program_setup(configdir, destination_hexhash, verbosity): try: dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 if len(destination_hexhash) != dest_len: @@ -21,8 +21,7 @@ def program_setup(configdir, destination_hexhash): print(str(e)) exit() - - reticulum = RNS.Reticulum(configdir = configdir) + reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity) if not RNS.Transport.has_path(destination_hash): RNS.Transport.request_path(destination_hash) @@ -37,11 +36,16 @@ def program_setup(configdir, destination_hexhash): sys.stdout.flush() i = (i+1)%len(syms) - hops = str(RNS.Transport.hops_to(destination_hash)) + 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)) - print("\rPath found, destination "+RNS.prettyhexrep(destination_hash)+" is "+hops+" hops away via "+next_hop+" on "+next_hop_interface) + if hops > 1: + ms = "s" + else: + ms = "" + + print("\rPath found, destination "+RNS.prettyhexrep(destination_hash)+" is "+str(hops)+" hop"+ms+" away via "+next_hop+" on "+next_hop_interface) def main(): @@ -68,6 +72,8 @@ def main(): help="hexadecimal hash of the destination", type=str ) + + parser.add_argument('-v', '--verbose', action='count', default=0) args = parser.parse_args() @@ -81,7 +87,7 @@ def main(): parser.print_help() print("") else: - program_setup(configdir = configarg, destination_hexhash = args.destination) + program_setup(configdir = configarg, destination_hexhash = args.destination, verbosity = args.verbose) except KeyboardInterrupt: print("") diff --git a/RNS/Utilities/rnprobe.py b/RNS/Utilities/rnprobe.py index cd3182c..85d8575 100644 --- a/RNS/Utilities/rnprobe.py +++ b/RNS/Utilities/rnprobe.py @@ -10,7 +10,7 @@ from RNS._version import __version__ DEFAULT_PROBE_SIZE = 16 -def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_name = None): +def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_name = None, verbosity = 0): if full_name == None: print("The full destination name including application name aspects must be specified for the destination") exit() @@ -35,7 +35,7 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_ exit() - reticulum = RNS.Reticulum(configdir = configdir) + reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity) if not RNS.Transport.has_path(destination_hash): RNS.Transport.request_path(destination_hash) @@ -75,7 +75,12 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_ print("\b\b ") sys.stdout.flush() - hops = str(RNS.Transport.hops_to(destination_hash)) + hops = RNS.Transport.hops_to(destination_hash) + if hops > 1: + ms = "s" + else: + ms = "" + rtt = receipt.get_rtt() if (rtt >= 1): rtt = round(rtt, 3) @@ -87,8 +92,8 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_ print( "Valid reply received from "+ RNS.prettyhexrep(receipt.destination.hash)+ - ", round-trip time is "+rttstring+ - " over "+hops+" hops" + "\nRound-trip time is "+rttstring+ + " over "+str(hops)+" hop"+ms ) @@ -126,6 +131,8 @@ def main(): type=str ) + parser.add_argument('-v', '--verbose', action='count', default=0) + args = parser.parse_args() if args.config: @@ -141,7 +148,8 @@ def main(): program_setup( configdir = configarg, destination_hexhash = args.destination_hash, - full_name = args.full_name + full_name = args.full_name, + verbosity = args.verbose ) except KeyboardInterrupt: