+
    i/  c                   s2   ^ RI t ^ RIt^ RIt^ RIHtHtHt ^RIHtH	t	 ^RI
Ht ^RIHtHtHt ^RIHtHtHt ^RIHtHt ]P.                  ! ]4      t ! R R	]4      t ! R
 R]4      t ! R R]]]4      t ! R R]4      t ! R R]4      t ! R R]4      t R# )i    N)AnyCallableSequence)
JsonObject	JsonValue)BridgeConfig)CockpitProblemCockpitProtocolCockpitProtocolError)EndpointRouterRoutingRule)SubprocessProtocolSubprocessTransportc                   s    ] tR t^tRtR# )	PeerError N)__name__
__module____qualname____firstlineno____static_attributes__r       1/usr/lib/python3.14/site-packages/cockpit/peer.pyr   r      s    r   r   c                   s2   a  ] tR t^t o V 3R lR ltRtV tR# )
PeerExitedc                    < V ^8  d   QhRS[ /# )   	exit_code)intformat__classdict__   "r   __annotate__ZPeerExited.__annotate__   s     # ## #r   c                s    Wn         R # Nr   )selfr      &&r   __init__ZPeerExited.__init__   s    "r   r"   N)r   r   r   r   r%   r   __classdictcell__r      @r   r   r      s     # #r   r   c                   s  a a ] tR t^t oV3R lV 3R lltV3R lR ltV3R lR ltR'V3R lR lltR'V3R	 lR
 lltV3R lR lt	V3R lR lt
V3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR  ltV3R! lR" ltV3R# lR$ ltV3R% ltR&tVtV ;t# )(Peerc                r   )r   router)r
   r   r   r   r    Peer.__annotate__!   s     ! !v !r   c                s   < \         SV `  V4       V P                  4        \        P                  ! 4       P                  4       V n        . V n        R # r!   )superr%   Zfreeze_endpointasyncioget_running_loopZcreate_futureinit_futuredone_callbacks)r#   r*   	__class__s   &&r   r%   ZPeer.__init__!   s@      	"335CCE r   c                   < V ^8  d   QhRR/# r   returnNr   r   r   r   r    r+   +   s     " "D "r   c                s   "   \         h5ir!   )ZNotImplementedErrorr#      &r   do_connect_transportZPeer.do_connect_transport+   s     !!s   	c                sf   < V ^8  d   QhRS[ S[,          RS[ S[,          RS[RS[P                  /# )r   argvenvkwargsr4   )r   strr    r-   Z	Transportr   r   r   r    r+   .   s>     a a aHSM aS aU\UfUf ar   c           	     s   "   \         P                  ! 4       p\        R  V 4       4      p\        W@V3R\        \        P
                  3/ VB /VB # 5i)c              3   sD   "   T F  qP                  R ^4      x  K  	  R# 5i)Z=N)Zsplit)Z.0Ze   & r   Z	<genexpr>ZPeer.spawn.<locals>.<genexpr>1   s     5AQs    r9   )r-   r.   Zdictr   osenviron)r#   r8   r9   r:   ZloopZuser_envs   &&&,  r   spawnZ
Peer.spawn.   sI     '')555"4t`bjj9UH9U`Y_``s   AAc                s*   < V ^8  d   QhRRRS[ RS[/# )r   	init_host
str | Noner:   r4   )r   r   r   r   r   r    r+   4   s#     > >\ >I >R\ >r   c           	     sf  a a"   S P                   f   Q hR VV 3R llp\        P                  ! S P                  4       4      oSP	                  V4        S P                   G Rj  xL
 p RS n         SP                  4       '       g   SP                  4        Te?   \        P                  RT4       S P                  ! R	RRR^RT/TB  S P                  4        T#  Lv  \
        \        3 d    SG Rj  xL 
  h i ; i  RS n         SP                  4       '       g   SP                  4        i i ; i5i)
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.
Nc                     V ^8  d   QhRRRR/# )r   taskzasyncio.Task[None]r4   Nr   r      "r   r    Z Peer.start.<locals>.__annotate__E   s     	  	 %9 	 d 	 r   c                 s   < V SJ g   Q h V P                  4        R #   \        P                   d     R # \         d   pSP	                  T4        R p?R # R p?ii ; ir!   )resultr-   CancelledError	Exceptionclose)rC   excconnect_taskr#   s   & r   _connect_task_doneZ&Peer.start.<locals>._connect_task_doneE   sM    <''' ))   

3 s    AAAAAz$  sending init message back, host %scommandinitZversionhostr!   )r/   r-   create_taskr7   add_done_callbackr   ZBrokenPipeErrordonecancelloggerdebugwrite_controlZthaw_endpoint)r#   r@   r:   rL   Zinit_messagerK   s   f&,  @r   startZ
Peer.start4   s'     +++	  	  **4+D+D+FG&&'9:	& "&!1!11L  $D  $$&&##% LL?KYVYQYYYRXY  5 2O, 	
 	  $D  $$&&##% 'sO   AD1C $C%C *D1AD1C C;3C64C;;C> >0D..D1c                s(   < V ^8  d   QhRRRS[ RR/# )r   r@   rA   r:   r4   N)r   r   r   r   r    r+   u   s#     
7 
7\ 
7I 
7Z^ 
7r   c                s   a R  V3R llp\         P                  ! V P                  ! V3/ VB 4      oSP                  V4       R# )c                rB   )r   rC   zasyncio.Task[JsonObject]r4   Nr   rD   rE   r   r    Z.Peer.start_in_background.<locals>.__annotate__v   s     	 	#= 	$ 	r   c                 s   < V SJ g   Q h V P                  4        R #   \        \        \        \        P
                  3 d     R # i ; ir!   )rF   ZOSErrorr   r   r-   rG   )rC   
start_tasks   &r   _start_task_doneZ2Peer.start_in_background.<locals>._start_task_donev   s@    :%%%Z9O9OP s    %AAN)r-   rP   rW   rQ   )r#   r@   r:   rY   rX   s   &&, @r   start_in_backgroundZPeer.start_in_backgroundu   s<    	 	 ((I)H)HI
$$%56r   c                s6   < V ^8  d   QhRS[ . R3,          RR/# )r   callbackNr4   )r   r   r   r   r    r+      s$     - -(2t8*< - -r   c                s<    V P                   P                  V4       R # r!   )r0   append)r#   r[   r$   r   rQ   ZPeer.add_done_callback   s    ""8,r   c                r2   r3   r   r   r   r   r    r+      s       r   c                    R # r!   r   r5   r6   r   do_superuser_init_doneZPeer.do_superuser_init_done       r   c                $   < V ^8  d   QhRS[ RR/# )r   messager4   Nr   r   r   r   r    r+      s      J 4 r   c                r]   r!   r   )r#   ra   r$   r   do_authorizeZPeer.do_authorize   r_   r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   rM   ra   r4   Nr;   r   r   r   r   r    r+      s'     	Y 	Y# 	Y
 	Yt 	Yr   c                s   VR 8X  dA   V P                   e3   \        P                  R4       V P                   P                  V4       R# VR8X  d   V P	                  V4       R# VR8X  d   V P                  4        R# \        RV 24      h)rN   Nz:Got init message with active init_future.  Setting result.Z	authorizezsuperuser-init-donez$Received unexpected control message )r/   rT   rU   Z
set_resultrc   r^   r   )r#   rM   ra      &&&r   transport_control_receivedZPeer.transport_control_received   st    f!1!1!=LLUV''0#g&--'')&)MgY'WXXr   c                r   )r   r4   )Zboolr   r   r   r    r+      s      d r   c                sZ    \         P                  R V P                  P                  4       R# )zPeer %s received unexpected EOFT)rT   rU   r1   r   r5   r6   r   eof_receivedZPeer.eof_received   s      	68O8OPr   c                s"   < V ^8  d   QhRRRR/# )r   rJ   zException | Noner4   Nr   r   r   r   r    r+      s      / D r   c                s   \         P                  R V P                  P                  \	        V4      V4       Vf   V P                  RR7       M\        V\        4      '       dF   VP                  ^8X  d   V P                  RR7       MV P                  RRVP                   2R7       M`\        V\        4      '       d   V P                  VP                  4       M.V P                  RRVP                  P                   R	V: 2R7       V P                  e[   V P                  P                  4       '       g;   Ve   V P                  P                  V4       MV P                  P                  4        V P                   F
  pV! 4        K  	  R# )
zPeer %s connection lost %s %sNZ
terminated)problemz
no-cockpitzPeer exited with status )ri   ra   zinternal-errorZ[z] )rT   rU   r1   r   ZtypeZshutdown_endpoint
isinstancer   r   r   Zattrsr/   rR   Zset_exceptionrS   r0   )r#   rJ   r[   s   && r   	do_closedZPeer.do_closed   s;   4dnn6M6MtTWyZ]^;""<"8Z((}}#&&|&<&&|G_`c`m`m_nEo&p^,,""399-""+;-.s}}/E/E.Fb+P # R
 '0@0@0E0E0G0G  ..s3  '')++HJ ,r   c                r2   r3   r   r   r   r   r    r+      s     + + +r   c                sh   \        V P                  \        4      '       g   Q h\        P	                  R V P
                  P                  V P                  P                  4       4       V P                  P                  4       p\        V\        4      '       g   Q hV P                  \        V4      4       R# )zPeer %s exited, status %dN)rj   Z	transportr   rT   rU   r1   r   Zget_returncoder   rI   r   )r#   Z
