+
    Dfj                      <   R t ^ RIt^ RIHtHt ^ RIHtHt ^ RIH	t	H
t
  ! R R]P                  4      t ! R R]P                  4      t ! R	 R
]4      t ! R R]4      t ! R R]P                  4      tR t ! R R]P&                  4      tR t]tR t]tR tR tR# )z
This module contains the implementation of the TCP forwarding, which allows
clients and servers to forward arbitrary TCP data across the connection.

Maintainer: Paul Swartz
N)channelcommon)protocolreactor)HostnameEndpointconnectProtocolc                   ,   a  ] tR t^t o R tR tRtV tR# )SSHListenForwardingFactoryc                *    Wn         W n        W0n        R # Nconnhostportklass)self
connectionr   r   s   &&&&>/usr/lib/python3/dist-packages/twisted/conch/ssh/forwarding.py__init__#SSHListenForwardingFactory.__init__   s    	 
    c                    V P                  V P                  R 7      p\        V4      pW2n        VP                  VP
                  3p\        V P                  V4      pV P                  P                  W%4       V# ))r   )	r   r   SSHForwardingClientclienthostportpackOpen_direct_tcpipr   openChannel)r   addrr   r   	addrTuplechannelOpenDatas   &&    r   buildProtocol(SSHListenForwardingFactory.buildProtocol   s^    **$))*,$W-YY		*	/yI		g7r   r   N)__name__
__module____qualname____firstlineno__r   r    __static_attributes____classdictcell____classdict__s   @r   r	   r	      s     
 r   r	   c                   >   a  ] tR t^#t o R tR tR tR tR tRt	V t
R# )SSHListenForwardingChannelc                   V P                   P                  R V P                  R7       \        V P                  P
                  4      ^8  d/   V P                  P
                  R,          pV P                  V4       RV P                  n        R# )zopened forwarding channel {id}id   NNr   N)_loginfor.   lenr   bufwrite)r   specificDatabs   && r   channelOpen&SSHListenForwardingChannel.channelOpen$   sX    		7DGGDt{{!##AJJqMr   c                &    V P                  4        R # r   )closedr   reasons   &&r   
openFailed%SSHListenForwardingChannel.openFailed+   s    r   c                P    V P                   P                  P                  V4       R # r   )r   	transportr5   r   datas   &&r   dataReceived'SSHListenForwardingChannel.dataReceived.   s    ##D)r   c                N    V P                   P                  P                  4        R # r   )r   rA   loseConnectionr   s   &r   eofReceived&SSHListenForwardingChannel.eofReceived1   s    ,,.r   c                    \        V R 4      '       dP   V P                  P                  RV P                  R7       V P                  P
                  P                  4        V =R# R# )r   z%closing local forwarding channel {id}r-   N)hasattrr1   r2   r.   r   rA   rG   rH   s   &r   r;   !SSHListenForwardingChannel.closed4   sH    4""IINNBtwwNOKK!!002 #r    N)r"   r#   r$   r%   r8   r>   rD   rI   r;   r&   r'   r(   s   @r   r+   r+   #   s#     */ r   r+   c                       ] tR t^;tRtRtR# ) SSHListenClientForwardingChannels   direct-tcpiprN   Nr"   r#   r$   r%   namer&   rN   r   r   rP   rP   ;   s    Dr   rP   c                       ] tR t^?tRtRtR# ) SSHListenServerForwardingChannels   forwarded-tcpiprN   NrQ   rN   r   r   rT   rT   ?   s    Dr   rT   c                   L   a  ] tR t^Ct o Rt]tR tR tR t	R t
R tR tRtV tR	# )
SSHConnectForwardingChannela  
Channel used for handling server side forwarding request.
It acts as a client for the remote forwarding destination.

@ivar hostport: C{(host, port)} requested by client as forwarding
    destination.
@type hostport: L{tuple} or a C{sequence}

@ivar client: Protocol connected to the forwarding destination.
@type client: L{protocol.Protocol}

@ivar clientBuf: Data received while forwarding channel is not yet
    connected.
@type clientBuf: L{bytes}

@var  _reactor: Reactor used for TCP connections.
@type _reactor: A reactor.

@ivar _channelOpenDeferred: Deferred used in testing to check the
    result of C{channelOpen}.
@type _channelOpenDeferred: L{twisted.internet.defer.Deferred}
c                v    \         P                  P                  ! V .VO5/ VB  Wn        R V n        RV n        R # )Nr   )r   
SSHChannelr   r   r   	clientBuf)r   r   argskws   &&*,r   r   $SSHConnectForwardingChannel.__init__]   s3    ##D64626 r   c                z   V P                   P                  RV P                  ^ ,          V P                  ^,          R7       \        V P                  V P                  ^ ,          V P                  ^,          4      p\        V\        V 4      4      pVP                  V P                  V P                  4       W0n
        R# )
See: L{channel.SSHChannel}
zconnecting to {host}:{port}r   r   N)r1   r2   r   r   _reactorr   r   addCallbacks
_setClient_close_channelOpenDeferred)r   r6   epds   &&  r   r8   'SSHConnectForwardingChannel.channelOpenc   s     			)a0@t}}UVGW 	 	
 dmmT]]1-=t}}Q?OPB 3D 9:	t4$%!r   c                   Wn         V P                  P                  RV P                  ^ ,          V P                  ^,          R7       V P                  '       d7   V P                   P
                  P                  V P                  4       RV n        V P                   P                  R,          '       d-   V P                  V P                   P                  R,          4       RV P                   n        R# )z
