관리-도구
편집 파일: peer.cpython-39.pyc
a ������g�1����������������������@���s����d�dl�Z�d�dlZd�dlZd�dlmZmZmZmZ�ddlm Z m Z �ddlmZ�ddl mZmZmZ�ddlmZmZmZ�ddlmZmZ�e�e�ZG�d d ��d e�ZG�dd��de�ZG�d d��deee�ZG�dd��de�ZG�dd��de�Z G�dd��de�Z!dS�)�����N)�Callable�List�Optional�Sequence����)� JsonObject� JsonValue)�BridgeConfig)�CockpitProblem�CockpitProtocol�CockpitProtocolError)�Endpoint�Router�RoutingRule)�SubprocessProtocol�SubprocessTransportc�������������������@���s���e�Zd�ZdS�)� PeerErrorN)�__name__� __module__�__qualname__��r���r����0/usr/lib/python3.9/site-packages/cockpit/peer.pyr��� ���s���r���c�������������������@���s���e�Zd�Zed�dd�ZdS�)� PeerExited�� exit_codec�����������������C���s ���||�_�d�S��Nr���)�selfr���r���r���r����__init__%���s����zPeerExited.__init__N)r���r���r����intr���r���r���r���r���r���$���s���r���c�����������������������s���e�Zd�ZU�eeg�df��ed<�eej�ed<�e d���fdd�Z dd�dd �Zee �ee �ejd �dd�Zd4ee �eed �dd�Zd5ee �edd �dd�Zeg�df�dd�dd�Zdd�dd�Zedd�dd�Ze edd�dd�Zed�dd�Zee�dd�d d!�Zdd�d"d#�Ze e edd$�d%d&�Ze edd'�d(d)�Ze e edd$�d*d+�Z e edd'�d,d-�Z!d.d.edd/�d0d1�Z"dd�d2d3�Z#���Z$S�)6�PeerN�done_callbacks�init_future)�routerc��������������������s,���t����|��|�����t������|�_g�|�_d�S�r���)�superr���Zfreeze_endpoint�asyncio�get_running_loopZ create_futurer!���r ���)r���r"����� __class__r���r���r���-���s����z Peer.__init__��returnc���������������������s���t��d�S�r���)�NotImplementedError�r���r���r���r����do_connect_transport7���s����zPeer.do_connect_transport)�argv�envr)���c���������������������s@���t����}tdd��|D���}t||�|fdttjfi�|��i|��S�)Nc�����������������s���s���|�]}|��d�d�V��qdS�)�=r���N)�split)�.0�er���r���r���� <genexpr>=��������zPeer.spawn.<locals>.<genexpr>r.���)r$���r%����dictr����os�environ)r���r-���r.����kwargsZloopZuser_envr���r���r����spawn:���s����z Peer.spawn)� init_hostr8���r)���c�������������� �������s�����j�dusJ��tjdd����fdd�}t�����������|��zNz�j�I�dH�}W�n"�ttfyr�����I�dH����Y�n0�W�d�_������s���� ���nd�_������s���� ���0�|dur�t �d|���jd dd|d�|����� ���|S�) a���Request that the Peer is started and connected to the router. Creates the transport, connects it to the protocol, and participates in exchanging of init messages. If anything goes wrong, the connection will be closed and an exception will be raised. The Peer starts out in a frozen state (ie: attempts to send messages to it will initially be queued). If init_host is not None then an init message is sent with the given 'host' field, plus any extra kwargs, and the queue is thawed. Otherwise, the caller is responsible for sending the init message and thawing the peer. In any case, the return value is the init message from the peer. N��taskr)���c�������������� ������s^���|���u�sJ��z|������W�n@�tjy,���Y�n.�tyX�}�z��|��W�Y�d�}~n d�}~0�0�d�S�r���)�resultr$����CancelledError� Exception�close)r<����exc�Zconnect_taskr���r���r����_connect_task_doneQ���s����z&Peer.start.<locals>._connect_task_donez$ sending init message back, host %s�initr���)�command�version�host)N)r!���r$����Task�create_taskr,����add_done_callbackr����BrokenPipeError�done�cancel�logger�debug� write_controlZ thaw_endpoint)r���r:���r8���rC���Zinit_messager���rB���r����start@���s(���� � z Peer.startc��������������������s<���t�jd�d���fdd�}t��|�j|fi�|��������|��d�S�)Nr;���c��������������������s:���|���u�sJ��z|������W�n�ttttjfy4���Y�n0�d�S�r���)r=����OSErrorr���r ���r$���r>���)r<����Z start_taskr���r����_start_task_done����s ����z2Peer.start_in_background.<locals>._start_task_done)r$���rH���rI���rQ���rJ���)r���r:���r8���rT���r���rS���r����start_in_background����s����zPeer.start_in_background)�callbackr)���c�����������������C���s���|�j��|��d�S�r���)r ����append)r���rV���r���r���r���rJ�������s����zPeer.add_done_callbackc�����������������C���s���d�S�r���r���r+���r���r���r����do_superuser_init_done����s����zPeer.do_superuser_init_done)�messager)���c�����������������C���s���d�S�r���r���)r���rY���r���r���r����do_authorize����s����zPeer.do_authorize)rE���rY���r)���c�����������������C���sb���|dkr*|�j�d�ur*t�d��|�j��|��n4|dkr>|��|��n |dkrP|�����ntd|�����d�S�)NrD���z:Got init message with active init_future. Setting result.Z authorizezsuperuser-init-donez$Received unexpected control message )r!���rN���rO���Z set_resultrZ���rX���r���)r���rE���rY���r���r���r����transport_control_received����s���� zPeer.transport_control_receivedc�����������������C���s���t��d|�jj��dS�)NzPeer %s received unexpected EOFT)rN���rO���r'���r���r+���r���r���r����eof_received����s����zPeer.eof_received)rA���r)���c�����������������C���s����t��d|�jjt|�|��|d�u�r.|�jdd��npt|t�rh|jdkrP|�jdd��q�|�jdd|j���d��n6t|t �r�|��|j ��n|�jdd |jj��d |��d��|�jd�ur�|�j���s�|d�ur�|�j� |��n |�j����|�jD�] }|���q�d�S�)NzPeer %s connection lost %s %sZ terminated)�problem����z no-cockpitzPeer exited with status )r]���rY���zinternal-error�[z] )rN���rO���r'���r����typeZshutdown_endpoint� isinstancer���r���r ����attrsr!���rL���Z set_exceptionrM���r ���)r���rA���rV���r���r���r���� do_closed����s$���� � zPeer.do_closedc�����������������C���sR���t�|�jt�sJ��t�d|�jj|�j�����|�j���}t�|t�s@J��|�� t |���d�S�)NzPeer %s exited, status %d)ra���Z transportr���rN���rO���r'���r���Zget_returncoder���r@���r���)r���� returncoder���r���r����process_exited����s ���� zPeer.process_exited)�channelrE���rY���r)���c�����������������C���s$���|�j�d�urtd��|��|||��d�S�)Nz7Received unexpected channel control message before init)r!���r���Zsend_channel_control�r���rf���rE���rY���r���r���r����channel_control_received����s���� zPeer.channel_control_received)rf����datar)���c�����������������C���s"���|�j�d�urtd��|��||��d�S�)Nz,Received unexpected channel data before init)r!���r���Zsend_channel_data�r���rf���ri���r���r���r����channel_data_received����s���� zPeer.channel_data_receivedc�����������������C���s���|�j�d�u�sJ��|��|��d�S�r����r!���rP���rg���r���r���r����do_channel_control����s����zPeer.do_channel_controlc�����������������C���s���|�j�d�u�sJ��|��||��d�S�r���)r!���Zwrite_channel_datarj���r���r���r����do_channel_data����s����zPeer.do_channel_dataz str | None)rG����grouprY���r)���c�����������������C���s���|�j�d�u�sJ��|��|��d�S�r���rl���)r���rG���ro���rY���r���r���r����do_kill����s����zPeer.do_killc�����������������C���s���|������d�S�r���)r@���r+���r���r���r����do_close����s����z Peer.do_close)N)N)%r���r���r���r���r����__annotations__r���r$���ZFuturer���r���r,���r����strZ Transportr9���r���r���rQ���rU���rJ���rX���rZ���r[����boolr\���r?���rc���re���rh����bytesrk���rm���rn���rp���rq���� __classcell__r���r���r&���r���r���)���s(��� A r���c�����������������������sT���e�Zd�ZU�eed<�ee�ed<�ee�ed<�eed���fdd�Zdd�d d �Z ���Z S�)�ConfiguredPeer�config�argsr.����r"���rx���c��������������������s&���||�_�|j|�_|j|�_t���|��d�S�r���)rx���r9���ry���r7���r.���r#���r����r���r"���rx���r&���r���r���r�������s����zConfiguredPeer.__init__Nr(���c���������������������s���|���|�j|�j�I�d�H��d�S�r���)r9���ry���r.���r+���r���r���r���r,�������s����z#ConfiguredPeer.do_connect_transport)r���r���r���r ���rr���r���rs���r���r���r,���rv���r���r���r&���r���rw�������s ��� rw���c�����������������������sf���e�Zd�ZU�eed<�eed<�ee�ed<�eed���fdd�Z eee�d�dd �Z d d��Zdd ��Z���Z S�)�PeerRoutingRulerx����match�peerrz���c��������������������s$���t����|��||�_|j|�_d�|�_d�S�r���)r#���r���rx���r}���r~���r{���r&���r���r���r������s����zPeerRoutingRule.__init__��optionsr)���c�����������������C���s����|�j����D�]P\}}||vr,t�d|���d�S�|d�ur ||�|kr t�d|||�|���d�S�q |�jd�u�r�t|�j|�j�|�_|�j�|�j ��|�jj s�J��|�jj|�jj d��|�jS�)Nz+ rejecting because key %s is missingz; rejecting because key %s has wrong value %s (vs %s))r:���)r}����itemsrN���rO���r~���rw���r"���rx���rJ����peer_closedr:���rU���)r���r�����key�valuer���r���r���� apply_rule��s���� zPeerRoutingRule.apply_rulec�����������������C���s ���d�|�_�d�S�r���)r~���r+���r���r���r���r������s����zPeerRoutingRule.peer_closedc�����������������C���s���|�j�d�ur|�j�����d�S�r���)r~���r@���r+���r���r���r����shutdown��s���� zPeerRoutingRule.shutdown)r���r���r���r ���rr���r���r���r���r���r���r����r����r����rv���r���r���r&���r���r|�������s��� r|���c�������������������@���sN���e�Zd�ZU�g�Zee�ed<�eee �d�dd�Z ee�dd�dd�Z d d ��ZdS�)�PeersRoutingRule�rulesr���c�����������������C���s`���t��dt|�j���|�jD�]8}t��d|jj��|�|�}|d�urt��d��|��S�qt��d��d�S�)Nz considering %d rulesz considering %sz selectedz no peer rules matched)rN���rO����lenr����rx����namer����)r���r�����ruleZendpointr���r���r���r����%��s���� zPeersRoutingRule.apply_ruleN)�bridge_configsr)���c�����������������C���s|���|�j�}g�|�_�|D�]T}|jsd|jv�r&qt|�D�]}|j|kr.|�|���qXq.t|�j|�}|�j��|��q|D�]}|� ���qjd�S�)NrG���) r����Z privilegedr}����listrx����remover|���r"���rW���r����)r���r����Z old_rulesrx���r����r���r���r����set_configs0��s���� zPeersRoutingRule.set_configsc�����������������C���s���|�j�D�]}|����qd�S�r���)r����r����)r���r����r���r���r���r����H��s���� zPeersRoutingRule.shutdown)r���r���r���r����r���r|���rr���r���r���r ���r����r���r ���r����r����r���r���r���r���r����"��s��� r����)"r$���Zloggingr6����typingr���r���r���r���Zjsonutilr���r���Zpackagesr ���Zprotocolr ���r���r���r"���r ���r���r���Z transportsr���r���Z getLoggerr���rN���r���r?���r���r���rw���r|���r����r���r���r���r����<module>���s ��� �D'