From bcc2ca7d3313fd5b5a2f3821599be2690607f652 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 15 May 2020 18:16:06 +0300 Subject: [PATCH] Immediately raise ValueError in connectionchooser.chooseConnection() if have no nodes for given stream. --- src/network/connectionchooser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index c31bbb6a..fddba10e 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -44,7 +44,10 @@ def chooseConnection(stream): # discovered peers are already filtered by allowed streams return getDiscoveredPeer() for _ in range(50): - peer = random.choice(knownnodes.knownNodes[stream].keys()) + try: + peer = random.choice(knownnodes.knownNodes[stream].keys()) + except IndexError: + break try: peer_info = knownnodes.knownNodes[stream][peer] if peer_info.get('self'):