Implementing proper bootstrap procedure #7

Merged
PeterSurda merged 6 commits from lee.miller/MiNode:bootstrap into v0.3 2024-10-22 03:07:55 +02:00
Showing only changes of commit ce8bef45b8 - Show all commits

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"""
try:
target = self.bootstrap_pool.pop() 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: else:
to_connect.update(shared.unchecked_node_pool) to_connect.update(shared.unchecked_node_pool)
if outgoing_connections < shared.outgoing_connections / 2:
bootstrap()
shared.unchecked_node_pool.difference_update(to_connect) shared.unchecked_node_pool.difference_update(to_connect)
if len(shared.node_pool) > 8: if len(shared.node_pool) > 8:
to_connect.update(random.sample( to_connect.update(random.sample(
tuple(shared.node_pool), 8)) tuple(shared.node_pool), 8))
else: else:
to_connect.update(shared.node_pool) to_connect.update(shared.node_pool)
else:
bootstrap()
if shared.i2p_enabled: if shared.i2p_enabled:
if len(shared.i2p_unchecked_node_pool) > 16: if len(shared.i2p_unchecked_node_pool) > 16: