
    @OOf                     n   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ e G d de             Ze G d de             Ze G d de             Ze G d de             Z G d deej0                           Z G d dej4                        Zy)    )	dataclass)flow)tcp)
Connection)ConnectionState)commands)events)layer)	StartHook)Context)MessageInjected)expectc                   0    e Zd ZU dZej
                  ed<   y)TcpStartHookz'
    A TCP connection has started.
    r   N__name__
__module____qualname____doc__r   TCPFlow__annotations__     [/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/proxy/layers/tcp.pyr   r           ++r   r   c                   0    e Zd ZU dZej
                  ed<   y)TcpMessageHookz
    A TCP connection has received a message. The most recent message
    will be flow.messages[-1]. The message is user-modifiable.
    r   Nr   r   r   r   r   r      s    
 ++r   r   c                   0    e Zd ZU dZej
                  ed<   y)
TcpEndHookz%
    A TCP connection has ended.
    r   Nr   r   r   r   r   r   #   r   r   r   c                   0    e Zd ZU dZej
                  ed<   y)TcpErrorHookzy
    A TCP error has occurred.

    Every TCP flow will receive either a tcp_error or a tcp_end event, but not both.
    r   Nr   r   r   r   r!   r!   ,   s     ++r   r!   c                       e Zd ZdZy)TcpMessageInjectedz5
    The user has injected a custom TCP message.
    N)r   r   r   r   r   r   r   r#   r#   7   s    r   r#   c                       e Zd ZU dZej
                  dz  ed<   ddedef fdZ	 e
ej                        dej                  d   fd       ZeZ e
ej"                  ej$                  e      d	ej(                  dej                  d   fd
       Z e
ej"                  ej$                  e      dej                  d   fd       Z xZS )TCPLayerz?
    Simple TCP layer that just relays messages right now.
    Nr   contextignorec                     t         |   |       |rd | _        y t        j                  | j
                  j                  | j
                  j                  d      | _        y )NT)super__init__r   r   r   r&   clientserver)selfr&   r'   	__class__s      r   r*   zTCPLayer.__init__D   sB    !DIDLL$7$79L9LdSDIr   returnc              #   (  K   | j                   rt        | j                          | j                  j                  j                  t        j                  | j                  j                        }|r| j                   rDt        j                  t        |            | j                   _	        t        | j                          t        j                  | j                  j                         | j                  | _        y | j                  | _        y w)N)r   r   r&   r,   timestamp_startr   OpenConnectionErrorstrerrorr!   CloseConnectionr+   done_handle_eventrelay_messages)r-   _errs      r   startzTCPLayer.startK   s     99tyy))<<..6 //0C0CDDC99&*jjS&:DIIO&tyy11..t||/B/BCC%)YY"!00s   DDeventc              #     K   t        |t              rjt        j                  |j                  j
                  r| j                  j                  n| j                  j                  |j                  j                        }t        |t        j                        sJ |j                  | j                  j                  k(  }|r| j                  j                  }n| j                  j                  }t        |t        j                        r| j                  rt        j                  ||j                        }| j                  j                   j#                  |       t%        | j                         t'        j(                  ||j                         y t'        j(                  ||j                         y t        |t        j*                        r~| j                  j                  j,                  t.        j0                  z  xs1 | j                  j                  j,                  t.        j0                  z   }|r| j2                  | _        | j                  j                  j,                  t.        j6                  ur+t'        j8                  | j                  j                         | j                  j                  j,                  t.        j6                  ur+t'        j8                  | j                  j                         | j                  rCt;        | j                         d| j                  _        y t'        j>                  |d       y y tA        d|       w)NFT)
half_closezUnexpected event: )!
isinstancer#   r	   DataReceivedmessagefrom_clientr&   r+   r,   contentConnectionEvent
connectionr   r   
TCPMessagedatamessagesappendr   r   SendDataConnectionClosedstater   CAN_READr7   r8   CLOSEDr6   r   liveCloseTcpConnectionAssertionError)r-   r=   rC   send_totcp_messageall_dones         r   r9   zTCPLayer.relay_messages]   sV    e/0''==,, ##\\((%%	E %!7!7888&&$,,*=*==ll))Gll))GeV001yy!nn[%**E		""))+6$TYY//''1D1DEE''<<v667$$**_-E-EE JLL''--0H0HHH %)YY"<<&&,,O4J4JJ"224<<3F3FGG<<&&,,O4J4JJ"224<<3F3FGG99$TYY//%*DIIN11'dKK	  !#5eW!=>>s   MMc              #   $   K   dE d {    y 7 w)Nr   r   )r-   r:   s     r   r7   zTCPLayer.done   s     s   )F)r   r   r   r   r   r   r   r   boolr*   r   r	   Startr
   CommandGeneratorr<   r8   rA   rL   r#   Eventr9   r7   __classcell__)r.   s   @r   r%   r%   =   s     ++
T T T FLL1%006 1 1 MF!8!8:LM-?FLL -?U5K5KD5Q -? N-?^ F!8!8:LM//5  Nr   r%   N)dataclassesr   	mitmproxyr   r   mitmproxy.connectionr   r   mitmproxy.proxyr   r	   r
   mitmproxy.proxy.commandsr   mitmproxy.proxy.contextr   mitmproxy.proxy.eventsr   mitmproxy.proxy.utilsr   r   r   r   r!   rG   r#   Layerr%   r   r   r   <module>re      s    !   + 0 $ " ! . + 2 ( 9   Y      9  8 Ru{{ Rr   