Added stamp cost display to utilities

This commit is contained in:
Mark Qvist 2026-10-31 17:48:24 +01:00
parent c4ed59be2c
commit 2117087710
No known key found for this signature in database
5 changed files with 26 additions and 7 deletions

View file

@ -596,7 +596,7 @@ class InterfaceDiscovery():
hops = info["hops"]; ms = "" if hops == 1 else "s"
filename = RNS.hexrep(discovery_hash, delimit=False)
filepath = os.path.join(self.storagepath, filename)
RNS.log(f"Discovered {interface_type}{version_str} {hops} hop{ms} away with stamp value {value}: {name}", RNS.LOG_DEBUG)
RNS.log(f"Discovered {interface_type}{version_str} {hops} hop{ms} away with stamp value {RNS.prettystampval(value)}: {name}", RNS.LOG_DEBUG)
with self.discovery_lock:
if not os.path.isfile(filepath):
try:

View file

@ -1829,10 +1829,13 @@ class Reticulum:
for dst_hash in RNS.Transport.path_table:
path_hops = RNS.Transport.path_table[dst_hash][2]
if max_hops == None or path_hops <= max_hops:
known_destination = RNS.Identity.known_destinations.get(dst_hash, None)
dst_value = known_destination[6] if known_destination else None
lr_cost = known_destination[7] if known_destination else None
entry = { "hash": dst_hash, "timestamp": RNS.Transport.path_table[dst_hash][0],
"via": RNS.Transport.path_table[dst_hash][1], "hops": path_hops,
"expires": RNS.Transport.path_table[dst_hash][3],
"used": RNS.Transport.path_table[dst_hash][7],
"expires": RNS.Transport.path_table[dst_hash][3], "value": dst_value,
"used": RNS.Transport.path_table[dst_hash][7], "lr_cost": lr_cost,
"interface": str(RNS.Transport.path_table[dst_hash][5]) }
path_table.append(entry)

View file

@ -286,6 +286,7 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity,
try: table = sorted(table, key=lambda e: e["used"], reverse=True)
except Exception as e: pass
now = time.time()
for path in table:
if destination_hash == None or destination_hash == path["hash"]:
displayed += 1
@ -296,7 +297,8 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity,
else:
if usage: u_str = f", last used {RNS.prettytime(now-path['used'])} ago" if path["used"] else ", never used"
else: u_str = ""
print(RNS.prettyhexrep(path["hash"])+" is "+str(path["hops"])+" hop"+m_str+" away via "+RNS.prettyhexrep(path["via"])+" on "+path["interface"]+" expires "+RNS.timestamp_str(path["expires"])+u_str)
# print(RNS.prettyhexrep(path["hash"])+" is "+str(path["hops"])+" hop"+m_str+" away via "+RNS.prettyhexrep(path["via"])+" on "+path["interface"]+" expires "+RNS.timestamp_str(path["expires"])+u_str)
print(f"{RNS.prettyhexrep(path['hash'])} {path["hops"]:>3}h via {RNS.prettyhexrep(path['via'])} on {path['interface']} expires in {RNS.prettytime(path["expires"]-now, compact=True)} (dv:{RNS.prettycost(path["value"])}/lc:{RNS.prettycost(path["lr_cost"])})")
if destination_hash != None and displayed == 0:
print("No path known")

View file

@ -261,6 +261,14 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
last_heard_display = f"{RNS.prettytime(hago, compact=True)} ago"
transport_str = "Enabled" if i["transport"] else "Disabled"
has_cost_info = "dst_cost" in i and "pr_cost" in i
dst_cost = None; pr_cost = None
if not has_cost_info: cost_str = "Unknown"
else:
dst_cost = i["dst_cost"]
pr_cost = i["pr_cost"]
cost_str = f"Dst {RNS.prettycost(dst_cost)}, PR {RNS.prettycost(pr_cost)}"
if i["latitude"] is not None and i["longitude"] is not None:
lat = round(i["latitude"], 4)
lon = round(i["longitude"], 4)
@ -287,6 +295,8 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
print(f"Stack : {impl_str}")
print(f"Status : {status_display}")
print(f"Transport : {transport_str}")
print(f"Stamp Value : {RNS.prettycost(i['value'])}")
print(f"Costs : {cost_str}") if has_cost_info else None
print(f"Distance : {i['hops']} hop{'' if i['hops'] == 1 else 's'}")
print(f"Discovered : {discovered_display}")
print(f"Last Heard : {last_heard_display}")
@ -300,8 +310,6 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
if "reachable_on" in i: print(f"Address : {i['reachable_on']}")
if "port" in i: print(f"Port : {i['port']}")
print(f"Stamp Value : {i['value']}")
print(f"\nConfiguration Entry:")
config_lines = i["config_entry"].split('\n')
for line in config_lines: print(f" {line}")
@ -345,7 +353,7 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
days = int(diff / 86400)
last_heard_display = f"{days}d ago"
value = str(i["value"])
value = RNS.prettycost(i["value"])
if i["latitude"] is not None and i["longitude"] is not None:
lat = round(i["latitude"], 4)

View file

@ -41,6 +41,7 @@ import bisect
from ._version import __version__
from collections import deque
from functools import partial, wraps
from RNS.Stamps import quantize_cost
py_modules = glob.glob(os.path.dirname(__file__)+"/*.py")
pyc_modules = glob.glob(os.path.dirname(__file__)+"/*.pyc")
@ -179,6 +180,11 @@ def prettyhexrep(data):
hexrep = "<"+delimiter.join("{:02x}".format(c) for c in data)+">"
return hexrep
def prettycost(value):
if value == None: return "?"
elif not type(value) in (float, int): return "?"
else: return f"{quantize_cost(value):.3f}"
def prettyspeed(num, suffix="b"):
return prettysize(num/8, suffix=suffix)+"ps"