HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/cockpit/__pycache__/peer.cpython-39.pyc
a

�/�h�1�@s�ddlZddlZddlZddlmZmZmZmZddlm	Z	m
Z
ddlmZddl
mZmZmZddlmZmZmZddlmZmZe�e�ZGd	d
�d
e�ZGdd�de�ZGd
d�deee�ZGdd�de�ZGdd�de�Z Gdd�de�Z!dS)�N)�Callable�List�Optional�Sequence�)�
JsonObject�	JsonValue)�BridgeConfig)�CockpitProblem�CockpitProtocol�CockpitProtocolError)�Endpoint�Router�RoutingRule)�SubprocessProtocol�SubprocessTransportc@seZdZdS)�	PeerErrorN)�__name__�
__module__�__qualname__�rr�0/usr/lib/python3.9/site-packages/cockpit/peer.pyr src@seZdZed�dd�ZdS)�
PeerExited��	exit_codecCs
||_dS�Nr)�selfrrrr�__init__%szPeerExited.__init__N)rrr�intrrrrrr$srcs�eZdZUeegdfed<eejed<e	d��fdd�Z
dd�dd	�Zee
ee
ejd
�dd�Zd4ee
eed
�dd�Zd5ee
edd
�dd�Zegdfdd�dd�Zdd�dd�Zedd�dd�Ze
edd�dd�Zed�dd�Zeedd�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)�routercs,t��|�|��t����|_g|_dSr)�superrZfreeze_endpoint�asyncio�get_running_loopZ
create_futurer!r )rr"��	__class__rrr-sz
Peer.__init__��returnc�st�dSr)�NotImplementedError�rrrr�do_connect_transport7szPeer.do_connect_transport)�argv�envr)c�s@t��}tdd�|D��}t|||fdttjfi|��i|��S)Ncss|]}|�dd�VqdS)�=rN)�split)�.0�errr�	<genexpr>=�zPeer.spawn.<locals>.<genexpr>r.)r$r%�dictr�os�environ)rr-r.�kwargsZloopZuser_envrrr�spawn:sz
Peer.spawn)�	init_hostr8r)c	�s��jdusJ�tjdd���fdd�}t��������|�zNz�jIdH}Wn"ttfyr�IdH�Yn0Wd�_���s���	�nd�_���s���	�0|dur�t
�d|��jd	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^|�usJ�z|��Wn@tjy,Yn.tyX}z��|�WYd}~n
d}~00dSr)�resultr$�CancelledError�	Exception�close)r<�exc�Zconnect_taskrrr�_connect_task_doneQs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)rr:r8rCZinit_messagerrBr�start@s(	



�
z
Peer.startcs<tjdd��fdd�}t�|j|fi|������|�dS)Nr;cs:|�usJ�z|��Wnttttjfy4Yn0dSr)r=�OSErrorrr
r$r>)r<�Z
start_taskrr�_start_task_done�s
z2Peer.start_in_background.<locals>._start_task_done)r$rHrIrQrJ)rr:r8rTrrSr�start_in_background�szPeer.start_in_background)�callbackr)cCs|j�|�dSr)r �append)rrVrrrrJ�szPeer.add_done_callbackcCsdSrrr+rrr�do_superuser_init_done�szPeer.do_superuser_init_done)�messager)cCsdSrr)rrYrrr�do_authorize�szPeer.do_authorize)rErYr)cCsb|dkr*|jdur*t�d�|j�|�n4|dkr>|�|�n |dkrP|��ntd|����dS)NrDz:Got init message with active init_future.  Setting result.Z	authorizezsuperuser-init-donez$Received unexpected control message )r!rNrOZ
set_resultrZrXr)rrErYrrr�transport_control_received�s

zPeer.transport_control_receivedcCst�d|jj�dS)NzPeer %s received unexpected EOFT)rNrOr'rr+rrr�eof_received�szPeer.eof_received)rAr)cCs�t�d|jjt|�|�|dur.|jdd�npt|t�rh|jdkrP|jdd�q�|jdd|j��d�n6t|t	�r�|�|j
�n|jdd	|jj�d
|��d�|jdur�|j��s�|dur�|j�
|�n
|j��|jD]
}|�q�dS)NzPeer %s connection lost %s %sZ
terminated)�problem�z
no-cockpitzPeer exited with status )r]rYzinternal-error�[z] )rNrOr'r�typeZshutdown_endpoint�
isinstancerrr
�attrsr!rLZ
set_exceptionrMr )rrArVrrr�	do_closed�s$


