コード例 #1
0
class App(object):  # pylint: disable=too-few-public-methods
    default_config = dict(
        host='',
        port=INITIAL_PORT,
        privatekey_hex='',
        # number of blocks that a node requires to learn the secret before the lock expires
        reveal_timeout=DEFAULT_REVEAL_TIMEOUT,
        settle_timeout=DEFAULT_SETTLE_TIMEOUT,
        # how long to wait for a transfer until TimeoutTransfer is sent (time in milliseconds)
        msg_timeout=100.00,
        # throttle policy for token bucket
        throttle_capacity=10.,
        throttle_fill_rate=10.,
        rpc=True,
        console=False,
    )

    def __init__(self, config, chain, discovery, transport_class=UDPTransport):
        self.config = config
        self.discovery = discovery
        if config.get('socket'):
            self.transport = transport_class(None,
                                             None,
                                             socket=config['socket'])
        else:
            self.transport = transport_class(config['host'], config['port'])
        self.transport.throttle_policy = TokenBucket(
            config['throttle_capacity'], config['throttle_fill_rate'])
        self.raiden = RaidenService(
            chain,
            decode_hex(config['privatekey_hex']),
            self.transport,
            discovery,
            config,
        )
        self.services = {'raiden': self.raiden}

        self.start_console = self.config['console']

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, graceful=False):
        """Stop the raiden app.
        Args:
            graceful (bool): if True, also close and settle all channels before stopping
        """
        if graceful:
            self.raiden.close_and_settle()

        self.raiden.stop()

        # The transport must be stopped after the protocol. The protocol can be
        # running multiple threads of execution and it expects the protocol to
        # be available.
        self.transport.stop()
コード例 #2
0
ファイル: app.py プロジェクト: AlphaX-IBS/raiden
class App:  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'transport': {
            'retry_interval': DEFAULT_TRANSPORT_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_TRANSPORT_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_TRANSPORT_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_TRANSPORT_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
        'shutdown_timeout': DEFAULT_SHUTDOWN_TIMEOUT,
        'transport_type': 'udp',
        'matrix': {
            'server': 'auto',
            'available_servers': [
                'https://transport01.raiden.network',
                'https://transport02.raiden.network',
                'https://transport03.raiden.network',
            ],
            'discovery_room': {
                'alias_fragment': 'discovery',
                'server': 'transport01.raiden.network',
            },
        },
    }

    def __init__(
            self,
            config: typing.Dict,
            chain: BlockChainService,
            query_start_block: typing.BlockNumber,
            default_registry: TokenNetworkRegistry,
            default_secret_registry: SecretRegistry,
            transport,
            discovery: Discovery = None,
    ):
        self.config = config
        self.discovery = discovery

        # check that the settlement timeout fits the limits of the contract
        invalid_timeout = (
            config['settle_timeout'] < default_registry.settlement_timeout_min() or
            config['settle_timeout'] > default_registry.settlement_timeout_max()
        )
        if invalid_timeout:
            raise InvalidSettleTimeout(
                (
                    'Settlement timeout for Registry contract {} must '
                    'be in range [{}, {}], is {}'
                ).format(
                    to_checksum_address(default_registry.address),
                    default_registry.settlement_timeout_min(),
                    default_registry.settlement_timeout_max(),
                    config['settle_timeout'],
                ),
            )

        try:
            self.raiden = RaidenService(
                chain=chain,
                query_start_block=query_start_block,
                default_registry=default_registry,
                default_secret_registry=default_secret_registry,
                private_key_bin=unhexlify(config['privatekey_hex']),
                transport=transport,
                config=config,
                discovery=discovery,
            )
        except filelock.Timeout:
            pubkey = to_normalized_address(
                privatekey_to_address(unhexlify(self.config['privatekey_hex'])),
            )
            print(
                f'FATAL: Another Raiden instance already running for account {pubkey} on '
                f'network id {chain.network_id}',
            )
            sys.exit(1)

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels: bool = False):
        """
        Stop the raiden app.

        Args:
            leave_channels: if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()
コード例 #3
0
class App:  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'transport': {
            'retry_interval': DEFAULT_TRANSPORT_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_TRANSPORT_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_TRANSPORT_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_TRANSPORT_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
        'shutdown_timeout': DEFAULT_SHUTDOWN_TIMEOUT,
        'transport_type': 'udp',
        'matrix': {
            'server':
            'auto',
            'available_servers': [
                'https://transport01.raiden.network',
                'https://transport02.raiden.network',
                'https://transport03.raiden.network',
            ],
            'discovery_room': {
                'alias_fragment': 'discovery',
                'server': 'transport01.raiden.network',
            },
        },
    }

    def __init__(
        self,
        config: Dict,
        chain: BlockChainService,
        default_registry: Registry,
        default_secret_registry: SecretRegistry,
        transport,
        discovery: Discovery = None,
    ):
        self.config = config
        self.discovery = discovery

        try:
            self.raiden = RaidenService(
                chain,
                default_registry,
                default_secret_registry,
                unhexlify(config['privatekey_hex']),
                transport,
                config,
                discovery,
            )
        except filelock.Timeout:
            pubkey = to_normalized_address(
                privatekey_to_address(unhexlify(
                    self.config['privatekey_hex'])), )
            print(
                f'FATAL: Another Raiden instance already running for account {pubkey} on '
                f'network id {chain.network_id}', )
            sys.exit(1)
        self.start_console = self.config['console']

        # raiden.ui.console:Console assumes that a services
        # attribute is available for auto-registration
        self.services = dict()

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels=False):
        """
        Stop the raiden app.

        Args:
            leave_channels (bool): if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()
