Added verbosity level to utilities

This commit is contained in:
Mark Qvist 2021-09-24 15:34:03 +02:00
parent 9c1ac46989
commit c71660a9c3
3 changed files with 33 additions and 12 deletions

View File

@ -104,6 +104,13 @@ class Reticulum:
self.share_instance = True self.share_instance = True
self.requested_loglevel = loglevel 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_shared_instance = False
self.is_connected_to_shared_instance = False self.is_connected_to_shared_instance = False

View File

@ -8,7 +8,7 @@ import argparse
from RNS._version import __version__ from RNS._version import __version__
def program_setup(configdir, destination_hexhash): def program_setup(configdir, destination_hexhash, verbosity):
try: try:
dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2
if len(destination_hexhash) != dest_len: if len(destination_hexhash) != dest_len:
@ -21,8 +21,7 @@ def program_setup(configdir, destination_hexhash):
print(str(e)) print(str(e))
exit() exit()
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
reticulum = RNS.Reticulum(configdir = configdir)
if not RNS.Transport.has_path(destination_hash): if not RNS.Transport.has_path(destination_hash):
RNS.Transport.request_path(destination_hash) RNS.Transport.request_path(destination_hash)
@ -37,11 +36,16 @@ def program_setup(configdir, destination_hexhash):
sys.stdout.flush() sys.stdout.flush()
i = (i+1)%len(syms) 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 = RNS.prettyhexrep(RNS.Transport.next_hop(destination_hash))
next_hop_interface = str(RNS.Transport.next_hop_interface(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(): def main():
@ -69,6 +73,8 @@ def main():
type=str type=str
) )
parser.add_argument('-v', '--verbose', action='count', default=0)
args = parser.parse_args() args = parser.parse_args()
if args.config: if args.config:
@ -81,7 +87,7 @@ def main():
parser.print_help() parser.print_help()
print("") print("")
else: else:
program_setup(configdir = configarg, destination_hexhash = args.destination) program_setup(configdir = configarg, destination_hexhash = args.destination, verbosity = args.verbose)
except KeyboardInterrupt: except KeyboardInterrupt:
print("") print("")

View File

@ -10,7 +10,7 @@ from RNS._version import __version__
DEFAULT_PROBE_SIZE = 16 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: if full_name == None:
print("The full destination name including application name aspects must be specified for the destination") print("The full destination name including application name aspects must be specified for the destination")
exit() exit()
@ -35,7 +35,7 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_
exit() exit()
reticulum = RNS.Reticulum(configdir = configdir) reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
if not RNS.Transport.has_path(destination_hash): if not RNS.Transport.has_path(destination_hash):
RNS.Transport.request_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 ") print("\b\b ")
sys.stdout.flush() 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() rtt = receipt.get_rtt()
if (rtt >= 1): if (rtt >= 1):
rtt = round(rtt, 3) rtt = round(rtt, 3)
@ -87,8 +92,8 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_
print( print(
"Valid reply received from "+ "Valid reply received from "+
RNS.prettyhexrep(receipt.destination.hash)+ RNS.prettyhexrep(receipt.destination.hash)+
", round-trip time is "+rttstring+ "\nRound-trip time is "+rttstring+
" over "+hops+" hops" " over "+str(hops)+" hop"+ms
) )
@ -126,6 +131,8 @@ def main():
type=str type=str
) )
parser.add_argument('-v', '--verbose', action='count', default=0)
args = parser.parse_args() args = parser.parse_args()
if args.config: if args.config:
@ -141,7 +148,8 @@ def main():
program_setup( program_setup(
configdir = configarg, configdir = configarg,
destination_hexhash = args.destination_hash, destination_hexhash = args.destination_hash,
full_name = args.full_name full_name = args.full_name,
verbosity = args.verbose
) )
except KeyboardInterrupt: except KeyboardInterrupt: