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
This commit is contained in:
Peter Šurda 2017-10-06 12:19:34 +02:00
parent 1abdc14807
commit 333170b172
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 10 additions and 4 deletions

View File

@ -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:

View File

@ -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:
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: