Download fixes

- don't make empty requests
- don't make requests if all objects are pending already
This commit is contained in:
Peter Šurda 2018-02-02 12:44:43 +01:00
parent 57c8c7c07c
commit 053f434e04
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 5 additions and 2 deletions

View File

@ -62,6 +62,8 @@ class DownloadThread(threading.Thread, StoppableThread):
continue
payload.extend(chunk)
missingObjects[chunk] = now
if not payload:
continue
i.append_write_buf(protocol.CreatePacket('getdata', payload))
logger.debug("%s:%i Requesting %i objects", i.destination.host, i.destination.port, len(request))
requested += len(request)

View File

@ -71,8 +71,9 @@ class RandomTrackingDict(object):
self.pendingTimeout = pendingTimeout
def randomKeys(self, count=1):
if self.len == 0 or (self.pendingLen >= self.maxPending and
self.lastPoll + self.pendingTimeout > time()):
if self.len == 0 or ((self.pendingLen >= self.maxPending or
self.pendingLen == self.len) and self.lastPoll +
self.pendingTimeout > time()):
raise KeyError
# reset if we've requested all
with self.lock: