More fixes for objects to be downloaded

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

View File

@ -86,12 +86,12 @@ class Inventory(collections.MutableMapping):
@Singleton
class Missing(object):
frequency = 60
def __init__(self):
super(self.__class__, self).__init__()
self.lock = RLock()
self.hashes = {}
self.stopped = False
self.frequency = 60
def add(self, objectHash):
if self.stopped:
@ -113,7 +113,7 @@ class Missing(object):
return
except ValueError:
pass
if len(self.hashes[objectHash]['peers']) == 0 and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency:
if len(self.hashes[objectHash]['peers']) == 0 and self.hashes[objectHash]['requested'] < time.time() - self.frequency:
self.delete(objectHash)
else:
self.hashes[objectHash]['requested'] = time.time()
@ -125,7 +125,11 @@ class Missing(object):
objectHashes = []
try:
for objectHash in self.hashes.keys():
if current_thread().peer in self.hashes[objectHash]['peers'] and self.hashes[objectHash]['requested'] < time.time() - Missing.frequency:
if self.hashes[objectHash]['requested'] < time.time() - self.frequency:
if len(self.hashes[objectHash]['peers']) == 0:
self.removeObjectFromCurrentThread(objectHash)
continue
if current_thread().peer in self.hashes[objectHash]['peers']:
objectHashes.append(objectHash)
self.removeObjectFromCurrentThread(objectHash)
if len(objectHashes) >= count: