
    @OOf=                     b   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j.                           Z G d de
j2                        Zy)    )	dataclass)flow)udp)
Connection)commands)events)layer)	StartHook)Context)MessageInjected)expectc                   0    e Zd ZU dZej
                  ed<   y)UdpStartHookz'
    A UDP connection has started.
    r   N__name__
__module____qualname____doc__r   UDPFlow__annotations__     [/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/proxy/layers/udp.pyr   r           ++r   r   c                   0    e Zd ZU dZej
                  ed<   y)UdpMessageHookz
    A UDP 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)
UdpEndHookz%
    A UDP 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)UdpErrorHookzy
    A UDP error has occurred.

    Every UDP flow will receive either a udp_error or a udp_end event, but not both.
    r   Nr   r   r   r   r    r    +   s     ++r   r    c                       e Zd ZdZy)UdpMessageInjectedz5
    The user has injected a custom UDP message.
    N)r   r   r   r   r   r   r   r"   r"   6   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 )UDPLayerz?
    Simple UDP 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UDPLayer.__init__C   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UDPLayer.startJ   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              #   v  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,                  | _        t'        j0                  |       | j                  r)t3        | j                         d| j                  _        y y t7        d|       w)NFzUnexpected event: )
isinstancer"   r   DataReceivedmessagefrom_clientr%   r*   r+   contentConnectionEvent
connectionr   r   
UDPMessagedatamessagesappendr   r   SendDataConnectionClosedr6   r7   r5   r   liveAssertionError)r,   r<   rA   send_toudp_messages        r   r8   zUDPLayer.relay_messages\   s    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!%D**733yy ++!&		  !#5eW!=>>s   H7H9c              #   $   K   dE d {    y 7 w)Nr   r   )r,   r9   s     r   r6   zUDPLayer.done   s     s   )F)r   r   r   r   r   r   r   r   boolr)   r   r   Startr	   CommandGeneratorr;   r7   r?   rJ   r"   Eventr8   r6   __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#?J F!8!8:LM//5  Nr   r$   N)dataclassesr   	mitmproxyr   r   mitmproxy.connectionr   mitmproxy.proxyr   r   r	   mitmproxy.proxy.commandsr
   mitmproxy.proxy.contextr   mitmproxy.proxy.eventsr   mitmproxy.proxy.utilsr   r   r   r   r    rE   r"   Layerr$   r   r   r   <module>r^      s    !   + $ " ! . + 2 ( 9   Y      9  8 Hu{{ Hr   