mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 21:50:18 +00:00
Compare commits
1 Commits
9f1320489c
...
b30f4fc9ba
Author | SHA1 | Date | |
---|---|---|---|
|
b30f4fc9ba |
@ -167,9 +167,6 @@ class Destination:
|
|||||||
identity = RNS.Identity()
|
identity = RNS.Identity()
|
||||||
aspects = aspects+(identity.hexhash,)
|
aspects = aspects+(identity.hexhash,)
|
||||||
|
|
||||||
if identity == None and direction == Destination.OUT and self.type != Destination.PLAIN:
|
|
||||||
raise ValueError("Can't create outbound SINGLE destination without an identity")
|
|
||||||
|
|
||||||
if identity != None and self.type == Destination.PLAIN:
|
if identity != None and self.type == Destination.PLAIN:
|
||||||
raise TypeError("Selected destination type PLAIN cannot hold an identity")
|
raise TypeError("Selected destination type PLAIN cannot hold an identity")
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class AX25KISSInterface(Interface):
|
|||||||
self.stopbits = stopbits
|
self.stopbits = stopbits
|
||||||
self.timeout = 100
|
self.timeout = 100
|
||||||
self.online = False
|
self.online = False
|
||||||
self.bitrate = AX25KISSInterface.BITRATE_GUESS
|
self.bitrate = KISSInterface.BITRATE_GUESS
|
||||||
|
|
||||||
self.packet_queue = []
|
self.packet_queue = []
|
||||||
self.flow_control = flow_control
|
self.flow_control = flow_control
|
||||||
|
@ -68,7 +68,6 @@ class Link:
|
|||||||
Timeout for link establishment in seconds per hop to destination.
|
Timeout for link establishment in seconds per hop to destination.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TRAFFIC_TIMEOUT_MIN_MS = 5
|
|
||||||
TRAFFIC_TIMEOUT_FACTOR = 6
|
TRAFFIC_TIMEOUT_FACTOR = 6
|
||||||
KEEPALIVE_TIMEOUT_FACTOR = 4
|
KEEPALIVE_TIMEOUT_FACTOR = 4
|
||||||
"""
|
"""
|
||||||
|
@ -381,7 +381,7 @@ class PacketReceipt:
|
|||||||
self.proof_packet = None
|
self.proof_packet = None
|
||||||
|
|
||||||
if packet.destination.type == RNS.Destination.LINK:
|
if packet.destination.type == RNS.Destination.LINK:
|
||||||
self.timeout = max(packet.destination.rtt * packet.destination.traffic_timeout_factor, RNS.Link.TRAFFIC_TIMEOUT_MIN_MS/1000)
|
self.timeout = packet.destination.rtt * packet.destination.traffic_timeout_factor
|
||||||
else:
|
else:
|
||||||
self.timeout = RNS.Reticulum.get_instance().get_first_hop_timeout(self.destination.hash)
|
self.timeout = RNS.Reticulum.get_instance().get_first_hop_timeout(self.destination.hash)
|
||||||
self.timeout += Packet.TIMEOUT_PER_HOP * RNS.Transport.hops_to(self.destination.hash)
|
self.timeout += Packet.TIMEOUT_PER_HOP * RNS.Transport.hops_to(self.destination.hash)
|
||||||
|
@ -160,9 +160,6 @@ class Reticulum:
|
|||||||
RNS.Transport.exit_handler()
|
RNS.Transport.exit_handler()
|
||||||
RNS.Identity.exit_handler()
|
RNS.Identity.exit_handler()
|
||||||
|
|
||||||
if RNS.profiler_ran:
|
|
||||||
RNS.profiler_results()
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sigint_handler(signal, frame):
|
def sigint_handler(signal, frame):
|
||||||
RNS.Transport.detach_interfaces()
|
RNS.Transport.detach_interfaces()
|
||||||
|
@ -301,23 +301,12 @@ class Transport:
|
|||||||
RNS.log("Transport instance "+str(Transport.identity)+" started", RNS.LOG_VERBOSE)
|
RNS.log("Transport instance "+str(Transport.identity)+" started", RNS.LOG_VERBOSE)
|
||||||
Transport.start_time = time.time()
|
Transport.start_time = time.time()
|
||||||
|
|
||||||
# Sort interfaces according to bitrate
|
|
||||||
Transport.prioritize_interfaces()
|
|
||||||
|
|
||||||
# Synthesize tunnels for any interfaces wanting it
|
# Synthesize tunnels for any interfaces wanting it
|
||||||
for interface in Transport.interfaces:
|
for interface in Transport.interfaces:
|
||||||
interface.tunnel_id = None
|
interface.tunnel_id = None
|
||||||
if hasattr(interface, "wants_tunnel") and interface.wants_tunnel:
|
if hasattr(interface, "wants_tunnel") and interface.wants_tunnel:
|
||||||
Transport.synthesize_tunnel(interface)
|
Transport.synthesize_tunnel(interface)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def prioritize_interfaces():
|
|
||||||
try:
|
|
||||||
Transport.interfaces.sort(key=lambda interface: interface.bitrate, reverse=True)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
RNS.log(f"Could not prioritize interfaces according to bitrate. The contained exception was: {e}", RNS.LOG_ERROR)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def jobloop():
|
def jobloop():
|
||||||
while (True):
|
while (True):
|
||||||
@ -675,7 +664,6 @@ class Transport:
|
|||||||
Transport.tables_last_culled = time.time()
|
Transport.tables_last_culled = time.time()
|
||||||
|
|
||||||
if time.time() > Transport.interface_last_jobs + Transport.interface_jobs_interval:
|
if time.time() > Transport.interface_last_jobs + Transport.interface_jobs_interval:
|
||||||
Transport.prioritize_interfaces()
|
|
||||||
for interface in Transport.interfaces:
|
for interface in Transport.interfaces:
|
||||||
interface.process_held_announces()
|
interface.process_held_announces()
|
||||||
Transport.interface_last_jobs = time.time()
|
Transport.interface_last_jobs = time.time()
|
||||||
|
138
RNS/__init__.py
138
RNS/__init__.py
@ -270,53 +270,6 @@ def prettytime(time, verbose=False, compact=False):
|
|||||||
else:
|
else:
|
||||||
return tstr
|
return tstr
|
||||||
|
|
||||||
def prettyshorttime(time, verbose=False, compact=False):
|
|
||||||
time = time*1e6
|
|
||||||
|
|
||||||
seconds = int(time // 1e6); time %= 1e6
|
|
||||||
milliseconds = int(time // 1e3); time %= 1e3
|
|
||||||
|
|
||||||
if compact:
|
|
||||||
microseconds = int(time)
|
|
||||||
else:
|
|
||||||
microseconds = round(time, 2)
|
|
||||||
|
|
||||||
ss = "" if seconds == 1 else "s"
|
|
||||||
sms = "" if milliseconds == 1 else "s"
|
|
||||||
sus = "" if microseconds == 1 else "s"
|
|
||||||
|
|
||||||
displayed = 0
|
|
||||||
components = []
|
|
||||||
if seconds > 0 and ((not compact) or displayed < 2):
|
|
||||||
components.append(str(seconds)+" second"+ss if verbose else str(seconds)+"s")
|
|
||||||
displayed += 1
|
|
||||||
|
|
||||||
if milliseconds > 0 and ((not compact) or displayed < 2):
|
|
||||||
components.append(str(milliseconds)+" millisecond"+sms if verbose else str(milliseconds)+"ms")
|
|
||||||
displayed += 1
|
|
||||||
|
|
||||||
if microseconds > 0 and ((not compact) or displayed < 2):
|
|
||||||
components.append(str(microseconds)+" microsecond"+sus if verbose else str(microseconds)+"µs")
|
|
||||||
displayed += 1
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
tstr = ""
|
|
||||||
for c in components:
|
|
||||||
i += 1
|
|
||||||
if i == 1:
|
|
||||||
pass
|
|
||||||
elif i < len(components):
|
|
||||||
tstr += ", "
|
|
||||||
elif i == len(components):
|
|
||||||
tstr += " and "
|
|
||||||
|
|
||||||
tstr += c
|
|
||||||
|
|
||||||
if tstr == "":
|
|
||||||
return "0us"
|
|
||||||
else:
|
|
||||||
return tstr
|
|
||||||
|
|
||||||
def phyparams():
|
def phyparams():
|
||||||
print("Required Physical Layer MTU : "+str(Reticulum.MTU)+" bytes")
|
print("Required Physical Layer MTU : "+str(Reticulum.MTU)+" bytes")
|
||||||
print("Plaintext Packet MDU : "+str(Packet.PLAIN_MDU)+" bytes")
|
print("Plaintext Packet MDU : "+str(Packet.PLAIN_MDU)+" bytes")
|
||||||
@ -332,94 +285,3 @@ def panic():
|
|||||||
def exit():
|
def exit():
|
||||||
print("")
|
print("")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
profiler_ran = False
|
|
||||||
profiler_tags = {}
|
|
||||||
def profiler(tag=None, capture=False, super_tag=None):
|
|
||||||
global profiler_ran, profiler_tags
|
|
||||||
try:
|
|
||||||
thread_ident = threading.get_ident()
|
|
||||||
|
|
||||||
if capture:
|
|
||||||
end = time.perf_counter()
|
|
||||||
if tag in profiler_tags and thread_ident in profiler_tags[tag]["threads"]:
|
|
||||||
if profiler_tags[tag]["threads"][thread_ident]["current_start"] != None:
|
|
||||||
begin = profiler_tags[tag]["threads"][thread_ident]["current_start"]
|
|
||||||
profiler_tags[tag]["threads"][thread_ident]["current_start"] = None
|
|
||||||
profiler_tags[tag]["threads"][thread_ident]["captures"].append(end-begin)
|
|
||||||
if not profiler_ran:
|
|
||||||
profiler_ran = True
|
|
||||||
|
|
||||||
else:
|
|
||||||
if not tag in profiler_tags:
|
|
||||||
profiler_tags[tag] = {"threads": {}, "super": super_tag}
|
|
||||||
if not thread_ident in profiler_tags[tag]["threads"]:
|
|
||||||
profiler_tags[tag]["threads"][thread_ident] = {"current_start": None, "captures": []}
|
|
||||||
|
|
||||||
profiler_tags[tag]["threads"][thread_ident]["current_start"] = time.perf_counter()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
trace_exception(e)
|
|
||||||
|
|
||||||
def profiler_results():
|
|
||||||
from statistics import mean, median, stdev
|
|
||||||
results = {}
|
|
||||||
|
|
||||||
for tag in profiler_tags:
|
|
||||||
tag_captures = []
|
|
||||||
tag_entry = profiler_tags[tag]
|
|
||||||
|
|
||||||
for thread_ident in tag_entry["threads"]:
|
|
||||||
thread_entry = tag_entry["threads"][thread_ident]
|
|
||||||
thread_captures = thread_entry["captures"]
|
|
||||||
sample_count = len(thread_captures)
|
|
||||||
|
|
||||||
if sample_count > 2:
|
|
||||||
thread_results = {
|
|
||||||
"count": sample_count,
|
|
||||||
"mean": mean(thread_captures),
|
|
||||||
"median": median(thread_captures),
|
|
||||||
"stdev": stdev(thread_captures)
|
|
||||||
}
|
|
||||||
|
|
||||||
tag_captures.extend(thread_captures)
|
|
||||||
|
|
||||||
sample_count = len(tag_captures)
|
|
||||||
if sample_count > 2:
|
|
||||||
tag_results = {
|
|
||||||
"name": tag,
|
|
||||||
"super": tag_entry["super"],
|
|
||||||
"count": len(tag_captures),
|
|
||||||
"mean": mean(tag_captures),
|
|
||||||
"median": median(tag_captures),
|
|
||||||
"stdev": stdev(tag_captures)
|
|
||||||
}
|
|
||||||
|
|
||||||
results[tag] = tag_results
|
|
||||||
|
|
||||||
def print_results_recursive(tag, results, level=0):
|
|
||||||
print_tag_results(tag, level+1)
|
|
||||||
|
|
||||||
for tag_name in results:
|
|
||||||
sub_tag = results[tag_name]
|
|
||||||
if sub_tag["super"] == tag["name"]:
|
|
||||||
print_results_recursive(sub_tag, results, level=level+1)
|
|
||||||
|
|
||||||
|
|
||||||
def print_tag_results(tag, level):
|
|
||||||
ind = " "*level
|
|
||||||
name = tag["name"]; count = tag["count"]
|
|
||||||
mean = tag["mean"]; tag["median"]; stdev = tag["stdev"]
|
|
||||||
print(f"{ind}{name}")
|
|
||||||
print(f"{ind} Samples : {count}")
|
|
||||||
print(f"{ind} Mean : {prettyshorttime(mean)}")
|
|
||||||
print(f"{ind} Median : {prettyshorttime(median)}")
|
|
||||||
print(f"{ind} St.dev. : {prettyshorttime(stdev)}")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
print("\nProfiler results:\n")
|
|
||||||
for tag_name in results:
|
|
||||||
tag = results[tag_name]
|
|
||||||
if tag["super"] == None:
|
|
||||||
print_results_recursive(tag, results)
|
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = "0.7.8"
|
__version__ = "0.7.7"
|
||||||
|
Loading…
Reference in New Issue
Block a user