コード例 #1
0
def start():
    # lbry daemon
    https_context()
    conf.initialize_settings()

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, True, [])

    # TODO: specify components, initialise auth
    conf.settings.update({
        'components_to_skip': [
            DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT
        ],
        'use_upnp':
        False
    })

    log.info('Final Settings: %s', conf.settings.get_current_settings_dict())
    log.info("Starting lbrynet-daemon")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to the Internet. Unable to start.")
コード例 #2
0
def start_daemon(settings: typing.Optional[typing.Dict] = None,
                 console_output: typing.Optional[bool] = True,
                 verbose: typing.Optional[typing.List[str]] = None,
                 data_dir: typing.Optional[str] = None,
                 wallet_dir: typing.Optional[str] = None,
                 download_dir: typing.Optional[str] = None):

    settings = settings or {}
    conf.initialize_settings(data_dir=data_dir,
                             wallet_dir=wallet_dir,
                             download_dir=download_dir)
    for k, v in settings.items():
        conf.settings.update({k, v}, data_types=(conf.TYPE_CLI, ))

    log_support.configure_logging(conf.settings.get_log_filename(),
                                  console_output, verbose)
    log_support.configure_loggly_handler()
    log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
    log.info("Starting lbrynet-daemon from command line")

    if check_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to internet, unable to start")
コード例 #3
0
    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.stream').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        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.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await self.account.receiving.get_addresses(limit=1, only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]
        self.daemon = Daemon(conf, ComponentManager(
            conf, skip_components=conf.components_to_skip, wallet=wallet_maker,
            exchange_rate_manager=ExchangeRateManagerComponent
        ))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage

        server_tmp_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, server_tmp_dir)
        self.server_config = Config()
        self.server_storage = SQLiteStorage(self.server_config, ':memory:')
        await self.server_storage.open()

        self.server_blob_manager = BlobManager(self.loop, server_tmp_dir, self.server_storage, self.server_config)
        self.server = BlobServer(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
        self.server.start_server(5567, '127.0.0.1')
        await self.server.started_listening.wait()

        self.reflector = ReflectorServer(self.server_blob_manager)
        self.reflector.start_server(5566, '127.0.0.1')
        await self.reflector.started_listening.wait()
        self.addCleanup(self.reflector.stop_server)
コード例 #4
0
ファイル: test_commands.py プロジェクト: mossmanpete/lbry
    async def setUp(self):
        await super().setUp()

        logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False,
                                      data_dir=self.wallet_node.data_path,
                                      wallet_dir=self.wallet_node.data_path,
                                      download_dir=self.wallet_node.data_path)
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            #UPNP_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT,
            REFLECTOR_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker,
                             dht=FakeDHT,
                             hash_announcer=FakeHashAnnouncerComponent,
                             exchange_rate_manager=FakeExchangeRateComponent,
                             upnp=FakeUPnP))
        await d2f(self.daemon.setup())
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage
コード例 #5
0
ファイル: DaemonControl.py プロジェクト: walidmujahid/lbry
def start(argv=None, conf_path=None):
    if conf_path is not None:
        conf.conf_file = conf_path

    conf.initialize_settings()

    parser = argparse.ArgumentParser()
    parser.add_argument("--http-auth",
                        dest="useauth",
                        action="store_true",
                        default=conf.settings['use_auth_http'])
    parser.add_argument('--quiet',
                        dest='quiet',
                        action="store_true",
                        help='Disable all console output.')
    parser.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    parser.add_argument('--version',
                        action="store_true",
                        help='Show daemon version and quit')

    args = parser.parse_args(argv)
    if args.useauth:
        conf.settings.update({'use_auth_http': args.useauth},
                             data_types=(conf.TYPE_CLI, ))

    if args.version:
        version = system_info.get_platform()
        version['installation_id'] = conf.settings.installation_id
        print(utils.json_dumps_pretty(version))
        return

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
    log_support.configure_loggly_handler()
    log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())

    log.info("Starting lbrynet-daemon from command line")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to internet, unable to start")
コード例 #6
0
 def setUp(self):
     skip = [
         DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT,
         DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT,
         PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT,
         RATE_LIMITER_COMPONENT, PAYMENT_RATE_COMPONENT
     ]
     conf.initialize_settings(load_conf_file=False)
     conf.settings['api_port'] = 5299
     conf.settings['use_auth_http'] = self.USE_AUTH
     conf.settings['components_to_skip'] = skip
     conf.settings.initialize_post_conf_load()
     Daemon.component_attributes = {}
     self.daemon = Daemon(analytics_manager=FakeAnalytics())
     yield self.daemon.start_listening()
