Ejemplo n.º 1
0
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
    if data_rate is None:
        data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]

    rates = {
        'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1},
        'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2}
    }
    component_manager = ComponentManager(
        skip_components=[DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, UPNP_COMPONENT,
                         PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                         STREAM_IDENTIFIER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT,
                         HEADERS_COMPONENT, RATE_LIMITER_COMPONENT],
        file_manager=FakeFileManager
    )
    daemon = LBRYDaemon(component_manager=component_manager)
    daemon.payment_rate_manager = OnlyFreePaymentsManager()
    daemon.wallet_manager = mock.Mock(spec=LbryWalletManager)
    daemon.wallet_manager.wallet = mock.Mock(spec=Wallet)
    daemon.wallet_manager.wallet.use_encryption = False
    daemon.wallet_manager.network = FakeNetwork()
    daemon.storage = mock.Mock(spec=SQLiteStorage)
    market_feeds = [BTCLBCFeed(), USDBTCFeed()]
    daemon.exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates)
    daemon.file_manager = component_manager.get_component(FILE_MANAGER_COMPONENT)

    metadata = {
        "author": "fake author",
        "language": "en",
        "content_type": "fake/format",
        "description": "fake description",
        "license": "fake license",
        "license_url": "fake license url",
        "nsfw": False,
        "sources": {
            "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
                            'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
        },
        "thumbnail": "fake thumbnail",
        "title": "fake title",
        "ver": "0.0.3"
    }
    if with_fee:
        metadata.update(
            {"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
    migrated = smart_decode(json.dumps(metadata))
    daemon._resolve = daemon.wallet_manager.resolve = lambda *_: defer.succeed(
        {"test": {'claim': {'value': migrated.claim_dict}}})
    return daemon
Ejemplo n.º 2
0
 def setUp(self):
     mocks.mock_conf_settings(self)
     self.tmp_db_dir, self.tmp_blob_dir = mk_db_and_blob_dir()
     self.wallet = FakeWallet()
     self.peer_manager = PeerManager()
     self.peer_finder = FakePeerFinder(5553, self.peer_manager, 2)
     self.rate_limiter = DummyRateLimiter()
     self.sd_identifier = StreamDescriptorIdentifier()
     self.storage = SQLiteStorage(self.tmp_db_dir)
     self.blob_manager = DiskBlobManager(self.tmp_blob_dir, self.storage)
     self.prm = OnlyFreePaymentsManager()
     self.lbry_file_manager = EncryptedFileManager(
         self.peer_finder, self.rate_limiter, self.blob_manager,
         self.wallet, self.prm, self.storage, self.sd_identifier)
     d = self.storage.setup()
     d.addCallback(lambda _: self.lbry_file_manager.setup())
     return d
Ejemplo n.º 3
0
    def setup(self):
        init_conf_windows()

        self.db_dir, self.blob_dir = mk_db_and_blob_dir()
        self.wallet = FakeWallet()
        self.peer_manager = PeerManager()
        self.rate_limiter = RateLimiter()
        if self.ul_rate_limit is not None:
            self.rate_limiter.set_ul_limit(self.ul_rate_limit)
        self.prm = OnlyFreePaymentsManager()
        self.storage = SQLiteStorage(self.db_dir)
        self.blob_manager = DiskBlobManager(self.blob_dir, self.storage)
        self.lbry_file_manager = EncryptedFileManager(
            FakePeerFinder(5553, self.peer_manager, 1), self.rate_limiter,
            self.blob_manager, self.wallet, self.prm, self.storage,
            StreamDescriptorIdentifier())

        yield self.storage.setup()
        yield self.blob_manager.setup()
        yield self.lbry_file_manager.setup()

        query_handler_factories = {
            1:
            BlobAvailabilityHandlerFactory(self.blob_manager),
            2:
            BlobRequestHandlerFactory(self.blob_manager, self.wallet, self.prm,
                                      None),
            3:
            self.wallet.get_wallet_info_query_handler_factory(),
        }
        server_factory = ServerProtocolFactory(self.rate_limiter,
                                               query_handler_factories,
                                               self.peer_manager)
        self.server_port = reactor.listenTCP(5553,
                                             server_factory,
                                             interface="localhost")
        test_file = GenFile(self.file_size,
                            b''.join([chr(i) for i in xrange(0, 64, 6)]))
        lbry_file = yield create_lbry_file(self.blob_manager, self.storage,
                                           self.prm, self.lbry_file_manager,
                                           "test_file", test_file)
        defer.returnValue(lbry_file.sd_hash)
Ejemplo n.º 4
0
    def setUp(self):
        mocks.mock_conf_settings(self)
        self.db_dir, self.blob_dir = mk_db_and_blob_dir()
        self.wallet = FakeWallet()
        self.peer_manager = PeerManager()
        self.peer_finder = FakePeerFinder(5553, self.peer_manager, 1)
        self.rate_limiter = RateLimiter()
        self.prm = OnlyFreePaymentsManager()
        self.storage = SQLiteStorage(self.db_dir)
        self.blob_manager = DiskBlobManager(self.blob_dir, self.storage)
        self.sd_identifier = StreamDescriptorIdentifier()
        self.lbry_file_manager = EncryptedFileManager(
            self.peer_finder, self.rate_limiter, self.blob_manager,
            self.wallet, self.prm, self.storage, self.sd_identifier)

        self.uploader = LbryUploader(5209343)
        self.sd_hash = yield self.uploader.setup()
        yield self.storage.setup()
        yield self.blob_manager.setup()
        yield self.lbry_file_manager.setup()
        yield add_lbry_file_to_sd_identifier(self.sd_identifier)
 def setUp(self):
     mocks.mock_conf_settings(self)
     self.session = None
     self.lbry_file_manager = None
     self.is_generous = True
     self.db_dir = tempfile.mkdtemp()
     self.blob_dir = os.path.join(self.db_dir, "blobfiles")
     os.mkdir(self.blob_dir)
     self.dht_node = FakeNode()
     self.wallet = FakeWallet()
     self.peer_manager = PeerManager()
     self.peer_finder = FakePeerFinder(5553, self.peer_manager, 2)
     self.rate_limiter = DummyRateLimiter()
     self.sd_identifier = StreamDescriptorIdentifier()
     self.storage = SQLiteStorage(self.db_dir)
     self.blob_manager = DiskBlobManager(self.blob_dir, self.storage,
                                         self.dht_node._dataStore)
     self.prm = OnlyFreePaymentsManager()
     self.lbry_file_manager = EncryptedFileManager(
         self.peer_finder, self.rate_limiter, self.blob_manager,
         self.wallet, self.prm, self.storage, self.sd_identifier)
     d = self.storage.setup()
     d.addCallback(lambda _: self.lbry_file_manager.setup())
     return d
Ejemplo n.º 6
0
 def __init__(self, component_manager):
     Component.__init__(self, component_manager)
     self.payment_rate_manager = OnlyFreePaymentsManager()
Ejemplo n.º 7
0
 def __init__(self):
     self._payment_rate_manager = OnlyFreePaymentsManager()
     self._rate_limiter = DummyRateLimiter()
     self._wallet = None
     self._blob_manager = None
Ejemplo n.º 8
0
    def setUp(self):
        self.reflector_port = None
        self.port = None
        mocks.mock_conf_settings(self)
        self.server_db_dir, self.server_blob_dir = mk_db_and_blob_dir()
        self.client_db_dir, self.client_blob_dir = mk_db_and_blob_dir()
        prm = OnlyFreePaymentsManager()
        wallet = mocks.Wallet()
        peer_manager = PeerManager.PeerManager()
        peer_finder = mocks.PeerFinder(5553, peer_manager, 2)
        self.server_storage = SQLiteStorage(self.server_db_dir)
        self.server_blob_manager = BlobManager.DiskBlobManager(
            self.server_blob_dir, self.server_storage)
        self.client_storage = SQLiteStorage(self.client_db_dir)
        self.client_blob_manager = BlobManager.DiskBlobManager(
            self.client_blob_dir, self.client_storage)
        self.server_lbry_file_manager = EncryptedFileManager(
            peer_finder, DummyRateLimiter(), self.server_blob_manager, wallet,
            prm, self.server_storage,
            StreamDescriptor.StreamDescriptorIdentifier())
        self.client_lbry_file_manager = EncryptedFileManager(
            peer_finder, DummyRateLimiter(), self.client_blob_manager, wallet,
            prm, self.client_storage,
            StreamDescriptor.StreamDescriptorIdentifier())

        self.expected_blobs = [
            ('dc4708f76a5e7af0f1cae0ee96b824e2ed9250c9346c093b'
             '441f0a20d3607c17948b6fcfb4bc62020fe5286693d08586', 2097152),
            ('f4067522c1b49432a2a679512e3917144317caa1abba0c04'
             '1e0cd2cf9f635d4cf127ce1824fa04189b63916174951f70', 2097152),
            ('305486c434260484fcb2968ce0e963b72f81ba56c11b08b1'
             'af0789b55b44d78422600f9a38e3cf4f2e9569897e5646a9', 1015056),
        ]

        d = self.server_storage.setup()
        d.addCallback(lambda _: self.server_blob_manager.setup())
        d.addCallback(lambda _: self.server_lbry_file_manager.setup())
        d.addCallback(lambda _: self.client_storage.setup())
        d.addCallback(lambda _: self.client_blob_manager.setup())
        d.addCallback(lambda _: self.client_lbry_file_manager.setup())

        @defer.inlineCallbacks
        def verify_equal(sd_info, stream_hash):
            self.assertDictEqual(mocks.create_stream_sd_file, sd_info)
            sd_hash = yield self.client_storage.get_sd_blob_hash_for_stream(
                stream_hash)
            defer.returnValue(sd_hash)

        def save_sd_blob_hash(sd_hash):
            self.sd_hash = sd_hash
            self.expected_blobs.append((sd_hash, 923))

        def verify_stream_descriptor_file(stream_hash):
            self.stream_hash = stream_hash
            d = get_sd_info(self.client_storage, stream_hash, True)
            d.addCallback(verify_equal, stream_hash)
            d.addCallback(save_sd_blob_hash)
            return d

        def create_stream():
            test_file = mocks.GenFile(5209343,
                                      bytes((i + 3) for i in range(0, 64, 6)))
            d = EncryptedFileCreator.create_lbry_file(
                self.client_blob_manager,
                self.client_storage,
                prm,
                self.client_lbry_file_manager,
                "test_file",
                test_file,
                key=b"0123456701234567",
                iv_generator=iv_generator())
            d.addCallback(lambda lbry_file: lbry_file.stream_hash)
            return d

        def start_server():
            server_factory = reflector.ServerFactory(
                peer_manager, self.server_blob_manager,
                self.server_lbry_file_manager)
            from twisted.internet import reactor
            port = 8943
            while self.reflector_port is None:
                try:
                    self.reflector_port = reactor.listenTCP(
                        port, server_factory)
                    self.port = port
                except error.CannotListenError:
                    port += 1

        d.addCallback(lambda _: create_stream())
        d.addCallback(verify_stream_descriptor_file)
        d.addCallback(lambda _: start_server())
        return d
Ejemplo n.º 9
0
    def __init__(self,
                 blob_data_payment_rate,
                 db_dir=None,
                 node_id=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,
                 blob_tracker_class=None,
                 payment_rate_manager_class=None,
                 is_generous=True,
                 external_ip=None,
                 storage=None):
        """@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 node_id: 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

        """
        self.db_dir = db_dir
        self.node_id = node_id
        self.peer_manager = peer_manager
        self.peer_finder = peer_finder
        self.hash_announcer = hash_announcer
        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.blob_dir = blob_dir
        self.blob_manager = blob_manager
        # self.blob_tracker = None
        # self.blob_tracker_class = blob_tracker_class or BlobAvailabilityTracker
        self.peer_port = peer_port
        self.use_upnp = use_upnp
        self.rate_limiter = rate_limiter
        self.external_ip = external_ip
        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)
        self.payment_rate_manager = OnlyFreePaymentsManager()
        # self.payment_rate_manager_class = payment_rate_manager_class or NegotiatedPaymentRateManager
        # self.is_generous = is_generous
        self.storage = storage or SQLiteStorage(self.db_dir)