예제 #1
0
def run(ctx, **kwargs):
    from raiden.api.python import RaidenAPI
    from raiden.ui.console import Console

    # TODO:
    # - Ask for confirmation to quit if there are any locked transfers that did
    # not timeout.
    (listen_host, listen_port) = split_endpoint(kwargs['listen_address'])
    with socket_factory(listen_host, listen_port) as mapped_socket:
        kwargs['socket'] = mapped_socket.socket

        app_ = ctx.invoke(app, **kwargs)

        # spawn address registration to avoid block while waiting for the next block
        registry_event = gevent.spawn(
            app_.discovery.register,
            app_.raiden.address,
            mapped_socket.external_ip,
            mapped_socket.external_port,
        )
        app_.raiden.register_registry(
            app_.raiden.chain.default_registry.address)

        domain_list = []
        if kwargs['rpccorsdomain']:
            if ',' in kwargs['rpccorsdomain']:
                for domain in kwargs['rpccorsdomain'].split(','):
                    domain_list.append(str(domain))
            else:
                domain_list.append(str(kwargs['rpccorsdomain']))

        if ctx.params['rpc']:
            raiden_api = RaidenAPI(app_.raiden)
            rest_api = RestAPI(raiden_api)
            api_server = APIServer(rest_api, cors_domain_list=domain_list)

            Greenlet.spawn(api_server.run,
                           ctx.params['api_port'],
                           debug=False,
                           use_evalex=False)

            print(
                "The RPC server is now running at http://localhost:{}/.\n\n"
                "See the Raiden documentation for all available endpoints at\n"
                "https://github.com/raiden-network/raiden/blob/master/docs/Rest-Api.rst"
                .format(ctx.params['api_port'], ))

        if ctx.params['console']:
            console = Console(app_)
            console.start()

        registry_event.join()
        # wait for interrupt
        event = gevent.event.Event()
        gevent.signal(signal.SIGQUIT, event.set)
        gevent.signal(signal.SIGTERM, event.set)
        gevent.signal(signal.SIGINT, event.set)
        event.wait()

        app_.stop(graceful=True)
예제 #2
0
def run(ctx, **kwargs):
    if ctx.invoked_subcommand is None:
        from raiden.api.python import RaidenAPI
        from raiden.ui.console import Console

        slogging.configure(kwargs['logging'], log_file=kwargs['logfile'])

        # TODO:
        # - Ask for confirmation to quit if there are any locked transfers that did
        # not timeout.
        (listen_host, listen_port) = split_endpoint(kwargs['listen_address'])
        with socket_factory(listen_host, listen_port) as mapped_socket:
            kwargs['mapped_socket'] = mapped_socket

            app_ = ctx.invoke(app, **kwargs)

            domain_list = []
            if kwargs['rpccorsdomain']:
                if ',' in kwargs['rpccorsdomain']:
                    for domain in kwargs['rpccorsdomain'].split(','):
                        domain_list.append(str(domain))
                else:
                    domain_list.append(str(kwargs['rpccorsdomain']))

            http_server = None
            if ctx.params['rpc']:
                raiden_api = RaidenAPI(app_.raiden)
                rest_api = RestAPI(raiden_api)
                api_server = APIServer(rest_api, cors_domain_list=domain_list)
                (api_host, api_port) = split_endpoint(kwargs["api_address"])

                http_server = WSGIServer((api_host, api_port),
                                         api_server.flask_app,
                                         log=slogging.getLogger('flask'))
                http_server.start()

                print(
                    "The Raiden API RPC server is now running at http://{}:{}/.\n\n"
                    "See the Raiden documentation for all available endpoints at\n"
                    "https://github.com/raiden-network/raiden/blob/master"
                    "/docs/Rest-Api.rst".format(
                        api_host,
                        api_port,
                    ))

            if ctx.params['console']:
                console = Console(app_)
                console.start()

            # wait for interrupt
            event = gevent.event.Event()
            gevent.signal(signal.SIGQUIT, event.set)
            gevent.signal(signal.SIGTERM, event.set)
            gevent.signal(signal.SIGINT, event.set)
            event.wait()

        if http_server:
            http_server.stop(5)
        app_.stop(leave_channels=False)
예제 #3
0
파일: cli.py 프로젝트: jeamick/raiden
def run(ctx, **kwargs):
    # TODO:
    # - Ask for confirmation to quit if there are any locked transfers that did
    # not timeout.
    (listen_host, listen_port) = split_endpoint(kwargs['listen_address'])
    with socket_factory(listen_host, listen_port) as mapped_socket:
        kwargs['socket'] = mapped_socket.socket

        app_ = ctx.invoke(app, **kwargs)

        app_.discovery.register(
            app_.raiden.address,
            mapped_socket.external_ip,
            mapped_socket.external_port,
        )

        app_.raiden.register_registry(app_.raiden.chain.default_registry.address)

        if ctx.params['rpc']:
            # instance of the raiden-api
            raiden_api = app_.raiden.api
            # wrap the raiden-api with rest-logic and encoding
            rest_api = RestAPI(raiden_api)
            # create the server and link the api-endpoints with flask / flask-restful middleware
            api_server = APIServer(rest_api)
            # run the server
            Greenlet.spawn(api_server.run, ctx.params['api_port'], debug=False, use_evalex=False)
            print(
                "The RPC server is now running",
                "at http://localhost:{0}/.".format(ctx.params['api_port'])
            )
            print(
                "See the Raiden documentation for all available endpoints at",
                "https://github.com/raiden-network/raiden/blob/master/docs/api.rst"
            )

        if ctx.params['console']:
            console = Console(app_)
            console.start()

        # wait for interrupt
        event = gevent.event.Event()
        gevent.signal(signal.SIGQUIT, event.set)
        gevent.signal(signal.SIGTERM, event.set)
        gevent.signal(signal.SIGINT, event.set)
        event.wait()

        app_.stop()