コード例 #7
0
ファイル: DaemonConsole.py プロジェクト: walidmujahid/lbry
def start_server_and_listen(use_auth, analytics_manager, quiet):
    log_support.configure_console()
    logging.getLogger("lbrynet").setLevel(logging.CRITICAL)
    logging.getLogger("lbryum").setLevel(logging.CRITICAL)
    logging.getLogger("requests").setLevel(logging.CRITICAL)

    analytics_manager.send_server_startup()
    yield Daemon().start_listening()
コード例 #8
0
ファイル: DaemonConsole.py プロジェクト: niteshldd/lbry
def start_server_and_listen(use_auth, analytics_manager, quiet):
    log_support.configure_console()
    logging.getLogger("lbrynet").setLevel(logging.CRITICAL)
    logging.getLogger("lbryum").setLevel(logging.CRITICAL)
    logging.getLogger("requests").setLevel(logging.CRITICAL)

    # TODO: turn this all into async. Until then this routine can't be called
    # analytics_manager.send_server_startup()
    yield Daemon().start_listening()
コード例 #9
0
def get_argument_parser():
    main = ArgumentParser(
        'lbrynet',
        description='An interface to the LBRY Network.',
        allow_abbrev=False,
    )
    main.add_argument('-v',
                      '--version',
                      dest='cli_version',
                      action="store_true",
                      help='Show lbrynet CLI version and exit.')
    main.set_defaults(group=None, command=None)
    CLIConfig.contribute_to_argparse(main)
    sub = main.add_subparsers(metavar='COMMAND')
    start = sub.add_parser(
        'start',
        usage=
        'lbrynet start [--config FILE] [--data-dir DIR] [--wallet-dir DIR] [--download-dir DIR] ...',
        help='Start LBRY Network interface.')
    start.add_argument('--quiet',
                       dest='quiet',
                       action="store_true",
                       help='Disable all console output.')
    start.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    Config.contribute_to_argparse(start)
    start.set_defaults(command='start',
                       start_parser=start,
                       doc=start.format_help())

    api = Daemon.get_api_definitions()
    groups = {}
    for group_name in sorted(api['groups']):
        group_parser = sub.add_parser(group_name,
                                      group_name=group_name,
                                      help=api['groups'][group_name])
        groups[group_name] = group_parser.add_subparsers(metavar='COMMAND')

    nicer_order = ['stop', 'get', 'publish', 'resolve']
    for command_name in sorted(api['commands']):
        if command_name not in nicer_order:
            nicer_order.append(command_name)

    for command_name in nicer_order:
        command = api['commands'][command_name]
        if command['group'] is None:
            add_command_parser(sub, command)
        else:
            add_command_parser(groups[command['group']], command)

    return main
コード例 #10
0
ファイル: generate_json_api.py プロジェクト: binaryflesh/lbry
def write_api(f):
    examples = get_examples()
    api_definitions = Daemon.get_api_definitions()
    apis = {'main': {'doc': 'Ungrouped commands.', 'commands': []}}
    for group_name, group_doc in api_definitions['groups'].items():
        apis[group_name] = {'doc': group_doc, 'commands': []}
    for method_name, command in api_definitions['commands'].items():
        if 'replaced_by' in command:
            continue
        apis[command['group'] or 'main']['commands'].append(
            get_api(method_name, examples.get(method_name, [])))
    json.dump(apis, f, indent=4)
コード例 #11
0
def start():
    keyring.set_keyring(LbryAndroidKeyring())
    private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(
        service.getApplicationContext())
    conf = Config(
        data_dir=f'{private_storage_dir}/lbrynet',
        wallet_dir=f'{private_storage_dir}/lbryum',
        download_dir=
        f'{lbrynet_android_utils.getInternalStorageDir(service.getApplicationContext())}/Download',
        blob_lru_cache_size=32,
        components_to_skip=[
            DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ],
        save_blobs=False,
        save_files=False,
        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_until_complete(daemon.stop_event.wait())
    except (GracefulExit):
        pass
    finally:
        loop.run_until_complete(daemon.stop())
    if hasattr(loop, 'shutdown_asyncgens'):
        loop.run_until_complete(loop.shutdown_asyncgens())
コード例 #12
0
    async def asyncSetUp(self):
        await super().asyncSetUp()

        twisted.internet.reactor = sys.modules[
            'twisted.internet.reactor'] = AsyncioSelectorReactor()

        logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False,
                                      data_dir=self.wallet_node.data_path,
                                      wallet_dir=self.wallet_node.data_path,
                                      download_dir=self.wallet_node.data_path)
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
            EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker))
        await self.daemon.setup()
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage
コード例 #13
0
ファイル: test_cli.py プロジェクト: woolf-wen/lbry
 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,
                                HEADERS_COMPONENT, WALLET_COMPONENT,
                                DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                                STREAM_MANAGER_COMPONENT,
                                PEER_PROTOCOL_SERVER_COMPONENT,
                                UPNP_COMPONENT,
                                EXCHANGE_RATE_MANAGER_COMPONENT)
     Daemon.component_attributes = {}
     self.daemon = Daemon(conf)
     await self.daemon.start()
コード例 #14
0
ファイル: test_sync.py プロジェクト: TTcoinDeveloper/lbry
    async def asyncSetUp(self):
        self.wallet_node = WalletNode(LbryWalletManager, RegTestLedger)
        await self.wallet_node.start(
            SPVNode(None),
            "carbon smart garage balance margin twelve chest sword toast envelope bottom stomach absent",
            False)
        self.account = self.wallet_node.account

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = False
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('localhost', 50001)]
        conf.reflector_servers = []
        conf.known_dht_nodes = []

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.wallet_node.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(conf,
                             skip_components=conf.components_to_skip,
                             wallet=wallet_maker))
        await self.daemon.initialize()
コード例 #15
0
ファイル: test_commands.py プロジェクト: stjordanis/lbry
    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = False
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('localhost', 50001)]
        conf.reflector_servers = []
        conf.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(conf,
                             skip_components=conf.components_to_skip,
                             wallet=wallet_maker))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage
コード例 #16
0
ファイル: testcase.py プロジェクト: jayd2446/lbry
    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)

        conf = Config()
        conf.data_dir = wallet_node.data_path
        conf.wallet_dir = wallet_node.data_path
        conf.download_dir = wallet_node.data_path
        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.known_dht_nodes = []
        conf.blob_lru_cache_size = self.blob_lru_cache_size
        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]

        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=ExchangeRateManagerComponent))
        await daemon.initialize()
        self.daemons.append(daemon)
        wallet_node.manager.old_db = daemon.storage
        return daemon
コード例 #17
0
ファイル: test_Daemon.py プロジェクト: mossmanpete/lbry
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
コード例 #18
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    parser = get_argument_parser()
    args, command_args = parser.parse_known_args(argv)

    conf = Config.create_from_arguments(args)
    for directory in (conf.data_dir, conf.download_dir, conf.wallet_dir):
        ensure_directory_exists(directory)

    if args.cli_version:
        print(f"{lbrynet_name} {lbrynet_version}")
        return 0

    elif args.command == 'start':

        if args.help:
            args.start_parser.print_help()
            return 0
        default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
        file_handler = logging.handlers.RotatingFileHandler(
            conf.log_file_path, maxBytes=2097152, backupCount=5
        )
        file_handler.setFormatter(default_formatter)
        log.addHandler(file_handler)
        logging.getLogger('torba').addHandler(file_handler)

        if not args.quiet:
            handler = logging.StreamHandler()
            handler.setFormatter(default_formatter)
            log.addHandler(handler)
            logging.getLogger('torba').addHandler(handler)
            logging.getLogger('torba').setLevel(logging.INFO)

        logging.getLogger('aioupnp').setLevel(logging.WARNING)
        logging.getLogger('aiohttp').setLevel(logging.CRITICAL)

        loop = asyncio.get_event_loop()

        if args.verbose:
            log.setLevel(logging.DEBUG)
            loop.set_debug(True)
        else:
            log.setLevel(logging.INFO)
        if conf.share_usage_data:
            loggly_handler = get_loggly_handler()
            loggly_handler.setLevel(logging.ERROR)
            log.addHandler(loggly_handler)

        daemon = Daemon(conf)
        try:
            loop.run_until_complete(daemon.start())
            loop.run_forever()
        except (GracefulExit, KeyboardInterrupt):
            pass
        finally:
            loop.run_until_complete(daemon.stop())
        if hasattr(loop, 'shutdown_asyncgens'):
            loop.run_until_complete(loop.shutdown_asyncgens())

    elif args.command is not None:

        doc = args.doc
        api_method_name = args.api_method_name
        if args.replaced_by:
            print(f"{args.api_method_name} is deprecated, using {args.replaced_by['api_method_name']}.")
            doc = args.replaced_by['doc']
            api_method_name = args.replaced_by['api_method_name']

        if args.help:
            print(doc)
        else:
            parsed = docopt(doc, command_args)
            params = set_kwargs(parsed)
            loop = asyncio.get_event_loop()
            loop.run_until_complete(execute_command(conf, api_method_name, params))

    elif args.group is not None:
        args.group_parser.print_help()

    else:
        parser.print_help()

    return 0
コード例 #19
0
class CommandTestCase(IntegrationTestCase):

    timeout = 180
    LEDGER = lbrynet.wallet
    MANAGER = LbryWalletManager
    VERBOSITY = logging.WARN

    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.stream').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        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.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(
                conf,
                skip_components=conf.components_to_skip,
                wallet=wallet_maker,
                exchange_rate_manager=ExchangeRateManagerComponent))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage

        server_tmp_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, server_tmp_dir)
        self.server_config = Config()
        self.server_storage = SQLiteStorage(self.server_config, ':memory:')
        await self.server_storage.open()

        self.server_blob_manager = BlobManager(self.loop, server_tmp_dir,
                                               self.server_storage,
                                               self.server_config)
        self.server = BlobServer(self.loop, self.server_blob_manager,
                                 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
        self.server.start_server(5567, '127.0.0.1')
        await self.server.started_listening.wait()

        self.reflector = ReflectorServer(self.server_blob_manager)
        self.reflector.start_server(5566, '127.0.0.1')
        await self.reflector.started_listening.wait()
        self.addCleanup(self.reflector.stop_server)

    async def asyncTearDown(self):
        await super().asyncTearDown()
        self.wallet_component._running = False
        await self.daemon.stop()

    async def confirm_tx(self, txid):
        """ Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
        await self.on_transaction_id(txid)
        await self.generate(1)
        await self.on_transaction_id(txid)

    async def on_transaction_dict(self, tx):
        await self.ledger.wait(
            self.ledger.transaction_class(unhexlify(tx['hex'])))

    @staticmethod
    def get_all_addresses(tx):
        addresses = set()
        for txi in tx['inputs']:
            addresses.add(txi['address'])
        for txo in tx['outputs']:
            addresses.add(txo['address'])
        return list(addresses)

    async def generate(self, blocks):
        """ Ask lbrycrd to generate some blocks and wait until ledger has them. """
        await self.blockchain.generate(blocks)
        await self.ledger.on_header.where(self.blockchain.is_expected_block)

    async def blockchain_claim_name(self,
                                    name: str,
                                    value: str,
                                    amount: str,
                                    confirm=True):
        txid = await self.blockchain._cli_cmnd('claimname', name, value,
                                               amount)
        if confirm:
            await self.generate(1)
        return txid

    async def blockchain_update_name(self,
                                     txid: str,
                                     value: str,
                                     amount: str,
                                     confirm=True):
        txid = await self.blockchain._cli_cmnd('updateclaim', txid, value,
                                               amount)
        if confirm:
            await self.generate(1)
        return txid

    async def out(self, awaitable):
        """ Serializes lbrynet API results to JSON then loads and returns it as dictionary. """
        return json.loads(
            jsonrpc_dumps_pretty(await awaitable,
                                 ledger=self.ledger))['result']

    def sout(self, value):
        """ Synchronous version of `out` method. """
        return json.loads(jsonrpc_dumps_pretty(value,
                                               ledger=self.ledger))['result']

    async def stream_create(self,
                            name='hovercraft',
                            bid='1.0',
                            data=b'hi!',
                            confirm=True,
                            **kwargs):
        with tempfile.NamedTemporaryFile() as file:
            file.write(data)
            file.flush()
            claim = await self.out(
                self.daemon.jsonrpc_stream_create(name,
                                                  bid,
                                                  file_path=file.name,
                                                  **kwargs))
            self.assertEqual(claim['outputs'][0]['name'], name)
            if confirm:
                await self.on_transaction_dict(claim)
                await self.generate(1)
                await self.on_transaction_dict(claim)
            return claim

    async def stream_update(self, claim_id, data=None, confirm=True, **kwargs):
        if data:
            with tempfile.NamedTemporaryFile() as file:
                file.write(data)
                file.flush()
                claim = await self.out(
                    self.daemon.jsonrpc_stream_update(claim_id,
                                                      file_path=file.name,
                                                      **kwargs))
        else:
            claim = await self.out(
                self.daemon.jsonrpc_stream_update(claim_id, **kwargs))
        self.assertIsNotNone(claim['outputs'][0]['name'])
        if confirm:
            await self.on_transaction_dict(claim)
            await self.generate(1)
            await self.on_transaction_dict(claim)
        return claim

    async def stream_abandon(self, *args, confirm=True, **kwargs):
        if 'blocking' not in kwargs:
            kwargs['blocking'] = False
        tx = await self.out(self.daemon.jsonrpc_stream_abandon(
            *args, **kwargs))
        if confirm:
            await self.on_transaction_dict(tx)
            await self.generate(1)
            await self.on_transaction_dict(tx)
        return tx

    async def publish(self, name, *args, confirm=True, **kwargs):
        claim = await self.out(
            self.daemon.jsonrpc_publish(name, *args, **kwargs))
        self.assertEqual(claim['outputs'][0]['name'], name)
        if confirm:
            await self.on_transaction_dict(claim)
            await self.generate(1)
            await self.on_transaction_dict(claim)
        return claim

    async def channel_create(self,
                             name='@arena',
                             bid='1.0',
                             confirm=True,
                             **kwargs):
        channel = await self.out(
            self.daemon.jsonrpc_channel_create(name, bid, **kwargs))
        self.assertEqual(channel['outputs'][0]['name'], name)
        if confirm:
            await self.on_transaction_dict(channel)
            await self.generate(1)
            await self.on_transaction_dict(channel)
        return channel

    async def channel_update(self, claim_id, confirm=True, **kwargs):
        channel = await self.out(
            self.daemon.jsonrpc_channel_update(claim_id, **kwargs))
        self.assertTrue(channel['outputs'][0]['name'].startswith('@'))
        if confirm:
            await self.on_transaction_dict(channel)
            await self.generate(1)
            await self.on_transaction_dict(channel)
        return channel

    async def channel_abandon(self, *args, confirm=True, **kwargs):
        if 'blocking' not in kwargs:
            kwargs['blocking'] = False
        tx = await self.out(
            self.daemon.jsonrpc_channel_abandon(*args, **kwargs))
        if confirm:
            await self.on_transaction_dict(tx)
            await self.generate(1)
            await self.on_transaction_dict(tx)
        return tx

    async def resolve(self, uri):
        return await self.out(self.daemon.jsonrpc_resolve(uri))

    async def claim_search(self, *args, **kwargs):
        return (await
                self.out(self.daemon.jsonrpc_claim_search(*args,
                                                          **kwargs)))['items']
コード例 #20
0
ファイル: test_commands.py プロジェクト: guzhenping/lbry
class CommandTestCase(IntegrationTestCase):

    timeout = 180
    MANAGER = LbryWalletManager

    async def setUp(self):
        await super().setUp()

        logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False)
        lbry_conf.settings['data_dir'] = self.wallet_node.data_path
        lbry_conf.settings['lbryum_wallet_dir'] = self.wallet_node.data_path
        lbry_conf.settings['download_directory'] = self.wallet_node.data_path
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await self.account.ensure_address_gap()
        address = (await self.account.receiving.get_addresses(limit=1, only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            #UPNP_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT,
            REFLECTOR_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(analytics_manager, ComponentManager(
            analytics_manager=analytics_manager,
            skip_components=skip, wallet=wallet_maker,
            dht=FakeDHT, hash_announcer=FakeHashAnnouncerComponent,
            exchange_rate_manager=FakeExchangeRateComponent,
            upnp=FakeUPnP
        ))
        await d2f(self.daemon.setup())
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage

    async def tearDown(self):
        await super().tearDown()
        self.wallet_component._running = False
        await d2f(self.daemon._shutdown())

    async def confirm_tx(self, txid):
        """ Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
        await self.on_transaction_id(txid)
        await self.generate(1)
        await self.on_transaction_id(txid)

    async def on_transaction_dict(self, tx):
        await asyncio.wait([
            self.ledger.on_transaction.where(
                partial(lambda address, event: address == event.address, address)
            ) for address in self.get_all_addresses(tx)
        ])

    @staticmethod
    def get_all_addresses(tx):
        addresses = set()
        for txi in tx['inputs']:
            addresses.add(txi['address'])
        for txo in tx['outputs']:
            addresses.add(txo['address'])
        return list(addresses)

    async def generate(self, blocks):
        """ Ask lbrycrd to generate some blocks and wait until ledger has them. """
        await self.blockchain.generate(blocks)
        await self.ledger.on_header.where(self.blockchain.is_expected_block)

    async def out(self, awaitable):
        """ Converts Daemon API call results (dictionary)
            to JSON and then back to a dictionary. """
        return json.loads(jsonrpc_dumps_pretty(await awaitable, ledger=self.ledger))['result']
コード例 #21
0
ファイル: test_sync.py プロジェクト: TTcoinDeveloper/lbry
class AccountSynchronization(AsyncioTestCase):
    async def asyncSetUp(self):
        self.wallet_node = WalletNode(LbryWalletManager, RegTestLedger)
        await self.wallet_node.start(
            SPVNode(None),
            "carbon smart garage balance margin twelve chest sword toast envelope bottom stomach absent",
            False)
        self.account = self.wallet_node.account

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = False
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('localhost', 50001)]
        conf.reflector_servers = []
        conf.known_dht_nodes = []

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.wallet_node.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(conf,
                             skip_components=conf.components_to_skip,
                             wallet=wallet_maker))
        await self.daemon.initialize()

    async def asyncTearDown(self):
        self.wallet_component._running = False
        await self.daemon.stop()

    @mock.patch('time.time', mock.Mock(return_value=12345))
    def test_sync(self):
        starting_hash = '69afcd60a300f47933917d77ef011beeeb4decfafebbda91c144c84282c6814f'
        self.account.modified_on = 123.456
        self.assertEqual(self.daemon.jsonrpc_sync_hash(), starting_hash)
        self.assertEqual(
            self.daemon.jsonrpc_sync_apply('password')['hash'], starting_hash)
        self.assertFalse(self.account.certificates)

        hash_w_cert = '974721f42dab42657b5911b7caf4af98ce4d3879eea6ac23d50c1d79bc5020ef'
        add_cert = (
            'czo4MTkyOjE2OjE6qs3JRvS/bhX8p1JD68sqyA2Qhx3EVTqskhqEAwtfAUfUsQqeJ1rtMdRf40vkGKnpt4NT0b'
            'XEqb5O+lba4nkLF7vZENhc2zuOrjobCPVbiVHNwOfH56Ayrh1ts5LMcnl5+Mk1BUyGCwXcqEg2KiUkd3YZpiHQ'
            'T7WfcODcU6l7IRivb8iawCebZJx9waVyQoqEDKwZUY1i5HA0VLC+s5cV7it1AWbewiyWOQtZdEPzNY44oXLJex'
            'SirElQqDqNZyl3Hjy8YqacBbSYoejIRnmXpC9y25keP6hep3f9i1K2HDNwhwns1W1vhuzuO2Gy9+a0JlVm5mwc'
            'N2pqO4tCZr6tE3aym2FaSAunOi7QYVFMI6arb9Gvn9P+T+WRiFYfzwDFVR+j5ZPmUDXxHisy5OF163jH61wbBY'
            'pPienjlVtDOxoZmA8+AwWXKRdINsRcull9pu7EVCq5yQmrmxoPbLxNh5pRGrBB0JwCCOMIf+KPwS+7Z6dDbiwO'
            '2NUpk8USJMTmXmFDCr2B0PJiG6Od2dD2oGN0F7aYZvUuKbqj8eDrJMe/zLbhq47jUjkJFCvtxUioo63ORk1pzH'
            'S0/X4/6/95PRSMaXm4DcZ9BdyxR2E/AKc8UN6AL5rrn6quXkC6R3ZhKgN3Si2S9y6EGFsL7dgzX331U08ZviLj'
            'NsrG0EKUnf+TGQ42MqnLQBOiO/ZoAwleOzNZnCYOQQ14Mm8y17xUpmdWRDiRKpAOJU22jKnxtqQ='
        )
        self.daemon.jsonrpc_sync_apply('password', data=add_cert)
        self.assertEqual(self.daemon.jsonrpc_sync_hash(), hash_w_cert)
        self.assertEqual(self.account.certificates,
                         {'abcdefg1234:0': '---PRIVATE KEY---'})

        # applying the same diff is idempotent
        self.daemon.jsonrpc_sync_apply('password', data=add_cert)
        self.assertEqual(self.daemon.jsonrpc_sync_hash(), hash_w_cert)
        self.assertEqual(self.account.certificates,
                         {'abcdefg1234:0': '---PRIVATE KEY---'})
コード例 #22
0
ファイル: testcase.py プロジェクト: xzc1017964340/lbry
class CommandTestCase(IntegrationTestCase):

    timeout = 180
    LEDGER = lbrynet.extras.wallet
    MANAGER = LbryWalletManager
    VERBOSITY = logging.WARN

    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.stream').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        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.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(
                conf,
                skip_components=conf.components_to_skip,
                wallet=wallet_maker,
                exchange_rate_manager=ExchangeRateManagerComponent))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage

        server_tmp_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, server_tmp_dir)
        self.server_storage = SQLiteStorage(Config(), ':memory:')
        await self.server_storage.open()
        self.server_blob_manager = BlobFileManager(self.loop, server_tmp_dir,
                                                   self.server_storage)
        self.server = BlobServer(self.loop, self.server_blob_manager,
                                 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
        self.server.start_server(5567, '127.0.0.1')
        await self.server.started_listening.wait()

        self.reflector = ReflectorServer(self.server_blob_manager)
        self.reflector.start_server(5566, '127.0.0.1')
        await self.reflector.started_listening.wait()
        self.addCleanup(self.reflector.stop_server)

    async def asyncTearDown(self):
        await super().asyncTearDown()
        self.wallet_component._running = False
        await self.daemon.stop()

    async def confirm_tx(self, txid):
        """ Wait for tx to be in mempool, then generate a block, wait for tx to be in a block. """
        await self.on_transaction_id(txid)
        await self.generate(1)
        await self.on_transaction_id(txid)

    async def on_transaction_dict(self, tx):
        await self.ledger.wait(
            self.ledger.transaction_class(unhexlify(tx['hex'])))

    @staticmethod
    def get_all_addresses(tx):
        addresses = set()
        for txi in tx['inputs']:
            addresses.add(txi['address'])
        for txo in tx['outputs']:
            addresses.add(txo['address'])
        return list(addresses)

    async def generate(self, blocks):
        """ Ask lbrycrd to generate some blocks and wait until ledger has them. """
        await self.blockchain.generate(blocks)
        await self.ledger.on_header.where(self.blockchain.is_expected_block)

    async def out(self, awaitable):
        """ Converts Daemon API call results (dictionary)
            to JSON and then back to a dictionary. """
        return json.loads(
            jsonrpc_dumps_pretty(await awaitable,
                                 ledger=self.ledger))['result']

    async def make_claim(self,
                         name='hovercraft',
                         amount='1.0',
                         data=b'hi!',
                         channel_name=None,
                         confirm=True,
                         account_id=None,
                         fee=None):
        with tempfile.NamedTemporaryFile() as file:
            file.write(data)
            file.flush()
            claim = await self.out(
                self.daemon.jsonrpc_publish(name,
                                            amount,
                                            file_path=file.name,
                                            channel_name=channel_name,
                                            account_id=account_id,
                                            fee=fee))
            self.assertTrue(claim['success'])
            if confirm:
                await self.on_transaction_dict(claim['tx'])
                await self.generate(1)
                await self.on_transaction_dict(claim['tx'])
            return claim

    async def make_channel(self,
                           name='@arena',
                           amount='1.0',
                           confirm=True,
                           account_id=None):
        channel = await self.out(
            self.daemon.jsonrpc_channel_new(name, amount, account_id))
        self.assertTrue(channel['success'])
        if confirm:
            await self.on_transaction_dict(channel['tx'])
            await self.generate(1)
            await self.on_transaction_dict(channel['tx'])
        return channel

    async def resolve(self, uri):
        return await self.out(self.daemon.jsonrpc_resolve(uri))