Example #1
0
def normalize_fixture(fixture):
    normalized_fixture = {
        'in':
        tuple((
            decode_hex(key) if is_0x_prefixed(key) else text_if_str(
                to_bytes, key),
            (decode_hex(value) if is_0x_prefixed(value) else text_if_str(
                to_bytes, value)) if value is not None else None,
        ) for key, value in (fixture['in'].items(
        ) if isinstance(fixture['in'], dict) else fixture['in'])),
        'root':
        decode_hex(fixture['root'])
    }
    return normalized_fixture
Example #2
0
    def datagram_received(self, data: bytes, addr: Tuple[str, int]) -> None:  # type: ignore
        ip_address, udp_port = addr
        # XXX: For now we simply discard all v5 messages. The prefix below is what geth uses to
        # identify them:
        # https://github.com/ethereum/go-ethereum/blob/c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5/p2p/discv5/udp.go#L149  # noqa: E501
        if text_if_str(to_bytes, data).startswith(b"temporary discovery v5"):
            self.logger.debug("Got discovery v5 msg, discarding")
            return

        self.receive(kademlia.Address(ip_address, udp_port), data)  # type: ignore
Example #3
0
 def datagram_received(self, data: Union[bytes, Text],
                       addr: Tuple[str, int]) -> None:
     ip_address, udp_port = addr
     address = kademlia.Address(ip_address, udp_port)
     # The prefix below is what geth uses to identify discv5 msgs.
     # https://github.com/ethereum/go-ethereum/blob/c4712bf96bc1bae4a5ad4600e9719e4a74bde7d5/p2p/discv5/udp.go#L149  # noqa: E501
     if text_if_str(to_bytes, data).startswith(V5_ID_STRING):
         self.receive_v5(address, cast(bytes, data))
     else:
         self.receive(address, cast(bytes, data))
Example #4
0
 def _mkpingid(self, token: AnyStr, node: Node) -> bytes:
     pid = text_if_str(to_bytes, token) + node.pubkey.to_bytes()
     return pid