
    mbi                         d dl mZ d dlZd dlZd dlmZ d dlmZmZ ddl	m
Z
 ddl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j                  Zedddddd%d$Z dS )&    )annotationsN)partial)Callablecast   )Buffer)QuicConfiguration)NetworkAddressQuicConnection)QuicPacketTypeencode_quic_retryencode_quic_version_negotiationpull_quic_header)QuicRetryTokenHandler)SessionTicketFetcherSessionTicketHandler   )QuicConnectionProtocolQuicStreamHandlerservec                  R    e Zd Zedddddd#dZd Zd$dZd%dZd&d Zd'd!Z	d(d"Z
dS ))
QuicServerNFcreate_protocolsession_ticket_fetchersession_ticket_handlerretrystream_handlerconfigurationr	   r   r   r   SessionTicketFetcher | Noner   SessionTicketHandler | Noner   boolr   QuicStreamHandler | NonereturnNonec                   || _         || _        t          j                    | _        i | _        || _        || _        d | _        || _	        |rt                      | _        d S d | _        d S N)_configuration_create_protocolasyncioget_running_loop_loop
_protocols_session_ticket_fetcher_session_ticket_handler
_transport_stream_handlerr   _retry)selfr   r   r   r   r   r   s          b/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/qh3/asyncio/server.py__init__zQuicServer.__init__   sn     , /-//
?A'=$'=$<@- 	/11DKKKDKKK    c                    t          | j                                                  D ]}|                                 | j                                         | j                                         d S r'   )setr-   valuescloseclearr0   )r3   protocols     r4   r:   zQuicServer.close2   sh    DO224455 	 	HNNr6   	transportasyncio.BaseTransportc                D    t          t          j        |          | _        d S r'   )r   r*   DatagramTransportr0   )r3   r=   s     r4   connection_madezQuicServer.connection_made8   s    w8)DDr6   databytes | straddrr
   c                @   t          t          |          }t          |          }	 t          || j        j                  }n# t          $ r Y d S w xY w|j        T|j        | j        j        vrA| j	        
                    t          |j        |j        | j        j                  |           d S | j                            |j        d           }d }d }|t!          |          dk    r|j        t$          j        k    r| j        |j        sqt-          j        d          }| j	        
                    t1          |j        ||j        |j        | j                            ||j        |                    |           d S 	 | j                            ||j                  \  }}n# t          $ r Y d S w xY w|j        }t7          | j        ||| j        | j                  }	|                     |	| j                  }|                     | j	                   tC          | j"        |	          |_#        tC          | j$        |	          |_%        tC          | j&        |	          |_'        || j        |j        <   || j        |	j(        <   ||)                    ||           d S d S )
N)rB   )host_cid_length)
source_ciddestination_cidsupported_versionsi     )versionrG   rH   original_destination_cidretry_token)r   "original_destination_connection_idretry_source_connection_idr   r   )r   )r<   )*r   bytesr   r   r(   connection_id_length
ValueErrorrK   rI   r0   sendtor   rH   rG   r-   getlenpacket_typer   INITIALr2   tokenosurandomr   create_tokenvalidate_tokenr   r.   r/   r)   r1   rA   r   _connection_id_issued_connection_id_issued_handler_connection_id_retired_connection_id_retired_handler_connection_terminated_connection_terminated_handlerhost_ciddatagram_received)
r3   rB   rD   bufheaderr<   rN   rO   rG   
connections
             r4   rd   zQuicServer.datagram_received;   s   E4  $	%T%8%M  FF  	 	 	FF	
 N&d&9&LLLO""/%5$*$5'+':'M  
    F?&&v'=tDD;?*37"D		T!!"n&<<< {&| !#AJO**)$*N'1,2,=5;5K(,(@(@ $f&<j) )      F !K66tV\JJ>66%    6<5K2 ("13U+E'+'C'+'C  J ,,4+? -  H $$T_555 6=*X6 6 6H2 7>+h7 7 7H3 7>+h7 7 7H3 7?DOF233;DOJ/0&&tT22222  s#   A 
AA #F$ $
F21F2cidrP   r<   r   c                    || j         |<   d S r'   r-   r3   rh   r<   s      r4   r]   z QuicServer._connection_id_issued   s    'r6   c                <    | j         |         |k    sJ | j         |= d S r'   rj   rk   s      r4   r_   z!QuicServer._connection_id_retired   s,     s#x////OC   r6   c                z    t          | j                                                  D ]\  }}||k    r| j        |= d S r'   )listr-   items)r3   r<   rh   protos       r4   ra   z!QuicServer._connection_terminated   sK    t446677 	) 	)JC  OC(	) 	)r6   )r   r	   r   r   r   r    r   r!   r   r"   r   r#   r$   r%   )r=   r>   r$   r%   )rB   rC   rD   r
   r$   r%   )rh   rP   r<   r   )rh   rP   r<   r   r$   r%   )r<   r   )__name__
__module____qualname__r   r5   r:   rA   rd   r]   r_   ra    r6   r4   r   r      s        
 %;>B>B37     2     E E E E\3 \3 \3 \3|( ( ( (! ! ! !) ) ) ) ) )r6   r   Fr   hoststrportintr   r	   r   r   r   r    r   r!   r   r"   r   r   r$   c                  K   t          j                    }|                    fd| |f           d{V \  }	}
|
S )aQ  
    Start a QUIC server at the given `host` and `port`.

    :func:`serve` requires a :class:`~qh3.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:`~qh3.asyncio.QuicConnectionProtocol` and returning
      an instance of :class:`~qh3.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   r4   <lambda>zserve.<locals>.<lambda>   s(    
'+#9#9)
 
 
 r6   )
local_addrN)r*   r+   create_datagram_endpoint)ru   rw   r   r   r   r   r   r   loop_r<   s     ``````   r4   r   r      s      H #%%D55	
 	
 	
 	
 	
 	
 	
 	
 	
 $< 6 
 
 
 
 
 
 
 
KAx Or6   )ru   rv   rw   rx   r   r	   r   r   r   r    r   r!   r   r"   r   r   r$   r   )!
__future__r   r*   rY   	functoolsr   typingr   r   _hazmatr   quic.configurationr	   quic.connectionr
   r   quic.packetr   r   r   r   
quic.retryr   tlsr   r   r<   r   r   __all__DatagramProtocolr   r   rt   r6   r4   <module>r      s   " " " " " "  				       ! ! ! ! ! ! ! !       2 2 2 2 2 2 < < < < < < < <            / . . . . . < < < < < < < < ? ? ? ? ? ? ? ?)M) M) M) M) M)) M) M) M)j !7:>:>(,1 1 1 1 1 1 1 1r6   