returncoder<   r   process_exitedZPeer.process_exited   sx    $..*=>>>>0$..2I2I4>>KhKhKjk^^224
*c****

:j)*r   c                0   < V ^8  d   QhRS[ RS[ RS[RR/# r   channelrM   ra   r4   Nre   r   r   r   r    r+      s*     = = =c =J =[_ =r   c                s\    V P                   e   \        R4      hV P                  WV4       R # )Nz7Received unexpected channel control message before init)r/   r   Zsend_channel_controlr#   ro   rM   ra      &&&&r   channel_control_receivedZPeer.channel_control_received   s*    '&'`aa!!'G<r   c                rd   r   ro   datar4   Nr;   Zbytesr   r   r   r    r+      s"     . .S . .$ .r   c                sZ    V P                   e   \        R4      hV P                  W4       R # )Nz,Received unexpected channel data before init)r/   r   Zsend_channel_datar#   ro   rt   rf   r   channel_data_receivedZPeer.channel_data_received   s(    '&'UVVw-r   c                rm   rn   re   r   r   r   r    r+      s*     $ $# $ $j $UY $r   c                H    V P                   e   Q hV P                  V4       R # r!   r/   rV   rp   rq   r   do_channel_controlZPeer.do_channel_control   "    '''7#r   c                rd   rs   ru   r   r   r   r    r+      s"     / /s /% /D /r   c                sH    V P                   e   Q hV P                  W4       R # r!   )r/   Zwrite_channel_datarv   rf   r   do_channel_dataZPeer.do_channel_data   s"    '''.r   c                s,   < V ^8  d   QhRRRRRS[ RR/# )r   rO   rA   groupra   r4   Nrb   r   r   r   r    r+      s*     $ $L $ $
 $W[ $r   c                rx   r!   ry   )r#   rO   r}   ra   rq   r   do_killZPeer.do_kill   r{   r   c                r2   r3   r   r   r   r   r    r+      s      $ r   c                s&    V P                  4        R # r!   )rI   r5   r6   r   do_closeZPeer.do_close   s    

r   c                s.   < V ^8  d   Qh/ R;R&   R;R&   # )r   zlist[Callable[[], None]]r0   z!asyncio.Future[JsonObject] | Noner/   r   r   r   r   r    r+      s     .. 44 r   )r0   r/   r!   )r   r   r   r   r%   r7   r?   rW   rZ   rQ   r^   rc   rg   rh   rk   rl   rr   rw   rz   r|   r~   r   __annotate_func__r   r&   __classcell__r1   r      @@r   r)   r)      s     ! !" "a a> >B
7 
7- -  	Y 	Y  8+ += =
. .$ $/ /$ $   r   r)   c                   s\   a a ] tR t^t oV3R lV 3R lltV3R lR ltV3R ltRtVtV ;t	# )ConfiguredPeerc                &   < V ^8  d   QhRS[ RS[/# r   r*   configr
   r   r   r   r   r    ConfiguredPeer.__annotate__   s     ! !v !| !r   c                s   < W n         VP                  V n        VP                  V n        VP                  V n        \        SV `  V4       R # r!   )r   methodr?   argsr>   r9   r,   r%   r#   r*   r   r1      &&&r   r%   ZConfiguredPeer.__init__   s6    mmLL	>> r   c                r2   r3   r   r   r   r   r    r      s     . .D .r   c                s   "   V P                   f   Q hV P                  V P                   V P                  4      G R j  xL
  R #  L5ir!   )r   r?   r9   r5   r6   r   r7   Z#ConfiguredPeer.do_connect_transport   s1     yy$$$jjDHH---s   :AAAc                sj   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[S[,          ;R&   S[S[,          ;R&   # )r   r   r   r   r9   )r   r;   r   r   r   r   r    r      s<      K  3-  
#	 r   )r   r   r9   r   )
r   r   r   r   r%   r7   r   r   r&   r   r   r   r   r   r      s      ! !. .  r   r   c                   s   a a ] tR t^t oV3R lV 3R lltV3R lR ltV3R lR ltV3R lR ltV3R	 ltR
t	Vt
V ;t# )PeerRoutingRulec                r   r   r   r   r   r   r    PeerRoutingRule.__annotate__   s      v | r   c                sb   < \         SV `  V4       W n        VP                  V n        R V n        R # r!   )r,   r%   r   matchpeerr   r   r   r%   ZPeerRoutingRule.__init__   s'     \\
	r   c                r`   )r   optionsr4   Peer | Nonerb   r   r   r   r    r      s      *  r   c                sR   V P                   P                  4        FX  w  r#W!9  d   \        P                  R V4        R# Vf   K*  W,          V8w  g   K9  \        P                  RW!V,          V4        R# 	  V P                  f   \        V P                  V P                  4      V n        V P                  P                  V P                  4       V P                  P                  '       g   Q hV P                  P                  V P                  P                  R7       V P                  # )z+        rejecting because key %s is missingNz;        rejecting because key %s has wrong value %s (vs %s))r@   )r   ZitemsrT   rU   r   r   r*   r   rQ   peer_closedr@   rZ   )r#   r   ZkeyZvalue   &&  r   
apply_ruleZPeerRoutingRule.apply_rule   s     ****,JC!JCP W\U%:Z\_ilamotu - 99&t{{DKK@DIII''(8(89;;(((((II))DKK4I4I)Jyyr   c                r2   r3   r   r   r   r   r    r     s      T r   c                s    R V n         R # r!   )r   r5   r6   r   r   ZPeerRoutingRule.peer_closed  s	    	r   c                r2   r3   r   r   r   r   r    r     s      $ r   c                sZ    V P                   e   V P                   P                  4        R # R # r!   )r   rI   r5   r6   r   shutdownZPeerRoutingRule.shutdown  s    99 IIOO !r   c                s<   < V ^8  d   Qh/ S[ ;R&   S[;R&   R;R&   # )r   r   r   r   r   )r   r   r   r   r   r    r      s(         r   )r   r   r   )r   r   r   r   r%   r   r   r   r   r   r&   r   r   r   r   r   r      s5     
  (  E  r   r   c                   sf   a  ] tR tRt o . tV 3R lR ltV 3R lR ltV 3R lR ltV 3R ltR	t	V t
R
# )PeersRoutingRulei  c                r`   )r   r   r4   zEndpoint | Nonerb   r   r   r   r    PeersRoutingRule.__annotate__  s     	 	* 	1B 	r   c                sX   \         P                  R \        V P                  4      4       V P                   F[  p\         P                  RVP                  P
                  4       VP                  V4      pVf   KD  \         P                  R4       Vu # 	  \         P                  R4       R# )z    considering %d rulesz      considering %sNz        selectedz      no peer rules matched)rT   rU   Zlenrulesr   Znamer   )r#   r   ruleZendpointr   r   r   ZPeersRoutingRule.apply_rule  sx    /TZZAJJDLL/1A1ABw/H#/0  	23r   c                s4   < V ^8  d   QhRS[ S[,          RR/# )r   bridge_configsr4   N)r   r   r   r   r   r    r   '  s       (<*@ T r   c                s   V P                   p. V n         V F  pVP                  '       g   R VP                  9   d   K(  \        V4       F'  pVP                  V8X  g   K  VP                  V4        M	  \        V P                  V4      pV P                   P                  V4       K  	  V F  pVP                  4        K  	  R# )rO   N)
r   Z
privilegedr   Zlistr   Zremover   r*   r\   r   )r#   r   Z	old_rulesr   r   s   &&   r   set_configsZPeersRoutingRule.set_configs'  s    JJ	
$F   Ffll$: Y;;&($$T* ( 't{{F;JJd# %" DMMO r   c                r2   r3   r   r   r   r   r    r   ?  s      $ r   c                sL    V P                    F  pVP                  4        K  	  R # r!   )r   r   )r#   r   r<   r   r   ZPeersRoutingRule.shutdown?  s    JJDMMO r   c                s$   < V ^8  d   Qh/ R;R&   # )r   zlist[PeerRoutingRule]r   r   r   r   r   r    r     s     "' r   )r   N)r   r   r   r   r   r   r   r   r   r   r&   r'   r(   r   r   r     s0     %'E	 	 0 M  r   r   )!r-   Zloggingr=   Ztypingr    r   r   Zjsonutilr   r   Zpackagesr   Zprotocolr   r   r   r*   r	   r
   r   Z
transportsr   r   Z	getLoggerr   rT   r   rH   r   r)   r   r   r   r   r   r   <module>r      s      	 * * + " K K 1 1 ?			8	$	 	# #
@?. @F.T .$$k $N({ (r   