Pending download counter fix

- handles expired objects better
- counts objects that failed download more accurately
This commit is contained in:
Peter Šurda 2017-02-06 11:02:03 +01:00
parent 23fcf2cdec
commit e434825bb2
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 9 additions and 3 deletions

View File

@ -111,6 +111,9 @@ class singleCleaner(threading.Thread, StoppableThread):
os._exit(0) os._exit(0)
shared.knownNodesLock.release() shared.knownNodesLock.release()
shared.needToWriteKnownNodesToDisk = False shared.needToWriteKnownNodesToDisk = False
# TODO: cleanup pending upload / download
if state.shutdown == 0: if state.shutdown == 0:
self.stop.wait(300) self.stop.wait(300)

View File

@ -117,7 +117,7 @@ class PendingDownload(object):
def len(self): def len(self):
with self.lock: 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): def pull(self, count=1):
if count < 1: if count < 1:
@ -242,7 +242,6 @@ class PendingUpload(object):
if current_thread().peer not in self.hashes[objectHash]: if current_thread().peer not in self.hashes[objectHash]:
self.hashes[objectHash].append(current_thread().peer) self.hashes[objectHash].append(current_thread().peer)
def len(self): def len(self):
with self.lock: with self.lock:
return sum(len(self.hashes[x]) > 0 for x in self.hashes) return sum(len(self.hashes[x]) > 0 for x in self.hashes)

View File

@ -27,7 +27,7 @@ import highlevelcrypto
#import helper_startup #import helper_startup
from helper_sql import * from helper_sql import *
from helper_threading import * from helper_threading import *
from inventory import Inventory from inventory import Inventory, PendingDownload
import protocol import protocol
import state import state
@ -435,18 +435,22 @@ def checkAndShareObjectWithPeers(data):
""" """
if len(data) > 2 ** 18: if len(data) > 2 ** 18:
logger.info('The payload length of this object is too large (%s bytes). Ignoring it.' % len(data)) logger.info('The payload length of this object is too large (%s bytes). Ignoring it.' % len(data))
PendingDownload().delete(calculateInventoryHash(data))
return 0 return 0
# Let us check to make sure that the proof of work is sufficient. # Let us check to make sure that the proof of work is sufficient.
if not protocol.isProofOfWorkSufficient(data): if not protocol.isProofOfWorkSufficient(data):
logger.info('Proof of work is insufficient.') logger.info('Proof of work is insufficient.')
PendingDownload().delete(calculateInventoryHash(data))
return 0 return 0
endOfLifeTime, = unpack('>Q', data[8:16]) 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 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) 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 return 0
if endOfLifeTime - int(time.time()) < - 3600: # The EOL time was more than an hour ago. That's too much. 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) 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 return 0
intObjectType, = unpack('>I', data[16:20]) intObjectType, = unpack('>I', data[16:20])
try: try: