From bd1024ff5c5ad4f3aa9a028fb09219f128df6f98 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 29 Nov 2026 14:14:18 +0100 Subject: [PATCH] Throttle and deduplicate timebase-equivalent announce emissions --- RNS/Destination.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index f618aa60..ec99b662 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -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()