Example #1
0
def main(args, global_state):
    global G

    G = global_state
    G.args = args

    if args.testnet:
        network.goto_testnet()

    if args.logfile:
        logger = coro.log.asn1.Logger(open(args.logfile, 'ab'))
    else:
        logger = coro.log.StderrLogger()

    coro.log.set_logger(logger)
    coro.log.redirect_stderr()

    if args.daemon:
        if not args.logfile:
            raise ValueError("--daemon without --logfile")
        else:
            daemonize()
            open('/var/run/caesure.pid', 'wb').write('%d\n' % os.getpid())

    coro.set_exception_notifier(exception_notifier)
    LOG('caesure', 'starting')

    coro.spawn(main1, args, G)

    try:
        coro.event_loop()
    except:
        LOG.exc()
    finally:
        LOG('caesure', 'stopping')
Example #2
0
def main (args, global_state):
    global G

    G = global_state
    G.args = args

    if args.testnet:
        network.goto_testnet()

    if args.logfile:
        logger = coro.log.asn1.Logger (open (args.logfile, 'ab'))
    else:
        logger = coro.log.StderrLogger()

    coro.log.set_logger (logger)
    coro.log.redirect_stderr()

    if args.daemon:
        if not args.logfile:
            raise ValueError ("--daemon without --logfile")
        else:
            daemonize()
            open('/var/run/caesure.pid', 'wb').write ('%d\n' % os.getpid())

    coro.set_exception_notifier (exception_notifier)
    LOG ('caesure', 'starting')

    coro.spawn (main1, args, G)

    try:
        coro.event_loop()
    except:
        LOG.exc()
    finally:
        LOG ('caesure', 'stopping')
Example #3
0
def go(args, global_state):
    global G
    G = global_state
    G.args = args
    G.logger = ASN1_Logger(open(os.path.join(G.args.base, 'log.asn1'), 'ab'))
    G.log = G.logger.log
    # needed for the sub-imports below...
    import coro
    coro.set_exception_notifier(exception_notifier)
    G.log('starting caesure')
    G.addr_cache = AddressCache()
    G.block_db = block_db.BlockDB(read_only=False)
    G.hoover = BlockHoover()
    G.txn_pool = TransactionPool()
    G.recent_blocks = ledger.catch_up(G)
    G.verbose = args.verbose
    G.connection_map = {}
    # install a real resolver
    coro.dns.cache.install()
    if args.monitor:
        import coro.backdoor
        coro.spawn(coro.backdoor.serve, unix_path='/tmp/caesure.bd')
    users = {}
    if args.user:
        for user in args.user:
            u, p = user.split(':')
            users[u] = p
    if args.webui:
        import coro.http
        import caesure.webadmin
        import zlib
        G.http_server = h = coro.http.server()
        G.webadmin_handler = caesure.webadmin.handler(G)
        if users:
            h.push_handler(
                coro.http.handlers.auth_handler(users, G.webadmin_handler))
            coro.spawn(h.start, (('', 8380)))
        else:
            h.push_handler(G.webadmin_handler)
            coro.spawn(h.start, (('127.0.0.1', 8380)))
        h.push_handler(coro.http.handlers.coro_status_handler())
        h.push_handler(
            coro.http.handlers.favicon_handler(
                zlib.compress(caesure.webadmin.favicon)))
    G.in_conn_sem = coro.semaphore(args.incoming)
    G.out_conn_sem = coro.semaphore(args.outgoing)
    if args.relay:
        Connection.relay = True
    if args.serve:
        for addr in args.serve:
            coro.spawn(serve, addr)
    if args.connect:
        for addr in args.connect:
            coro.spawn(connect, addr)
    coro.spawn(G.addr_cache.purge_thread)
    coro.spawn(new_block_thread)
    coro.spawn(new_connection_thread)
    coro.spawn(G.recent_blocks.save_ledger_thread)
Example #4
0
def run_tests():
    global main_thread
    coro.install_signal_handlers = 0
    coro.signal_handler.register (signal.SIGTERM, sigterm_handler)
    coro.signal_handler.register (signal.SIGINT, sigterm_handler)
    coro.set_exception_notifier(exception_notifier)
    main_thread = coro.spawn(main)
    coro.set_print_exit_string(False)
    coro.event_loop()
    sys.exit(exit_code)
Example #5
0
def run_tests():
    global main_thread
    coro.install_signal_handlers = 0
    coro.signal_handler.register(signal.SIGTERM, sigterm_handler)
    coro.signal_handler.register(signal.SIGINT, sigterm_handler)
    coro.set_exception_notifier(exception_notifier)
    main_thread = coro.spawn(main)
    coro.set_print_exit_string(False)
    coro.event_loop()
    sys.exit(exit_code)
Example #6
0
def go (args, global_state):
    global G
    G = global_state
    G.args = args
    G.logger = ASN1_Logger (
        open (os.path.join (G.args.base, 'log.asn1'), 'ab')
        )
    G.log = G.logger.log
    # needed for the sub-imports below...
    import coro
    coro.set_exception_notifier (exception_notifier)
    G.log ('starting caesure')
    G.addr_cache = AddressCache()
    G.block_db = block_db.BlockDB (read_only=False)
    G.hoover = BlockHoover()
    G.txn_pool = TransactionPool()
    G.recent_blocks = ledger.catch_up (G)
    G.verbose = args.verbose
    G.connection_map = {}
    # install a real resolver
    coro.dns.cache.install()
    if args.monitor:
        import coro.backdoor
        coro.spawn (coro.backdoor.serve, unix_path='/tmp/caesure.bd')
    users = {}
    if args.user:
        for user in args.user:
            u, p = user.split (':')
            users[u] = p
    if args.webui:
        import coro.http
        import caesure.webadmin
        import zlib
        G.http_server = h = coro.http.server()
        G.webadmin_handler = caesure.webadmin.handler (G)
        if users:
            h.push_handler (coro.http.handlers.auth_handler (users, G.webadmin_handler))
            coro.spawn (h.start, (('', 8380)))
        else:
            h.push_handler (G.webadmin_handler)
            coro.spawn (h.start, (('127.0.0.1', 8380)))
        h.push_handler (coro.http.handlers.coro_status_handler())
        h.push_handler (
            coro.http.handlers.favicon_handler (
                zlib.compress (caesure.webadmin.favicon)
            )
        )
    G.in_conn_sem = coro.semaphore (args.incoming)
    G.out_conn_sem = coro.semaphore (args.outgoing)
    if args.relay:
        Connection.relay = True
    if args.serve:
        for addr in args.serve:
            coro.spawn (serve, addr)
    if args.connect:
        for addr in args.connect:
            coro.spawn (connect, addr)
    coro.spawn (G.addr_cache.purge_thread)
    coro.spawn (new_block_thread)
    coro.spawn (new_connection_thread)
    coro.spawn (G.recent_blocks.save_ledger_thread)