Ejemplo n.º 1
0
    def on_hello(self, payload):
        hello = rlp.decode(payload, Hello)

        capabilities = []
        for c in hello.capabilities:
            capabilities.append((c.protocol, c.version))
        self._log_message("receive",
                          "Hello, capabilities:{}".format(capabilities))
        ip = [127, 0, 0, 1]
        if self.remote:
            ip = get_ip_address()
        endpoint = NodeEndpoint(address=bytes(ip),
                                tcp_port=32325,
                                udp_port=32325)
        # FIXME: Use a valid pos_public_key.
        hello = Hello(
            DEFAULT_PY_TEST_CHAIN_ID,
            [Capability(self.protocol, self.protocol_version)], endpoint,
            decode_hex(
                'ac4a9103a323cf3a0d64712de2cbacf6df5d4c2cad7458aa612696f60a6de0a0958da59c7736b71cf24139b1be94be1503efefa083263438fd07edd1e03246683ff58da8bdde286c321032765258d0c34f'
            ))

        self.send_packet(PACKET_HELLO, rlp.encode(hello, Hello))
        self.had_hello = True
        self.send_status()
Ejemplo n.º 2
0
    def on_hello(self, payload):
        hello = rlp.decode(payload, Hello)

        capabilities = []
        for c in hello.capabilities:
            capabilities.append((c.protocol, c.version))
        self._log_message(
            "receive", "Hello, capabilities:{}".format(capabilities))
        ip = [127, 0, 0, 1]
        if self.remote:
            ip = get_ip_address()
        endpoint = NodeEndpoint(address=bytes(ip), port=32325, udp_port=32325)
        hello = Hello(1, [Capability(self.protocol, self.protocol_version)], endpoint)

        self.send_packet(PACKET_HELLO, rlp.encode(hello, Hello))
        self.had_hello = True
        self.send_status()
Ejemplo n.º 3
0
    def on_hello(self, payload):
        h = payload[:32]
        hash_signed = sha3_256(payload[32:])
        if h != hash_signed:
            return
        signature = payload[32:32 + 65]
        r = big_endian_to_int(signature[:32])
        s = big_endian_to_int(signature[32:64])
        v = big_endian_to_int(signature[64:]) + 27
        signed = payload[32 + 65:]
        h_signed = sha3_256(signed)
        node_id = ecrecover_to_pub(h_signed, v, r, s)
        # if node_id == encode_int32(self.pub_key[0])+encode_int32(self.pub_key[1]):
        #     print("Match")
        # else:
        #     print(node_id, encode_int32(self.pub_key[0])+encode_int32(self.pub_key[1]))
        self.peer_pubkey = node_id
        hello = rlp.decode(signed, Hello)

        capabilities = []
        for c in hello.capabilities:
            capabilities.append((c.protocol, c.version))
        self._log_message("receive",
                          "Hello, capabilities:{}".format(capabilities))
        ip = [127, 0, 0, 1]
        if self.remote:
            ip = get_ip_address()
        endpoint = NodeEndpoint(address=bytes(ip), port=32325, udp_port=32325)
        hello = Hello([Capability(self.protocol, self.protocol_version)],
                      endpoint)
        to_sign = rlp.encode(hello, Hello)
        sig = ecsign(sha3_256(to_sign), self.priv_key)
        v = (sig[0] - 27).to_bytes(1, "big")
        r = sig[1].to_bytes(32, "big")
        s = sig[2].to_bytes(32, "big")
        to_hash = r + s + v + to_sign
        hash_signed = sha3_256(to_hash)
        self.send_packet(PACKET_HELLO, hash_signed + to_hash)
        self.had_hello = True
        self.send_status()