示例#1
0
    def register(self, node_address: bytes, host: str, port: int):
        if node_address != self.node_address:
            raise ValueError('You can only register your own endpoint.')

        if not isaddress(node_address):
            raise ValueError('node_address must be a valid address')

        try:
            socket.inet_pton(socket.AF_INET, host)
        except OSError:
            raise ValueError('invalid ip address provided: {}'.format(host))

        if not isinstance(port, int):
            raise ValueError('port must be a valid number')

        try:
            current_value = self.get(node_address)
        except UnknownAddress:
            current_value = None

        if current_value == (host, port):
            log.info('endpoint already registered',
                     node_address=pex(node_address),
                     host=host,
                     port=port)
        else:
            endpoint = host_port_to_endpoint(host, port)
            self.discovery_proxy.register_endpoint(node_address, endpoint)
            log.info('registered endpoint in discovery',
                     node_address=pex(node_address),
                     host=host,
                     port=port)
示例#2
0
    def nodeid_by_host_port(self, host_port):
        host, port = host_port
        endpoint = host_port_to_endpoint(host, port)
        address = self.discovery_proxy.findAddressByEndpoint.call(endpoint)

        if set(address) == {'0'}:  # the 0 address means nothing found
            return None

        return address.decode('hex')
示例#3
0
    def register(self, nodeid, host, port):
        if nodeid != self.chain.node_address:
            raise ValueError('You can only register your own endpoint.')

        transaction_hash = self.discovery_proxy.registerEndpoint.transact(
            host_port_to_endpoint(host, port), )

        self.chain.client.poll(
            transaction_hash.decode('hex'),
            timeout=self.poll_timeout,
        )
示例#4
0
def test_endpointregistry_gas(endpoint_discovery_services):
    """ GAS_REQUIRED_FOR_DISCOVERY_REGISTER value must be equal to the gas requried to call
    registerEndpoint.
    """
    contract_discovery = endpoint_discovery_services[0]
    discovery_proxy = contract_discovery.discovery_proxy
    endpoint = host_port_to_endpoint('127.0.0.1', 44444)

    transaction_hash = discovery_proxy.proxy.transact('registerEndpoint', endpoint)
    discovery_proxy.client.poll(transaction_hash)

    receipt = discovery_proxy.client.get_transaction_receipt(transaction_hash)
    assert receipt['gasUsed'] <= GAS_REQUIRED_FOR_DISCOVERY_REGISTER
def test_endpointregistry_gas(endpoint_discovery_services):
    """ DISCOVERY_TX_GAS_LIMIT value must be equal to the gas requried to call
    registerEndpoint.
    """
    contract_discovery = endpoint_discovery_services[0]
    discovery_proxy = contract_discovery.discovery_proxy
    endpoint = host_port_to_endpoint('127.0.0.1', 44444)

    transaction_hash = discovery_proxy.proxy.transact('registerEndpoint', endpoint)
    discovery_proxy.client.poll(unhexlify(transaction_hash))

    receipt = discovery_proxy.client.web3.eth.getTransactionReceipt(transaction_hash)
    assert receipt['gasUsed'] <= DISCOVERY_TX_GAS_LIMIT
示例#6
0
def test_endpointregistry_gas(endpoint_discovery_services):
    """ DISCOVERY_TX_GAS_LIMIT value must be equal to the gas requried to call
    registerEndpoint.
    """
    contract_discovery = endpoint_discovery_services[0]
    discovery_proxy = contract_discovery.discovery_proxy
    endpoint = host_port_to_endpoint('127.0.0.1', 44444)

    transaction_hash = discovery_proxy.proxy.transact('registerEndpoint',
                                                      endpoint)
    discovery_proxy.client.poll(unhexlify(transaction_hash))

    receipt = discovery_proxy.client.web3.eth.getTransactionReceipt(
        transaction_hash)
    assert receipt['gasUsed'] <= DISCOVERY_TX_GAS_LIMIT
示例#7
0
def test_endpointregistry_gas(endpoint_discovery_services):
    """ GAS_REQUIRED_FOR_ENDPOINT_REGISTER value must be equal to the gas required to call
    registerEndpoint.
    """
    contract_discovery = endpoint_discovery_services[0]
    discovery_proxy = contract_discovery.discovery_proxy
    endpoint = host_port_to_endpoint("127.0.0.1", 44444)

    transaction_hash = discovery_proxy.proxy.transact(
        "registerEndpoint", safe_gas_limit(GAS_REQUIRED_FOR_ENDPOINT_REGISTER),
        endpoint)
    discovery_proxy.client.poll(transaction_hash)

    receipt = discovery_proxy.client.get_transaction_receipt(transaction_hash)
    msg = "the transaction failed, check if it was because of the gas being too low"
    assert receipt["status"] != 0, msg
