From 90efa09c96f8c9997659dd98cf5b9bb7b7d4cfb7 Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 6 Mar 2024 15:24:16 +0700 Subject: [PATCH] fix overlay max peers --- pytoniq/adnl/overlay/overlay_manager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pytoniq/adnl/overlay/overlay_manager.py b/pytoniq/adnl/overlay/overlay_manager.py index 5e86a75..21c9baa 100644 --- a/pytoniq/adnl/overlay/overlay_manager.py +++ b/pytoniq/adnl/overlay/overlay_manager.py @@ -67,11 +67,12 @@ async def get_more_peers(self): self.logger.debug(f'Got {len(self.overlay.peers)} first peers') await asyncio.sleep(10) continue + if len(self.overlay.peers) >= self.max_peers: + await asyncio.sleep(10) + continue clients = [] tasks = [] for _, peer in list(self.overlay.peers.items()): - if len(self.overlay.peers) > self.max_peers: - return 0 self.logger.debug(f'getting nodes from peer {peer.get_key_id().hex()}') if not peer.connected: self.logger.debug(f'peer {peer.get_key_id().hex()} is already not connected') @@ -108,7 +109,7 @@ async def try_connect(client): tasks = [] for new_client in clients: - if len(self.overlay.peers) > self.max_peers: + if len(self.overlay.peers) + len(tasks) >= self.max_peers: break if new_client is not None: tasks.append(try_connect(new_client))