From e434825bb2cdf7b2b5efbe4e9b5dfd37f4308f5a Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 6 Feb 2017 11:02:03 +0100 Subject: [PATCH] Pending download counter fix - handles expired objects better - counts objects that failed download more accurately --- src/class_singleCleaner.py | 3 +++ src/inventory.py | 3 +-- src/shared.py | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index ab16e985..733e4607 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -111,6 +111,9 @@ class singleCleaner(threading.Thread, StoppableThread): os._exit(0) shared.knownNodesLock.release() shared.needToWriteKnownNodesToDisk = False + + # TODO: cleanup pending upload / download + if state.shutdown == 0: self.stop.wait(300) diff --git a/src/inventory.py b/src/inventory.py index 99b4ca4d..4424942f 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -117,7 +117,7 @@ class PendingDownload(object): def len(self): with self.lock: - return len(self.hashes) + return sum(1 for x in self.hashes.values() if len(x) > 0) def pull(self, count=1): if count < 1: @@ -242,7 +242,6 @@ class PendingUpload(object): if current_thread().peer not in self.hashes[objectHash]: self.hashes[objectHash].append(current_thread().peer) - def len(self): with self.lock: return sum(len(self.hashes[x]) > 0 for x in self.hashes) diff --git a/src/shared.py b/src/shared.py index cd70d6c8..5582a961 100644 --- a/src/shared.py +++ b/src/shared.py @@ -27,7 +27,7 @@ import highlevelcrypto #import helper_startup from helper_sql import * from helper_threading import * -from inventory import Inventory +from inventory import Inventory, PendingDownload import protocol import state @@ -435,18 +435,22 @@ def checkAndShareObjectWithPeers(data): """ if len(data) > 2 ** 18: logger.info('The payload length of this object is too large (%s bytes). Ignoring it.' % len(data)) + PendingDownload().delete(calculateInventoryHash(data)) return 0 # Let us check to make sure that the proof of work is sufficient. if not protocol.isProofOfWorkSufficient(data): logger.info('Proof of work is insufficient.') + PendingDownload().delete(calculateInventoryHash(data)) return 0 endOfLifeTime, = unpack('>Q', data[8:16]) if endOfLifeTime - int(time.time()) > 28 * 24 * 60 * 60 + 10800: # The TTL may not be larger than 28 days + 3 hours of wiggle room logger.info('This object\'s End of Life time is too far in the future. Ignoring it. Time is %s' % endOfLifeTime) + PendingDownload().delete(calculateInventoryHash(data)) return 0 if endOfLifeTime - int(time.time()) < - 3600: # The EOL time was more than an hour ago. That's too much. logger.info('This object\'s End of Life time was more than an hour ago. Ignoring the object. Time is %s' % endOfLifeTime) + PendingDownload().delete(calculateInventoryHash(data)) return 0 intObjectType, = unpack('>I', data[16:20]) try: