Pending download counter fix

- handles expired objects better
- counts objects that failed download more accurately
master
Peter Šurda 6 years ago
parent 23fcf2cdec
commit e434825bb2
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

@ -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)

@ -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)

@ -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:

Loading…
Cancel
Save