コード例 #1
0
async def test_feed_talk_requests_ignores_wrongly_typed_msgs(
    bob,
    bob_alexandria_client,
    alice_alexandria_client,
    autojump_clock,
):
    async with bob_alexandria_client.network.dispatcher.subscribe(
            TalkRequestMessage) as sub:
        async with bob_alexandria_client.subscribe(
                PongMessage) as client_subscription:

            # Send a PongMessage via TALKREQ.
            msg = PongMessage(
                PongPayload(enr_seq=1234, advertisement_radius=4321))
            await alice_alexandria_client.network.client.send_talk_request(
                bob.node_id,
                bob.endpoint,
                protocol=ALEXANDRIA_PROTOCOL_ID,
                payload=msg.to_wire_bytes(),
                request_id=b"\x01\x02",
            )

            # The message will be received by bob.
            with trio.fail_after(1):
                inbound_msg = await sub.receive()

            assert inbound_msg.request_id == b"\x01\x02"

            # But the alexandria client will not deliver it to any subscribers. And it should
            # log a warning about it.
            with trio.move_on_after(0.5) as scope:
                await client_subscription.receive()

            assert scope.cancelled_caught
コード例 #2
0
def test_pong_message_encoding_round_trip(enr_seq, advertisement_radius):
    payload = PongPayload(enr_seq=enr_seq,
                          advertisement_radius=advertisement_radius)
    message = PongMessage(payload)
    encoded = message.to_wire_bytes()
    result = decode_message(encoded)
    assert result == message
コード例 #3
0
async def test_request_ensures_valid_msg_type(bob, alice_alexandria_client):
    with pytest.raises(TypeError):
        await alice_alexandria_client._request(
            bob.node_id,
            bob.endpoint,
            PongMessage(PongPayload(enr_seq=1234, advertisement_radius=4321)),
            PongMessage,
            request_id=b"\x01\x02",
        )
コード例 #4
0
 async def send_pong(
     self,
     node_id: NodeID,
     endpoint: Endpoint,
     *,
     enr_seq: int,
     advertisement_radius: int,
     request_id: bytes,
 ) -> None:
     message = PongMessage(PongPayload(enr_seq, advertisement_radius))
     await self._send_response(node_id,
                               endpoint,
                               message,
                               request_id=request_id)
コード例 #5
0
async def test_alexandria_client_subscription_via_talk_response_unknown_request_id(
    alice_network, alice, bob, bob_alexandria_client, autojump_clock
):
    async with bob_alexandria_client.subscribe(PongMessage) as subscription:
        message = PongMessage(PongPayload(alice.enr.sequence_number, 1234))
        data_payload = message.to_wire_bytes()
        await alice_network.client.send_talk_response(
            bob.node_id,
            bob.endpoint,
            payload=data_payload,
            request_id=b"\x01\x02\x03",  # unknown/unexpected request_id
        )
        with pytest.raises(trio.TooSlowError):
            with trio.fail_after(1):
                message = await subscription.receive()