From 333170b17256842a12a00bebe0e3e0863271d02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0urda?= Date: Fri, 6 Oct 2017 12:19:34 +0200 Subject: [PATCH] Dandelion fixes - more exception handling - only use outbound connections for stems (thanks to @amillter for info) - don't create stems if config disabled - addresses #1049 --- src/network/connectionpool.py | 3 +-- src/network/dandelion.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index 2943200b..7ae8afd9 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -55,8 +55,7 @@ class BMConnectionPool(object): # Choose 2 peers randomly # TODO: handle streams peers = [] - connections = self.inboundConnections.values() + \ - self.outboundConnections.values() + connections = self.outboundConnections.values() random.shuffle(connections) for i in connections: if i == node: diff --git a/src/network/dandelion.py b/src/network/dandelion.py index 045f7288..840cc909 100644 --- a/src/network/dandelion.py +++ b/src/network/dandelion.py @@ -1,6 +1,8 @@ from random import choice from threading import RLock +from time import time +from bmconfigparser import BMConfigParser from singleton import Singleton # randomise routes after 600 seconds @@ -16,10 +18,15 @@ class DandelionStems(): self.lock = RLock() def add(self, hashId, source, stems): + if BMConfigParser().safeGetInt('network', 'dandelion') == 0: + return with self.lock: - self.stem[hashId] = choice(stems) + try: + self.stem[hashId] = choice(stems) + except IndexError: + self.stem = None self.source[hashId] = source - self.timeouts[hashId] = time.time() + self.timeouts[hashId] = time() def remove(self, hashId): with self.lock: