mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-05 13:50:14 +00:00
Improved announce queue processing
This commit is contained in:
parent
e95e9e6a89
commit
1b50f5267a
@ -592,7 +592,6 @@ class Transport:
|
|||||||
interface.announce_queue = []
|
interface.announce_queue = []
|
||||||
|
|
||||||
queued_announces = True if len(interface.announce_queue) > 0 else False
|
queued_announces = True if len(interface.announce_queue) > 0 else False
|
||||||
|
|
||||||
if not queued_announces and outbound_time > interface.announce_allowed_at:
|
if not queued_announces and outbound_time > interface.announce_allowed_at:
|
||||||
tx_time = (len(packet.raw)*8) / interface.bitrate
|
tx_time = (len(packet.raw)*8) / interface.bitrate
|
||||||
wait_time = (tx_time / interface.announce_cap)
|
wait_time = (tx_time / interface.announce_cap)
|
||||||
@ -605,24 +604,50 @@ class Transport:
|
|||||||
else:
|
else:
|
||||||
should_transmit = False
|
should_transmit = False
|
||||||
if not len(interface.announce_queue) >= RNS.Reticulum.MAX_QUEUED_ANNOUNCES:
|
if not len(interface.announce_queue) >= RNS.Reticulum.MAX_QUEUED_ANNOUNCES:
|
||||||
entry = {"time": outbound_time, "hops": packet.hops, "raw": packet.raw}
|
should_queue = True
|
||||||
queued_announces = True if len(interface.announce_queue) > 0 else False
|
|
||||||
interface.announce_queue.append(entry)
|
|
||||||
|
|
||||||
if not queued_announces:
|
already_queued = False
|
||||||
wait_time = max(interface.announce_allowed_at - time.time(), 0)
|
for e in interface.announce_queue:
|
||||||
timer = threading.Timer(wait_time, interface.process_announce_queue)
|
if e["destination"] == packet.destination_hash:
|
||||||
timer.start()
|
already_queued = True
|
||||||
|
existing_entry = e
|
||||||
|
|
||||||
wait_time_str = str(round(wait_time*1000,3))+"ms"
|
emission_timestamp = Transport.announce_emitted(packet)
|
||||||
ql_str = str(len(interface.announce_queue))
|
if already_queued:
|
||||||
RNS.log("Added announce to queue (height "+ql_str+") on "+str(interface)+" for processing in "+wait_time_str, RNS.LOG_EXTREME)
|
should_queue = False
|
||||||
|
|
||||||
else:
|
if emission_timestamp > existing_entry["emitted"]:
|
||||||
wait_time = max(interface.announce_allowed_at - time.time(), 0)
|
e["time"] = outbound_time
|
||||||
wait_time_str = str(round(wait_time*1000,3))+"ms"
|
e["hops"] = packet.hops
|
||||||
ql_str = str(len(interface.announce_queue))
|
e["emitted"] = emission_timestamp
|
||||||
RNS.log("Added announce to queue (height "+ql_str+") on "+str(interface)+" for processing in "+wait_time_str, RNS.LOG_EXTREME)
|
e["raw"] = packet.raw
|
||||||
|
|
||||||
|
if should_queue:
|
||||||
|
entry = {
|
||||||
|
"destination": packet.destination_hash,
|
||||||
|
"time": outbound_time,
|
||||||
|
"hops": packet.hops,
|
||||||
|
"emitted": Transport.announce_emitted(packet),
|
||||||
|
"raw": packet.raw
|
||||||
|
}
|
||||||
|
|
||||||
|
queued_announces = True if len(interface.announce_queue) > 0 else False
|
||||||
|
interface.announce_queue.append(entry)
|
||||||
|
|
||||||
|
if not queued_announces:
|
||||||
|
wait_time = max(interface.announce_allowed_at - time.time(), 0)
|
||||||
|
timer = threading.Timer(wait_time, interface.process_announce_queue)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
wait_time_str = str(round(wait_time*1000,3))+"ms"
|
||||||
|
ql_str = str(len(interface.announce_queue))
|
||||||
|
RNS.log("Added announce to queue (height "+ql_str+") on "+str(interface)+" for processing in "+wait_time_str, RNS.LOG_EXTREME)
|
||||||
|
|
||||||
|
else:
|
||||||
|
wait_time = max(interface.announce_allowed_at - time.time(), 0)
|
||||||
|
wait_time_str = str(round(wait_time*1000,3))+"ms"
|
||||||
|
ql_str = str(len(interface.announce_queue))
|
||||||
|
RNS.log("Added announce to queue (height "+ql_str+") on "+str(interface)+" for processing in "+wait_time_str, RNS.LOG_EXTREME)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@ -985,8 +1010,9 @@ class Transport:
|
|||||||
# First, check that the announce is not for a destination
|
# First, check that the announce is not for a destination
|
||||||
# local to this system, and that hops are less than the max
|
# local to this system, and that hops are less than the max
|
||||||
if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
|
if (not any(packet.destination_hash == d.hash for d in Transport.destinations) and packet.hops < Transport.PATHFINDER_M+1):
|
||||||
|
announce_emitted = Transport.announce_emitted(packet)
|
||||||
|
|
||||||
random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8]
|
random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8]
|
||||||
announce_emitted = int.from_bytes(random_blob[5:10], "big")
|
|
||||||
random_blobs = []
|
random_blobs = []
|
||||||
if packet.destination_hash in Transport.destination_table:
|
if packet.destination_hash in Transport.destination_table:
|
||||||
random_blobs = Transport.destination_table[packet.destination_hash][4]
|
random_blobs = Transport.destination_table[packet.destination_hash][4]
|
||||||
@ -1772,6 +1798,13 @@ class Transport:
|
|||||||
if registered_destination.type == RNS.Destination.SINGLE:
|
if registered_destination.type == RNS.Destination.SINGLE:
|
||||||
registered_destination.announce(path_response=True)
|
registered_destination.announce(path_response=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def announce_emitted(packet):
|
||||||
|
random_blob = packet.data[RNS.Identity.KEYSIZE//8:RNS.Identity.KEYSIZE//8+RNS.Reticulum.TRUNCATED_HASHLENGTH//8]
|
||||||
|
announce_emitted = int.from_bytes(random_blob[5:10], "big")
|
||||||
|
|
||||||
|
return announce_emitted
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user