From fba7aa635a241882f04d1c1d5066b80a67d115be Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Tue, 3 Sep 2024 05:09:02 +0300 Subject: [PATCH] Try to rewrite sending big invs not using sets --- minode/connection.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/minode/connection.py b/minode/connection.py index b7f9a75..e72849c 100644 --- a/minode/connection.py +++ b/minode/connection.py @@ -277,22 +277,19 @@ class ConnectionBase(threading.Thread): if len(addr) != 0: self.send_queue.put(message.Addr(addr)) - with shared.objects_lock: - if len(shared.objects) > 0: - to_send = { + if len(shared.objects) > 0: + with shared.objects_lock: + to_send = [ vector for vector in shared.objects.keys() - if shared.objects[vector].expires_time > time.time()} - while len(to_send) > 0: - if len(to_send) > 10000: - # We limit size of inv messaged to 10000 entries - # because they might time out - # in very slow networks (I2P) - pack = random.sample(tuple(to_send), 10000) - self.send_queue.put(message.Inv(pack)) - to_send.difference_update(pack) - else: - self.send_queue.put(message.Inv(to_send)) - to_send.clear() + if shared.objects[vector].expires_time > time.time()] + random.shuffle(to_send) + offset = 0 + while offset < len(to_send): + # We limit size of inv messaged to 10000 entries + # because they might time out + # in very slow networks (I2P) + self.send_queue.put(message.Inv(to_send[offset:offset+10000])) + offset += 10000 self.status = 'fully_established' def _process_queue(self):