Reduce number of simultaneous bootstrappers, refill the bootstrap pool

This commit is contained in:
Lee Miller 2023-08-19 05:40:10 +03:00
parent 7053ac84f7
commit ce8bef45b8
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -29,11 +29,15 @@ class Manager(threading.Thread):
self.last_published_i2p_destination = \ self.last_published_i2p_destination = \
time.time() - 50 * 60 + random.uniform(-1, 1) * 300 # nosec B311 time.time() - 50 * 60 + random.uniform(-1, 1) * 300 # nosec B311
def fill_bootstrap_pool(self):
"""Populate the bootstrap pool by core nodes and checked ones"""
self.bootstrap_pool = list(shared.core_nodes.union(shared.node_pool))
random.shuffle(self.bootstrap_pool)
def run(self): def run(self):
self.load_data() self.load_data()
self.clean_objects() self.clean_objects()
self.bootstrap_pool = list(shared.core_nodes.union(shared.node_pool)) self.fill_bootstrap_pool()
random.shuffle(self.bootstrap_pool)
while True: while True:
time.sleep(0.8) time.sleep(0.8)
now = time.time() now = time.time()
@ -87,7 +91,13 @@ class Manager(threading.Thread):
def bootstrap(): def bootstrap():
"""Bootstrap from DNS seed-nodes and known nodes""" """Bootstrap from DNS seed-nodes and known nodes"""
target = self.bootstrap_pool.pop() try:
target = self.bootstrap_pool.pop()
except IndexError:
logging.warning(
'Ran out of bootstrap nodes, refilling')
self.fill_bootstrap_pool()
return
logging.info('Starting a bootstrapper for %s:%s', *target) logging.info('Starting a bootstrapper for %s:%s', *target)
connect(target, Bootstrapper) connect(target, Bootstrapper)
@ -116,20 +126,19 @@ class Manager(threading.Thread):
): ):
if shared.ip_enabled: if shared.ip_enabled:
if shared.unchecked_node_pool: if len(shared.unchecked_node_pool) > 16:
if len(shared.unchecked_node_pool) > 16: to_connect.update(random.sample(
to_connect.update(random.sample( tuple(shared.unchecked_node_pool), 16))
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)
else: else:
bootstrap() to_connect.update(shared.unchecked_node_pool)
if outgoing_connections < shared.outgoing_connections / 2:
bootstrap()
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 shared.i2p_enabled:
if len(shared.i2p_unchecked_node_pool) > 16: if len(shared.i2p_unchecked_node_pool) > 16: