Esempio n. 1
0
    def _on_completed_blob(self, blob, response_key):
        yield self.blob_manager.blob_completed(blob, should_announce=False)

        if response_key == RECEIVED_SD_BLOB:
            sd_info = yield BlobStreamDescriptorReader(blob).get_info()
            yield save_sd_info(self.blob_manager, blob.blob_hash, sd_info)
            yield self.blob_manager.set_should_announce(blob.blob_hash, True)

            # if we already have the head blob, set it to be announced now that we know it's
            # a head blob
            d = self.check_head_blob_announce(sd_info['stream_hash'])

        else:
            d = defer.succeed(None)
            stream_hash = yield self.storage.get_stream_of_blob(blob.blob_hash)
            if stream_hash is not None:
                blob_num = yield self.storage.get_blob_num_by_hash(stream_hash,
                                                                   blob.blob_hash)
                if blob_num == 0:
                    sd_hash = yield self.storage.get_sd_blob_hash_for_stream(stream_hash)
                    yield self.blob_manager.set_should_announce(blob.blob_hash, True)

                    # if we already have the sd blob, set it to be announced now that we know it's
                    # a sd blob
                    d.addCallback(lambda _: self.check_sd_blob_announce(sd_hash))

        yield self.close_blob()
        yield d
        log.info("Received %s", blob)
        yield self.send_response({response_key: True})
Esempio n. 2
0
 def make_downloader(self, metadata, data_rate, payment_rate_manager, download_directory, file_name=None):
     stream_hash = yield save_sd_info(self.lbry_file_manager.session.blob_manager,
                                      metadata.source_blob_hash,
                                      metadata.validator.raw_info)
     if file_name:
         file_name = binascii.hexlify(file_name)
     lbry_file = yield self.lbry_file_manager.add_downloaded_file(
         stream_hash, metadata.source_blob_hash, binascii.hexlify(download_directory), payment_rate_manager,
         data_rate, file_name=file_name
     )
     defer.returnValue(lbry_file)
Esempio n. 3
0
 def get_descriptor_response(self, sd_blob):
     if sd_blob.get_is_verified():
         sd_info = yield BlobStreamDescriptorReader(sd_blob).get_info()
         yield save_sd_info(self.blob_manager, sd_blob.blob_hash, sd_info)
         yield self.storage.verify_will_announce_head_and_sd_blobs(sd_info['stream_hash'])
         response = yield self.request_needed_blobs({SEND_SD_BLOB: False}, sd_info['stream_hash'])
     else:
         self.incoming_blob = sd_blob
         self.receiving_blob = True
         self.handle_incoming_blob(RECEIVED_SD_BLOB)
         response = {SEND_SD_BLOB: True}
     defer.returnValue(response)
Esempio n. 4
0
 def check_sd_blob_announce(self, sd_hash):
     if sd_hash in self.blob_manager.blobs:
         sd_blob = self.blob_manager.blobs[sd_hash]
         if sd_blob.get_is_verified():
             should_announce = yield self.blob_manager.get_should_announce(sd_hash)
             if should_announce == 0:
                 yield self.blob_manager.set_should_announce(sd_hash, 1)
                 log.info("Discovered previously completed sd blob (%s), "
                          "setting it to be announced", sd_hash[:8])
                 stream_hash = yield self.storage.get_stream_hash_for_sd_hash(sd_hash)
                 if not stream_hash:
                     log.info("Adding blobs to stream")
                     sd_info = yield BlobStreamDescriptorReader(sd_blob).get_info()
                     yield save_sd_info(self.blob_manager, sd_hash, sd_info)
     defer.returnValue(None)
    def make_downloader(self, metadata, options, payment_rate_manager, **kwargs):
        assert len(options) == 1
        data_rate = options[0]
        payment_rate_manager.min_blob_data_payment_rate = data_rate

        def save_source_if_blob(stream_hash):
            return defer.succeed(metadata.source_blob_hash)

        def create_downloader(stream_hash):
            downloader = self._make_downloader(stream_hash, payment_rate_manager,
                                               metadata.validator.raw_info)
            return defer.succeed(downloader)

        d = save_sd_info(self.blob_manager, metadata.source_blob_hash, metadata.validator.raw_info)
        d.addCallback(save_source_if_blob)
        d.addCallback(create_downloader)
        return d
Esempio n. 6
0
    def _on_completed_blob(self, blob, response_key):
        yield self.blob_manager.blob_completed(blob, should_announce=False)

        if response_key == RECEIVED_SD_BLOB:
            sd_info = yield BlobStreamDescriptorReader(blob).get_info()
            yield save_sd_info(self.blob_manager, blob.blob_hash, sd_info)
            yield self.blob_manager.set_should_announce(blob.blob_hash, True)
        else:
            stream_hash = yield self.storage.get_stream_of_blob(blob.blob_hash)
            if stream_hash is not None:
                blob_num = yield self.storage.get_blob_num_by_hash(stream_hash,
                                                                   blob.blob_hash)
                if blob_num == 0:
                    yield self.blob_manager.set_should_announce(blob.blob_hash, True)

        yield self.close_blob()
        log.info("Received %s", blob)
        yield self.send_response({response_key: True})
Esempio n. 7
0
 def get_descriptor_response(self, sd_blob):
     if sd_blob.get_is_verified():
         # if we already have the sd blob being offered, make sure we have it and the head blob
         # marked as such for announcement now that we know it's an sd blob that we have.
         yield self.check_sd_blob_announce(sd_blob.blob_hash)
         try:
             stream_hash = yield self.storage.get_stream_hash_for_sd_hash(
                 sd_blob.blob_hash)
         except NoSuchSDHash:
             sd_info = yield BlobStreamDescriptorReader(sd_blob).get_info()
             stream_hash = sd_info['stream_hash']
             yield save_sd_info(self.blob_manager, sd_blob.blob_hash, sd_info)
         yield self.check_head_blob_announce(stream_hash)
         response = yield self.request_needed_blobs({SEND_SD_BLOB: False}, sd_blob)
     else:
         self.incoming_blob = sd_blob
         self.receiving_blob = True
         self.handle_incoming_blob(RECEIVED_SD_BLOB)
         response = {SEND_SD_BLOB: True}
     defer.returnValue(response)
 def make_downloader(self,
                     metadata,
                     data_rate,
                     payment_rate_manager,
                     download_directory,
                     file_name=None,
                     download_mirrors=None):
     stream_hash = yield save_sd_info(self.blob_manager,
                                      metadata.source_blob_hash,
                                      metadata.validator.raw_info)
     if file_name:
         file_name = hexlify(file_name.encode())
     hex_download_directory = hexlify(download_directory.encode())
     lbry_file = yield self.lbry_file_manager.add_downloaded_file(
         stream_hash,
         metadata.source_blob_hash,
         hex_download_directory,
         payment_rate_manager,
         data_rate,
         file_name=file_name,
         download_mirrors=download_mirrors)
     defer.returnValue(lbry_file)