+
    Dfj                        R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHtHt ^ RI	H
t
  ! R R]P                  4      t ! R R]P                  4      t ! R R	]P                  4      t ! R
 R]P                  4      t ! R R]P                  4      tR# )z)
Implementation of the SOCKSv4 protocol.
N)deferprotocolreactor)logc                   >   a  ] tR t^t o R tR tR tR tR tRt	V t
R# )SOCKSv4Outgoingc                    Wn         R # Nsocksselfr   s   &&9/usr/lib/python3/dist-packages/twisted/protocols/socks.py__init__SOCKSv4Outgoing.__init__   s    
    c                    V P                   P                  4       pV P                  P                  ^Z^ VP                  VP
                  R7       W P                  n        R# )Z   )portipN)	transportgetPeerr   	makeReplyr   host	otherConn)r   peers   & r   connectionMadeSOCKSv4Outgoing.connectionMade   sA    ~~%%'

RtyyA#

r   c                N    V P                   P                  P                  4        R # r	   r   r   loseConnectionr   reasons   &&r   connectionLostSOCKSv4Outgoing.connectionLost       

++-r   c                <    V P                   P                  V4       R # r	   r   writer   datas   &&r   dataReceivedSOCKSv4Outgoing.dataReceived!       

r   c                r    V P                   P                  W4       V P                  P                  V4       R # r	   r   r   r   r(   r)   s   &&r   r(   SOCKSv4Outgoing.write$   $    

t"T"r   r
   N)__name__
__module____qualname____firstlineno__r   r   r#   r+   r(   __static_attributes____classdictcell____classdict__s   @r   r   r      s#     $
.# #r   r   c                   8   a  ] tR t^)t o R tR tR tR tRtV t	R# )SOCKSv4Incomingc                2    Wn         W P                   n        R # r	   )r   r   r   s   &&r   r   SOCKSv4Incoming.__init__*   s    
#

r   c                N    V P                   P                  P                  4        R # r	   r   r!   s   &&r   r#   SOCKSv4Incoming.connectionLost.   r%   r   c                <    V P                   P                  V4       R # r	   r'   r)   s   &&r   r+   SOCKSv4Incoming.dataReceived1   r-   r   c                r    V P                   P                  W4       V P                  P                  V4       R # r	   r/   r)   s   &&r   r(   SOCKSv4Incoming.write4   r1   r   r
   N)
r2   r3   r4   r5   r   r#   r+   r(   r6   r7   r8   s   @r   r;   r;   )   s     $.# #r   r;   c                   r   a  ] tR t^9t o RtR]3R ltR tR tR t	R t
R tR	 tR
 tRR ltR tR tRtV tR# )SOCKSv4a  
An implementation of the SOCKSv4 protocol.

@type logging: L{str} or L{None}
@ivar logging: If not L{None}, the name of the logfile to which connection
    information will be written.

@type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
@ivar reactor: The reactor used to create connections.

@type buf: L{str}
@ivar buf: Part of a SOCKSv4 connection request.

@type otherConn: C{SOCKSv4Incoming}, C{SOCKSv4Outgoing} or L{None}
@ivar otherConn: Until the connection has been established, C{otherConn} is
    L{None}. After that, it is the proxy-to-destination protocol instance
    along which the client's connection is being forwarded.
Nc                    Wn         W n        R # r	   )loggingr   )r   rG   r   s   &&&r   r   SOCKSv4.__init__M   s    r   c                "    R V n         RV n        R# )r   N)bufr   )r   s   &r   r   SOCKSv4.connectionMadeQ   s    r   c                n   V P                   '       d   V P                   P                  V4       R# V P                  V,           V n        V P                  pRV P                  R,          9   EdI   V P                  R,          V P                  R,          uq0n        \        P                  ! RVR,          4      w  rEpV P                  P                  R^4      w  qpn        VR,          R8X  d   VR	,          R8w  d   RV P                  9  d	   W n        R# V P                  P                  R^4      w  qn        V P                  P                  V4      p	V	P                  V P                  WtWV4       V	P                  V 3R
 l4       R# \        P                  ! VR,          4      pV P                  WWEV4       R# R# )zg
Called whenever data is received.

