Ignore self node in connectionchooser.chooseConnection()

This commit is contained in:
Dmitri Bogomolov 2019-07-29 14:37:56 +03:00
parent 7215003c6f
commit bdb09c2d00
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -1,3 +1,4 @@
# pylint: disable=too-many-branches
import random # nosec import random # nosec
import knownnodes import knownnodes
@ -38,7 +39,10 @@ def chooseConnection(stream):
for _ in range(50): for _ in range(50):
peer = random.choice(knownnodes.knownNodes[stream].keys()) peer = random.choice(knownnodes.knownNodes[stream].keys())
try: try:
rating = knownnodes.knownNodes[stream][peer]['rating'] peer_info = knownnodes.knownNodes[stream][peer]
if peer_info.get('self'):
continue
rating = peer_info["rating"]
except TypeError: except TypeError:
logger.warning('Error in %s', peer) logger.warning('Error in %s', peer)
rating = 0 rating = 0