async def test_packer_processes_handshake_initiation(nursery, packer, enr, remote_enr, remote_endpoint, incoming_packet_channels): assert not packer.is_peer_packer_registered(remote_enr.node_id) # receive packet tag = compute_tag(source_node_id=remote_enr.node_id, destination_node_id=enr.node_id) incoming_packet = IncomingPacket( packet=AuthTagPacketFactory(tag=tag), sender_endpoint=remote_endpoint, ) await incoming_packet_channels[0].send(incoming_packet) await trio.sleep(0) assert packer.is_peer_packer_registered(remote_enr.node_id)
async def handle_outgoing_message_post_handshake(self, outgoing_message: OutgoingMessage, ) -> None: if not self.is_post_handshake: raise ValueError("Can only handle message post handshake") if self.session_keys is None: raise TypeError("session_keys are None even though handshake has been completed") packet = AuthTagPacket.prepare( tag=compute_tag(self.local_node_id, self.remote_node_id), auth_tag=get_random_auth_tag(), message=outgoing_message.message, key=self.session_keys.encryption_key, ) outgoing_packet = OutgoingPacket( packet, outgoing_message.receiver_endpoint, ) self.logger.debug("Sending %s", outgoing_message) await self.outgoing_packet_send_channel.send(outgoing_packet)
def tag(self) -> Tag: return compute_tag( source_node_id=self.local_node_id, destination_node_id=self.remote_node_id, )
def test_tags(source, destination, tag): assert compute_tag(source, destination) == tag assert recover_source_id_from_tag(tag, destination) == source
def test_source_recovery(source, destination): tag = compute_tag(source, destination) recovered_src = recover_source_id_from_tag(tag, destination) assert recovered_src == source