Ejemplo n.º 1
0
def calculate_negotation_turns(client_base, host_base, host_is_generous=True, client_is_generous=True):
    blobs = [
        "b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc509138c99509a25423a4cef788d571dca7988e1dca69e6fa0",
        "d7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787",
        "5a450b416275da4bdff604ee7b58eaedc7913c5005b7184fc3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd",
        "f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0",
        "9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c",
        "91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7",
        "6d8017aba362e5c5d0046625a039513419810a0397d728318c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07",
        "6af95cd062b4a179576997ef1054c9d2120f8592eea045e9667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd",
        "8c70d5e2f5c3a6085006198e5192d157a125d92e7378794472007a61947992768926513fc10924785bdb1761df3c37e6",
        "c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c",
    ]

    host = mock.Mock()
    host.host = "1.2.3.4"
    client = mock.Mock()
    client.host = "1.2.3.5"

    client_base_prm = BasePaymentRateManager(client_base)
    client_prm = NegotiatedPaymentRateManager(
        client_base_prm, DummyBlobAvailabilityTracker(), generous=client_is_generous
    )
    host_base_prm = BasePaymentRateManager(host_base)
    host_prm = NegotiatedPaymentRateManager(host_base_prm, DummyBlobAvailabilityTracker(), generous=host_is_generous)
    blobs_to_query = get_random_sample(blobs)
    accepted = False
    turns = 0
    while not accepted:
        rate = client_prm.get_rate_blob_data(host, blobs_to_query)
        offer = Offer(rate)
        accepted = host_prm.accept_rate_blob_data(client, blobs_to_query, offer)
        turns += 1
    return turns
Ejemplo n.º 2
0
 def setUp(self):
     mock_conf_settings(self)
     self.blob_manager = mock.Mock()
     self.payment_rate_manager = NegotiatedPaymentRateManager(
         BasePaymentRateManager(0.001), DummyBlobAvailabilityTracker())
     self.handler = BlobRequestHandler.BlobRequestHandler(
         self.blob_manager, None, self.payment_rate_manager, None)
Ejemplo n.º 3
0
 def set_options_and_restore(rowid, stream_hash, options):
     payment_rate_manager = NegotiatedPaymentRateManager(self.session.base_payment_rate_manager,
                                                         self.session.blob_tracker)
     d = self.start_lbry_file(rowid, stream_hash, payment_rate_manager,
                              blob_data_rate=options)
     d.addCallback(lambda downloader: downloader.restore())
     return d
Ejemplo n.º 4
0
 def _start_lbry_files(self):
     files_and_options = yield self._get_all_lbry_files()
     stream_infos = yield self.stream_info_manager._get_all_stream_infos()
     b_prm = self.session.base_payment_rate_manager
     payment_rate_manager = NegotiatedPaymentRateManager(
         b_prm, self.session.blob_tracker)
     log.info("Trying to start %i files", len(stream_infos))
     for i, (rowid, stream_hash, blob_data_rate,
             status) in enumerate(files_and_options):
         if len(files_and_options) > 500 and i % 500 == 0:
             log.info("Started %i/%i files", i, len(stream_infos))
         if stream_hash in stream_infos:
             lbry_file = self._get_lbry_file(
                 rowid, stream_hash, payment_rate_manager,
                 stream_infos[stream_hash]['sd_hash'],
                 stream_infos[stream_hash]['key'],
                 stream_infos[stream_hash]['stream_name'],
                 stream_infos[stream_hash]['suggested_file_name'])
             log.info("initialized file %s", lbry_file.stream_name)
             try:
                 # restore will raise an Exception if status is unknown
                 lbry_file.restore(status)
                 self.lbry_files.append(lbry_file)
             except Exception:
                 log.warning("Failed to start %i", rowid)
                 continue
     log.info("Started %i lbry files", len(self.lbry_files))
     if self.auto_re_reflect is True:
         safe_start_looping_call(self.lbry_file_reflector,
                                 self.auto_re_reflect_interval)
