mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-07 14:50:15 +00:00
Added path table output to rnpath utility
This commit is contained in:
parent
1be00a5c41
commit
6d23da360d
@ -738,6 +738,9 @@ class Reticulum:
|
||||
if path == "interface_stats":
|
||||
rpc_connection.send(self.get_interface_stats())
|
||||
|
||||
if path == "path_table":
|
||||
rpc_connection.send(self.get_path_table())
|
||||
|
||||
if path == "next_hop_if_name":
|
||||
rpc_connection.send(self.get_next_hop_if_name(call["destination_hash"]))
|
||||
|
||||
@ -809,6 +812,28 @@ class Reticulum:
|
||||
|
||||
return stats
|
||||
|
||||
def get_path_table(self):
|
||||
if self.is_connected_to_shared_instance:
|
||||
rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
|
||||
rpc_connection.send({"get": "path_table"})
|
||||
response = rpc_connection.recv()
|
||||
return response
|
||||
|
||||
else:
|
||||
path_table = []
|
||||
for dst_hash in RNS.Transport.destination_table:
|
||||
entry = {
|
||||
"hash": dst_hash,
|
||||
"timestamp": RNS.Transport.destination_table[dst_hash][0],
|
||||
"via": RNS.Transport.destination_table[dst_hash][1],
|
||||
"hops": RNS.Transport.destination_table[dst_hash][2],
|
||||
"expires": RNS.Transport.destination_table[dst_hash][3],
|
||||
"interface": str(RNS.Transport.destination_table[dst_hash][5]),
|
||||
}
|
||||
path_table.append(entry)
|
||||
|
||||
return path_table
|
||||
|
||||
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)
|
||||
|
@ -30,7 +30,16 @@ import argparse
|
||||
from RNS._version import __version__
|
||||
|
||||
|
||||
def program_setup(configdir, destination_hexhash, verbosity):
|
||||
def program_setup(configdir, table, destination_hexhash, verbosity):
|
||||
if table:
|
||||
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
||||
table = sorted(reticulum.get_path_table(), key=lambda e: (e["interface"], e["hops"]) )
|
||||
|
||||
for path in table:
|
||||
exp_str = RNS.timestamp_str(path["expires"])
|
||||
print(RNS.prettyhexrep(path["hash"])+" is "+str(path["hops"])+" hops away via "+RNS.prettyhexrep(path["via"])+" on "+path["interface"]+" expires "+RNS.timestamp_str(path["expires"]))
|
||||
|
||||
else:
|
||||
try:
|
||||
dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2
|
||||
if len(destination_hexhash) != dest_len:
|
||||
@ -87,6 +96,14 @@ def main():
|
||||
version="rnpath {version}".format(version=__version__)
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--table",
|
||||
action="store_true",
|
||||
help="show all known paths",
|
||||
default=False
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"destination",
|
||||
nargs="?",
|
||||
@ -104,12 +121,12 @@ def main():
|
||||
else:
|
||||
configarg = None
|
||||
|
||||
if not args.destination:
|
||||
if not args.table and not args.destination:
|
||||
print("")
|
||||
parser.print_help()
|
||||
print("")
|
||||
else:
|
||||
program_setup(configdir = configarg, destination_hexhash = args.destination, verbosity = args.verbose)
|
||||
program_setup(configdir = configarg, table = args.table, destination_hexhash = args.destination, verbosity = args.verbose)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
|
@ -93,12 +93,15 @@ def host_os():
|
||||
from .vendor.platformutils import get_platform
|
||||
return get_platform()
|
||||
|
||||
def timestamp_str(time_s):
|
||||
timestamp = time.localtime(time_s)
|
||||
return time.strftime(logtimefmt, timestamp)
|
||||
|
||||
def log(msg, level=3, _override_destination = False):
|
||||
global _always_override_destination
|
||||
|
||||
if loglevel >= level:
|
||||
timestamp = time.time()
|
||||
logstring = "["+time.strftime(logtimefmt)+"] ["+loglevelname(level)+"] "+msg
|
||||
logstring = "["+timestamp_str(time.time())+"] ["+loglevelname(level)+"] "+msg
|
||||
logging_lock.acquire()
|
||||
|
||||
if (logdest == LOG_STDOUT or _always_override_destination or _override_destination):
|
||||
|
Loading…
Reference in New Issue
Block a user