def run_daemon(args: argparse.Namespace, conf: Config): loop = asyncio.get_event_loop() if args.verbose is not None: loop.set_debug(True) if not args.no_logging: setup_logging(logging.getLogger(), args, conf) daemon = Daemon(conf) def __exit(): raise GracefulExit() try: loop.add_signal_handler(signal.SIGINT, __exit) loop.add_signal_handler(signal.SIGTERM, __exit) except NotImplementedError: pass # Not implemented on Windows try: loop.run_until_complete(daemon.start()) loop.run_forever() except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError): pass finally: loop.run_until_complete(daemon.stop()) logging.shutdown() if hasattr(loop, 'shutdown_asyncgens'): loop.run_until_complete(loop.shutdown_asyncgens())
async def test_download_blob_using_jsonrpc_blob_get(self): blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed" mock_blob_bytes = b'1' * ((2 * 2 ** 20) - 1) await self._add_blob_to_server(blob_hash, mock_blob_bytes) # setup RPC Daemon daemon_config = copy.deepcopy(self.client_config) daemon_config.fixed_peers = [(self.server_from_client.address, self.server_from_client.tcp_port)] daemon = Daemon(daemon_config) mock_node = mock.Mock(spec=Node) def _mock_accumulate_peers(q1, q2=None): async def _task(): pass q2 = q2 or asyncio.Queue(loop=self.loop) return q2, self.loop.create_task(_task()) mock_node.accumulate_peers = _mock_accumulate_peers with mock.patch('lbry.extras.daemon.componentmanager.ComponentManager.all_components_running', return_value=True): with mock.patch('lbry.extras.daemon.daemon.Daemon.dht_node', new_callable=mock.PropertyMock) \ as daemon_mock_dht: with mock.patch('lbry.extras.daemon.daemon.Daemon.blob_manager', new_callable=mock.PropertyMock) \ as daemon_mock_blob_manager: daemon_mock_dht.return_value = mock_node daemon_mock_blob_manager.return_value = self.client_blob_manager result = await daemon.jsonrpc_blob_get(blob_hash, read=True) self.assertIsNotNone(result) self.assertEqual(mock_blob_bytes.decode(), result, "Downloaded blob is different than server blob")
def run_daemon(args: argparse.Namespace, conf: Config): if sys.version_info < (3, 8) and platform.system() == "Windows": # TODO: remove after we move to requiring Python 3.8 asyncio.set_event_loop(asyncio.ProactorEventLoop()) loop = asyncio.get_event_loop() if args.verbose is not None: loop.set_debug(True) if not args.no_logging: setup_logging(logging.getLogger(), args, conf) daemon = Daemon(conf) def __exit(): raise GracefulExit() try: loop.add_signal_handler(signal.SIGINT, __exit) loop.add_signal_handler(signal.SIGTERM, __exit) except NotImplementedError: pass # Not implemented on Windows try: loop.run_until_complete(daemon.start()) loop.run_forever() except (GracefulExit, KeyboardInterrupt, asyncio.CancelledError): pass finally: loop.run_until_complete(daemon.stop()) logging.shutdown() if hasattr(loop, 'shutdown_asyncgens'): loop.run_until_complete(loop.shutdown_asyncgens())
async def add_daemon(self, wallet_node=None, seed=None): if wallet_node is None: wallet_node = WalletNode(self.wallet_node.manager_class, self.wallet_node.ledger_class, port=self.extra_wallet_node_port) self.extra_wallet_node_port += 1 await wallet_node.start(self.conductor.spv_node, seed=seed) self.extra_wallet_nodes.append(wallet_node) upload_dir = os.path.join(wallet_node.data_path, 'uploads') os.mkdir(upload_dir) conf = Config() conf.data_dir = wallet_node.data_path conf.wallet_dir = wallet_node.data_path conf.download_dir = wallet_node.data_path conf.upload_dir = upload_dir # not a real conf setting conf.share_usage_data = False conf.use_upnp = False conf.reflect_streams = True conf.blockchain_name = 'lbrycrd_regtest' conf.lbryum_servers = [('127.0.0.1', 50001)] conf.reflector_servers = [('127.0.0.1', 5566)] conf.fixed_peers = [('127.0.0.1', 5567)] conf.known_dht_nodes = [] conf.blob_lru_cache_size = self.blob_lru_cache_size conf.transaction_cache_size = 10000 conf.components_to_skip = [ DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT ] if self.skip_libtorrent: conf.components_to_skip.append(LIBTORRENT_COMPONENT) wallet_node.manager.config = conf def wallet_maker(component_manager): wallet_component = WalletComponent(component_manager) wallet_component.wallet_manager = wallet_node.manager wallet_component._running = True return wallet_component daemon = Daemon( conf, ComponentManager(conf, skip_components=conf.components_to_skip, wallet=wallet_maker, exchange_rate_manager=partial( ExchangeRateManagerComponent, rates={ 'BTCLBC': 1.0, 'USDBTC': 2.0 }))) await daemon.initialize() self.daemons.append(daemon) wallet_node.manager.old_db = daemon.storage return daemon
def start(): keyring.set_keyring(LbryAndroidKeyring()) private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(service.getApplicationContext()) configured_download_dir = lbrynet_android_utils.getConfiguredDownloadDirectory(service.getApplicationContext()) components_to_skip = [] dht_state = 'off' try: dht_path = f'{private_storage_dir}/dht'; with open(dht_path, 'r') as file: dht_state = file.read() except: pass dht_enabled = dht_state == 'on' if not dht_enabled: components_to_skip = [DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT] conf = Config( data_dir=f'{private_storage_dir}/lbrynet', wallet_dir=f'{private_storage_dir}/lbryum', download_dir=configured_download_dir, blob_lru_cache_size=32, components_to_skip=components_to_skip, save_blobs=False, save_files=False, share_usage_data=True, use_upnp=False ) for directory in (conf.data_dir, conf.download_dir, conf.wallet_dir): ensure_directory_exists(directory) configure_logging(conf) log.info('Starting lbry sdk {}'.format(lbrynet_version)); loop = asyncio.get_event_loop() loop.set_debug(lbrynet_android_utils.isDebug()) daemon = Daemon(conf) try: loop.run_until_complete(daemon.start()) loop.run_forever() except (GracefulExit, asyncio.CancelledError): pass finally: loop.run_until_complete(daemon.stop()) if hasattr(loop, 'shutdown_asyncgens'): loop.run_until_complete(loop.shutdown_asyncgens())
async def asyncSetUp(self): conf = Config() conf.data_dir = '/tmp' conf.share_usage_data = False conf.api = 'localhost:5299' conf.components_to_skip = ( DATABASE_COMPONENT, BLOB_COMPONENT, WALLET_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, WALLET_SERVER_PAYMENTS_COMPONENT, LIBTORRENT_COMPONENT ) Daemon.component_attributes = {} self.daemon = Daemon(conf) await self.daemon.start() self.addCleanup(self.daemon.stop)