예제 #4
0
def run(ctx, **kwargs):
    if ctx.invoked_subcommand is None:
        from raiden.api.python import RaidenAPI
        from raiden.ui.console import Console

        slogging.configure(
            kwargs['logging'],
            log_json=kwargs['log_json'],
            log_file=kwargs['logfile']
        )

        # TODO:
        # - Ask for confirmation to quit if there are any locked transfers that did
        # not timeout.
        (listen_host, listen_port) = split_endpoint(kwargs['listen_address'])
        try:
            with socket_factory(listen_host, listen_port) as mapped_socket:
                kwargs['mapped_socket'] = mapped_socket

                app_ = ctx.invoke(app, **kwargs)

                domain_list = []
                if kwargs['rpccorsdomain']:
                    if ',' in kwargs['rpccorsdomain']:
                        for domain in kwargs['rpccorsdomain'].split(','):
                            domain_list.append(str(domain))
                    else:
                        domain_list.append(str(kwargs['rpccorsdomain']))

                if ctx.params['rpc']:
                    raiden_api = RaidenAPI(app_.raiden)
                    rest_api = RestAPI(raiden_api)
                    api_server = APIServer(
                        rest_api,
                        cors_domain_list=domain_list,
                        web_ui=ctx.params['web_ui'],
                    )
                    (api_host, api_port) = split_endpoint(kwargs["api_address"])
                    api_server.start(api_host, api_port)

                    print(
                        "The Raiden API RPC server is now running at http://{}:{}/.\n\n"
                        "See the Raiden documentation for all available endpoints at\n"
                        "https://github.com/raiden-network/raiden/blob/master"
                        "/docs/Rest-Api.rst".format(
                            api_host,
                            api_port,
                        )
                    )

                if ctx.params['console']:
                    console = Console(app_)
                    console.start()

                # wait for interrupt
                event = gevent.event.Event()
                gevent.signal(signal.SIGQUIT, event.set)
                gevent.signal(signal.SIGTERM, event.set)
                gevent.signal(signal.SIGINT, event.set)

                gevent.signal(signal.SIGUSR1, toogle_cpu_profiler)
                gevent.signal(signal.SIGUSR2, toggle_trace_profiler)

                event.wait()

                try:
                    api_server.stop()
                except NameError:
                    pass
        except socket.error as v:
            if v.args[0] == errno.EADDRINUSE:
                print("ERROR: Address %s:%s is in use. "
                      "Use --listen-address <host:port> to specify port to listen on." %
                      (listen_host, listen_port))
                sys.exit(1)
            raise
        app_.stop(leave_channels=False)
    else:
        # Pass parsed args on to subcommands.
        ctx.obj = kwargs
예제 #5
0
from raiden.network.sockfactory import socket_factory


class DummyProtocol(object):
    def __init__(self):
        self.raiden = None

    def receive(self, data):
        print data


if __name__ == "__main__":
    slogging.configure(':DEBUG')
    options = docopt(__doc__)
    port = int(options['--port'])
    target = options['<target_ip_optional_port>']
    stun_host = options['--stun-host']
    ip = options['--ip']
    if target and ':' in target:
        target, target_port = target.split(':')
        target_port = int(target_port)
    else:
        target_port = port
    with socket_factory(ip, port, stun_host=stun_host) as mapped_socket:
        print mapped_socket
        t = UDPTransport(mapped_socket.socket, protocol=DummyProtocol())
        while True:
            time.sleep(1)
            if target:
                t.send(None, (target, target_port), b'hello')

class DummyProtocol:

    def __init__(self):
        self.raiden = None

    def receive(self, data):
        print(data)


if __name__ == "__main__":
    slogging.configure(':DEBUG')
    options = docopt(__doc__)
    port = int(options['--port'])
    target = options['<target_ip_optional_port>']
    stun_host = options['--stun-host']
    ip = options['--ip']
    if target and ':' in target:
        target, target_port = target.split(':')
        target_port = int(target_port)
    else:
        target_port = port
    with socket_factory(ip, port, stun_host=stun_host) as mapped_socket:
        print(mapped_socket)
        t = UDPTransport(mapped_socket.socket, protocol=DummyProtocol())
        while True:
            time.sleep(1)
            if target:
                t.send(None, (target, target_port), b'hello')