Added ability to drop all paths via a specific transport instance to rnpath
This commit is contained in:
parent
ed424fa0a2
commit
03340ed091
@ -1077,6 +1077,9 @@ class Reticulum:
|
|||||||
if path == "path":
|
if path == "path":
|
||||||
rpc_connection.send(self.drop_path(call["destination_hash"]))
|
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":
|
if path == "announce_queues":
|
||||||
rpc_connection.send(self.drop_announce_queues())
|
rpc_connection.send(self.drop_announce_queues())
|
||||||
|
|
||||||
@ -1241,6 +1244,22 @@ class Reticulum:
|
|||||||
else:
|
else:
|
||||||
return RNS.Transport.expire_path(destination)
|
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):
|
def drop_announce_queues(self):
|
||||||
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)
|
||||||
|
@ -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):
|
def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, timeout, drop_queues, drop_via):
|
||||||
if table:
|
if table:
|
||||||
destination_hash = None
|
destination_hash = None
|
||||||
if destination_hexhash != None:
|
if destination_hexhash != None:
|
||||||
@ -155,6 +155,29 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity,
|
|||||||
sys.exit(1)
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2
|
dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2
|
||||||
@ -256,6 +279,13 @@ def main():
|
|||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-x", "--drop-via",
|
||||||
|
action="store_true",
|
||||||
|
help="drop all paths via specified transport instance",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-w",
|
"-w",
|
||||||
action="store",
|
action="store",
|
||||||
@ -282,7 +312,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
configarg = None
|
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("")
|
print("")
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
print("")
|
print("")
|
||||||
@ -296,6 +326,7 @@ def main():
|
|||||||
verbosity = args.verbose,
|
verbosity = args.verbose,
|
||||||
timeout = args.w,
|
timeout = args.w,
|
||||||
drop_queues = args.drop_announces,
|
drop_queues = args.drop_announces,
|
||||||
|
drop_via = args.drop_via,
|
||||||
)
|
)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user