From 07a7dbe040688ecfba9f0e2fac95111749985ab1 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Sat, 19 Aug 2023 05:40:10 +0300 Subject: [PATCH] Reduce number of simultaneous bootstrappers, refill the bootstrap pool --- minode/manager.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/minode/manager.py b/minode/manager.py index 6ebae5d..6761755 100644 --- a/minode/manager.py +++ b/minode/manager.py @@ -29,11 +29,14 @@ class Manager(threading.Thread): self.last_published_i2p_destination = \ time.time() - 50 * 60 + random.uniform(-1, 1) * 300 # nosec B311 + def fill_bootstrap_pool(self): + self.bootstrap_pool = list(shared.core_nodes.union(shared.node_pool)) + random.shuffle(self.bootstrap_pool) + def run(self): self.load_data() self.clean_objects() - self.bootstrap_pool = list(shared.core_nodes.union(shared.node_pool)) - random.shuffle(self.bootstrap_pool) + self.fill_bootstrap_pool() while True: time.sleep(0.8) now = time.time() @@ -111,20 +114,24 @@ class Manager(threading.Thread): ): if shared.ip_enabled: - if shared.unchecked_node_pool: - if len(shared.unchecked_node_pool) > 16: - to_connect.update(random.sample( - tuple(shared.unchecked_node_pool), 16)) - else: - to_connect.update(shared.unchecked_node_pool) - shared.unchecked_node_pool.difference_update(to_connect) - if len(shared.node_pool) > 8: - to_connect.update(random.sample( - tuple(shared.node_pool), 8)) - else: - to_connect.update(shared.node_pool) + if len(shared.unchecked_node_pool) > 16: + to_connect.update(random.sample( + tuple(shared.unchecked_node_pool), 16)) else: - bootstrap() + to_connect.update(shared.unchecked_node_pool) + if outgoing_connections < shared.outgoing_connections / 2: + try: + bootstrap() + except IndexError: + logging.warning( + 'Ran out of bootstrap nodes, refilling') + self.fill_bootstrap_pool() + shared.unchecked_node_pool.difference_update(to_connect) + if len(shared.node_pool) > 8: + to_connect.update(random.sample( + tuple(shared.node_pool), 8)) + else: + to_connect.update(shared.node_pool) if shared.i2p_enabled: if len(shared.i2p_unchecked_node_pool) > 16: