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 untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

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