Better handling of pending downloading objects

This commit is contained in:
Peter Šurda 2017-01-15 22:36:12 +01:00
parent b750e67bfb
commit d04c0e78e4
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -86,6 +86,7 @@ class Inventory(collections.MutableMapping):
@Singleton @Singleton
class Missing(object): class Missing(object):
frequency = 60
def __init__(self): def __init__(self):
super(self.__class__, self).__init__() super(self.__class__, self).__init__()
self.lock = RLock() self.lock = RLock()
@ -112,7 +113,7 @@ class Missing(object):
return return
except ValueError: except ValueError:
pass pass
if len(self.hashes[objectHash]['peers']) == 0: if len(self.hashes[objectHash]['peers']) == 0 and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency:
self.delete(objectHash) self.delete(objectHash)
else: else:
self.hashes[objectHash]['requested'] = time.time() self.hashes[objectHash]['requested'] = time.time()
@ -121,11 +122,10 @@ class Missing(object):
if count < 1: if count < 1:
raise ValueError("Must be at least one") raise ValueError("Must be at least one")
with self.lock: with self.lock:
since = time.time() - 60 # once every minute
objectHashes = [] objectHashes = []
try: try:
for objectHash in self.hashes.keys(): for objectHash in self.hashes.keys():
if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < since: if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency:
objectHashes.append(objectHash) objectHashes.append(objectHash)
self.removeObjectFromCurrentThread(objectHash) self.removeObjectFromCurrentThread(objectHash)
if len(objectHashes) >= count: if len(objectHashes) >= count: