mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-30 01:00:18 +00:00
Compare commits
No commits in common. "3a163c6f09eb28458fac1ae9c7c384e10e1e906c" and "b994db37457d722c2db2c31e15d0edbb488d0f48" have entirely different histories.
3a163c6f09
...
b994db3745
@ -1100,9 +1100,6 @@ class Reticulum:
|
|||||||
if path == "first_hop_timeout":
|
if path == "first_hop_timeout":
|
||||||
rpc_connection.send(self.get_first_hop_timeout(call["destination_hash"]))
|
rpc_connection.send(self.get_first_hop_timeout(call["destination_hash"]))
|
||||||
|
|
||||||
if path == "link_count":
|
|
||||||
rpc_connection.send(self.get_link_count())
|
|
||||||
|
|
||||||
if path == "packet_rssi":
|
if path == "packet_rssi":
|
||||||
rpc_connection.send(self.get_packet_rssi(call["packet_hash"]))
|
rpc_connection.send(self.get_packet_rssi(call["packet_hash"]))
|
||||||
|
|
||||||
@ -1351,16 +1348,6 @@ class Reticulum:
|
|||||||
else:
|
else:
|
||||||
return RNS.Transport.next_hop(destination)
|
return RNS.Transport.next_hop(destination)
|
||||||
|
|
||||||
def get_link_count(self):
|
|
||||||
if self.is_connected_to_shared_instance:
|
|
||||||
rpc_connection = multiprocessing.connection.Client(self.rpc_addr, authkey=self.rpc_key)
|
|
||||||
rpc_connection.send({"get": "link_count"})
|
|
||||||
response = rpc_connection.recv()
|
|
||||||
return response
|
|
||||||
|
|
||||||
else:
|
|
||||||
return len(RNS.Transport.link_table)
|
|
||||||
|
|
||||||
def get_packet_rssi(self, packet_hash):
|
def get_packet_rssi(self, packet_hash):
|
||||||
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)
|
||||||
@ -1389,6 +1376,7 @@ class Reticulum:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_packet_q(self, packet_hash):
|
def get_packet_q(self, packet_hash):
|
||||||
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)
|
||||||
|
@ -34,14 +34,13 @@ from RNS._version import __version__
|
|||||||
APP_NAME = "rncp"
|
APP_NAME = "rncp"
|
||||||
allow_all = False
|
allow_all = False
|
||||||
allow_fetch = False
|
allow_fetch = False
|
||||||
fetch_jail = None
|
|
||||||
allowed_identity_hashes = []
|
allowed_identity_hashes = []
|
||||||
|
|
||||||
REQ_FETCH_NOT_ALLOWED = 0xF0
|
REQ_FETCH_NOT_ALLOWED = 0xF0
|
||||||
|
|
||||||
def listen(configdir, verbosity = 0, quietness = 0, allowed = [], display_identity = False,
|
def listen(configdir, verbosity = 0, quietness = 0, allowed = [], display_identity = False,
|
||||||
limit = None, disable_auth = None, fetch_allowed = False, jail = None, announce = False):
|
limit = None, disable_auth = None, fetch_allowed = False, announce = False):
|
||||||
global allow_all, allow_fetch, allowed_identity_hashes, fetch_jail
|
global allow_all, allow_fetch, allowed_identity_hashes
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
|
|
||||||
allow_fetch = fetch_allowed
|
allow_fetch = fetch_allowed
|
||||||
@ -52,10 +51,6 @@ def listen(configdir, verbosity = 0, quietness = 0, allowed = [], display_identi
|
|||||||
targetloglevel = 3+verbosity-quietness
|
targetloglevel = 3+verbosity-quietness
|
||||||
reticulum = RNS.Reticulum(configdir=configdir, loglevel=targetloglevel)
|
reticulum = RNS.Reticulum(configdir=configdir, loglevel=targetloglevel)
|
||||||
|
|
||||||
if jail != None:
|
|
||||||
fetch_jail = os.path.abspath(os.path.expanduser(jail))
|
|
||||||
RNS.log("Restricting fetch requests to paths under \""+fetch_jail+"\"", RNS.LOG_VERBOSE)
|
|
||||||
|
|
||||||
identity_path = RNS.Reticulum.identitypath+"/"+APP_NAME
|
identity_path = RNS.Reticulum.identitypath+"/"+APP_NAME
|
||||||
if os.path.isfile(identity_path):
|
if os.path.isfile(identity_path):
|
||||||
identity = RNS.Identity.from_file(identity_path)
|
identity = RNS.Identity.from_file(identity_path)
|
||||||
@ -126,20 +121,16 @@ def listen(configdir, verbosity = 0, quietness = 0, allowed = [], display_identi
|
|||||||
print("Warning: No allowed identities configured, rncp will not accept any files!")
|
print("Warning: No allowed identities configured, rncp will not accept any files!")
|
||||||
|
|
||||||
def fetch_request(path, data, request_id, link_id, remote_identity, requested_at):
|
def fetch_request(path, data, request_id, link_id, remote_identity, requested_at):
|
||||||
global allow_fetch, fetch_jail
|
global allow_fetch
|
||||||
if not allow_fetch:
|
if not allow_fetch:
|
||||||
return REQ_FETCH_NOT_ALLOWED
|
return REQ_FETCH_NOT_ALLOWED
|
||||||
|
|
||||||
file_path = os.path.abspath(os.path.expanduser(data))
|
|
||||||
if fetch_jail:
|
|
||||||
if not file_path.startswith(jail):
|
|
||||||
return REQ_FETCH_NOT_ALLOWED
|
|
||||||
|
|
||||||
target_link = None
|
target_link = None
|
||||||
for link in RNS.Transport.active_links:
|
for link in RNS.Transport.active_links:
|
||||||
if link.link_id == link_id:
|
if link.link_id == link_id:
|
||||||
target_link = link
|
target_link = link
|
||||||
|
|
||||||
|
file_path = os.path.expanduser(data)
|
||||||
if not os.path.isfile(file_path):
|
if not os.path.isfile(file_path):
|
||||||
RNS.log("Client-requested file not found: "+str(file_path), RNS.LOG_VERBOSE)
|
RNS.log("Client-requested file not found: "+str(file_path), RNS.LOG_VERBOSE)
|
||||||
return False
|
return False
|
||||||
@ -447,25 +438,25 @@ def fetch(configdir, verbosity = 0, quietness = 0, destination = None, file = No
|
|||||||
if not silent: print("\r \r", end="")
|
if not silent: print("\r \r", end="")
|
||||||
print("Fetch request failed, fetching the file "+str(file)+" was not allowed by the remote")
|
print("Fetch request failed, fetching the file "+str(file)+" was not allowed by the remote")
|
||||||
link.teardown()
|
link.teardown()
|
||||||
time.sleep(0.15)
|
time.sleep(1)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif request_status == "not_found":
|
elif request_status == "not_found":
|
||||||
if not silent: print("\r \r", end="")
|
if not silent: print("\r \r", end="")
|
||||||
print("Fetch request failed, the file "+str(file)+" was not found on the remote")
|
print("Fetch request failed, the file "+str(file)+" was not found on the remote")
|
||||||
link.teardown()
|
link.teardown()
|
||||||
time.sleep(0.15)
|
time.sleep(1)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif request_status == "remote_error":
|
elif request_status == "remote_error":
|
||||||
if not silent: print("\r \r", end="")
|
if not silent: print("\r \r", end="")
|
||||||
print("Fetch request failed due to an error on the remote system")
|
print("Fetch request failed due to an error on the remote system")
|
||||||
link.teardown()
|
link.teardown()
|
||||||
time.sleep(0.15)
|
time.sleep(1)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif request_status == "unknown":
|
elif request_status == "unknown":
|
||||||
if not silent: print("\r \r", end="")
|
if not silent: print("\r \r", end="")
|
||||||
print("Fetch request failed due to an unknown error (probably not authorised)")
|
print("Fetch request failed due to an unknown error (probably not authorised)")
|
||||||
link.teardown()
|
link.teardown()
|
||||||
time.sleep(0.15)
|
time.sleep(1)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif request_status == "found":
|
elif request_status == "found":
|
||||||
if not silent: print("\r \r", end="")
|
if not silent: print("\r \r", end="")
|
||||||
@ -495,7 +486,7 @@ def fetch(configdir, verbosity = 0, quietness = 0, destination = None, file = No
|
|||||||
else:
|
else:
|
||||||
print("\r \r"+str(file)+" fetched from "+RNS.prettyhexrep(destination_hash))
|
print("\r \r"+str(file)+" fetched from "+RNS.prettyhexrep(destination_hash))
|
||||||
link.teardown()
|
link.teardown()
|
||||||
time.sleep(0.15)
|
time.sleep(0.25)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
link.teardown()
|
link.teardown()
|
||||||
@ -687,7 +678,6 @@ def main():
|
|||||||
parser.add_argument("-l", '--listen', action='store_true', default=False, help="listen for incoming transfer requests")
|
parser.add_argument("-l", '--listen', action='store_true', default=False, help="listen for incoming transfer requests")
|
||||||
parser.add_argument("-F", '--allow-fetch', action='store_true', default=False, help="allow authenticated clients to fetch files")
|
parser.add_argument("-F", '--allow-fetch', action='store_true', default=False, help="allow authenticated clients to fetch files")
|
||||||
parser.add_argument("-f", '--fetch', action='store_true', default=False, help="fetch file from remote listener instead of sending")
|
parser.add_argument("-f", '--fetch', action='store_true', default=False, help="fetch file from remote listener instead of sending")
|
||||||
parser.add_argument("-j", "--jail", metavar="path", action="store", default=None, help="restrict fetch requests to specified path", type=str)
|
|
||||||
parser.add_argument("-b", action='store', metavar="seconds", default=-1, help="announce interval, 0 to only announce at startup", type=int)
|
parser.add_argument("-b", action='store', metavar="seconds", default=-1, help="announce interval, 0 to only announce at startup", type=int)
|
||||||
parser.add_argument('-a', metavar="allowed_hash", dest="allowed", action='append', help="allow this identity", type=str)
|
parser.add_argument('-a', metavar="allowed_hash", dest="allowed", action='append', help="allow this identity", type=str)
|
||||||
parser.add_argument('-n', '--no-auth', action='store_true', default=False, help="accept requests from anyone")
|
parser.add_argument('-n', '--no-auth', action='store_true', default=False, help="accept requests from anyone")
|
||||||
@ -705,7 +695,6 @@ def main():
|
|||||||
quietness=args.quiet,
|
quietness=args.quiet,
|
||||||
allowed = args.allowed,
|
allowed = args.allowed,
|
||||||
fetch_allowed = args.allow_fetch,
|
fetch_allowed = args.allow_fetch,
|
||||||
jail = args.jail,
|
|
||||||
display_identity=args.print_identity,
|
display_identity=args.print_identity,
|
||||||
# limit=args.limit,
|
# limit=args.limit,
|
||||||
disable_auth=args.no_auth,
|
disable_auth=args.no_auth,
|
||||||
|
@ -46,16 +46,9 @@ def size_str(num, suffix='B'):
|
|||||||
|
|
||||||
return "%.2f%s%s" % (num, last_unit, suffix)
|
return "%.2f%s%s" % (num, last_unit, suffix)
|
||||||
|
|
||||||
def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=False, astats=False, lstats=False, sorting=None, sort_reverse=False):
|
def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=False, astats=False, sorting=None, sort_reverse=False):
|
||||||
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
||||||
|
|
||||||
link_count = None
|
|
||||||
if lstats:
|
|
||||||
try:
|
|
||||||
link_count = reticulum.get_link_count()
|
|
||||||
except Exception as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
stats = None
|
stats = None
|
||||||
try:
|
try:
|
||||||
stats = reticulum.get_interface_stats()
|
stats = reticulum.get_interface_stats()
|
||||||
@ -215,22 +208,11 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
|
|||||||
|
|
||||||
print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"])))
|
print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"])))
|
||||||
|
|
||||||
lstr = ""
|
|
||||||
if link_count != None and lstats:
|
|
||||||
ms = "y" if link_count == 1 else "ies"
|
|
||||||
if "transport_id" in stats and stats["transport_id"] != None:
|
|
||||||
lstr = f", {link_count} entr{ms} in link table"
|
|
||||||
else:
|
|
||||||
lstr = f" {link_count} entr{ms} in link table"
|
|
||||||
|
|
||||||
if "transport_id" in stats and stats["transport_id"] != None:
|
if "transport_id" in stats and stats["transport_id"] != None:
|
||||||
print("\n Transport Instance "+RNS.prettyhexrep(stats["transport_id"])+" running")
|
print("\n Transport Instance "+RNS.prettyhexrep(stats["transport_id"])+" running")
|
||||||
if "probe_responder" in stats and stats["probe_responder"] != None:
|
if "probe_responder" in stats and stats["probe_responder"] != None:
|
||||||
print(" Probe responder at "+RNS.prettyhexrep(stats["probe_responder"])+ " active")
|
print(" Probe responder at "+RNS.prettyhexrep(stats["probe_responder"])+ " active")
|
||||||
print(" Uptime is "+RNS.prettytime(stats["transport_uptime"])+lstr)
|
print(" Uptime is "+RNS.prettytime(stats["transport_uptime"]))
|
||||||
else:
|
|
||||||
if lstr != "":
|
|
||||||
print(f"\n{lstr}")
|
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
@ -259,14 +241,6 @@ def main():
|
|||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"-l",
|
|
||||||
"--link-stats",
|
|
||||||
action="store_true",
|
|
||||||
help="show link stats",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-s",
|
"-s",
|
||||||
"--sort",
|
"--sort",
|
||||||
@ -310,7 +284,6 @@ def main():
|
|||||||
name_filter=args.filter,
|
name_filter=args.filter,
|
||||||
json=args.json,
|
json=args.json,
|
||||||
astats=args.announce_stats,
|
astats=args.announce_stats,
|
||||||
lstats=args.link_stats,
|
|
||||||
sorting=args.sort,
|
sorting=args.sort,
|
||||||
sort_reverse=args.reverse,
|
sort_reverse=args.reverse,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user