Added max hops filter to rnpath table output
This commit is contained in:
parent
219d717afb
commit
cf87b1352a
|
@ -1194,7 +1194,8 @@ class Reticulum:
|
||||||
rpc_connection.send(self.get_interface_stats())
|
rpc_connection.send(self.get_interface_stats())
|
||||||
|
|
||||||
if path == "path_table":
|
if path == "path_table":
|
||||||
rpc_connection.send(self.get_path_table())
|
mh = call["max_hops"]
|
||||||
|
rpc_connection.send(self.get_path_table(max_hops=mh))
|
||||||
|
|
||||||
if path == "rate_table":
|
if path == "rate_table":
|
||||||
rpc_connection.send(self.get_rate_table())
|
rpc_connection.send(self.get_rate_table())
|
||||||
|
@ -1340,25 +1341,27 @@ class Reticulum:
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def get_path_table(self):
|
def get_path_table(self, max_hops=None):
|
||||||
if self.is_connected_to_shared_instance:
|
if self.is_connected_to_shared_instance:
|
||||||
rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
|
rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
|
||||||
rpc_connection.send({"get": "path_table"})
|
rpc_connection.send({"get": "path_table", "max_hops": max_hops})
|
||||||
response = rpc_connection.recv()
|
response = rpc_connection.recv()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
else:
|
else:
|
||||||
path_table = []
|
path_table = []
|
||||||
for dst_hash in RNS.Transport.destination_table:
|
for dst_hash in RNS.Transport.destination_table:
|
||||||
entry = {
|
path_hops = RNS.Transport.destination_table[dst_hash][2]
|
||||||
"hash": dst_hash,
|
if max_hops == None or path_hops <= max_hops:
|
||||||
"timestamp": RNS.Transport.destination_table[dst_hash][0],
|
entry = {
|
||||||
"via": RNS.Transport.destination_table[dst_hash][1],
|
"hash": dst_hash,
|
||||||
"hops": RNS.Transport.destination_table[dst_hash][2],
|
"timestamp": RNS.Transport.destination_table[dst_hash][0],
|
||||||
"expires": RNS.Transport.destination_table[dst_hash][3],
|
"via": RNS.Transport.destination_table[dst_hash][1],
|
||||||
"interface": str(RNS.Transport.destination_table[dst_hash][5]),
|
"hops": path_hops,
|
||||||
}
|
"expires": RNS.Transport.destination_table[dst_hash][3],
|
||||||
path_table.append(entry)
|
"interface": str(RNS.Transport.destination_table[dst_hash][5]),
|
||||||
|
}
|
||||||
|
path_table.append(entry)
|
||||||
|
|
||||||
return path_table
|
return path_table
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import argparse
|
||||||
from RNS._version import __version__
|
from RNS._version import __version__
|
||||||
|
|
||||||
|
|
||||||
def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, timeout, drop_queues, drop_via):
|
def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, timeout, drop_queues, drop_via, max_hops):
|
||||||
if table:
|
if table:
|
||||||
destination_hash = None
|
destination_hash = None
|
||||||
if destination_hexhash != None:
|
if destination_hexhash != None:
|
||||||
|
@ -47,7 +47,7 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity,
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
||||||
table = sorted(reticulum.get_path_table(), key=lambda e: (e["interface"], e["hops"]) )
|
table = sorted(reticulum.get_path_table(max_hops=max_hops), key=lambda e: (e["interface"], e["hops"]) )
|
||||||
|
|
||||||
displayed = 0
|
displayed = 0
|
||||||
for path in table:
|
for path in table:
|
||||||
|
@ -255,6 +255,16 @@ def main():
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-m",
|
||||||
|
"--max",
|
||||||
|
action="store",
|
||||||
|
metavar="hops",
|
||||||
|
type=int,
|
||||||
|
help="maximum hops to filter path table by",
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-r",
|
"-r",
|
||||||
"--rates",
|
"--rates",
|
||||||
|
@ -327,6 +337,7 @@ def main():
|
||||||
timeout = args.w,
|
timeout = args.w,
|
||||||
drop_queues = args.drop_announces,
|
drop_queues = args.drop_announces,
|
||||||
drop_via = args.drop_via,
|
drop_via = args.drop_via,
|
||||||
|
max_hops = args.max,
|
||||||
)
|
)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue