Esempio n. 1
0
    def start(self, stream_info, name, txid, nout, file_name=None):
        """
        Start download

        Returns:
            (tuple) Tuple containing (downloader, finished_deferred)

            downloader - instance of ManagedEncryptedFileDownloader
            finished_deferred - deferred callbacked when download is finished
        """
        self.set_status(INITIALIZING_CODE, name)
        key_fee = yield self._initialize(stream_info)

        safe_start_looping_call(self.checker, 1)
        self.set_status(DOWNLOAD_METADATA_CODE, name)
        try:
            sd_blob = yield self._download_sd_blob()
            yield self._download(sd_blob, name, key_fee, txid, nout, file_name)
            self.set_status(DOWNLOAD_RUNNING_CODE, name)
            yield self.data_downloading_deferred
        except (DownloadDataTimeout, InvalidStreamDescriptorError) as err:
            safe_stop_looping_call(self.checker)
            raise err

        defer.returnValue((self.downloader, self.finished_deferred))
Esempio n. 2
0
 def _check_status(self, status):
     if status.num_completed > 0 and not self.data_downloading_deferred.called:
         self.data_downloading_deferred.callback(True)
     if self.data_downloading_deferred.called:
         safe_stop_looping_call(self.checker)
     else:
         log.debug("Waiting for stream data (%i seconds)",
                   self.timeout_counter)
Esempio n. 3
0
 def finish(self, results, name):
     self.set_status(DOWNLOAD_STOPPED_CODE, name)
     log.info("Finished downloading lbry://%s (%s) --> %s", name,
              self.sd_hash[:6], self.download_path)
     safe_stop_looping_call(self.checker)
     status = yield self.downloader.status()
     self._check_status(status)
     defer.returnValue(self.download_path)
Esempio n. 4
0
 def _check_if_finished(self):
     if self.stream_position() == 1:
         blob_downloaded = self.download_manager.blobs[0]
         log.debug(
             "The blob %s has been downloaded. Calling the finished callback",
             str(blob_downloaded))
         safe_stop_looping_call(self.checker)
         self.finished_callback(blob_downloaded)
     elif self.timeout is not None:
         self.timeout_counter += 1
         if self.timeout_counter >= self.timeout:
             safe_stop_looping_call(self.checker)
             self.timeout_callback()
Esempio n. 5
0
 def check_status(self):
     """
     Check if we've got the first data blob in the stream yet
     """
     self.timeout_counter += 1
     if self.timeout_counter > self.timeout:
         if not self.data_downloading_deferred.called:
             if self.downloader:
                 err = DownloadDataTimeout(self.sd_hash)
             else:
                 err = DownloadSDTimeout(self.sd_hash)
             self.data_downloading_deferred.errback(err)
         safe_stop_looping_call(self.checker)
     elif self.downloader:
         d = self.downloader.status()
         d.addCallback(self._check_status)
     else:
         log.debug("Waiting for stream descriptor (%i seconds)",
                   self.timeout_counter)
Esempio n. 6
0
 def stop(self):
     safe_stop_looping_call(self.lbry_file_reflector)
     yield self._stop_lbry_files()
     log.info("Stopped encrypted file manager")
     defer.returnValue(True)
Esempio n. 7
0
 def stop(self):
     safe_stop_looping_call(self.checker)
     return defer.succeed(True)
Esempio n. 8
0
 def fail(self, err):
     safe_stop_looping_call(self.checker)
     raise err