예제 #1
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
예제 #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)
예제 #3
0
    def __init__(self,
                 blob_data_payment_rate,
                 db_dir=None,
                 lbryid=None,
                 peer_manager=None,
                 dht_node_port=None,
                 known_dht_nodes=None,
                 peer_finder=None,
                 hash_announcer=None,
                 blob_dir=None,
                 blob_manager=None,
                 peer_port=None,
                 use_upnp=True,
                 rate_limiter=None,
                 wallet=None,
                 dht_node_class=node.Node):
        """
        @param blob_data_payment_rate: The default payment rate for blob data

        @param db_dir: The directory in which levelDB files should be stored

        @param lbryid: The unique ID of this node

        @param peer_manager: An object which keeps track of all known peers. If None, a PeerManager will be created

        @param dht_node_port: The port on which the dht node should listen for incoming connections

        @param known_dht_nodes: A list of nodes which the dht node should use to bootstrap into the dht

        @param peer_finder: An object which is used to look up peers that are associated with some hash. If None,
            a DHTPeerFinder will be used, which looks for peers in the distributed hash table.

        @param hash_announcer: An object which announces to other peers that this peer is associated with some hash.
            If None, and peer_port is not None, a DHTHashAnnouncer will be used. If None and
            peer_port is None, a DummyHashAnnouncer will be used, which will not actually announce
            anything.

        @param blob_dir: The directory in which blobs will be stored. If None and blob_manager is None, blobs will
            be stored in memory only.

        @param blob_manager: An object which keeps track of downloaded blobs and provides access to them. If None,
            and blob_dir is not None, a DiskBlobManager will be used, with the given blob_dir.
            If None and blob_dir is None, a TempBlobManager will be used, which stores blobs in
            memory only.

        @param peer_port: The port on which other peers should connect to this peer

        @param use_upnp: Whether or not to try to open a hole in the firewall so that outside peers can connect to
            this peer's peer_port and dht_node_port

        @param rate_limiter: An object which keeps track of the amount of data transferred to and from this peer,
            and can limit that rate if desired

        @param wallet: An object which will be used to keep track of expected payments and which will pay peers.
            If None, a wallet which uses the Point Trader system will be used, which is meant for testing
            only

        @return:
        """
        self.db_dir = db_dir

        self.lbryid = lbryid

        self.peer_manager = peer_manager

        self.dht_node_port = dht_node_port
        self.known_dht_nodes = known_dht_nodes
        if self.known_dht_nodes is None:
            self.known_dht_nodes = []
        self.peer_finder = peer_finder
        self.hash_announcer = hash_announcer

        self.blob_dir = blob_dir
        self.blob_manager = blob_manager

        self.peer_port = peer_port

        self.use_upnp = use_upnp

        self.rate_limiter = rate_limiter

        self.external_ip = '127.0.0.1'

        self.upnp_redirects = []

        self.wallet = wallet
        self.dht_node_class = dht_node_class
        self.dht_node = None

        self.base_payment_rate_manager = BasePaymentRateManager(
            blob_data_payment_rate)