mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 05:30:17 +00:00
Compare commits
12 Commits
b30f4fc9ba
...
9f1320489c
Author | SHA1 | Date | |
---|---|---|---|
|
9f1320489c | ||
|
c71ece6b8e | ||
|
1e45a002e1 | ||
|
68e64523b5 | ||
|
d9e6145034 | ||
|
a91e67129e | ||
|
76362bad4a | ||
|
421b5ef32e | ||
|
8d61ee8a81 | ||
|
2329181c88 | ||
|
a666bb6e73 | ||
|
5c6ee07d66 |
@ -167,6 +167,9 @@ 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 = KISSInterface.BITRATE_GUESS
|
self.bitrate = AX25KISSInterface.BITRATE_GUESS
|
||||||
|
|
||||||
self.packet_queue = []
|
self.packet_queue = []
|
||||||
self.flow_control = flow_control
|
self.flow_control = flow_control
|
||||||
|
@ -200,7 +200,7 @@ class TCPClientInterface(Interface):
|
|||||||
if initial:
|
if initial:
|
||||||
RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG)
|
RNS.log("Establishing TCP connection for "+str(self)+"...", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.socket = socket.socket(socket.AF_INET|socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT)
|
self.socket.settimeout(TCPClientInterface.INITIAL_CONNECT_TIMEOUT)
|
||||||
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
self.socket.connect((self.target_ip, self.target_port))
|
self.socket.connect((self.target_ip, self.target_port))
|
||||||
|
@ -68,6 +68,7 @@ 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 = packet.destination.rtt * packet.destination.traffic_timeout_factor
|
self.timeout = max(packet.destination.rtt * packet.destination.traffic_timeout_factor, RNS.Link.TRAFFIC_TIMEOUT_MIN_MS/1000)
|
||||||
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,6 +160,9 @@ 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,12 +301,23 @@ 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):
|
||||||
@ -664,6 +675,7 @@ 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,6 +270,53 @@ 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")
|
||||||
@ -285,3 +332,94 @@ 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.7"
|
__version__ = "0.7.8"
|
||||||
|
Loading…
Reference in New Issue
Block a user