Ejemplo n.º 5
0
    def _start_lbry_files(self):
        files = yield self.session.storage.get_all_lbry_files()
        b_prm = self.session.base_payment_rate_manager
        payment_rate_manager = NegotiatedPaymentRateManager(
            b_prm, self.session.blob_tracker)

        log.info("Trying to start %i files", len(files))
        for i, file_info in enumerate(files):
            if len(files) > 500 and i % 500 == 0:
                log.info("Started %i/%i files", i, len(files))

            lbry_file = self._get_lbry_file(
                file_info['row_id'], file_info['stream_hash'],
                payment_rate_manager, file_info['sd_hash'], file_info['key'],
                file_info['stream_name'], file_info['file_name'],
                file_info['download_directory'],
                file_info['suggested_file_name'])
            yield lbry_file.get_claim_info()
            try:
                # restore will raise an Exception if status is unknown
                lbry_file.restore(file_info['status'])
                self.lbry_files.append(lbry_file)
            except Exception:
                log.warning("Failed to start %i", file_info['rowid'])
                continue
        log.info("Started %i lbry files", len(self.lbry_files))
        if self.auto_re_reflect is True:
            safe_start_looping_call(self.lbry_file_reflector,
                                    self.auto_re_reflect_interval)
Ejemplo n.º 6
0
 def _set_options_and_restore(self, rowid, stream_hash, options):
     try:
         b_prm = self.session.base_payment_rate_manager
         payment_rate_manager = NegotiatedPaymentRateManager(
             b_prm, self.session.blob_tracker)
         downloader = yield self.start_lbry_file(
             rowid, stream_hash, payment_rate_manager, blob_data_rate=options)
         yield downloader.restore()
     except Exception:
         log.error('An error occurred while starting a lbry file (%s, %s, %s)',
                       rowid, stream_hash, options)
Ejemplo n.º 7
0
    def _start_lbry_files(self):
        files = yield self.session.storage.get_all_lbry_files()
        claim_infos = yield self.session.storage.get_claims_from_stream_hashes([file['stream_hash'] for file in files])
        b_prm = self.session.base_payment_rate_manager
        payment_rate_manager = NegotiatedPaymentRateManager(b_prm, self.session.blob_tracker)

        log.info("Starting %i files", len(files))
        for file_info in files:
            claim_info = claim_infos.get(file_info['stream_hash'])
            self._start_lbry_file(file_info, payment_rate_manager, claim_info)

        log.info("Started %i lbry files", len(self.lbry_files))
        if self.auto_re_reflect is True:
            safe_start_looping_call(self.lbry_file_reflector, self.auto_re_reflect_interval / 10)
Ejemplo n.º 8
0
    def _start_lbry_files(self):
        files = yield self.session.storage.get_all_lbry_files()
        b_prm = self.session.base_payment_rate_manager
        payment_rate_manager = NegotiatedPaymentRateManager(b_prm, self.session.blob_tracker)

        log.info("Starting %i files", len(files))
        dl = []
        for file_info in files:
            dl.append(self._start_lbry_file(file_info, payment_rate_manager))

        yield defer.DeferredList(dl)

        log.info("Started %i lbry files", len(self.lbry_files))
        if self.auto_re_reflect is True:
            safe_start_looping_call(self.lbry_file_reflector, self.auto_re_reflect_interval / 10)