コード例 #4
0
class App:  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'protocol': {
            'retry_interval': DEFAULT_PROTOCOL_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_PROTOCOL_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_PROTOCOL_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_PROTOCOL_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
        'shutdown_timeout': DEFAULT_SHUTDOWN_TIMEOUT,
    }

    def __init__(self, config, chain, default_registry, discovery, transport_class=UDPTransport):
        self.config = config
        self.discovery = discovery

        if config.get('socket'):
            transport = transport_class(
                None,
                None,
                socket=config['socket'],
            )
        else:
            transport = transport_class(
                config['host'],
                config['port'],
            )

        transport.throttle_policy = TokenBucket(
            config['protocol']['throttle_capacity'],
            config['protocol']['throttle_fill_rate']
        )
        try:
            self.raiden = RaidenService(
                chain,
                default_registry,
                unhexlify(config['privatekey_hex']),
                transport,
                discovery,
                config,
            )
        except filelock.Timeout:
            pubkey = privatekey_to_address(unhexlify(self.config['privatekey_hex']))
            print('FATAL: Another Raiden instance already running for account 0x%s' %
                  hexlify(str(pubkey)))
            sys.exit(1)
        self.start_console = self.config['console']

        # raiden.ui.console:Console assumes that a services
        # attribute is available for auto-registration
        self.services = dict()

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels=False):
        """
        Stop the raiden app.

        Args:
            leave_channels (bool): if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()
コード例 #5
0
class App(object):  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'protocol': {
            'retry_interval': DEFAULT_PROTOCOL_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_PROTOCOL_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_PROTOCOL_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_PROTOCOL_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
    }

    def __init__(self, config, chain, discovery, transport_class=UDPTransport):
        self.config = config
        self.discovery = discovery

        if config.get('socket'):
            transport = transport_class(
                None,
                None,
                socket=config['socket'],
            )
        else:
            transport = transport_class(
                config['host'],
                config['port'],
            )

        transport.throttle_policy = TokenBucket(
            config['protocol']['throttle_capacity'],
            config['protocol']['throttle_fill_rate'])
        self.raiden = RaidenService(
            chain,
            decode_hex(config['privatekey_hex']),
            transport,
            discovery,
            config,
        )
        self.start_console = self.config['console']

        # raiden.ui.console:Console assumes that a services
        # attribute is available for auto-registration
        self.services = dict()

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels=False):
        """Stop the raiden app.
        Args:
            leave_channels (bool): if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()