@type data: L{bytes}
@param data: Part or all of a SOCKSv4 packet.
N    :   NN:NrN   N!BBH:N   N:rP      Ns      :rQ   rN   Nc                 $    VP                  ^[4      # [   r   resultr   s   &&r   <lambda>&SOCKSv4.dataReceived.<locals>.<lambda>p   s    t~~b7Ir   :rP   rN   N)r   r(   rJ   structunpacksplitr   resolveaddCallback_dataReceived2
addErrbacksocket	inet_ntoa)
r   r*   completeBufferheadversioncoder   userserverds
   &&        r   r+   SOCKSv4.dataReceivedU   sC    >>>NN  &88d?dhhrl"!XXb\488B<ND("(--R"AG4!XX^^GQ7ND(CyO+S	W0D
 $((*-H#'88>>'1#= LL((0d114$MIJ))$s)4gTB) #r   c                   V^8X  g   Q RV,          4       hV P                  WAWR4      '       g   V P                  ^[4       R# V^8X  d.   V P                  W\        V 4      pVP	                  V 3R l4       MBV^8X  d.   V P                  ^ \        W4      pVP                  V 3R l4       M\        RV 24      hV P                  R8X  g"   Q R\        V P                  4      ,          4       hR# )a  
The second half of the SOCKS connection setup. For a SOCKSv4 packet this
is after the server address has been extracted from the header. For a
SOCKSv4a packet this is after the host name has been resolved.

@type server: L{str}
@param server: The IP address of the destination, represented as a
    dotted quad.

@type user: L{str}
@param user: The username associated with the connection.

@type version: L{int}
@param version: The SOCKS protocol version number.

@type code: L{int}
@param code: The command code. 1 means establish a TCP/IP stream
    connection, and 2 means establish a TCP/IP port binding.

@type port: L{int}
@param port: The port number associated with the connection.
zBad version code: %sNc                 $    VP                  ^[4      # rS   rU   rV   s   &&r   rX   (SOCKSv4._dataReceived2.<locals>.<lambda>   s    4>>"3Er   c                 F    VP                  ^Z^ V ^,          V ^ ,          4      # )r   rU   )xr   s   &&r   rX   rm      s    t~~b!QqT1Q4/Pr   zBad Connect Code: r   z hmm, still stuff in buffer... %s)	authorizer   connectClassr   r`   listenClassSOCKSv4IncomingFactoryr^   RuntimeErrorrJ   repr)r   rh   rg   re   rf   r   ri   s   &&&&&& r   r_   SOCKSv4._dataReceived2w   s    . !|=3g==|~~dD77NN219!!&FALLTEFQY  $:DIAMMPQ!3D6:;;xx3S BT$((^ SSr   c                v    V P                   '       d'   V P                   P                  P                  4        R # R # r	   )r   r   r    r!   s   &&r   r#   SOCKSv4.connectionLost   s&    >>>NN$$335 r   c                T    \         P                  ! R V: RV: RV: RV: R2	4       ^# )zcode z connection to :z (user z) authorized)r   msg)r   rf   rh   r   rg   s   &&&&&r   rp   SOCKSv4.authorize   s!    VT4)	
 r   c                Z    \         P                  ! \        V.VO5!  P                  W4      # r	   )r   ClientCreatorr   
connectTCP)r   r   r   klassargss   &&&&*r   rq   SOCKSv4.connectClass   s%    %%gu<t<GGSSr   c                    \         P                  ! W! V!  4      p\        P                  ! VP	                  4       R ,          4      # ):   NN)r   	listenTCPr   succeedgetHost)r   r   r   r   servs   &&&* r   rr   SOCKSv4.listenClass   s2      ud|4}}T\\^B/00r   c                    V P                   P                  \        P                  ! R W!V4      \        P
                  ! V4      ,           4       V^Z8w  d   V P                   P                  4        R# R# )rO   N)r   r(   rZ   packra   	inet_atonr    )r   replyre   r   r   s   &&&&&r   r   SOCKSv4.makeReply   sR    KK58H8H8LL	
 B;NN))+ r   c                ^    V P                  W4       V P                  P                  V4       R # r	   )r   r   r(   r)   s   &&r   r(   SOCKSv4.write   s     T"r   c           	        V P                   '       g   R # V P                  P                  4       pV P                  P                  P                  4       p\	        V P                   R4      pTP                  R\        P                  ! 4       VP                  VP                  W8H  ;'       d    R;'       g    RVP                  VP                  3,          4       V'       d   VR,          VR,          r&VP                  \        P                  ! \        R V4      R4      R,           4       VP                  ^\        V4      ,
          ^,          R,          4       V F@  p\        \        V4      4      ^8  d   VP                  R	4       K/  VP                  V4       KB  	  VP                  R
4       K  VP                  R
4       VP                  4        R # )Naz%s	%s:%d %s %s:%d
<>:N   N:r   NNc                 &    R \        V 4      ,          # )z%02X)ord)ro   s   &r   rX   SOCKSv4.log.<locals>.<lambda>   s    fs1vor    .
)rG   r   r   r   openr(   timectimer   r   stringjoinmaplenru   close)r   protor*   r   
their_peerfpcs   &&&     r   r   SOCKSv4.log   sB   |||~~%%'^^--557
s#	"

				-''C//C
	
 3ictGGFKK$=q A3G#MNGGR#a&[A%+,tAw<!#GGCLGGAJ	 
 GGDM			r   )rJ   rG   r   r   )    r   z0.0.0.0)r2   r3   r4   r5   __doc__r   r   r   r+   r_   r#   rp   rq   rr   r   r(   r   r6   r7   r8   s   @r   rE   rE   9   sR     &  $W  CD#TJ6T1,# r   rE   c                   0   a  ] tR t^t o RtR tR tRtV tR# )SOCKSv4FactoryzT
A factory for a SOCKSv4 proxy.

Constructor accepts one argument, a log file name.
c                    Wn         R # r	   rG   )r   r   s   &&r   r   SOCKSv4Factory.__init__   s    r   c                6    \        V P                  \        4      # r	   )rE   rG   r   r   addrs   &&r   buildProtocolSOCKSv4Factory.buildProtocol   s    t||W--r   r   N	r2   r3   r4   r5   r   r   r   r6   r7   r8   s   @r   r   r      s     . .r   r   c                   0   a  ] tR t^t o RtR tR tRtV tR# )rs   zB
A utility class for building protocols for incoming connections.
c                    Wn         W n        R # r	   )r   r   )r   r   r   s   &&&r   r   SOCKSv4IncomingFactory.__init__   s    
r   c                   V^ ,          V P                   8X  d9   RV n         V P                  P                  ^Z^ 4       \        V P                  4      # V P                   R8X  d   R# V P                  P                  ^[^ 4       RV n         R# )r    N)r   r   r   r;   r   s   &&r   r   $SOCKSv4IncomingFactory.buildProtocol   sh    7dggDGJJ  Q'"4::..WW]JJ  Q'DGr   )r   r   Nr   r8   s   @r   rs   rs      s     
 
r   rs   )r   ra   r   rZ   r   twisted.internetr   r   r   twisted.pythonr   Protocolr   r;   rE   Factoryr   rs    r   r   <module>r      s   
     6 5 #h'' #(#h'' # \h \~.X%% .X-- r   