Ejemplo n.º 9
0
    def _start_lbry_files(self):
        files = yield self.session.storage.get_all_lbry_files()
        b_prm = self.session.base_payment_rate_manager
        payment_rate_manager = NegotiatedPaymentRateManager(
            b_prm, self.session.blob_tracker)

        log.info("Trying to start %i files", len(files))
        for i, file_info in enumerate(files):
            if len(files) > 500 and i % 500 == 0:
                log.info("Started %i/%i files", i, len(files))

            lbry_file = self._get_lbry_file(
                file_info['row_id'], file_info['stream_hash'],
                payment_rate_manager, file_info['sd_hash'], file_info['key'],
                file_info['stream_name'], file_info['file_name'],
                file_info['download_directory'],
                file_info['suggested_file_name'])
            yield lbry_file.get_claim_info()
            try:
                # verify the stream is valid (we might have downloaded an invalid stream
                # in the past when the validation check didn't work)
                stream_info = yield get_sd_info(self.storage,
                                                file_info['stream_hash'],
                                                include_blobs=True)
                validate_descriptor(stream_info)
            except InvalidStreamDescriptorError as err:
                log.warning(
                    "Stream for descriptor %s is invalid (%s), cleaning it up",
                    lbry_file.sd_hash, err.message)
                yield lbry_file.delete_data()
                yield self.session.storage.delete_stream(lbry_file.stream_hash)
            else:
                try:
                    # restore will raise an Exception if status is unknown
                    lbry_file.restore(file_info['status'])
                    self.storage.content_claim_callbacks[
                        lbry_file.stream_hash] = lbry_file.get_claim_info
                    self.lbry_files.append(lbry_file)
                except Exception:
                    log.warning("Failed to start %i", file_info.get('rowid'))
        log.info("Started %i lbry files", len(self.lbry_files))
        if self.auto_re_reflect is True:
            safe_start_looping_call(self.lbry_file_reflector,
                                    self.auto_re_reflect_interval)
Ejemplo n.º 10
0
def calculate_negotation_turns(client_base,
                               host_base,
                               host_is_generous=True,
                               client_is_generous=True):
    blobs = [
        'b2e48bb4c88cf46b76adf0d47a72389fae0cd1f19ed27dc5'
        '09138c99509a25423a4cef788d571dca7988e1dca69e6fa0',
        'd7c82e6cac093b3f16107d2ae2b2c75424f1fcad2c7fbdbe'
        '66e4a13c0b6bd27b67b3a29c403b82279ab0f7c1c48d6787',
        '5a450b416275da4bdff604ee7b58eaedc7913c5005b7184f'
        'c3bc5ef0b1add00613587f54217c91097fc039ed9eace9dd',
        'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0'
        'b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0',
        '9dbda74a472a2e5861a5d18197aeba0f5de67c67e401124c'
        '243d2f0f41edf01d7a26aeb0b5fc9bf47f6361e0f0968e2c',
        '91dc64cf1ff42e20d627b033ad5e4c3a4a96856ed8a6e3fb'
        '4cd5fa1cfba4bf72eefd325f579db92f45f4355550ace8e7',
        '6d8017aba362e5c5d0046625a039513419810a0397d72831'
        '8c328a5cc5d96efb589fbca0728e54fe5adbf87e9545ee07',
        '6af95cd062b4a179576997ef1054c9d2120f8592eea045e9'
        '667bea411d520262cd5a47b137eabb7a7871f5f8a79c92dd',
        '8c70d5e2f5c3a6085006198e5192d157a125d92e73787944'
        '72007a61947992768926513fc10924785bdb1761df3c37e6',
        'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835'
        'eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c'
    ]

    host = mock.Mock()
    host.host = "1.2.3.4"
    client = mock.Mock()
    client.host = "1.2.3.5"

    client_base_prm = BasePaymentRateManager(client_base)
    client_prm = NegotiatedPaymentRateManager(client_base_prm,
                                              DummyBlobAvailabilityTracker(),
                                              generous=client_is_generous)
    host_base_prm = BasePaymentRateManager(host_base)
    host_prm = NegotiatedPaymentRateManager(host_base_prm,
                                            DummyBlobAvailabilityTracker(),
                                            generous=host_is_generous)
    blobs_to_query = get_random_sample(blobs)
    accepted = False
    turns = 0
    while not accepted:
        rate = client_prm.get_rate_blob_data(host, blobs_to_query)
        offer = Offer(rate)
        accepted = host_prm.accept_rate_blob_data(client, blobs_to_query,
                                                  offer)
        turns += 1
    return turns