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:
parent
1abdc14807
commit
333170b172
|
@ -55,8 +55,7 @@ class BMConnectionPool(object):
|
||||||
# Choose 2 peers randomly
|
# Choose 2 peers randomly
|
||||||
# TODO: handle streams
|
# TODO: handle streams
|
||||||
peers = []
|
peers = []
|
||||||
connections = self.inboundConnections.values() + \
|
connections = self.outboundConnections.values()
|
||||||
self.outboundConnections.values()
|
|
||||||
random.shuffle(connections)
|
random.shuffle(connections)
|
||||||
for i in connections:
|
for i in connections:
|
||||||
if i == node:
|
if i == node:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from random import choice
|
from random import choice
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
from bmconfigparser import BMConfigParser
|
||||||
from singleton import Singleton
|
from singleton import Singleton
|
||||||
|
|
||||||
# randomise routes after 600 seconds
|
# randomise routes after 600 seconds
|
||||||
|
@ -16,10 +18,15 @@ class DandelionStems():
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
|
|
||||||
def add(self, hashId, source, stems):
|
def add(self, hashId, source, stems):
|
||||||
|
if BMConfigParser().safeGetInt('network', 'dandelion') == 0:
|
||||||
|
return
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.stem[hashId] = choice(stems)
|
try:
|
||||||
|
self.stem[hashId] = choice(stems)
|
||||||
|
except IndexError:
|
||||||
|
self.stem = None
|
||||||
self.source[hashId] = source
|
self.source[hashId] = source
|
||||||
self.timeouts[hashId] = time.time()
|
self.timeouts[hashId] = time()
|
||||||
|
|
||||||
def remove(self, hashId):
|
def remove(self, hashId):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user