async def test_send_endpoint_vote(ping_sender, routing_table,
                                  incoming_message_channels,
                                  outgoing_message_channels,
                                  endpoint_vote_channels, local_enr,
                                  remote_enr, remote_endpoint):
    # wait for ping
    with trio.fail_after(ROUTING_TABLE_PING_INTERVAL):
        outgoing_message = await outgoing_message_channels[1].receive()
    ping = outgoing_message.message

    # respond with pong
    fake_local_endpoint = EndpointFactory()
    pong = PongMessage(
        request_id=ping.request_id,
        enr_seq=0,
        packet_ip=fake_local_endpoint.ip_address,
        packet_port=fake_local_endpoint.port,
    )
    incoming_message = IncomingMessage(
        message=pong,
        sender_endpoint=outgoing_message.receiver_endpoint,
        sender_node_id=outgoing_message.receiver_node_id,
    )
    await incoming_message_channels[0].send(incoming_message)
    await wait_all_tasks_blocked()

    # receive endpoint vote
    endpoint_vote = endpoint_vote_channels[1].receive_nowait()
    assert endpoint_vote.endpoint == fake_local_endpoint
    assert endpoint_vote.node_id == incoming_message.sender_node_id
Пример #2
0
async def test_endpoint_tracker_updates_enr(endpoint_tracker, initial_enr, enr_db, vote_channels):
    endpoint = EndpointFactory()
    endpoint_vote = EndpointVoteFactory(endpoint=endpoint)
    await vote_channels[0].send(endpoint_vote)
    await wait_all_tasks_blocked()  # wait until vote has been processed

    updated_enr = await enr_db.get(initial_enr.node_id)
    assert updated_enr.sequence_number == initial_enr.sequence_number + 1
    assert updated_enr[IP_V4_ADDRESS_ENR_KEY] == endpoint.ip_address
    assert updated_enr[UDP_PORT_ENR_KEY] == endpoint.port
Пример #3
0
async def test_peer_packer_sends_who_are_you(peer_packer,
                                             incoming_packet_channels,
                                             outgoing_packet_channels,
                                             nursery):
    incoming_packet = IncomingPacket(
        AuthTagPacketFactory(),
        EndpointFactory(),
    )

    incoming_packet_channels[0].send_nowait(incoming_packet)
    with trio.fail_after(0.5):
        outgoing_packet = await outgoing_packet_channels[1].receive()

    assert peer_packer.is_during_handshake
    assert outgoing_packet.receiver_endpoint == incoming_packet.sender_endpoint
    assert isinstance(outgoing_packet.packet, WhoAreYouPacket)
    assert outgoing_packet.packet.token == incoming_packet.packet.auth_tag
Пример #4
0
async def test_peer_packer_initiates_handshake(peer_packer,
                                               outgoing_message_channels,
                                               outgoing_packet_channels,
                                               nursery):
    outgoing_message = OutgoingMessage(
        PingMessageFactory(),
        EndpointFactory(),
        peer_packer.remote_node_id,
    )

    outgoing_message_channels[0].send_nowait(outgoing_message)
    with trio.fail_after(0.5):
        outgoing_packet = await outgoing_packet_channels[1].receive()

    assert peer_packer.is_during_handshake
    assert outgoing_packet.receiver_endpoint == outgoing_message.receiver_endpoint
    assert isinstance(outgoing_packet.packet, AuthTagPacket)
Пример #5
0
def remote_endpoint():
    return EndpointFactory()
Пример #6
0
def endpoint():
    return EndpointFactory()