示例#8
0
    def register(self, node_address, host, port):
        if node_address != self.node_address:
            raise ValueError('You can only register your own endpoint.')

        if not isaddress(node_address):
            raise ValueError('node_address must be a valid address')

        try:
            socket.inet_pton(socket.AF_INET, host)
        except OSError:
            raise ValueError('invalid ip address provided: {}'.format(host))

        if not isinstance(port, (int, long)):
            raise ValueError('port must be a valid number')

        endpoint = host_port_to_endpoint(host, port)
        self.discovery_proxy.register_endpoint(node_address, endpoint)
def test_endpointregistry_gas(endpoint_discovery_services):
    """ GAS_REQUIRED_FOR_ENDPOINT_REGISTER value must be equal to the gas required to call
    registerEndpoint.
    """
    contract_discovery = endpoint_discovery_services[0]
    discovery_proxy = contract_discovery.discovery_proxy
    endpoint = host_port_to_endpoint('127.0.0.1', 44444)

    transaction_hash = discovery_proxy.proxy.transact(
        'registerEndpoint',
        safe_gas_limit(GAS_REQUIRED_FOR_ENDPOINT_REGISTER),
        endpoint,
    )
    discovery_proxy.client.poll(transaction_hash)

    receipt = discovery_proxy.client.get_transaction_receipt(transaction_hash)
    msg = 'the transaction failed, check if it was because of the gas being too low'
    assert receipt['status'] != 0, msg
示例#10
0
    def register(self, node_address: bytes, host: str, port: int):
        if node_address != self.node_address:
            raise ValueError('You can only register your own endpoint.')

        if not is_binary_address(node_address):
            raise ValueError('node_address must be a valid address')

        try:
            socket.inet_pton(socket.AF_INET, host)
        except OSError:
            raise ValueError('invalid ip address provided: {}'.format(host))

        if not isinstance(port, int):
            raise ValueError('port must be a valid number')

        try:
            current_value = self.get(node_address)
        except UnknownAddress:
            current_value = None

        if current_value == (host, port):
            log.info(
                'endpoint already registered',
                node_address=pex(node_address),
                host=host,
                port=port,
            )
        else:
            endpoint = host_port_to_endpoint(host, port)
            self.discovery_proxy.register_endpoint(node_address, endpoint)
            log.info(
                'registered endpoint in discovery',
                node_address=pex(node_address),
                host=host,
                port=port,
            )
示例#11
0
    def register(self, node_address: bytes, host: str, port: int):
        if node_address != self.node_address:
            raise ValueError("You can only register your own endpoint.")

        if not is_binary_address(node_address):
            raise ValueError("node_address must be a valid address")

        try:
            socket.inet_pton(socket.AF_INET, host)
        except OSError:
            raise ValueError("invalid ip address provided: {}".format(host))

        if not isinstance(port, int):
            raise ValueError("port must be a valid number")

        try:
            current_value = self.get(node_address)
            if current_value == (host, port):
                log.info(
                    "endpoint already registered",
                    node_address=pex(node_address),
                    host=host,
                    port=port,
                )
                return
        except UnknownAddress:
            pass

        endpoint = host_port_to_endpoint(host, port)
        self.discovery_proxy.register_endpoint(node_address, endpoint)
        log.info(
            "registered endpoint in discovery",
            node_address=pex(node_address),
            host=host,
            port=port,
        )
示例#12
0
 def nodeid_by_host_port(self, host_port):
     host, port = host_port
     endpoint = host_port_to_endpoint(host, port)
     return self.discovery_proxy.address_by_endpoint(endpoint)
示例#13
0
    def register(self, node_address, host, port):
        if node_address != self.node_address:
            raise ValueError('You can only register your own endpoint.')

        endpoint = host_port_to_endpoint(host, port)
        self.discovery_proxy.register_endpoint(node_address, endpoint)
示例#14
0
 def nodeid_by_host_port(self, host_port: Tuple[str, int]):
     host, port = host_port
     endpoint = host_port_to_endpoint(host, port)
     return self.discovery_proxy.address_by_endpoint(endpoint)
示例#15
0
 def find_address(self, host, port):
     return self.discovery_proxy.findAddressByEndpoint(
         host_port_to_endpoint(host, port))
示例#16
0
 def update_endpoint(self, host, port):
     self.discovery_proxy.updateEndpoint(host_port_to_endpoint(host, port))
示例#17
0
 def register_endpoint(self, host, port):
     self.discovery_proxy.registerEndpoint(host_port_to_endpoint(
         host, port))
示例#18
0
    def register(self, node_address, host, port):
        if node_address != self.node_address:
            raise ValueError('You can only register your own endpoint.')

        endpoint = host_port_to_endpoint(host, port)
        self.discovery_proxy.register_endpoint(node_address, endpoint)