�

zPeer.do_closedcCsRt|jt�sJ�t�d|jj|j���|j��}t|t�s@J�|�	t
|��dS)NzPeer %s exited, status %d)raZ	transportrrNrOr'rZget_returncoderr@r)r�
returncoderrr�process_exited�s

zPeer.process_exited)�channelrErYr)cCs$|jdurtd��|�|||�dS)Nz7Received unexpected channel control message before init)r!rZsend_channel_control�rrfrErYrrr�channel_control_received�s
zPeer.channel_control_received)rf�datar)cCs"|jdurtd��|�||�dS)Nz,Received unexpected channel data before init)r!rZsend_channel_data�rrfrirrr�channel_data_received�s
zPeer.channel_data_receivedcCs|jdusJ�|�|�dSr�r!rPrgrrr�do_channel_control�szPeer.do_channel_controlcCs|jdusJ�|�||�dSr)r!Zwrite_channel_datarjrrr�do_channel_data�szPeer.do_channel_dataz
str | None)rG�grouprYr)cCs|jdusJ�|�|�dSrrl)rrGrorYrrr�do_kill�szPeer.do_killcCs|��dSr)r@r+rrr�do_close�sz
Peer.do_close)N)N)%rrrrr�__annotations__rr$ZFuturerrr,r�strZ	Transportr9rrrQrUrJrXrZr[�boolr\r?rcrerh�bytesrkrmrnrprq�
__classcell__rrr&rr)s(

A

rcsTeZdZUeed<eeed<eeed<eed��fdd�Zdd�d	d
�Z	�Z
S)�ConfiguredPeer�config�argsr.�r"rxcs&||_|j|_|j|_t��|�dSr)rxr9ryr7r.r#r�rr"rxr&rrr�szConfiguredPeer.__init__Nr(c�s|�|j|j�IdHdSr)r9ryr.r+rrrr,�sz#ConfiguredPeer.do_connect_transport)rrrr	rrrrsrrr,rvrrr&rrw�s

rwcsfeZdZUeed<eed<eeed<eed��fdd�Z	eeed�dd	�Z
d
d�Zdd
�Z�Z
S)�PeerRoutingRulerx�match�peerrzcs$t��|�||_|j|_d|_dSr)r#rrxr}r~r{r&rrrszPeerRoutingRule.__init__��optionsr)cCs�|j��D]P\}}||vr,t�d|�dS|dur
|||kr
t�d||||�dSq
|jdur�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}�itemsrNrOr~rwr"rxrJ�peer_closedr:rU)rr��key�valuerrr�
apply_rules
zPeerRoutingRule.apply_rulecCs
d|_dSr)r~r+rrrr�szPeerRoutingRule.peer_closedcCs|jdur|j��dSr)r~r@r+rrr�shutdowns
zPeerRoutingRule.shutdown)rrrr	rrrrrrrr�r�r�rvrrr&rr|�s
r|c@sNeZdZUgZeeed<eee	d�dd�Z
eedd�dd�Z
d	d
�ZdS)�PeersRoutingRule�rulesrcCs`t�dt|j��|jD]8}t�d|jj�|�|�}|durt�d�|Sqt�d�dS)Nz    considering %d rulesz      considering %sz        selectedz      no peer rules matched)rNrO�lenr�rx�namer�)rr��ruleZendpointrrrr�%s




zPeersRoutingRule.apply_ruleN)�bridge_configsr)cCs||j}g|_|D]T}|jsd|jvr&qt|�D]}|j|kr.|�|�qXq.t|j|�}|j�|�q|D]}|�	�qjdS)NrG)
r�Z
privilegedr}�listrx�remover|r"rWr�)rr�Z	old_rulesrxr�rrr�set_configs0s

zPeersRoutingRule.set_configscCs|jD]}|��qdSr)r�r�)rr�rrrr�Hs
zPeersRoutingRule.shutdown)rrrr�rr|rrrrr
r�rr	r�r�rrrrr�"s
r�)"r$Zloggingr6�typingrrrrZjsonutilrrZpackagesr	Zprotocolr
rrr"r
rrZ
transportsrrZ	getLoggerrrNrr?rrrwr|r�rrrr�<module>s 
D'