This commit is contained in:
Mark Qvist 2025-10-30 19:45:40 +01:00
parent 6446db4f11
commit a62ffa12b1
2 changed files with 45 additions and 63 deletions

View file

@ -84,4 +84,4 @@ class LXMFPropagationAnnounceHandler:
except Exception as e:
RNS.log("Error while evaluating propagation node announce, ignoring announce.", RNS.LOG_DEBUG)
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
RNS.log(f"The contained exception was: {str(e)}", RNS.LOG_DEBUG)

View file

@ -243,14 +243,13 @@ class LXMPeer:
purged_ids = []
for transient_id in self.unhandled_messages:
if transient_id in self.router.propagation_entries:
unhandled_entry = [
transient_id,
unhandled_entry = [ transient_id,
self.router.get_weight(transient_id),
self.router.get_size(transient_id),
]
self.router.get_size(transient_id) ]
unhandled_entries.append(unhandled_entry)
else:
purged_ids.append(transient_id)
else: purged_ids.append(transient_id)
for transient_id in purged_ids:
RNS.log("Dropping unhandled message "+RNS.prettyhexrep(transient_id)+" for peer "+RNS.prettyhexrep(self.destination_hash)+" since it no longer exists in the message store.", RNS.LOG_DEBUG)
@ -260,6 +259,7 @@ class LXMPeer:
per_message_overhead = 16 # Really only 2 bytes, but set a bit higher for now
cumulative_size = 24 # Initialised to highest reasonable binary structure overhead
RNS.log(f"Syncing to peer with per-message limit {RNS.prettysize(self.propagation_transfer_limit*1000)} and sync limit {RNS.prettysize(self.propagation_sync_limit*1000)}") # TODO: Remove debug
for unhandled_entry in unhandled_entries:
transient_id = unhandled_entry[0]
weight = unhandled_entry[1]
@ -288,14 +288,11 @@ class LXMPeer:
else:
RNS.log("Postponing sync with peer "+RNS.prettyhexrep(self.destination_hash)+" for "+RNS.prettytime(self.next_sync_attempt-time.time())+" due to previous failures", RNS.LOG_DEBUG)
if self.last_sync_attempt > self.last_heard:
self.alive = False
if self.last_sync_attempt > self.last_heard: self.alive = False
def request_failed(self, request_receipt):
RNS.log("Sync request to peer "+str(self.destination)+" failed", RNS.LOG_DEBUG)
if self.link != None:
self.link.teardown()
RNS.log(f"Sync request to peer {self.destination} failed", RNS.LOG_DEBUG)
if self.link != None: self.link.teardown()
self.state = LXMPeer.IDLE
def offer_response(self, request_receipt):
@ -396,9 +393,7 @@ class LXMPeer:
self.add_handled_message(transient_id)
self.remove_unhandled_message(transient_id)
if self.link != None:
self.link.teardown()
if self.link != None: self.link.teardown()
self.link = None
self.state = LXMPeer.IDLE
@ -453,18 +448,13 @@ class LXMPeer:
def process_queues(self):
if len(self.unhandled_messages_queue) > 0 or len(self.handled_messages_queue) > 0:
# TODO: Remove debug
# st = time.time(); lu = len(self.unhandled_messages_queue); lh = len(self.handled_messages_queue)
handled_messages = self.handled_messages
unhandled_messages = self.unhandled_messages
while len(self.handled_messages_queue) > 0:
transient_id = self.handled_messages_queue.pop()
if not transient_id in handled_messages:
self.add_handled_message(transient_id)
if transient_id in unhandled_messages:
self.remove_unhandled_message(transient_id)
if not transient_id in handled_messages: self.add_handled_message(transient_id)
if transient_id in unhandled_messages: self.remove_unhandled_message(transient_id)
while len(self.unhandled_messages_queue) > 0:
transient_id = self.unhandled_messages_queue.pop()
@ -472,8 +462,6 @@ class LXMPeer:
self.add_unhandled_message(transient_id)
del handled_messages, unhandled_messages
# TODO: Remove debug
# RNS.log(f"{self} processed {lh}/{lu} in {RNS.prettytime(time.time()-st)}")
@property
def handled_messages(self):
@ -493,16 +481,12 @@ class LXMPeer:
@property
def handled_message_count(self):
if not self._hm_counts_synced:
self._update_counts()
if not self._hm_counts_synced: self._update_counts()
return self._hm_count
@property
def unhandled_message_count(self):
if not self._um_counts_synced:
self._update_counts()
if not self._um_counts_synced: self._update_counts()
return self._um_count
@property
@ -541,7 +525,5 @@ class LXMPeer:
self._um_counts_synced = False
def __str__(self):
if self.destination_hash:
return RNS.prettyhexrep(self.destination_hash)
else:
return "<Unknown>"
if self.destination_hash: return RNS.prettyhexrep(self.destination_hash)
else: return "<Unknown>"