fix download problem
This commit is contained in:
parent
d86e709b90
commit
5e1fdf66b0
2 changed files with 25 additions and 14 deletions
|
@ -11,10 +11,10 @@ MAX_BLOB_INFOS_TO_REQUEST = 20
|
||||||
BLOBFILES_DIR = ".blobfiles"
|
BLOBFILES_DIR = ".blobfiles"
|
||||||
BLOB_SIZE = 2**21
|
BLOB_SIZE = 2**21
|
||||||
|
|
||||||
MIN_BLOB_DATA_PAYMENT_RATE = .0005 # points/megabyte
|
MIN_BLOB_DATA_PAYMENT_RATE = .005 # points/megabyte
|
||||||
MIN_BLOB_INFO_PAYMENT_RATE = .002 # points/1000 infos
|
MIN_BLOB_INFO_PAYMENT_RATE = .02 # points/1000 infos
|
||||||
MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE = .005 # points/1000 infos
|
MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE = .05 # points/1000 infos
|
||||||
MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE = .005 # points/1000 infos
|
MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE = .05 # points/1000 infos
|
||||||
MAX_CONNECTIONS_PER_STREAM = 5
|
MAX_CONNECTIONS_PER_STREAM = 5
|
||||||
|
|
||||||
KNOWN_DHT_NODES = [('104.236.42.182', 4000),
|
KNOWN_DHT_NODES = [('104.236.42.182', 4000),
|
||||||
|
|
|
@ -67,7 +67,7 @@ class GetStream(object):
|
||||||
self.download_directory = download_directory
|
self.download_directory = download_directory
|
||||||
self.download_path = None
|
self.download_path = None
|
||||||
self.downloader = None
|
self.downloader = None
|
||||||
self.finished = defer.Deferred()
|
self.finished = defer.Deferred(None)
|
||||||
self.checker = LoopingCall(self.check_status)
|
self.checker = LoopingCall(self.check_status)
|
||||||
self.code = STREAM_STAGES[0]
|
self.code = STREAM_STAGES[0]
|
||||||
|
|
||||||
|
@ -105,7 +105,9 @@ class GetStream(object):
|
||||||
return defer.fail(KeyFeeAboveMaxAllowed())
|
return defer.fail(KeyFeeAboveMaxAllowed())
|
||||||
log.info("Key fee %f below limit of %f, downloading lbry://%s" % (self.fee.to_lbc(), max_key.to_lbc(), self.resolved_name))
|
log.info("Key fee %f below limit of %f, downloading lbry://%s" % (self.fee.to_lbc(), max_key.to_lbc(), self.resolved_name))
|
||||||
|
|
||||||
def _cause_timeout():
|
def _cause_timeout(err):
|
||||||
|
log.error(err)
|
||||||
|
log.debug('Forcing a timeout')
|
||||||
self.timeout_counter = self.timeout * 2
|
self.timeout_counter = self.timeout * 2
|
||||||
|
|
||||||
def _set_status(x, status):
|
def _set_status(x, status):
|
||||||
|
@ -113,20 +115,29 @@ class GetStream(object):
|
||||||
self.code = next(s for s in STREAM_STAGES if s[0] == status)
|
self.code = next(s for s in STREAM_STAGES if s[0] == status)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
def get_downloader_factory(metadata):
|
||||||
|
for factory in metadata.factories:
|
||||||
|
if isinstance(factory, ManagedLBRYFileDownloaderFactory):
|
||||||
|
return factory, metadata
|
||||||
|
raise Exception('No suitable factory was found in {}'.format(metadata.factories))
|
||||||
|
|
||||||
|
def make_downloader(args):
|
||||||
|
factory, metadata = args
|
||||||
|
return factory.make_downloader(metadata,
|
||||||
|
[self.data_rate, True],
|
||||||
|
self.payment_rate_manager,
|
||||||
|
download_directory=self.download_directory,
|
||||||
|
file_name=self.file_name)
|
||||||
|
|
||||||
self.checker.start(1)
|
self.checker.start(1)
|
||||||
|
|
||||||
self.d.addCallback(lambda _: _set_status(None, DOWNLOAD_METADATA_CODE))
|
self.d.addCallback(lambda _: _set_status(None, DOWNLOAD_METADATA_CODE))
|
||||||
self.d.addCallback(lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
|
self.d.addCallback(lambda _: download_sd_blob(self.session, self.stream_hash, self.payment_rate_manager))
|
||||||
self.d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
|
self.d.addCallback(self.sd_identifier.get_metadata_for_sd_blob)
|
||||||
self.d.addCallback(lambda r: _set_status(r, DOWNLOAD_RUNNING_CODE))
|
self.d.addCallback(lambda r: _set_status(r, DOWNLOAD_RUNNING_CODE))
|
||||||
self.d.addCallback(lambda metadata: (next(factory for factory in metadata.factories if isinstance(factory, ManagedLBRYFileDownloaderFactory)),
|
self.d.addCallback(get_downloader_factory)
|
||||||
metadata))
|
self.d.addCallback(make_downloader)
|
||||||
self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata,
|
self.d.addCallbacks(self._start_download, _cause_timeout)
|
||||||
[self.data_rate, True],
|
|
||||||
self.payment_rate_manager,
|
|
||||||
download_directory=self.download_directory,
|
|
||||||
file_name=self.file_name))
|
|
||||||
self.d.addCallbacks(self._start_download, lambda _: _cause_timeout())
|
|
||||||
self.d.callback(None)
|
self.d.callback(None)
|
||||||
|
|
||||||
return self.finished
|
return self.finished
|
||||||
|
|
Loading…
Reference in a new issue