
    @OOf                      &   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZ dgZ  G d de jB                        Z"edddddde#de$dededee   dee   de%dede"fdZ&y)    N)partial)CallableDictOptionalTextUnioncast   )Buffer)SMALLEST_MAX_DATAGRAM_SIZEQuicConfiguration)NetworkAddressQuicConnection)PACKET_TYPE_INITIALencode_quic_retryencode_quic_version_negotiationpull_quic_header)QuicRetryTokenHandler)SessionTicketFetcherSessionTicketHandler   )QuicConnectionProtocolQuicStreamHandlerservec                       e Zd Zeddddddededee   dee   de	d	ee
   d
dfdZd Zdej                  d
dfdZdeeef   ded
dfdZdedefdZdeded
dfdZdefdZy)
QuicServerNFcreate_protocolsession_ticket_fetchersession_ticket_handlerretrystream_handlerconfigurationr   r   r    r!   r"   returnc                    || _         || _        t        j                         | _        i | _        || _        || _        d | _        || _	        |rt               | _        y d | _        y N)_configuration_create_protocolasyncioget_event_loop_loop
_protocols_session_ticket_fetcher_session_ticket_handler
_transport_stream_handlerr   _retry)selfr#   r   r   r    r!   r"   s          W/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/aioquic/asyncio/server.py__init__zQuicServer.__init__   s^     , /++-
?A'=$'=$?C-/1DKDK    c                     t        | j                  j                               D ]  }|j                           | j                  j	                          | j
                  j                          y r&   )setr,   valuescloseclearr/   )r2   protocols     r3   r9   zQuicServer.close0   sM    DOO2245 	HNN	r5   	transportc                 B    t        t        j                  |      | _        y r&   )r	   r)   DatagramTransportr/   )r2   r<   s     r3   connection_madezQuicServer.connection_made6   s    w88)Dr5   dataaddrc                    t        t        |      }t        |      }	 t        || j                  j
                        }|j                  s|j                  | j                  j                  vrQ| j                  j                  t        |j                  |j                  | j                  j                        |       y | j                  j                  |j                  d       }d }d }|t!        |      t"        k\  r|j$                  t&        k(  r| j(                  |j*                  st-        j.                  d      }| j                  j                  t1        |j                  ||j                  |j                  | j(                  j3                  ||j                  |            |       y 	 | j(                  j5                  ||j*                        \  }}n|j                  }t7        | j                  ||| j8                  | j:                        }	| j=                  |	| j>                        }|jA                  | j                         tC        | jD                  |      |_#        tC        | jH                  |      |_%        tC        | jL                  |      |_'        || j                  |j                  <   || j                  |	jP                  <   ||jS                  ||       y y # t        $ r Y y w xY w# t        $ r Y y w xY w)	N)r@   )host_cid_length)
source_ciddestination_cidsupported_versions   )versionrD   rE   original_destination_cidretry_token)r#   "original_destination_connection_idretry_source_connection_idr   r    )r"   )r;   )*r	   bytesr   r   r'   connection_id_length
ValueErrorrH   rF   r/   sendtor   rE   rD   r,   getlenr   packet_typer   r1   tokenosurandomr   create_tokenvalidate_tokenr   r-   r.   r(   r0   r?   r   _connection_id_issued_connection_id_issued_handler_connection_id_retired_connection_id_retired_handler_connection_terminated_connection_terminated_handlerhost_ciddatagram_received)
r2   r@   rA   bufheaderr;   rK   rL   rD   
connections
             r3   r`   zQuicServer.datagram_received9   s   E4 $	%T%8%8%M%MF NN&d&9&9&L&LLOO""/%55$*$5$5'+':':'M'M
  ??&&v'='=tD>B*6:"D	77""&99 {{&||!#AJOO**)$*NN'1,2,=,=5;5K5K(,(@(@ $f&<&<j)   !KK66tV\\J>6
 6<5K5K2 ("113U+E'+'C'C'+'C'CJ ,,4+?+? - H $$T__5 6=**X6H2 7>++h7H3 7>++h7H3 7?DOOF2233;DOOJ//0&&tT2  g  		f & s#   !K& .)K5 &	K21K25	L Lcidr;   c                 "    || j                   |<   y r&   r,   r2   rd   r;   s      r3   rY   z QuicServer._connection_id_issued   s    'r5   c                 F    | j                   |   |k(  sJ | j                   |= y r&   rf   rg   s      r3   r[   z!QuicServer._connection_id_retired   s'     s#x///OOC r5   c                     t        | j                  j                               D ]  \  }}||k(  s| j                  |=  y r&   )listr,   items)r2   r;   rd   protos       r3   r]   z!QuicServer._connection_terminated   s;    t4467 	)JC OOC(	)r5   )__name__
__module____qualname__r   r   r   r   r   r   boolr   r4   r9   r)   BaseTransportr?   r   rM   r   r   r`   rY   r[   r]    r5   r3   r   r      s    
 %;AEAE6: ) "	
 !))= > !))= >  !!23 
2 E)>)> E4 E\3eE4K&8 \3 \3SW \3|( (:P (!!$:!	!)/E )r5   r   Fr   hostportr#   r   r   r    r!   r"   r$   c                   K   t        j                         }|j                  fd| |f       d{   \  }	}
|
S 7 	w)a]  
    Start a QUIC server at the given `host` and `port`.

    :func:`serve` requires a :class:`~aioquic.quic.configuration.QuicConfiguration`
    containing TLS certificate and private key as the ``configuration`` argument.

    :func:`serve` also accepts the following optional arguments:

    * ``create_protocol`` allows customizing the :class:`~asyncio.Protocol` that
      manages the connection. It should be a callable or class accepting the same
      arguments as :class:`~aioquic.asyncio.QuicConnectionProtocol` and returning
      an instance of :class:`~aioquic.asyncio.QuicConnectionProtocol` or a subclass.
    * ``session_ticket_fetcher`` is a callback which is invoked by the TLS
      engine when a session ticket is presented by the peer. It should return
      the session ticket with the specified ID or `None` if it is not found.
    * ``session_ticket_handler`` is a callback which is invoked by the TLS
      engine when a new session ticket is issued. It should store the session
      ticket for future lookup.
    * ``retry`` specifies whether client addresses should be validated prior to
      the cryptographic handshake using a retry packet.
    * ``stream_handler`` is a callback which is invoked whenever a stream is
      created. It must accept two arguments: a :class:`asyncio.StreamReader`
      and a :class:`asyncio.StreamWriter`.
    c                  &    t               S )N)r#   r   r   r    r!   r"   )r   )r#   r   r!   r   r    r"   s   r3   <lambda>zserve.<locals>.<lambda>   s    
'+#9#9)
 r5   )
local_addrN)r)   r*   create_datagram_endpoint)rs   rt   r#   r   r   r    r!   r"   loop_r;   s     ``````   r3   r   r      sU     H !!#D55	
 	
 $< 6 
 
KAx O
s   5A	A
A	)'r)   rU   	functoolsr   typingr   r   r   r   r   r	   bufferr   quic.configurationr   r   quic.connectionr   r   quic.packetr   r   r   r   
quic.retryr   tlsr   r   r;   r   r   __all__DatagramProtocolr   strintrp   r   rr   r5   r3   <module>r      s     	  > >  N <  / < ?)M))) M)j !7=A=A(,1
1
1 %	1
 1 %%9:1 %%9:1 1 &1 1r5   