grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a q©jÓ/ã@sòddlZddlZddlZddlmZmZmZddlmZm Z ddl m Z ddl m Z mZmZddlmZmZmZddlmZmZe e¡ZGd d „d e ƒZGd d „d eƒZGd d„deeeƒZGdd„deƒZGdd„deƒZGdd„deƒZ dS)éN)ÚAnyÚCallableÚ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.pyrsrc@seZdZedœdd„ZdS)Ú PeerExited©Ú exit_codecCs ||_dS©Nr)ÚselfrrrrÚ__init__szPeerExited.__init__N)rrrÚintrrrrrrsrcsjeZdZUded<ded<edœ‡fdd„ Zdd œd d „Zeeeee e j d œd d„Z d7de edœdd„Zd8de ddœdd„Zegdfddœdd„Zdd œdd„Zeddœdd„Zeeddœdd„Zed œd d!„Zd"dd#œd$d%„Zdd œd&d'„Zeeedd(œd)d*„Zeedd+œd,d-„Zeeedd(œd.d/„Zeedd+œd0d1„Zddedd2œd3d4„Zdd œd5d6„Z ‡Z!S)9ÚPeerzlist[Callable[[], None]]Údone_callbacksz!asyncio.Future[JsonObject] | NoneÚ init_future)Úroutercs,tƒ |¡| ¡t ¡ ¡|_g|_dSr)ÚsuperrZfreeze_endpointÚasyncioÚget_running_loopZ create_futurer r)rr!©Ú __class__rrr!s z Peer.__init__N©ÚreturncÃst‚dSr)ÚNotImplementedError©rrrrÚdo_connect_transport+szPeer.do_connect_transport)ÚargvÚenvÚkwargsr(cËs@t ¡}tdd„|Dƒƒ}t|||fdttjfi|¤Ži|¤ŽS)Ncss|]}| dd¡VqdS)ú=rN)Úsplit)Ú.0ÚerrrÚ 1ózPeer.spawn..r-)r#r$ÚdictrÚosÚenviron)rr,r-r.ZloopZuser_envrrrÚspawn.sz Peer.spawnz str | None)Ú init_hostr.r(c ‹s܈jdusJ‚dddœ‡‡fdd„ }t ˆ ¡¡‰ˆ |¡zNzˆjIdH}Wn"ttfypˆ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. Nzasyncio.Task[None]©Ú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_doneEs  z&Peer.start.._connect_task_donez$ sending init message back, host %sÚinitr)ÚcommandÚversionÚhost)N) r r#Ú create_taskr+Úadd_done_callbackrÚBrokenPipeErrorÚdoneÚcancelÚloggerÚdebugÚ write_controlZ thaw_endpoint)rr9r.rBZ init_messagerrArÚstart4s(     ü  z Peer.startc s:dddœ‡fdd„ }t |j|fi|¤Ž¡‰ˆ |¡dS)Nzasyncio.Task[JsonObject]r:c s:|ˆus J‚z | ¡Wnttttjfy4Yn0dSr)r<ÚOSErrorrr r#r=)r;©Z start_taskrrÚ_start_task_donevs   z2Peer.start_in_background.._start_task_done)r#rGrOrH)rr9r.rRrrQrÚstart_in_backgrounduszPeer.start_in_background)Úcallbackr(cCs|j |¡dSr)rÚappend)rrTrrrrH‚szPeer.add_done_callbackcCsdSrrr*rrrÚdo_superuser_init_done†szPeer.do_superuser_init_done)Úmessager(cCsdSrr)rrWrrrÚ do_authorize‰szPeer.do_authorize)rDrWr(cCsb|dkr*|jdur*t d¡|j |¡n4|dkr>| |¡n |dkrP| ¡ntd|›�ƒ‚dS)NrCz:Got init message with active init_future. Setting result.Z authorizezsuperuser-init-donez$Received unexpected control message )r rLrMZ set_resultrXrVr )rrDrWrrrÚtransport_control_receivedŒs   zPeer.transport_control_receivedcCst d|jj¡dS)NzPeer %s received unexpected EOFT)rLrMr&rr*rrrÚ eof_received—szPeer.eof_receivedzException | None)r@r(cCsèt d|jjt|ƒ|¡|dur.|jdd�npt|tƒrh|jdkrP|jdd�qž|jdd|j›�d�n6t|t ƒr€| |j ¡n|jdd |jj›d |›�d�|j durÒ|j   ¡sÒ|durÈ|j   |¡n |j  ¡|jD] }|ƒqØdS) NzPeer %s connection lost %s %sZ terminated)Úprobleméz no-cockpitzPeer exited with status )r[rWzinternal-errorú[z] )rLrMr&rÚtypeZshutdown_endpointÚ isinstancerrr Úattrsr rJZ set_exceptionrKr)rr@rTrrrÚ do_closed¡s$   ÿ  zPeer.do_closedcCsRt|jtƒsJ‚t d|jj|j ¡¡|j ¡}t|tƒs@J‚|  t |ƒ¡dS)NzPeer %s exited, status %d) r_Z transportrrLrMr&rZget_returncoderr?r)rÚ returncoderrrÚprocess_exited½s  zPeer.process_exited)ÚchannelrDrWr(cCs$|jdurtdƒ‚| |||¡dS)Nz7Received unexpected channel control message before init)r r Zsend_channel_control©rrdrDrWrrrÚchannel_control_receivedÅs zPeer.channel_control_received)rdÚdatar(cCs"|jdurtdƒ‚| ||¡dS)Nz,Received unexpected channel data before init)r r Zsend_channel_data©rrdrgrrrÚchannel_data_receivedÊs zPeer.channel_data_receivedcCs|jdusJ‚| |¡dSr©r rNrerrrÚdo_channel_controlÐszPeer.do_channel_controlcCs|jdusJ‚| ||¡dSr)r Zwrite_channel_datarhrrrÚdo_channel_dataÔszPeer.do_channel_data)rFÚgrouprWr(cCs|jdusJ‚| |¡dSrrj)rrFrmrWrrrÚdo_killØsz Peer.do_killcCs | ¡dSr)r?r*rrrÚdo_closeÜsz Peer.do_close)N)N)"rrrÚ__annotations__r rr+rÚstrrr#Z Transportr8rrrOrSrrHrVrXrYÚboolrZrarcrfÚbytesrirkrlrnroÚ __classcell__rrr%rrs(  A   rcs\eZdZUeed<eed<eeed<eeed<eedœ‡fdd„ Zdd œd d „Z ‡Z S) ÚConfiguredPeerÚconfigÚmethodÚargsr-©r!rvcs.||_|j|_|j|_|j|_tƒ |¡dSr)rvrwr8rxr7r-r"r©rr!rvr%rrræs zConfiguredPeer.__init__Nr'cÃs(|jdusJ‚| |j|j¡IdHdSr)rxr8r-r*rrrr+ísz#ConfiguredPeer.do_connect_transport) rrrrrprqrr rr+rtrrr%rruàs   rucsjeZdZUeed<eed<ded<eedœ‡fdd„ Zeddœd d „Zd d œd d„Z d d œdd„Z ‡Z S)ÚPeerRoutingRulervÚmatchz Peer | NoneÚpeerrycs$tƒ |¡||_|j|_d|_dSr)r"rrvr|r}rzr%rrr÷s 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))r9) r|ÚitemsrLrMr}rur!rvrHÚ peer_closedr9rS)rrÚkeyÚvaluerrrÚ apply_ruleýs   zPeerRoutingRule.apply_ruleNr'cCs d|_dSr)r}r*rrrr�szPeerRoutingRule.peer_closedcCs|jdur|j ¡dSr)r}r?r*rrrÚshutdowns zPeerRoutingRule.shutdown) rrrrrprr rr„r�r…rtrrr%rr{òs r{c@sLeZdZUgZded<eddœdd„Zeeddœd d „Z dd œd d „Z dS)ÚPeersRoutingRulezlist[PeerRoutingRule]ÚruleszEndpoint | Noner~cCs`t dt|jƒ¡|jD]8}t d|jj¡| |¡}|durt d¡|Sqt d¡dS)Nz considering %d rulesz considering %sz selectedz no peer rules matched)rLrMÚlenr‡rvÚ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)NrF) r‡Z privilegedr|ÚlistrvÚremover{r!rUr…)rr‹Z old_rulesrvrŠrrrÚ set_configs's    zPeersRoutingRule.set_configsr'cCs|jD] }| ¡qdSr)r‡r…)rrŠrrrr…?s zPeersRoutingRule.shutdown) rrrr‡rprr„rrrŽr…rrrrr†s   r†)!r#Zloggingr6ÚtypingrrrZjsonutilrrZpackagesrZprotocolr r r r!r r rZ transportsrrZ getLoggerrrLrr>rrrur{r†rrrrÚs   D'