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))