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: