async def test_feed_talk_responses_ignores_wrongly_typed_msgs( bob, bob_alexandria_client, alice_alexandria_client, autojump_clock, ): async with bob_alexandria_client.network.dispatcher.subscribe( TalkResponseMessage) as sub: async with bob_alexandria_client.subscribe( PingMessage) as client_subscription: # Send a PingMessage via TALKRESP. msg = PingMessage( PingPayload(enr_seq=1234, advertisement_radius=4321)) await alice_alexandria_client.network.client.send_talk_response( bob.node_id, bob.endpoint, 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
def test_ping_message_encoding_round_trip(enr_seq, advertisement_radius): payload = PingPayload(enr_seq=enr_seq, advertisement_radius=advertisement_radius) message = PingMessage(payload) encoded = message.to_wire_bytes() result = decode_message(encoded) assert result == message
async def test_send_response_ensures_valid_msg_type(bob, alice_alexandria_client): with pytest.raises(TypeError): await alice_alexandria_client._send_response( bob.node_id, bob.endpoint, PingMessage(PingPayload(enr_seq=1234, advertisement_radius=4321)), request_id=b"\x01\x02", )
async def ping( self, node_id: NodeID, endpoint: Endpoint, enr_seq: int, advertisement_radius: int, request_id: Optional[bytes] = None, ) -> PongMessage: request = PingMessage(PingPayload(enr_seq, advertisement_radius)) response = await self._request(node_id, endpoint, request, PongMessage, request_id) return response
async def send_ping( self, node_id: NodeID, endpoint: Endpoint, *, enr_seq: int, advertisement_radius: int, request_id: Optional[bytes] = None, ) -> bytes: message = PingMessage(PingPayload(enr_seq, advertisement_radius)) return await self._send_request(node_id, endpoint, message, request_id=request_id)
async def test_alexandria_client_subscription_via_talk_request_protocol_mismatch( alice_network, alice, bob, bob_alexandria_client, autojump_clock ): async with bob_alexandria_client.subscribe(PingMessage) as subscription: message = PingMessage(PingPayload(alice.enr.sequence_number, 1234)) data_payload = message.to_wire_bytes() await alice_network.client.send_talk_request( bob.node_id, bob.endpoint, protocol=b"wrong-protocol-id", payload=data_payload, ) with pytest.raises(trio.TooSlowError): with trio.fail_after(1): message = await subscription.receive()