Exemple #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': test_utils.DEFAULT_ISO_TIME + 1},
        'USDBTC': {'spot': 2.0, 'ts': test_utils.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,
                         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
 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(':memory:')
     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 = f2d(self.storage.open())
     d.addCallback(lambda _: f2d(self.lbry_file_manager.setup()))
     return d
Exemple #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(':memory:')
        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 f2d(self.storage.open())
        yield f2d(self.blob_manager.setup())
        yield f2d(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, bytes(i for i in range(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)
Exemple #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(':memory:')
        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 f2d(self.storage.open())
        yield f2d(self.blob_manager.setup())
        yield f2d(self.lbry_file_manager.setup())
        yield add_lbry_file_to_sd_identifier(self.sd_identifier)
Exemple #5
0
 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(':memory:')
     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)
     yield f2d(self.storage.open())
     yield f2d(self.lbry_file_manager.setup())
Exemple #6
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()
        peer_finder = mocks.PeerFinder(5553, peer_manager, 2)
        self.server_storage = SQLiteStorage(':memory:')
        self.server_blob_manager = BlobManager.DiskBlobManager(
            self.server_blob_dir, self.server_storage)
        self.client_storage = SQLiteStorage(':memory:')
        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),
        ]

        yield f2d(self.server_storage.open())
        yield f2d(self.server_blob_manager.setup())
        yield f2d(self.server_lbry_file_manager.setup())
        yield f2d(self.client_storage.open())
        yield f2d(self.client_blob_manager.setup())
        yield f2d(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 f2d(
                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 = f2d(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 = ReflectorServerFactory(
                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

        stream_hash = yield create_stream()
        yield verify_stream_descriptor_file(stream_hash)
        yield start_server()
 def __init__(self):
     self._payment_rate_manager = OnlyFreePaymentsManager()
     self._rate_limiter = DummyRateLimiter()
     self._wallet = None
     self._blob_manager = None
Exemple #8
0
 def __init__(self, component_manager):
     super().__init__(component_manager)
     self.payment_rate_manager = OnlyFreePaymentsManager()