+
    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)Z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kwargsr3   )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    r8   )r,   r-   Zdictr   osenviron)r"   r7   r8   r9   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 | Noner9   r3   )r   r   r   r   r   r   r*   4   s#     > >\ >I >R\ >r   c           	     sF  a a"   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.
c                     V ^8  d   QhRRRR/# )r   taskzasyncio.Task[None]r3   Nr   r      "r   r   Z Peer.start.<locals>.__annotate__E   s     	  	 %9 	 d 	 r   c                 s   <  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)rB   excconnect_taskr"   s   & r   _connect_task_doneZ&Peer.start.<locals>._connect_task_doneE   s?     ))   

3 s    AAAAANz$  sending init message back, host %scommandinitZversionhostr    )r,   create_taskr6   add_done_callbackr.   r   ZBrokenPipeErrordonecancelloggerdebugwrite_controlZthaw_endpoint)r"   r?   r9   rK   Zinit_messagerJ   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 D!C CC D!7AD!C C+#C&$C++C. .0DD!c                s(   < V ^8  d   QhRRRS[ RR/# )r   r?   r@   r9   r3   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                rA   )r   rB   zasyncio.Task[JsonObject]r3   Nr   rC   rD   r   r   Z.Peer.start_in_background.<locals>.__annotate__v   s     	 	#= 	$ 	r   c                 s   <  V P                  4        R #   \        \        \        \        P
                  3 d     R # i ; ir    )rE   ZOSErrorr   r   r,   rF   )rB   
start_tasks   &r   _start_task_doneZ2Peer.start_in_background.<locals>._start_task_donev   s2    Z9O9OP s    %>>N)r,   rO   rV   rP   )r"   r?   r9   rX   rW   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   callbackNr3   )r   r   r   r   r   r*      s$     - -(2t8*< - -r   c                s<    V P                   P                  V4       R # r    )r/   append)r"   rZ   r#   r   rP   ZPeer.add_done_callback   s    ""8,r   c                r1   r2   r   r   r   r   r   r*      s       r   c                    R # r    r   r4   r5   r   do_superuser_init_doneZPeer.do_superuser_init_done       r   c                $   < V ^8  d   QhRS[ RR/# )r   messager3   Nr   r   r   r   r   r*      s      J 4 r   c                r\   r    r   )r"   r`   r#   r   do_authorizeZPeer.do_authorize   r^   r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   rL   r`   r3   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)rM   Nz:Got init message with active init_future.  Setting result.Z	authorizezsuperuser-init-donez$Received unexpected control message )r.   rS   rT   Z
set_resultrb   r]   r   )r"   rL   r`      &&&r   transport_control_receivedZPeer.transport_control_received   st    f!1!1!=LLUV''0#g&--'')&)MgY'WXXr   c                r   )r   r3   )Zboolr   r   r   r   r*      s      d r   c                sZ    \         P                  R V P                  P                  4       R# )zPeer %s received unexpected EOFT)rS   rT   r0   r   r4   r5   r   eof_receivedZPeer.eof_received   s      	68O8OPr   c                s"   < V ^8  d   QhRRRR/# )r   rI   zException | Noner3   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 )rh   r`   zinternal-errorZ[z] )rS   rT   r0   r   ZtypeZshutdown_endpointZ
isinstancer   r   r   Zattrsr.   rQ   Zset_exceptionrR   r/   )r"   rI   rZ   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                r1   r2   r   r   r   r   r   r*      s     + + +r   c                s    \         P                  R V P                  P                  V P                  P                  4       4       V P                  P                  4       pV P                  \        V4      4       R# )zPeer %s exited, status %dN)rS   rT   r0   r   Z	transportZget_returncoderH   r   )r"   Z
returncoder;   r   process_exitedZPeer.process_exited   sM    0$..2I2I4>>KhKhKjk^^224


:j)*r   c                0   < V ^8  d   QhRS[ RS[ RS[RR/# r   channelrL   r`   r3   Nrd   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"   rm   rL   r`      &&&&r   channel_control_receivedZPeer.channel_control_received   s*    '&'`aa!!'G<r   c                rc   r   rm   datar3   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"   rm   rr   re   r   channel_data_receivedZPeer.channel_data_received   s(    '&'UVVw-r   c                rk   rl   rd   r   r   r   r   r*      s*     $ $# $ $j $UY $r   c                (    V P                  V4       R # r    rU   rn   ro   r   do_channel_controlZPeer.do_channel_control       7#r   c                rc   rq   rs   r   r   r   r   r*      s"     / /s /% /D /r   c                s(    V P                  W4       R # r    )Zwrite_channel_datart   re   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   rN   r@   groupr`   r3   Nra   r   r   r   r   r*      s*     $ $L $ $
 $W[ $r   c                rv   r    rw   )r"   rN   r{   r`   ro   r   do_killZPeer.do_kill   ry   r   c                r1   r2   r   r   r   r   r   r*      s      $ r   c                s&    V P                  4        R # r    )rH   r4   r5   r   do_closeZPeer.do_close   s    

r   c                s.   < V ^8  d   Qh/ R;R&   R;R&   # )r   zlist[Callable[[], None]]r/   z!asyncio.Future[JsonObject] | Noner.   r   r   r   r   r   r*      s     .. 44 r   )r/   r.   r    )r   r   r   r   r$   r6   r>   rV   rY   rP   r]   rb   rf   rg   ri   rj   rp   ru   rx   rz   r|   r}   __annotate_func__r   r%   __classcell__r0   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=   r8   r+   r$   r"   r)   r   r0      &&&r   r$   ZConfiguredPeer.__init__   s6    mmLL	>> r   c                r1   r2   r   r   r   r   r   r      s     . .D .r   c                sn   "   V P                  V P                  V P                  4      G R j  xL
  R #  L5ir    )r>   r   r8   r4   r5   r   r6   Z#ConfiguredPeer.do_connect_transport   s!     jjDHH---s   *535c                sj   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[S[,          ;R&   S[S[,          ;R&   # )r   r   r   r   r8   )r   r:   r   r   r   r   r   r      s<      K  3-  
#	 r   )r   r   r8   r   )
r   r   r   r   r$   r6   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   optionsr3   Peer | Nonera   r   r   r   r   r      s      *  r   c                s   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                  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itemsrS   rT   r   r   r)   r   rP   peer_closedrY   r?   )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                r1   r2   r   r   r   r   r   r     s      T r   c                s    R V n         R # r    )r   r4   r5   r   r   ZPeerRoutingRule.peer_closed  s	    	r   c                r1   r2   r   r   r   r   r   r     s      $ r   c                sZ    V P                   e   V P                   P                  4        R # R # r    )r   rH   r4   r5   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   r3   zEndpoint | Nonera   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)rS   rT   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_configsr3   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# )rN   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                r1   r2   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   rS   r   rG   r   r(   r   r   r   r   r   r   <module>r      s      	 * * + " K K 1 1 ?			8	$	 	# #
@?. @F.T .$$k $N({ (r   