コード例 #6
0
class App:  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'protocol': {
            'retry_interval': DEFAULT_PROTOCOL_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_PROTOCOL_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_PROTOCOL_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_PROTOCOL_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
        'shutdown_timeout': DEFAULT_SHUTDOWN_TIMEOUT,
    }

    def __init__(self, config, chain, default_registry, discovery, transport):
        self.config = config
        self.discovery = discovery

        try:
            self.raiden = RaidenService(
                chain,
                default_registry,
                unhexlify(config['privatekey_hex']),
                transport,
                discovery,
                config,
            )
        except filelock.Timeout:
            pubkey = privatekey_to_address(
                unhexlify(self.config['privatekey_hex']))
            print(
                'FATAL: Another Raiden instance already running for account 0x%s'
                % hexlify(str(pubkey)))
            sys.exit(1)
        self.start_console = self.config['console']

        # raiden.ui.console:Console assumes that a services
        # attribute is available for auto-registration
        self.services = dict()

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels=False):
        """
        Stop the raiden app.

        Args:
            leave_channels (bool): if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()
コード例 #7
0
class App:  # pylint: disable=too-few-public-methods
    DEFAULT_CONFIG = {
        'host': '',
        'port': INITIAL_PORT,
        'external_ip': '',
        'external_port': INITIAL_PORT,
        'privatekey_hex': '',
        'reveal_timeout': DEFAULT_REVEAL_TIMEOUT,
        'settle_timeout': DEFAULT_SETTLE_TIMEOUT,
        'database_path': '',
        'msg_timeout': 100.0,
        'transport': {
            'retry_interval': DEFAULT_TRANSPORT_RETRY_INTERVAL,
            'retries_before_backoff': DEFAULT_TRANSPORT_RETRIES_BEFORE_BACKOFF,
            'throttle_capacity': DEFAULT_TRANSPORT_THROTTLE_CAPACITY,
            'throttle_fill_rate': DEFAULT_TRANSPORT_THROTTLE_FILL_RATE,
            'nat_invitation_timeout': DEFAULT_NAT_INVITATION_TIMEOUT,
            'nat_keepalive_retries': DEFAULT_NAT_KEEPALIVE_RETRIES,
            'nat_keepalive_timeout': DEFAULT_NAT_KEEPALIVE_TIMEOUT,
        },
        'rpc': True,
        'console': False,
        'shutdown_timeout': DEFAULT_SHUTDOWN_TIMEOUT,
        'transport_type': 'udp',
        'matrix': {
            'server':
            'auto',
            'available_servers': [
                'https://transport01.raiden.network',
                'https://transport02.raiden.network',
                'https://transport03.raiden.network',
            ],
            'discovery_room': {
                'alias_fragment': 'discovery',
                'server': 'transport01.raiden.network',
            },
        },
    }

    def __init__(
        self,
        config: typing.Dict,
        chain: BlockChainService,
        query_start_block: typing.BlockNumber,
        default_registry: TokenNetworkRegistry,
        default_secret_registry: SecretRegistry,
        transport,
        discovery: Discovery = None,
    ):
        self.config = config
        self.discovery = discovery

        # check that the settlement timeout fits the limits of the contract
        invalid_timeout = (config['settle_timeout'] <
                           default_registry.settlement_timeout_min()
                           or config['settle_timeout'] >
                           default_registry.settlement_timeout_max())
        if invalid_timeout:
            raise InvalidSettleTimeout(
                ('Settlement timeout for Registry contract {} must '
                 'be in range [{}, {}], is {}').format(
                     to_checksum_address(default_registry.address),
                     default_registry.settlement_timeout_min(),
                     default_registry.settlement_timeout_max(),
                     config['settle_timeout'],
                 ), )

        try:
            self.raiden = RaidenService(
                chain=chain,
                query_start_block=query_start_block,
                default_registry=default_registry,
                default_secret_registry=default_secret_registry,
                private_key_bin=unhexlify(config['privatekey_hex']),
                transport=transport,
                config=config,
                discovery=discovery,
            )
        except filelock.Timeout:
            pubkey = to_normalized_address(
                privatekey_to_address(unhexlify(
                    self.config['privatekey_hex'])), )
            print(
                f'FATAL: Another Raiden instance already running for account {pubkey} on '
                f'network id {chain.network_id}', )
            sys.exit(1)

    def __repr__(self):
        return '<{} {}>'.format(
            self.__class__.__name__,
            pex(self.raiden.address),
        )

    def stop(self, leave_channels: bool = False):
        """
        Stop the raiden app.

        Args:
            leave_channels: if True, also close and settle all channels before stopping
        """
        if leave_channels:
            self.raiden.close_and_settle()

        self.raiden.stop()