mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-12-02 12:57:09 -05:00
Throttle and deduplicate timebase-equivalent announce emissions
This commit is contained in:
parent
20bd15cdf6
commit
bd1024ff5c
1 changed files with 19 additions and 1 deletions
|
|
@ -182,6 +182,8 @@ class Destination:
|
|||
self.latest_ratchet_time = None
|
||||
self.latest_ratchet_id = None
|
||||
self.__enforce_ratchets = False
|
||||
self.timebase_deferred_waiting = False
|
||||
self.announce_timebase = 0
|
||||
self.mtu = 0
|
||||
|
||||
self.path_responses = {}
|
||||
|
|
@ -294,6 +296,20 @@ class Destination:
|
|||
if self.type != Destination.SINGLE: raise TypeError("Only SINGLE destination types can be announced")
|
||||
if self.direction != Destination.IN: raise TypeError("Only IN destination types can be announced")
|
||||
|
||||
if not path_response and send and int(time.time()) <= self.announce_timebase:
|
||||
if self.timebase_deferred_waiting: RNS.log(f"Timebase-equivalent announce emission with already deferred announce attempted on {self}, dropping", RNS.LOG_WARNING)
|
||||
else:
|
||||
RNS.log(f"Timebase-equivalent announce emission attempted on {self}, deferring", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
self.timebase_deferred_waiting = True
|
||||
def job():
|
||||
time.sleep(2.5)
|
||||
try: self.announce(app_data=app_data, path_response=path_response, attached_interface=attached_interface, tag=tag)
|
||||
except Exception as e: RNS.log(f"Error while processing timebase-deferred announce: {e}", RNS.LOG_ERROR)
|
||||
finally: self.timebase_deferred_waiting = False
|
||||
threading.Thread(target=job, daemon=True).start()
|
||||
|
||||
return
|
||||
|
||||
if send and RNS.Transport.STAMP_DESTINATIONS and self.stamp == None:
|
||||
# If no stamp is available, queue for background generation
|
||||
# and announce emission once ready.
|
||||
|
|
@ -330,7 +346,9 @@ class Destination:
|
|||
|
||||
else:
|
||||
destination_hash = self.hash
|
||||
random_hash = RNS.Identity.get_random_hash()[0:5]+int(time.time()).to_bytes(5, "big")
|
||||
announce_timebase = int(time.time())
|
||||
random_hash = RNS.Identity.get_random_hash()[0:5]+announce_timebase.to_bytes(5, "big")
|
||||
self.announce_timebase = announce_timebase
|
||||
|
||||
if self.ratchets != None:
|
||||
self.rotate_ratchets()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue