예제 #1
0
def close_pool(pool: NodePool) -> None:
    """
    Close node pool.

    :param pool: node pool to close
    """

    do_wait(pool.close())
예제 #2
0
def close_anchor(anchor: NominalAnchor) -> None:
    """
    Close anchor.

    :param anchor: anchor to close
    """

    do_wait(anchor.wallet.close())
    do_wait(anchor.close())
예제 #3
0
def dispatch(profile: Profile, noman: NominalAnchor) -> None:
    """
    Dispatch a sync invocation.

    :param profile: tails client profile
    :param noman: open nominal anchor or None
    """

    if LOCK.acquire(False):  # demur if sync in progress
        try:
            do_wait(main(profile, noman))
        finally:
            LOCK.release()
예제 #4
0
def sched() -> None:
    """
    Schedule sync invocations for dispatch evenly over a minute as per script arguments.
    """

    arg_n = sys.argv[1]

    if arg_n.isdigit():
        arg_config_ini = sys.argv[2]
        (profile, noman) = do_wait(setup(arg_config_ini))

        iterations = min(max(1, int(arg_n)),
                         30)  # 1 <= n <= 60 iterations per minute
        interval = 60.0 / iterations

        threads = []
        for i in range(iterations):
            threads.append(Timer(i * interval, dispatch, [profile, noman]))

        for thread in threads:
            thread.start()

        for thread in threads:
            thread.join()

    else:
        usage()
예제 #5
0
def main(args: Sequence[str] = None) -> int:
    """
    Main line for script: check arguments and dispatch operation to set nym.

    :param args: command-line arguments
    :return: 0 for OK, 1 for failure
    """

    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)-15s | %(levelname)-8s | %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    logging.getLogger('von_anchor').setLevel(logging.WARNING)
    logging.getLogger('indy').setLevel(logging.ERROR)

    if args is None:
        args = sys.argv[1:]

    if len(sys.argv) == 2:
        try:
            return do_wait(setnym(sys.argv[1]))
        except VonAnchorError as vax:
            print(str(vax))
            return 1
    else:
        usage()
        return 1
예제 #6
0
파일: cfg.py 프로젝트: sklump/von_tails
def set_config() -> dict:
    """
    Read configuration file content into memory cache.

    :return: configuration dict
    """

    ini_path = join(dirname(realpath(__file__)), 'config', 'config.ini')
    do_wait(MEM_CACHE.set('config.ini', ini_path))

    do_wait(MEM_CACHE.delete('config'))
    do_wait(MEM_CACHE.set('config', inis2dict(ini_path)))

    return do_wait(MEM_CACHE.get('config'))
예제 #7
0
def boot() -> None:
    """
    Boot the service: instantiate tails server anchor. Raise AbsentPool if node pool ledger configuration
    neither present nor sufficiently specified; raise AbsentNym if tails server anchor nym is not on the ledger.
    """

    config = do_wait(MEM_CACHE.get('config'))

    # setup pool and wallet
    pool_data = NodePoolData(config['Node Pool']['name'],
                             config['Node Pool'].get('genesis.txn.path', None)
                             or None)  # nudge empty value from '' to None
    p_mgr = NodePoolManager()
    if pool_data.name not in do_wait(p_mgr.list()):
        if pool_data.genesis_txn_path:
            do_wait(
                p_mgr.add_config(pool_data.name, pool_data.genesis_txn_path))
        else:
            LOGGER.debug(
                'Node pool %s has no ledger configuration but %s specifies no genesis txn path',
                pool_data.name, do_wait(MEM_CACHE.get('config.ini')))
            raise AbsentPool(
                'Node pool {} has no ledger configuration but {} specifies no genesis txn path'
                .format(pool_data.name, do_wait(MEM_CACHE.get('config.ini'))))

    pool = p_mgr.get(pool_data.name)
    do_wait(pool.open())
    do_wait(MEM_CACHE.set('pool', pool))

    # instantiate tails server anchor
    tsan_data = AnchorData(
        Role.USER, config['VON Anchor']['name'],
        config['VON Anchor'].get('seed', None) or None, None,
        config['VON Anchor'].get('wallet.create', '0').lower()
        in ['1', 'true', 'yes'], config['VON Anchor'].get('wallet.type', None)
        or None, config['VON Anchor'].get('wallet.access', None) or None)

    w_mgr = WalletManager()
    wallet = None

    wallet_config = {'id': tsan_data.name}
    if tsan_data.wallet_type:
        wallet_config['storage_type'] = tsan_data.wallet_type
    if tsan_data.wallet_create:
        if tsan_data.seed:
            wallet_config['seed'] = tsan_data.seed
        try:
            wallet = do_wait(
                w_mgr.create(wallet_config, access=tsan_data.wallet_access))
            LOGGER.info('Created wallet %s', tsan_data.name)
        except ExtantWallet:
            wallet = w_mgr.get(wallet_config, access=tsan_data.wallet_access)
            LOGGER.warning(
                'Wallet %s already exists: remove seed and wallet.create from config file',
                tsan_data.name)
    else:
        wallet = w_mgr.get(wallet_config, access=tsan_data.wallet_access)

    do_wait(wallet.open())
    tsan = NominalAnchor(wallet, pool)
    do_wait(tsan.open())
    if not json.loads(do_wait(tsan.get_nym())):
        LOGGER.debug('Anchor %s has no cryptonym on ledger %s',
                     tsan_data.wallet_name, pool_data.name)
        raise AbsentNym('Anchor {} has no cryptonym on ledger {}'.format(
            tsan_data.wallet_name, pool_data.name))

    do_wait(MEM_CACHE.set('tsan', tsan))
예제 #8
0
            NominalAnchor(wallet, pool)) as noman:

        host = config['Tails Server']['host']
        port = config['Tails Server']['port']
        epoch = int(time())
        url = 'http://{}:{}/tails/{}/{}'.format(host, port, quote(ident), epoch)
        signature = await noman.sign('{}||{}'.format(epoch, ident))
        try:
            resp = requests.delete(url, data=signature)
            logging.info('DELETE: url %s status %s', url, resp.status_code)
            if resp.status_code != requests.codes.ok:
                return 1
        except RequestsConnectionError:
            logging.error('DELETE connection refused: %s', url)
            return 1


if __name__ == '__main__':
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)-15s | %(levelname)-8s | %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    logging.getLogger('urllib').setLevel(logging.ERROR)
    logging.getLogger('von_anchor').setLevel(logging.WARNING)
    logging.getLogger('indy').setLevel(logging.CRITICAL)

    if len(sys.argv) != 3:
        usage()
    else:
        do_wait(admin_delete(sys.argv[1], sys.argv[2]))
예제 #9
0
                (paths_local, tails_remote) = survey(dir_tails, host, port)
                await sync_prover(
                    dir_tails, host, port,
                    tails_remote - set(basename(p) for p in paths_local))
        except RequestsConnectionError:
            logging.error(
                'Could not connect to tails server at %s:%s - connection refused',
                host, port)
    else:
        usage()


if __name__ == '__main__':
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)-15s | %(levelname)-8s | %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    logging.getLogger('urllib').setLevel(logging.ERROR)
    logging.getLogger('von_anchor').setLevel(logging.WARNING)
    logging.getLogger('indy').setLevel(logging.CRITICAL)

    if len(sys.argv) != 2:
        usage()
    else:
        (profile, noman) = do_wait(setup(sys.argv[1]))
        if profile:
            do_wait(main(profile, noman))
        else:
            logging.error(
                'Configured tails client profile must be issuer or prover.')