Called when the connection was established to the forwarding
destination.

@param client: Client protocol connected to the forwarding destination.
@type  client: L{protocol.Protocol}
zconnected to {host}:{port}r_   Nr/   r   )r   r1   r2   r   rY   rA   r5   r4   )r   r   s   &&r   rb   &SSHConnectForwardingChannel._setCliento   s     		(t}}Q/?dmmTUFV 	 	
 >>>KK!!''7!DN;;??2JJt{{r*+r   c                    V P                   P                  RV P                  ^ ,          V P                  ^,          VR7       V P                  4        R# )z
Called when failed to connect to the forwarding destination.

@param reason: Reason why connection failed.
@type  reason: L{twisted.python.failure.Failure}
z,failed to connect to {host}:{port}: {reason})r   r   r=   N)r1   errorr   rG   r<   s   &&r   rc   "SSHConnectForwardingChannel._close   sE     			:q!q!	 	 	
 	r   c                    V P                   '       d(   V P                   P                  P                  V4       R# V ;P                  V,          un        R# )r^   N)r   rA   r5   rY   rB   s   &&r   rD   (SSHConnectForwardingChannel.dataReceived   s3     ;;;KK!!''-NNd"Nr   c                    V P                   '       d|   V P                  P                  RV P                  R7       V P                   P                  '       d   V P                  4        V P                   P                  P                  4        V = R# R# )r^   z%closed remote forwarding channel {id}r-   N)r   r1   r2   r.   r   rG   rA   rH   s   &r   r;   "SSHConnectForwardingChannel.closed   sb     ;;;IINNBtwwNO{{"""##%KK!!002 r   )rd   r   rY   r   N)r"   r#   r$   r%   __doc__r   r`   r   r8   rb   rc   rD   r;   r&   r'   r(   s   @r   rV   rV   C   s4     . H
&&#	 	r   rV   c                 :    \        V4      w  rE\        VV VVR 7      # ))remoteWindowremoteMaxPacketavatar)unpackOpen_direct_tcpiprV   )rs   rt   rC   ru   remoteHPorigHPs   &&&&  r   openConnectForwardingClientry      s(    .t4H&!'	 r   c                   2   a  ] tR t^t o R tR tR tRtV tR# )r   c                     Wn         R V n        R# )    N)r   r4   )r   r   s   &&r   r   SSHForwardingClient.__init__   s    r   c                    V P                   '       d   V ;P                   V,          un         R # V P                  P                  V4       R # r   )r4   r   r5   rB   s   &&r   rD    SSHForwardingClient.dataReceived   s+    888HHHLLt$r   c                p    V P                   '       d$   V P                   P                  4        R V n         R # R # r   )r   rG   r<   s   &&r   connectionLost"SSHForwardingClient.connectionLost   s'    <<<LL'')DL r   )r4   r   N)	r"   r#   r$   r%   r   rD   r   r&   r'   r(   s   @r   r   r      s     %   r   r   c                   V w  r#Vw  rE\        V\        4      '       d   VP                  R4      p\        V\        4      '       d   VP                  R4      p\        P                  ! V4      \
        P                  ! RV4      ,           p\        P                  ! V4      \
        P                  ! RV4      ,           pWg,           # )z
Pack the data suitable for sending in a CHANNEL_OPEN packet.

@type destination: L{tuple}
@param destination: A tuple of the (host, port) of the destination host.

@type source: L{tuple}
@param source: A tuple of the (host, port) of the source host.
utf-8>L)
isinstancestrencoder   NSstructpack)destinationsourceconnHostconnPortorigHostorigPortr   origs   &&      r   r   r      s     'X!X(C  ??7+(C  ??7+99XT8!<<D99XT8!<<D;r   c                   \         P                  ! V 4      w  r\        V\        4      '       d   VP	                  R4      p\        \        P                  ! RVR,          4      ^ ,          4      p\         P                  ! VR,          4      w  rB\        V\        4      '       d   VP	                  R4      p\        \        P                  ! RVR,          4      ^ ,          4      pW3WE33# )z#Unpack the data to a usable format.r   r   N   N:r   NNr   getNSr   bytesdecodeintr   unpack)rC   r   restr   r   r   s   &     r   rv   rv      s    \\$'NH(E""??7+6==tBx034H\\$r(+NH(E""??7+6==tBx034H(!555r   c                n    V w  r\         P                  ! V4      \        P                  ! RV4      ,           # )zf
Pack the data for tcpip forwarding.

@param peer: A tuple of the (host, port) .
@type peer: L{tuple}
r   )r   r   r   r   )peerr   r   s   &  r   packGlobal_tcpip_forwardr      s)     LT99T?V[[t444r   c                     \         P                  ! V 4      w  r\        V\        4      '       d   VP	                  R 4      p\        \        P                  ! RVR,          4      ^ ,          4      pW3# )r   r   r   r   )rC   r   r   r   s   &   r   unpackGlobal_tcpip_forwardr      sS    d#JD${{7#v}}T48,Q/0D:r   )rq   r   twisted.conch.sshr   r   twisted.internetr   r   twisted.internet.endpointsr   r   Factoryr	   rX   r+   rP   rT   rV   ry   Protocolr   r   packOpen_forwarded_tcpiprv   unpackOpen_forwarded_tcpipr   r   rN   r   r   <module>r      s     - . H!1!1  !3!3 0'A 'A `'"4"4 `F (++  "* 1 
6 5 5r   