From 03340ed091a8dc04faa819a438825c6790e8d196 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 1 Oct 2023 11:39:07 +0200 Subject: [PATCH] Added ability to drop all paths via a specific transport instance to rnpath --- RNS/Reticulum.py | 19 +++++++++++++++++++ RNS/Utilities/rnpath.py | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 3acf9dc..2a01074 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -1077,6 +1077,9 @@ class Reticulum: if path == "path": rpc_connection.send(self.drop_path(call["destination_hash"])) + if path == "all_via": + rpc_connection.send(self.drop_all_via(call["destination_hash"])) + if path == "announce_queues": rpc_connection.send(self.drop_announce_queues()) @@ -1241,6 +1244,22 @@ class Reticulum: else: return RNS.Transport.expire_path(destination) + def drop_all_via(self, transport_hash): + if self.is_connected_to_shared_instance: + rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) + rpc_connection.send({"drop": "all_via", "destination_hash": transport_hash}) + response = rpc_connection.recv() + return response + + else: + dropped_count = 0 + for destination_hash in RNS.Transport.destination_table: + if RNS.Transport.destination_table[destination_hash][1] == transport_hash: + RNS.Transport.expire_path(destination_hash) + dropped_count += 1 + + return dropped_count + def drop_announce_queues(self): if self.is_connected_to_shared_instance: rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key) diff --git a/RNS/Utilities/rnpath.py b/RNS/Utilities/rnpath.py index 28512ab..cf20bfa 100644 --- a/RNS/Utilities/rnpath.py +++ b/RNS/Utilities/rnpath.py @@ -30,7 +30,7 @@ import argparse from RNS._version import __version__ -def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, timeout, drop_queues): +def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, timeout, drop_queues, drop_via): if table: destination_hash = None if destination_hexhash != None: @@ -155,6 +155,29 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, sys.exit(1) + elif drop_via: + try: + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError("Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2)) + try: + destination_hash = bytes.fromhex(destination_hexhash) + except Exception as e: + raise ValueError("Invalid destination entered. Check your input.") + except Exception as e: + print(str(e)) + sys.exit(1) + + + reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity) + + if reticulum.drop_all_via(destination_hash): + print("Dropped all paths via "+RNS.prettyhexrep(destination_hash)) + else: + print("Unable to drop paths via "+RNS.prettyhexrep(destination_hash)+". Does the transport instance exist?") + sys.exit(1) + + else: try: dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 @@ -256,6 +279,13 @@ def main(): default=False ) + parser.add_argument( + "-x", "--drop-via", + action="store_true", + help="drop all paths via specified transport instance", + default=False + ) + parser.add_argument( "-w", action="store", @@ -282,7 +312,7 @@ def main(): else: configarg = None - if not args.drop_announces and not args.table and not args.rates and not args.destination: + if not args.drop_announces and not args.table and not args.rates and not args.destination and not args.drop_via: print("") parser.print_help() print("") @@ -296,6 +326,7 @@ def main(): verbosity = args.verbose, timeout = args.w, drop_queues = args.drop_announces, + drop_via = args.drop_via, ) sys.exit(0)