From 3aa6f386dbb0099b99babf150893ba4ac40d1996 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 18 Nov 2017 09:47:17 +0100 Subject: [PATCH] Dandelion fixes - dandelion would always think there is a cycle and trigger fluff - cycle fluff trigger didn't correctly re-download and re-announce the object. Now it remembers between (d)inv and object commands that it's in a fluff trigger phase. --- src/network/bmproto.py | 2 +- src/network/connectionpool.py | 2 ++ src/network/dandelion.py | 9 +++++++++ src/network/objectracker.py | 10 ++++------ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index e4f7b406..17b2c761 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -326,8 +326,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker): return True for i in map(str, items): - Dandelion().addHash(i, self) self.handleReceivedInventory(i) + Dandelion().addHash(i, self) return True diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index d0cbdcd0..46bb8aba 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -51,6 +51,8 @@ class BMConnectionPool(object): del i.objectsNewToThem[hashid] except KeyError: pass + if hashid in Dandelion().fluff: + Dandelion.removeHash(hashid) def reRandomiseDandelionStems(self): # Choose 2 peers randomly diff --git a/src/network/dandelion.py b/src/network/dandelion.py index a7ef4083..3e49d906 100644 --- a/src/network/dandelion.py +++ b/src/network/dandelion.py @@ -16,6 +16,7 @@ class Dandelion(): self.stem = [] self.nodeMap = {} self.hashMap = {} + self.fluff = {} self.timeout = {} self.refresh = time() + REASSIGN_INTERVAL self.lock = RLock() @@ -37,6 +38,14 @@ class Dandelion(): del self.timeout[hashId] except KeyError: pass + try: + del self.fluff[hashId] + except KeyError: + pass + + def fluffTrigger(self, hashId): + with self.lock: + self.fluff[hashId] = None def maybeAddStem(self, connection): # fewer than MAX_STEMS outbound connections at last reshuffle? diff --git a/src/network/objectracker.py b/src/network/objectracker.py index a86ec23f..f846e7d5 100644 --- a/src/network/objectracker.py +++ b/src/network/objectracker.py @@ -82,16 +82,14 @@ class ObjectTracker(object): del self.objectsNewToThem[hashId] except KeyError: pass - if hashId not in Inventory(): + # Fluff trigger by cycle detection + if hashId not in Inventory() or hashId in Dandelion().hashMap: + if hashId in Dandelion().hashMap: + Dandelion().fluffTrigger(hashId) if hashId not in missingObjects: missingObjects[hashId] = time.time() with self.objectsNewToMeLock: self.objectsNewToMe[hashId] = True - elif hashId in Dandelion().hashMap: - # Fluff trigger by cycle detection - Dandelion().removeHash(hashId) - with self.objectsNewToMeLock: - self.objectsNewToMe[hashId] = True def hasAddr(self, addr): if haveBloom: