This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-11-28/src/network/dandelion.py
Peter Šurda 333170b172
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
2017-10-06 16:33:44 +02:00

39 lines
1016 B
Python

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
REASSIGN_INTERVAL = 600
FLUFF_TRIGGER_TIMEOUT = 300
@Singleton
class DandelionStems():
def __init__(self):
self.stem = {}
self.source = {}
self.timeouts = {}
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()
def remove(self, hashId):
with self.lock:
try:
del self.stem[hashId]
del self.source[hashId]
del self.timeouts[hashId]
except KeyError:
pass