From 5e1fdf66b0fa8be029203bb3374c18414f17e57a Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 26 Jul 2016 18:18:34 -0400 Subject: [PATCH] fix download problem --- lbrynet/conf.py | 8 +++--- lbrynet/lbrynet_daemon/LBRYDownloader.py | 31 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 71df9f8fd..85a9f6836 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -11,10 +11,10 @@ MAX_BLOB_INFOS_TO_REQUEST = 20 BLOBFILES_DIR = ".blobfiles" BLOB_SIZE = 2**21 -MIN_BLOB_DATA_PAYMENT_RATE = .0005 # points/megabyte -MIN_BLOB_INFO_PAYMENT_RATE = .002 # points/1000 infos -MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE = .005 # points/1000 infos -MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE = .005 # points/1000 infos +MIN_BLOB_DATA_PAYMENT_RATE = .005 # points/megabyte +MIN_BLOB_INFO_PAYMENT_RATE = .02 # points/1000 infos +MIN_VALUABLE_BLOB_INFO_PAYMENT_RATE = .05 # points/1000 infos +MIN_VALUABLE_BLOB_HASH_PAYMENT_RATE = .05 # points/1000 infos MAX_CONNECTIONS_PER_STREAM = 5 KNOWN_DHT_NODES = [('104.236.42.182', 4000), diff --git a/lbrynet/lbrynet_daemon/LBRYDownloader.py b/lbrynet/lbrynet_daemon/LBRYDownloader.py index 00c137869..909a3f340 100644 --- a/lbrynet/lbrynet_daemon/LBRYDownloader.py +++ b/lbrynet/lbrynet_daemon/LBRYDownloader.py @@ -67,7 +67,7 @@ class GetStream(object): self.download_directory = download_directory self.download_path = None self.downloader = None - self.finished = defer.Deferred() + self.finished = defer.Deferred(None) self.checker = LoopingCall(self.check_status) self.code = STREAM_STAGES[0] @@ -105,7 +105,9 @@ class GetStream(object): 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)) - def _cause_timeout(): + def _cause_timeout(err): + log.error(err) + log.debug('Forcing a timeout') self.timeout_counter = self.timeout * 2 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) 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.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(self.sd_identifier.get_metadata_for_sd_blob) 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)), - metadata)) - self.d.addCallback(lambda (factory, metadata): factory.make_downloader(metadata, - [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.addCallback(get_downloader_factory) + self.d.addCallback(make_downloader) + self.d.addCallbacks(self._start_download, _cause_timeout) self.d.callback(None) return self.finished