
    mbi)                      d dl mZ d dlZd dlZd dlZd dl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 erdd	lmZ dd
lmZ ddlmZ ddlmZmZmZ ddlmZmZmZ ddlm Z! ddlm"Z" ddl#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZEmFZF ddlGmHZHmIZImJZJ  ejK        d          ZdZLejM        jN        ejM        jO        ejM        jP        ejM        jQ        dZRdZSdZTdZUdZVg dg dgZWdZXd ZYd!ZZd"Z[eZ\d#Z]ddez  z   Z^dez   Z_dZ`ddez  z   Zaddez  z   dz   e)z   e-z   Zbd$Zcd$ZddZedd%ez  z   Zfdez   Zgddez  z   Zhdez   Zidd%ez  z   ZjdMd*ZkdNd/ZldOd2ZmdPd6ZndQd8ZodQd9Zp e            dRd;            Zq e            dRd<            Zr G d= d>          Zs G d? d@et          Zu G dA dBejv                  Zw edSi e G dC dD                      Zx G dE dFe
          Zy G dG dH          Zz edSi e G dI dJ                      Z{ e|eyj}        eyj~        eyj        g          Z G dK dL          ZdS )T    )annotationsN)deque)	dataclass)IntEnum)	lru_cachepartial)TYPE_CHECKINGAnySequence   )QuicConfiguration)QuicLoggerTrace   )tls)DATACLASS_KWARGSUINT_VAR_MAXUINT_VAR_MAX_SIZE)BufferBufferReadErrorsize_uint_var)Certificate)events)CryptoError
CryptoPairKeyUnavailableError
NoCallback)CONNECTION_ID_MAX_SIZENON_ACK_ELICITING_FRAME_TYPESPROBING_FRAME_TYPESRETRY_INTEGRITY_TAG_SIZESTATELESS_RESET_TOKEN_SIZEQuicErrorCodeQuicFrameType
QuicHeaderQuicPacketTypeQuicProtocolVersionQuicStreamFrameQuicTransportParametersQuicVersionInformationget_retry_integrity_tagget_spin_bitpretty_protocol_versionpull_ack_framepull_quic_headerpull_quic_transport_parameterspush_ack_framepush_quic_transport_parameters)PACKET_MAX_SIZEQuicDeliveryStateQuicPacketBuilderQuicPacketBuilderStop)K_GRANULARITYQuicPacketRecoveryQuicPacketSpace)FinalSizeError
QuicStreamStreamFinishedErrorquic @  )IH01l           d   )NCLIENT_EARLY_TRAFFIC_SECRETCLIENT_HANDSHAKE_TRAFFIC_SECRETCLIENT_TRAFFIC_SECRET_0)NNSERVER_HANDSHAKE_TRAFFIC_SECRETSERVER_TRAFFIC_SECRET_0   l               i   @   	      shortcutstrreturnfrozenset[tls.Epoch]c                4    t          d | D                       S )Nc              3  0   K   | ]}t           |         V  d S N)EPOCH_SHORTCUTS).0is     c/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/qh3/quic/connection.py	<genexpr>zEPOCHS.<locals>.<genexpr>l   s'      ::A_Q'::::::    )	frozenset)rO   s    rY   EPOCHSr]   k   s    ::::::::r[   from_versionint
to_versionboolc                >    | |ht           j        t           j        hk    S )zz
    Return whether it is possible to perform compatible version negotiation
    from `from_version` to `to_version`.
    )r&   	VERSION_1	VERSION_2)r^   r`   s     rY   is_version_compatiblere   o   s'     *%%%*  r[   cidbytesc                P    t          j        |                               d          S )Nascii)binasciihexlifydecode)rf   s    rY   dump_cidrm   |   s!    C  ''000r[   packet_typer%   	tls.Epochc                    | t           j        k    rt          j        j        S | t           j        k    rt          j        j        S | t           j        k    rt          j        j        S t          j        j        S rU   )r%   INITIALr   EpochZERO_RTT	HANDSHAKEONE_RTT)rn   s    rY   	get_epochrv      sX    n,,,y  	/	/	/y!!	0	0	0y""y  r[   	stream_idc                    | dz   S )z9
    Returns True if the stream is client initiated.
    r    rw   s    rY   stream_is_client_initiatedr{      s     Ar[   c                    | dz  rdS dS )z7
    Returns True if the stream is unidirectional.
    r   TFry   rz   s    rY   stream_is_unidirectionalr}      s     1} t5r[   	is_clientc                D    t          |          | u pt          |           S rU   r{   r}   r~   rw   s     rY   check_stream_id_for_sendingr      s2    % 	 >29===>r[   c                D    t          |          | upt          |           S rU   r   r   s     rY   check_stream_id_for_receivingr      s4    %  B6yAAABr[   c                      e Zd ZddZdS )	Limit
frame_typer_   namerP   valuec                L    || _         || _        || _        d| _        || _        d S Nr   )r   r   sentusedr   )selfr   r   r   s       rY   __init__zLimit.__init__   s)    $			


r[   N)r   r_   r   rP   r   r_   )__name__
__module____qualname__r   ry   r[   rY   r   r      s(             r[   r   c                      e Zd ZddZdd	Zd
S )QuicConnectionError
error_coder_   r   
int | Nonereason_phraserP   c                0    || _         || _        || _        d S rU   r   r   r   r   r   r   r   s       rY   r   zQuicConnectionError.__init__   s    $$*r[   rQ   c                R    d| j          d| j         }| j        |d| j         z  }|S )NzError: z
, reason: z, frame_type: )r   r   r   )r   ss     rY   __str__zQuicConnectionError.__str__   s>    EdoEE1CEE?&3$/333Ar[   N)r   r_   r   r   r   rP   )rQ   rP   )r   r   r   r   r   ry   r[   rY   r   r      s<        + + + +
     r[   r   c                      e Zd Zd	dZdS )
QuicConnectionAdaptermsgrP   kwargsr
   rQ   tuple[str, Any]c                H    d                     | j        d         |          |fS )Nz[{}] {}id)formatextra)r   r   r   s      rY   processzQuicConnectionAdapter.process   s$    
4 0#66>>r[   N)r   rP   r   r
   rQ   r   )r   r   r   r   ry   r[   rY   r   r      s(        ? ? ? ? ? ?r[   r   c                  @    e Zd ZU ded<   ded<   dZded<   dZded	<   d
S )QuicConnectionIdrg   rf   r_   sequence_numberr[   stateless_reset_tokenFra   was_sentN)r   r   r   __annotations__r   r   ry   r[   rY   r   r      sJ         JJJ#&&&&&Hr[   r   c                  "    e Zd ZdZdZdZdZdZdS )QuicConnectionStater   r   r   rN      N)r   r   r   FIRSTFLIGHT	CONNECTEDCLOSINGDRAINING
TERMINATEDry   r[   rY   r   r      s'        KIGHJJJr[   r   c                       e Zd ZdddZdd
ZdS )QuicNetworkPathFaddrNetworkAddressis_validatedra   c                r    || _         d| _        d| _        || _        d| _        t                      | _        d S )Nr   F)r   bytes_received
bytes_sentr   local_challenge_sentr   remote_challenges)r   r   r   s      rY   r   zQuicNetworkPath.__init__   s:    $(	#$ ".*/!/4wwr[   sizer_   rQ   c                <    | j         p| j        |z   d| j        z  k    S )NrN   )r   r   r   )r   r   s     rY   can_sendzQuicNetworkPath.can_send   s$     WT_t%;DDW@W$WWr[   NF)r   r   r   ra   )r   r_   rQ   ra   )r   r   r   r   r   ry   r[   rY   r   r      sG        7 7 7 7 7X X X X X Xr[   r   c                  L    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   dS )QuicReceiveContextro   epochrg   host_cidr   network_pathzlist[Any] | Nonequic_logger_framesfloattimer   versionN)r   r   r   r   ry   r[   rY   r   r      sT         OOO!!!!((((KKKr[   r   c                     e Zd ZdZdZdddddddZedd            Zedd            Zedd            Z	ddZ
ddZddZedd            Zedd            ZddZej        ddfdd%Zdd*Zdd,Zddd.Zdd0Zdd1Zdd3Zdd5Zdd6Zdd8Zdd:Zdd;Z	 ddd>Zdd?ZddAZ ddBZ!ddCZ"ddDZ#ddFZ$ddGZ%ddHZ&ddKZ'ddMZ(ddOZ)ddPZ*ddSZ+ddUZ,ddZZ-dd[Z.dd\Z/dd]Z0dd^Z1dd_Z2dd`Z3ddaZ4ddbZ5ddcZ6dddZ7ddeZ8ddfZ9ddgZ:ddhZ;ddiZ<ddjZ=ddkZ>ddlZ?ddmZ@ddnZAddoZBddrZCddsZDddyZEdd|ZFdd}ZGddZHddZIddZJddZK	 dddZLddZMddZNddZOddZPddZQddZR	 dddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcg dfddZdddZeddZfddZgddZhddZiddZjdS )QuicConnectiona  
    A QUIC connection.

    The state machine is driven by three kinds of sources:

    - the API user requesting data to be send out (see :meth:`connect`,
      :meth:`reset_stream`, :meth:`send_ping`, :meth:`send_datagram_frame`
      and :meth:`send_stream_data`)
    - data being received from the network (see :meth:`receive_datagram`)
    - a timer firing (see :meth:`handle_timer`)

    :param configuration: The QUIC configuration to use.
    )T_configuration
_is_client
_ack_delay	_close_at_close_event_connect_called_cryptos_cryptos_initial_crypto_buffers_crypto_frame_type_crypto_packet_version_crypto_retransmitted_crypto_streams_events_handshake_complete_handshake_confirmed
_host_cidsr   _host_cid_seq_local_ack_delay_exponent!_local_active_connection_id_limit_local_challenges#_local_initial_source_connection_id_local_max_data!_local_max_stream_data_bidi_local"_local_max_stream_data_bidi_remote_local_max_stream_data_uni_local_max_streams_bidi_local_max_streams_uni_local_next_stream_id_bidi_local_next_stream_id_uni_loss_at_network_paths
_pacing_at_packet_number	_peer_cid_peer_cid_available_peer_cid_sequence_numbers_peer_retire_prior_to_peer_token_quic_logger_remote_ack_delay_exponent"_remote_active_connection_id_limit$_remote_initial_source_connection_id_remote_max_idle_timeout_remote_max_data_remote_max_data_used_remote_max_datagram_frame_size"_remote_max_stream_data_bidi_local#_remote_max_stream_data_bidi_remote_remote_max_stream_data_uni_remote_max_streams_bidi_remote_max_streams_uni_remote_version_information_retry_count_retry_source_connection_id_spaces	_spin_bit_spin_highest_pn_state_streams_streams_queue_streams_blocked_bidi_streams_blocked_uni_streams_finished_version_version_negotiated_compatible _version_negotiated_incompatible#_original_destination_connection_id_logger_loss_close_pending_datagrams_pending_handshake_done_pending_ping_pending_probe_pending_retire_connection_ids_streams_blocked_pending_session_ticket_fetcher_session_ticket_handler__frame_handlersr   _local_max_data_used_initial_source_connection_idN)"original_destination_connection_idretry_source_connection_idsession_ticket_fetchersession_ticket_handlerconfigurationr   r!  bytes | Noner"  r#  tls.SessionTicketFetcher | Noner$  tls.SessionTicketHandler | NonerQ   Nonec                  |j         r|
J d            |
J d            n.|j        
J d            |j        
J d            |
J d            || _        |j         | _        t
          | _        d | _        d | _        d| _	        i | _
        i | _        i | _        d | _        d | _        d| _        i | _        t#                      | _        d| _        d| _        t+          t-          j        |j                  d| j        st-          j        d          nd d	
          g| _        | j        d         j        | _        d| _        d| _        d| _        i | _        | j        d         j        | _         tC          tD          j#        d|j$                  | _%        |j&        | _'        |j&        | _(        |j&        | _)        tC          tD          j*        dd          | _+        tC          tD          j,        dd          | _-        | j        rdnd| _.        | j        rdnd| _/        d | _0        g | _1        d | _2        d| _3        t+          t-          j        |j                  d           | _4        g | _5        dh| _6        d| _7        d| _8        d | _9        d| _:        d| _;        d | _<        d| _=        d| _>        d| _?        d | _@        d| _A        d| _B        d| _C        d| _D        d| _E        d | _F        d| _G        || _H        i | _I        d| _J        d| _K        t          jM        | _N        i | _O        g | _P        g | _Q        g | _R        t                      | _T        d | _U        d| _V        d| _W        | j        r| j4        j        | _X        n|| _X        t          t          dt          | jX                  i          | _\        |j]        r+|j]        ^                    |j         | jX                  | _9        t          |j`        | j         | j9        | ja        | j\                  | _b        d| _c        t#                      | _d        d| _e        g | _f        d| _g        g | _h        d| _i        || _j        || _k        i d| jl        t          d          fd| jn        t          d          fd| jo        t          d          fd| jo        t          d          fd| jp        t          d          fd| jq        t          d          fd| jr        t          d          fd | js        t          d!          fd| jt        t          d          fd"| jt        t          d          fd#| jt        t          d          fd$| jt        t          d          fd%| jt        t          d          fd&| jt        t          d          fd'| jt        t          d          fd(| jt        t          d          fd| ju        t          d          fi d)| jv        t          d          fd*| jw        t          d          fd+| jx        t          d          fd,| jy        t          d          fd-| jz        t          d          fd.| j{        t          d          fd/| j{        t          d          fd0| j|        t          d          fd1| j}        t          d          fd2| j~        t          d          fd3| j        t          d          fd4| j        t          d          fd5| j        t          d          fd6| j        t          d!          fd7| j        t          d          fd8| j        t          d          f| _        d S )9Nz:Cannot set original_destination_connection_id for a clientz2Cannot set retry_source_connection_id for a clientz(SSL certificate is required for a serverz(SSL private key is required for a serverz;original_destination_connection_id is required for a serverFr      T)rf   r   r   r   r   rN   rK   max_data)r   r   r   max_streams_bidi   max_streams_unir   )rf   r   r[   g        r   )r~   odcid)initial_rtt!peer_completed_address_validationquic_logger
send_probeloggerIH01IH1r   01rC      rJ   rA   rM   
                                                            0   1   )r~   certificateprivate_keyr   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   osurandomconnection_id_lengthr   rf   r   r   r   r   r   r   r   r#   MAX_DATAr,  r   max_stream_datar   r   r   MAX_STREAMS_BIDIr   MAX_STREAMS_UNIr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r   r   r	  r
  r  r  r  setr  r  r  r  r  r   r5  rm   r  r3  start_tracer7   r1  _send_prober  r  r  r  r  r  r  r  r  r  _handle_padding_framer]   _handle_ping_frame_handle_ack_frame_handle_reset_stream_frame_handle_stop_sending_frame_handle_crypto_frame_handle_new_token_frame_handle_stream_frame_handle_max_data_frame_handle_max_stream_data_frame_handle_max_streams_bidi_frame_handle_max_streams_uni_frame_handle_data_blocked_frame!_handle_stream_data_blocked_frame_handle_streams_blocked_frame_handle_new_connection_id_frame"_handle_retire_connection_id_frame_handle_path_challenge_frame_handle_path_response_frame_handle_connection_close_frame_handle_handshake_done_frame_handle_datagram_frame_QuicConnection__frame_handlers)r   r%  r!  r"  r#  r$  s         rY   r   zQuicConnection.__init__Z  s/    " 	5==L >== .55D 6555 !,88: 988 !,88: 988 6AAM BAA
 ,'1''+@D$57798:.226#%*"<>05#( $)!J}ABB !<@O&UbjnnnQU	  
 *.)*&12.?A37?13E3I0$$-( 
  
  

 2?1N.2?2O/*7*G'',$5#(
 (
 (
$
 ',$4;LTW'
 '
 '
# 04*E!!A'.2o)D1&&*57(,)
==>>PT
 
 
 <> 56C'%&"48*+'23/BF1(+% !%&";?,23/340+,(()%'($JN(+E(9; !)5/10279"68!+.55$(.3+05-? 	7;~7ID44 3 4
 -T8D$LMMN
 
 $ 	 - 9 E E'1> !F ! !D (%126/.A)'<
 
 

 $05',$(*#13#(-% (>$'=$"!
4-vf~~>"!
4*F6NN;"!
 4)6%==9"!
 4)6%==9	"!

 42F4LLA"!
 42F4LLA"!
 4,fUmm<"!
 4/="!
 4,fTll;"!
 4,fTll;"!
 4,fTll;"!
 4,fTll;"!
 4,fTll;"!
 4,fTll;"!
 4,fTll;"!
  4,fTll;!"!
" 4.t=#"!
 "!
$ 45vd||D%"!
& 46tE'"!
( 45vd||D)"!
* 42F4LLA+"!
, 496$<<H-"!
. 45vd||D/"!
0 45vd||D1"!
2 47F3"!
4 4:F4LLI5"!
6 44fTllC7"!
8 43VD\\B9"!
: 46vG;"!
< 46tE="!
> 44fSkkB?"!
@ 4.t=A"!
B 4.t=C"!
 "!
r[   r_   c                *    t          | j                  S rU   )lenr
  r   s    rY   open_outbound_streamsz$QuicConnection.open_outbound_streams  s    4=!!!r[   c                    | j         S rU   )r  ru  s    rY   max_concurrent_bidi_streamsz*QuicConnection.max_concurrent_bidi_streams  s    ,,r[   c                    | j         S rU   )r  ru  s    rY   max_concurrent_uni_streamsz)QuicConnection.max_concurrent_uni_streams#  s    ++r[   tls.CipherSuite | Nonec                @    | j         j        r| j         j        j        nd S rU   )r   key_schedulecipher_suiteru  s    rY   
get_cipherzQuicConnection.get_cipher'  s     59X5JTtx$11PTTr[   X509Certificate | Nonec                    | j         j        S rU   )r   peer_certificateru  s    rY   get_peercertzQuicConnection.get_peercert*  s    x((r[   list[X509Certificate]c                    | j         j        S rU   )r   peer_certificate_chainru  s    rY   get_issuercertszQuicConnection.get_issuercerts-  s    x..r[   c                    | j         S rU   )r   ru  s    rY   r%  zQuicConnection.configuration0  s    ""r[   rg   c                    | j         S rU   )r  ru  s    rY   r!  z1QuicConnection.original_destination_connection_id4  s    77r[   c                t    | j         r0|                     | j                   |                                  dS dS )z
        Switch to the next available connection ID and retire
        the previous one.

        After calling this method call :meth:`datagrams_to_send` to retrieve data
        which needs to be sent.
        N)r   _retire_peer_cidr   _consume_peer_cidru  s    rY   change_connection_idz#QuicConnection.change_connection_id8  sI     # 	%!!$.111 ""$$$$$	% 	%r[    r   r   r   r   rP   c                ~    | j         3| j        t          vr't          j        |||          | _         d| _        dS dS dS )a  
        Close the connection.

        :param error_code: An error code indicating why the connection is
                           being closed.
        :param reason_phrase: A human-readable explanation of why the
                              connection is being closed.
        Nr   T)r   r	  
END_STATESr   ConnectionTerminatedr  r   s       rY   closezQuicConnection.closeG  sZ     $J)F)F & ;%%+! ! !D
 #'D %$)F)Fr[   r   r   nowr   c                   | j         r| j        r
J d            d| _        t          |d          g| _        | j        j        | j        j        | _        n| j        j        d         | _        |                     |           dS )aK  
        Initiate the TLS handshake.

        This method can only be called for clients and a single time.

        After calling this method call :meth:`datagrams_to_send` to retrieve data
        which needs to be sent.

        :param addr: The network address of the remote peer.
        :param now: The current time.
        z:connect() can only be called for clients and a single timeT)r   Nr   r  )	r   r   r   r   r   original_versionr  supported_versions_connect)r   r   r  s      rY   connectzQuicConnection.connect]  s      	
t'; 	
 	
H	
 	
 	
  $.t$GGGH/; /@DMM /B1EDM#r[   "list[tuple[bytes, NetworkAddress]]c                b   | j         d         }| j        t          v rg S t          | j        | j        | j        | j        j        | j	        | j
        | j        | j                  }| j        rAg }| j        s=|t          j        j        t$          j        ft          j        j        t$          j        fgz  }|                    t          j        j        t$          j        f           |D ]y\  }}| j        |         }|j                                        rN|                    ||           |                     ||| j        j        | j        j        | j        j                   z| j                             d| j        j        | j        j                   d| _        | !                    d|           n| j"        j#        | j"        j$        z
  |_%        | j&        r|j%        tN          k     rtN          |_%        |j(        s|j)        dz  |j*        z
  |_+        	 | j        s<t          j        j        t          j        j        fD ]}| ,                    |||           | -                    |||           n# t\          $ r Y nw xY w|/                                \  }}	|r*|j0        | _        d}
|	D ]}||_1        | j"        2                    || j3        |j4                 	           |j4        t          j        j        k    rd}
| j
        | j
        5                    dd|j6        |j0        | j
        7                    |j7                  |j7        t$          j        k    rdntq          | j                  tq          | j        j                  dd|j9        id           |
r+| j        r$| :                    t          j        j                   g }|D ]p}tw          |          }|xj*        |z  c_*        |                    ||j<        f           | j
        ,| j
        5                    dddtz          |z   |dgd           q|S )a1  
        Return a list of `(data, addr)` tuples of datagrams which need to be
        sent, and the network address to which they need to be sent.

        After calling this method call :meth:`get_timer` to know when the next
        timer needs to be set.

        :param now: The current time.
        r   )r   r~   packet_numberpeer_cid
peer_tokenr3  spin_bitr   )builderr   r   r   r   z,Connection close sent (code 0x%X, reason %s)FTis_initiatorr  rN   )packetspaceN	transportpacket_sentr  )r  rn   sciddcidlengthframesheaderrawcategoryeventdatadatagrams_sentr   r  payload_lengthcountr  )>r   r	  r  r4   r   r   r   r   rf   r   r   r  r  r  r   r   rr   rq   r%   rt   appendru   r   sendis_validstart_packet_write_connection_close_framer   r   r   r   r  debug_close_beginr  congestion_windowbytes_in_flightmax_flight_bytesr  r2   r   r   r   max_total_bytes_write_handshake_write_applicationr5   flushr  	sent_timeon_packet_sentr  r   	log_eventr   rn   rm   
sent_bytes_discard_epochrt  r   UDP_HEADER_SIZE)r   r  r   r  epoch_packet_typesr   rn   crypto	datagramspacketssent_handshaker  retdatagramr  s                  rY   datagrams_to_sendz QuicConnection.datagrams_to_sendu  s    *1-;*$$I $]o-^'')^M	
 	
 	
  .	!#, "Y&(>?Y(.*BC' " %%sy'8.:P&QRRR&8 
 
"{u-;'')) ((f===66 '##'#4#?#'#4#?&*&7&E 7    L>!,!/  
 #(D4S9999 
,tz/II $ " ;w'?/'Q'Q+:(  ,  /!3l6MM '0 C"%)"3SY5H!I C C--gucBBBB''sCCCC(    %]]__	7 &	7")"7D #N!  #& 
))!fl)C *    <39#666%)N $0%//!,+&,&?171E/3/@/L/L$*$60" 0"
 (.'9^=S'S'S %'B)1$-)@)@(01C(D(D' ' %-f.?#@  0   ,  7$/ 7##CI$5666 ! 	 	H ]]N##~5##JJ,"34555 ,!++(*!" +:N*J2@    ,    
s   AI& &
I32I3Fc                "    |r| j         S | j        S )zT
        Return the stream ID for the next stream created by this endpoint.
        )r   r   )r   is_unidirectionals     rY   get_next_available_stream_idz+QuicConnection.get_next_available_stream_id   s      	31122r[   float | Nonec                    | j         }| j        t          vrx| j        j        D ]}|j        |j        |k     r|j        }| j                                        | _        | j        | j        |k     r| j        }| j        | j        |k     r| j        }|S )z_
        Return the time at which the timer should fire or None if no timer is needed.
        )	r   r	  r  r  spacesack_atget_loss_detection_timer   r   )r   timer_atr  s      rY   	get_timerzQuicConnection.get_timer	  s     >;j((* , ,<+x0G0G$|H !J>>@@DM}(T]X-E-E= *t/I/I?r[   c                L   || j         k    rM| j        0t          j        t          j        t          j        d          | _        |                                  dS | j	        B|| j	        k    r9| j
                            d           | j                            |           dS dS dS )z
        Handle the timer.

        After calling this method call :meth:`datagrams_to_send` to retrieve data
        which needs to be sent.

        :param now: The current time.
        NzIdle timeoutr   zLoss detection triggeredr  )r   r   r   r  r"   INTERNAL_ERRORr#   PADDING
_close_endr   r  r  r  on_loss_detection_timeoutr   r  s     rY   handle_timerzQuicConnection.handle_timer  s     $.   ($*$?,;,4"0% % %!
 OOF =$)=)=L9:::J00S099999 %$)=)=r[   events.QuicEvent | Nonec                X    	 | j                                         S # t          $ r Y dS w xY w)zy
        Retrieve the next event from the event buffer.

        Returns `None` if there are no buffered events.
        N)r   popleft
IndexErrorru  s    rY   
next_eventzQuicConnection.next_event8  s=    	<''))) 	 	 	44	s    
))r  c                   | j         t          v rdS t          |          }| j        ,| j                            dddt
          |z   |dgd           |                     |          }|j        s|xj        |z  c_        | j	        || j
        j        z   | _	        t          |          }|                                s|                                }	 t          || j
        j        	          }nB# t"          $ r5 | j        *| j                            dd
dd|j        |z
  id           Y dS w xY wd}	| j        D ]}
|j        |
j        k    r	|
j        }	 n| j        r*|	(| j        | j                            dd
ddi           dS |j        t2          j        k    r|                     ||           dS |j        C|j        | j
        j        vr0| j        '| j                            dd
dd|j        id           dS |j        t2          j        k    rH|                      ||!                    ||                                tD          z
            |           dS d}| j        sb| j         tF          j$        u rO|j        t2          j%        k    s
J d            d}|g| _&        |j        | _'        | (                    |j                   tS          |j                  }|tT          j+        j%        k    r| j,        |j                 }n| j-        |         }|tT          j+        j.        k    r| j/        tT          j+        j0                 }n| j/        |         }|                                |z
  }||j        z   }|1                    |           	 |2                    |||         ||j3                  \  }}}n# th          $ r}| j5        6                    |           | j        '| j                            dd
dd|j        id           | j        rM|tT          j+        j7        tT          j+        j0        fv r)| j8        s"| j9        :                    |           d| _8        Y d}~d}~wtv          $ rS}| j5        6                    |           | j        '| j                            dd
dd|j        id           Y d}~d}~ww xY w|j        t2          j0        k    rd}nd}|d         |z  r.| <                    tz          j>        t~          j@        d           dS d}| j        pg }| j                            dd||| j                            |j                  t          |j                  t          |jB                  dd|j        id            ||j3        k    r
|dz   |_3        | j        s9|tT          j+        j7        k    r$| C                    tT          j+        j%                   | jD        j        |jB        | jD        _        d| jD        _        | j         tF          j$        u r+|jB        | _E        | F                    tF          jG                   |j        t2          j0        k    ri|| jH        k    r^t          |d                   }| j        r	| | _J        n|| _J        || _H        | j        $| j                            d!d"d#| jJ        i           t          ||j        ||||j        $          }	 | L                    |||          \  }}nX# t          $ rK}| j5        6                    |           | <                    |jN        |jO        |jP                   Y d}~nd}~ww xY w| j         t          v s| jQ        rdS || j
        j        z   | _	        | j        ss|jR        | jR        k    rc|tT          j+        j0        k    rN| j5        6                    d%t          |jR                  |	           |jR        | _R        | S                                 |j        s<|tT          j+        j7        k    r'| j5        6                    d&|jT                   d|_        || j&        vr| j&        U                    |           | j&        V                    |          }|rb|s`||jW        k    rU| j5        6                    d'|jT                   | j&        X                    |           | j&        Y                    d|           |jZ        sK||jW        k    r||_W        ||_[        |j\        ]                    |           |r|j^        || j_        z   |_^        |                                dS dS )(aM  
        Handle an incoming datagram.

        After calling this method call :meth:`datagrams_to_send` to retrieve data
        which needs to be sent.

        :param data: The datagram which was received.
        :param addr: The network address from which the datagram was received.
        :param now: The current time.
        Nr  datagrams_receivedr   r  r  r  r  )host_cid_lengthpacket_droppedheader_parse_errorr  triggerr  r  unknown_connection_id)r  r  unsupported_version)r  packet_without_tagr  Fzfirst packet must be INITIALTkey_unavailabler  payload_decrypt_errorrG  r<  r   zReserved bits must be zeror   packet_received)r  rn   r  r  r  connectivityspin_bit_updatedstate)r   r   r   r   r   r   zPeer switching to CID %s (%d)z&Network path %s validated by handshakezNetwork path %s promoted)`r	  r  rt  r   r  r  _find_network_pathr   r   r   r   idle_timeoutr   eoftellr.   rT  
ValueErrorcapacityr   destination_cidrf   r   r   rn   r%   VERSION_NEGOTIATION#_receive_version_negotiation_packetr   r  packet_lengthRETRY_receive_retry_packet
data_slicer    r   r   rq   r   r  _initializerv   r   rr   r   r   rs   r  ru   seekdecrypt_packetexpected_packet_numberr   r  r  rt   r   r  reschedule_datar   r  r"   PROTOCOL_VIOLATIONr#   r  rm   
source_cidr  r   r   
_set_stater   r  r+   r  r   _payload_receivedr   r   r   r   r  r   r  r   r  indexlargest_received_packetpopinsert	discardedlargest_received_time	ack_queueaddr  r   )r   r  r   r  r  r   buf	start_offr  destination_cid_seqconnection_idcrypto_frame_requiredr   r  r  encrypted_offend_offplain_headerplain_payloadr  excreserved_maskr   r  contextis_ack_eliciting
is_probingidxs                               rY   receive_datagramzQuicConnection.receive_datagramC  s
    ;*$$FT (''$* '6&F.<   (   0 ..t44( 	:''>9'' >! 4#6#CCDN$'')) G	9

I))<)Q    
 
 
$0%//!,.';$,clY.F#G  0    
 /3!%  )]->>>*7*G'E ?  #6#>$0%//!,.')@A 0   
  !^%GGG88C8PPP *N$*=*PPP$0%//!,.'<$,f.B#C  0     !^%999**!'*~~!388::0H#H( (  +    $)! ? 9t{6I6U'U'U)^-CCCC2 DCC )-%'3n# &  !7888 f011E	))).v~>u-	***SY%67U+  HHJJ2M&"66GHHW%=C=R=R7*+]E<X> >:m]] '   ""3'''$0%//!,.'8$,f.B#C  0    O6#)"5sy7H!III 6 J J..3.77715D.   ""3'''$0%//!,.'>$,f.B#C  0     !^%;;; $ $A. 

,?,4">    
  59 ,%'"!++(+"4-:+/+<+H+H & 2, , %-V-C$D$D$,V->$?$?# # !)&*>?  ,   $ u;;;/<q/@, ? 7u	0C'C'C##CI$5666 ~-5%+%6"12.{1===<B<M9 3 =>>> "n&<<<!D$999'Q88? .)1\DNN%-DN(5%$0%//!/0%t~6 0    )/)#5  G
/3/E/E],A0 0, ** '   ""3'''

"~"~"%"3          {j((D,?( !4#6#CCDN O,$55SY...""3W-..'  
 !( 0))+++  , 1#):M1M1M""<l>O   -1)4#666#**<888%++L99C <: <-%:W*W*W""#=|?PQQQ#'',,,#**1l;;; ? 9 5#@@@4AE125E/##M222# 9(<#&#8ELO '')) G	9 G	9 G	9 G	9 G	9sQ   C0 0;D/.D/(N1 1
R=;BQR=*AR88R=&\ 
]A]]c                    | j         s
J d            | j        t          j        j                                                  dS )z;
        Request an update of the encryption keys.
        z,cannot change key before handshake completesN)r   r   r   rr   ru   
update_keyru  s    rY   request_key_updatez!QuicConnection.request_key_update  s@     'WW)WWWWci'(3355555r[   rw   c                d    |                      |          }|j                            |           dS )ah  
        Abruptly terminate the sending part of a stream.

        This method has no effect if a reset has already been triggered either by a
        call to :meth:`reset_stream` or by the reception of a STOP_SENDING frame.

        :param stream_id: The stream's ID.
        :param error_code: An error code indicating why the stream is being reset.
        N)_get_or_create_stream_for_sendsenderresetr   rw   r   streams       rY   reset_streamzQuicConnection.reset_stream  s3     44Y??J'''''r[   uidc                :    | j                             |           dS )z`
        Send a PING frame to the peer.

        :param uid: A unique ID for this PING.
        N)r  r  )r   r2  s     rY   	send_pingzQuicConnection.send_ping  s!     	!!#&&&&&r[   c                :    | j                             |           dS )zS
        Send a DATAGRAM frame.

        :param data: The data to be sent.
        N)r  r  )r   r  s     rY   send_datagram_framez"QuicConnection.send_datagram_frame  s!     	&&t,,,,,r[   
end_streamra   c                h    |                      |          }|j                            ||           dS )z
        Send data on the specific stream.

        :param stream_id: The stream's ID.
        :param data: The data to be sent.
        :param end_stream: If set to `True`, the FIN bit will be set.
        )r7  N)r,  r-  write)r   rw   r  r7  r0  s        rY   send_stream_datazQuicConnection.send_stream_data  s8     44Y??DZ88888r[   c                    t          | j        |          st          d          | j                            |d          }|t          d          |j                            |           dS )z
        Request termination of the receiving part of a stream.

        :param stream_id: The stream's ID.
        :param error_code: An error code indicating why the stream is being stopped.
        z@Cannot stop receiving on a local-initiated unidirectional streamNz*Cannot stop receiving on an unknown stream)r   r   r  r
  getreceiverstopr/  s       rY   stop_streamzQuicConnection.stop_stream  sv     -T_iHH 	R   ""9d33>IJJJZ(((((r[   alpn_protocolc                   | j         j        D ]1\  }}|t           j        j        k    r|                     |            n42t          t          j        t           j        j	        z   | j
        d          | j        s| j        s| j        | j        j        D ]}|| j        k    r n|| j        j        v rrt%          | j        |          r]|| _        | j        |         | j        t           j        j        <   t           j        j        |                                 fg| j         _         nd| _        | j                            dt7          | j                             | j                            t=          j        |                     dS )z
        Callback which is invoked by the TLS engine at most once, when the
        ALPN negotiation completes.

        At this point, TLS extensions have been received so we can parse the
        transport parameters.
        z%No QUIC transport parameters receivedr   NTNegotiated protocol version %s)r@  ) r   received_extensionsExtensionTypeQUIC_TRANSPORT_PARAMETERS_parse_transport_parametersr   r"   CRYPTO_ERRORAlertDescriptionmissing_extensionr   r   r  r  available_versionsr  r   r  re   r   r   rr   rq   _serialize_transport_parametershandshake_extensionsr  r  r,   r   r  r   ProtocolNegotiated)r   r@  ext_typeext_datar   s        rY   _alpn_handlerzQuicConnection._alpn_handler  s    #'("> 
	 
	Hh3,FFF00::: G &(5&892E	     	t'J 	/;  $?R  G$-//4#6#III1$-II J )0;?;P#<ci&78 !$ 1 K $ D D F F95 26D/L02I$-2X2X  
 	F5MRRRSSSSSr[   c                h    t          | j        |          st          t          j        |d          dS )z^
        Check the specified stream can receive data or raises a QuicConnectionError.
        zStream is send-onlyr   N)r   r   r   r"   STREAM_STATE_ERRORr   r   rw   s      rY   _assert_stream_can_receivez)QuicConnection._assert_stream_can_receive  sE     -T_iHH 	%(;%3   	 	r[   c                h    t          | j        |          st          t          j        |d          dS )z[
        Check the specified stream can send data or raises a QuicConnectionError.
        zStream is receive-onlyr   N)r   r   r   r"   rR  rS  s      rY   _assert_stream_can_sendz&QuicConnection._assert_stream_can_send	  sE     +4?IFF 	%(;%6   	 	r[   c                    | j                             d          | _        | j                            dt          | j        j                  | j        j                   dS )z
        Update the destination connection ID by taking the next
        available connection ID provided by the peer.
        r   zSwitching to CID %s (%d)N)r   r  r   r  r  rm   rf   r   ru  s    rY   r  z QuicConnection._consume_peer_cid  s[     155a88&T^'((N*	
 	
 	
 	
 	
r[   r  c                    |d| j                                         z  z   | _        |r!|                     t          j                   dS |                     t          j                   dS )z,
        Begin the close procedure.
        rN   N)r  get_probe_timeoutr   r  r   r   r   )r   r  r  s      rY   r  zQuicConnection._close_begin!  sc     q4:#?#?#A#AAA 	:OO/788888OO/899999r[   c                Z   d| _         | j                                        D ]}|                     |           | j                            | j                   |                     t          j	                   | j
        -| j        j                            | j
                   d| _
        dS dS )z*
        End the close procedure.
        N)r   r  keysr  r   r  r   r  r   r   r   r   r3  	end_trace)r   r   s     rY   r  zQuicConnection._close_end+  s     \&&(( 	' 	'E&&&&D-...+6777 (+55d6GHHH $D )(r[   c                    | j         sJ || j        j        z   | _        |                     | j        j                   | j                            d| j	                   | 
                                 dS )z-
        Start the client handshake.
        r[   N)r   r   r  r   r  r   rf   r   handle_messager   _push_crypto_datar  s     rY   r  zQuicConnection._connect:  sp     t2??+,,,T%9:::     r[   r   ro   c                   | j         |         j        s| j                            d|           | j        |                                          |t          j        j        k    rR| j	        
                                D ]8}t          |j        _        t          |j        _        |                                 9| j                            | j         |                    d| j         |         _        d S d S )NzDiscarding epoch %sT)r  r  r  r  r   teardownr   rr   rq   r   valuesr   recv_teardown_cbr  r  discard_space)r   r   r  s      rY   r  zQuicConnection._discard_epochF  s    |E", 	1L4e<<<M% ))+++	))) #3::<< & &F/9FK,/9FK,OO%%%%J$$T\%%8999,0DL)))	1 	1r[   r   c                    | j         D ]}|j        |k    r|c S | j                            d|           t	          |          S )NzNetwork path %s discovered)r   r   r  r  r   )r   r   r   s      rY   r  z!QuicConnection._find_network_pathT  s\     / 	$ 	$L D((#### ) 	7>>>t$$$r[   r:   c                x   || j         v rt          | j                            |d          }|t	          |          | j        u rt          t          j        |d          t          |          r| j
        }d}| j        }n| j        }| j        }| j        }|dz  dz   }||j        k    rt          t          j        |d          ||j        k    r||_        | j                            d| d	           t)          |||t          |           
          x}| j        |<   | j                            |           |S )zI
        Get or create a stream in response to a received frame.
        NzWrong stream initiatorr   r   r   r   zToo many streams openStream z created by peer)rw   max_stream_data_localmax_stream_data_remotewritable)r  r;   r
  r<  r{   r   r   r"   rR  r}   r   r   r   r   r   r   STREAM_LIMIT_ERRORr   r  r  r:   r  r  )r   r   rw   r0  ri  rj  max_streamsstream_counts           rY   _get_or_create_streamz$QuicConnection._get_or_create_stream_  s    ...%%""9d33>))44GG),?)":    (	22 ;(,(G%)*&"9(,(O%)-)P&": &Na/Lk///),?)"9   
  000#/  LDDDDEEE0:#&;'=5i@@@	1 1 1 FT]9- &&v...r[   c                l   t          | j        |          st          d          | j                            |d          }|t          |          | j        urt          d          t          |          rd}| j        }| j        }| j	        }n| j
        }| j        }| j        }| j        }t          |          }t          ||||           x}| j        |<   | j                            |           |r|dz   | _        n
|dz   | _        |dz  |k    r#d|_        |                    |           d| _        |S )z
        Get or create a QUIC stream in order to send data to the peer.

        This always occurs as a result of an API call.
        z8Cannot send data on peer-initiated unidirectional streamNz1Cannot send data on unknown peer-initiated streamr   )rw   ri  rj  readabler   T)r   r   r  r
  r<  r{   r}   r   r  r  r   r   r  r  r:   r  r  r   r   
is_blockedr  )r   rw   r0  ri  rj  rm  streams_blockedr  s           rY   r,  z-QuicConnection._get_or_create_stream_for_send  su    +4?IFF 	YWXXX""9d33>))44DOKK !TUUU (	22 	=()%)-)I&":"&";(,(N%)-)Q&";"&"< !9 C C0:#&;'=..	1 1 1 FT]9- &&v...  @1:Q..2;a-/ A~,,$(!&&v...04-r[   session_tickettls.SessionTicketc                    |j         >|j         t          k    r.t          t          j        t
          j        d|j                    |                     |           d S )NzInvalid max_early_data value r   )max_early_data_sizeMAX_EARLY_DATAr   r"   r  r#   CRYPTOr  )r   rt  s     rY   _handle_session_ticketz%QuicConnection._handle_session_ticket  sm    .:2nDD%(;(/8!58 8    	$$^44444r[   r  c                	    t          j         j        j         j        j         j        j         j        j         j        j         j	         j
         j	        rd nt           j        j         j        j         j        j         j        j         j        j                   _          j        j        .t%           j        j        t&                    st)          d           j        j         j         _         j        j        r4t%           j        j        d         t&                    st)          d           j        j         j         _         j        j        r7dt/          t1           j        j                            v rt)          d           j        j         j         _        t           j        j                                         fg j         _         j        j        } j	        r|}|j        rv|j         j        j        k    ra j        j         j         _        |j         t          k    r;|j!        D ]3\  }}|t           j        j        k    r "                    |d            n4 j#         j         _$         j%         j%         j         _&         j'         j(         j         _)         j*         j         _+        d fdi  _,         j        j-        D ]7}t]                      }|/                    | j	        |           | j,        |<   8fdt           j0        j1        t           j0        j2        t           j0        j3        t           j0        j4        fD              _5         j,         j6                  j5        t           j0        j1        <   t           j0        j1        to          tp                    t           j0        j3        to          tp                    t           j0        j4        to          tp                    i _9        t           j0        j1        tu                      t           j0        j3        tu                      t           j0        j4        tu                      i _;        t           j0        j1        ty                      t           j0        j3        ty                      t           j0        j4        ty                      i _=        t}           j=        ?                                           j@        _A        d S )N)alpn_protocolscadatacafilecapathcipher_suitesr~   r5  max_early_dataserver_nameverify_modehostname_checks_common_nameassert_fingerprintverify_hostnamezqh3 v1.0+ no longer support passing cryptography certificate objects within a QuicConfiguration object. Use configuration.load_cert_chain(...) instead using PEM encoded values.r   cryptographyzqh3 v1.0+ no longer support passing cryptography private key object within a QuicConfiguration object. Use configuration.load_cert_chain(...) instead using PEM encoded values.T)from_session_ticketr   ro   rQ   r   c           	     .   g d| j                  }d| dd| dg}|j                  }|j                 }t          t          j        |          t          j        |          t          j        |          t          j        |                    S )N)initial0rtt	handshake1rttserver__secretclient_)recv_setup_cbrecv_teardown_cbsend_setup_cbsend_teardown_cb)r   r   r   r   _log_key_updated_log_key_retired)r   
epoch_namesecret_namesrecv_secret_namesend_secret_namer   s        rY   create_crypto_pairz6QuicConnection._initialize.<locals>.create_crypto_pair$  s    AAA%+NJ-*----*---L  ,,?@+DO<%d&;=MNN!()>@P!Q!Q%d&;=MNN!()>@P!Q!Q	   r[   )rf   r~   r   c                (    i | ]}| |          S ry   ry   )rW   r   r  s     rY   
<dictcomp>z.QuicConnection._initialize.<locals>.<dictcomp><  s7     
 
 
 %%e,,
 
 
r[   r  )r   ro   rQ   r   )Br   Contextr   r|  r}  r~  r  r%  r  r   r  rx  r  r  r  r  r  rP  
isinstanceX509CertificateRuntimeErrorcertificate_chainrQ  rP   typecertificate_private_keyrD  rE  rK  rL  rt  r  rw  other_extensionsrF  rP  alpn_cbr  get_session_ticket_cbr  rz  new_session_ticket_cb_update_traffic_keyupdate_traffic_key_cbr   r  r   setup_initialrr   rq   rs   rt   ru   r   r  r   CRYPTO_BUFFER_SIZEr   r:   r   r8   r  listrb  r  r  )r   r  rt  rN  rO  r   pairr  s   `      @rY   r  zQuicConnection._initialize  s   ;.=&-&-&-,:o<#'?F44+7+7(,(;(W#2E /?
 
 
 *6z+_@
 @
6 &    $2>0 	1!4o:
 :
 	 &   &*%8%J"* 	~$011B
 B
 0
 0
 &   ,0+>+J( !;4466)
% ,;O	*' +*d.A.MMM&*&9&HDH# 1^CC*8*I  &Hh3#4#NNN88$$ 9    	 O  -'3-1-IDH*'3-1-HDH*)-)A&	 	 	 	 	 	" !#*= 	2 	2G<<D8tPWXXX-1D!'**
 
 
 
 	!	"	#	!	
 
 
 ,0+@+Oci'( Iv/ABBBI1C!D!D!DIv/ABBB 
 Iz||IIz|| 
 I00I!2!2I00
 !!4!4!6!677
r[   r#  r   r  r   c                8   t          |          \  }}|t          j        k    r<|                                 |                                 |                                 || j        z  dz  }| j        3|j                            | j                            ||                     | j	        j
        s5|j        t          j        j        t          j        j        fv rd| j	        _
        | j	                            | j        |j                 |||j                   dS )z&
        Handle an ACK frame.
        @B NT)r  ack_rangeset	ack_delayr  )r-   r#   ACK_ECNpull_uint_varr   r   r   r  encode_ack_framer  r2  r   r   rr   rt   ru   on_ack_receivedr  r   )r   r#  r   r  r  ack_delay_encodedr  s          rY   r^  z QuicConnection._handle_ack_frameZ  s,    +9*=*=''...&$*IIWT	 (&--!22<KK  
 z; 	@IIR
 A
 A
 <@DJ8
"",w}-%	 	# 	
 	
 	
 	
 	
r[   c                N   |                                 }|t          j        k    r|                                 }nd}|                                 }	 |                    |                              d          }n# t
          $ r d}Y nw xY w| j        5|j                            | j        	                    |||                     | j
                            d||           | j        :t          j        |||          | _        |                     d|j                   dS dS )z2
        Handle a CONNECTION_CLOSE frame.
        Nutf8r  r   z0Connection close received (code 0x%X, reason %s)Fr  )r  r#   TRANSPORT_CLOSE
pull_bytesrl   UnicodeDecodeErrorr   r   r  encode_connection_close_framer  r  r   r   r  r  r   )r   r#  r   r  r   reason_lengthr   s          rY   ro  z-QuicConnection._handle_connection_close_frame{  s_    &&((
666**,,JJJ))++	NN=99@@HHMM! 	 	 	MMM	 (&--!??))"/ @     	>	
 	
 	

 $ & ;%%+! ! !D
 5glCCCCC %$s   (A: :B	B	c                   |                                 }|                                 }||z   t          k    rt          t          j        |d          t          ||                    |                    }| j        2|j        	                    | j        
                    |                     | j        |j                 }||z   |j                                        z
  }|t          k    rt          t          j        |d          |j                            |          }	|	|| _        |j        | _        	 | j                            |	j        | j                   |                                  nU# t*          j        $ rC}
t          t          j        t9          |
j                  z   |t=          |
                    d}
~
ww xY w| j        s"| j        j         t*          j!        j"        t*          j!        j#        fv rd| _        | j$        s2| %                    t*          j&        j'                   d| _(        d| _)        | *                                 | j+        	                    tY          j-        | j        j.        | j        j/        | j        j0                             | 1                    d	           | 1                    d	           | j2        3                    d
| j        j.                   dS dS dS | j2        3                    d|j                   | j$        sJ|j        t*          j&        j4        k    r2| j5        s-| j6        7                    |j8                   d| _5        dS dS dS dS )z(
        Handle a CRYPTO frame.
        &offset + length cannot exceed 2^62 - 1r   )offsetr  Nztoo much crypto bufferingT)r@  early_data_acceptedsession_resumedFr  zALPN negotiated protocol %sz+Duplicate CRYPTO data received for epoch %sr  )9r  r   r   r"   FRAME_ENCODING_ERRORr'   r  r   r   r  encode_crypto_framer   r   r=  starting_offsetMAX_PENDING_CRYPTOCRYPTO_BUFFER_EXCEEDEDhandle_framer   r   r   r   r^  r  r   r_  AlertrG  r_   descriptionrP   r   r  StateCLIENT_POST_HANDSHAKESERVER_POST_HANDSHAKEr   r  rr   rt   r   r  _replenish_connection_idsr   r   HandshakeCompletedalpn_negotiatedr  r  _unblock_streamsr  r  rq   r   r  r  r   )r   r#  r   r  r  r  framer0  pendingr  r!  s              rY   ra  z#QuicConnection._handle_crypto_frame  s    ""$$""$$F?\))%(=%F   
  vCNN64J4JKKK (&--!55e<<   %gm46/FO$C$C$E$EE'''%(?%9    ,,U33 '1D#*1/D'''
D4HIII&&((((9   ),9C<P<PP)"%c((    + 	/	/C 1 1 ,0(  8''	(;<<<04D-37D0..000##-&*h&>,0H,H(,(@     %%%>>>%%%===""1483K    -  1 14 L=w}   O2MSY%6662 7 
**w|*<<<-1***2 26666s   99E3 3G>G  Gc                    |                                 }| j        5|j                            | j                            |                     dS dS )z.
        Handle a DATA_BLOCKED frame.
        N)limit)r  r   r   r  encode_data_blocked_framer   r#  r   r  r  s        rY   rh  z)QuicConnection._handle_data_blocked_frame  sd     !!## (&--!;;%;HH     )(r[   c                   |                                 }|t          j        k    r|                                }n
|j        |z
  }|                    |          }| j        3|j                            | j        	                    |                     | j
        j        %|                                 |z
  | j
        j        k    rt          t          j        |d          | j                            t!          j        |                     dS )z*
        Handle a DATAGRAM frame.
        Nr  zUnexpected DATAGRAM framer   r  )r  r#   DATAGRAM_WITH_LENGTHr  r  r  r   r   r  encode_datagram_framer   max_datagram_frame_sizer   r"   r  r   r   DatagramFrameReceived)r   r#  r   r  startr  r  s          rY   rq  z%QuicConnection._handle_datagram_frame  s    

;;;&&((FF\E)F~~f%% (&--!77v7FF   7?xxzzE!T%8%PPP%(;%9    	F8dCCCDDDDDr[   c                <   | j         1|j                            | j                                                    | j        st          t          j        |d          | j        s9| 	                    t          j        j                   d| _        d| j        _        dS dS )z0
        Handle a HANDSHAKE_DONE frame.
        Nz+Clients must not send HANDSHAKE_DONE framesr   T)r   r   r  encode_handshake_done_framer   r   r"   r  r   r  r   rr   rt   r  r2  r   r#  r   r  s       rY   rp  z+QuicConnection._handle_handshake_done_frame,  s     (&--!==??    	%(;%K    ( 	@	 3444(,D%;?DJ888	@ 	@r[   c                   |                                 }| j        4|j                            | j                            ||                     || j        k    r$| j                            d|           || _        dS dS )zm
        Handle a MAX_DATA frame.

        This adjusts the total amount of we can send to the peer.
        Nr   maximumzRemote max_data raised to %d)r  r   r   r  encode_connection_limit_framer   r  r  )r   r#  r   r  r,  s        rY   rd  z%QuicConnection._handle_max_data_frameE  s     $$&& (&--!??)8 @     d+++L=xHHH$,D!!! ,+r[   c                   |                                 }|                                 }| j        4|j                            | j                            ||                     |                     ||           |                     ||          }||j        k    r%| j        	                    d||           ||_        dS dS )z|
        Handle a MAX_STREAM_DATA frame.

        This adjusts the amount of data we can send on a specific stream.
        Nr  rw   z-Stream %d remote max_stream_data raised to %d)
r  r   r   r  encode_max_stream_data_framerV  ro  rj  r  r  )r   r#  r   r  rw   rV  r0  s          rY   re  z,QuicConnection._handle_max_stream_data_frame[  s     %%''	++-- (&--!>>+y ?     	$$Z;;;++J	BBV:::L?  
 -<F))) ;:r[   c                |   |                                 }|t          k    rt          t          j        |d          | j        4|j                            | j                            ||                     || j	        k    r:| j
                            d|           || _	        |                     d           dS dS )z
        Handle a MAX_STREAMS_BIDI frame.

        This raises number of bidirectional streams we can initiate to the peer.
        "Maximum Streams cannot exceed 2^60r   Nr  z$Remote max_streams_bidi raised to %dFr  )r  STREAM_COUNT_MAXr   r"   r  r   r   r  r  r  r  r  r  r   r#  r   r  rm  s        rY   rf  z-QuicConnection._handle_max_streams_bidi_framez  s     '')))))%(=%B    (&--!??); @     666LE{SSS,7D)!!E!::::: 76r[   c                |   |                                 }|t          k    rt          t          j        |d          | j        4|j                            | j                            ||                     || j	        k    r:| j
                            d|           || _	        |                     d           dS dS )z
        Handle a MAX_STREAMS_UNI frame.

        This raises number of unidirectional streams we can initiate to the peer.
        r  r   Nr  z#Remote max_streams_uni raised to %dTr  )r  r  r   r"   r  r   r   r  r  r  r  r  r  r  s        rY   rg  z,QuicConnection._handle_max_streams_uni_frame  s     '')))))%(=%B    (&--!??); @     555LDkRRR+6D(!!D!99999 65r[   c                    |                                 }|                                 }|                                }|                    |          }|                    t                    }|rt	          |          t
          k    rt          t          j        |d           j	        6|j
                             j	                            ||||                     ||k    rt          t          j        |d          t          | j                   _        d}	 fd j        D             }
 j        j        |k     rd}	|
                    d	 j                    fd
 j        D              _        | j        k    rM| j        vrD j                            t+          |||                      j                            |           |
D ]}                     |           |	r                                  dt	           j                  z    j        k    rt          t          j        |d          t	           j                  t9           j        dz  t:                    k    rt          t          j        |d          dS )z3
        Handle a NEW_CONNECTION_ID frame.
        z.Length must be greater than 0 and less than 20r   Nr  retire_prior_tor   r   z/Retire Prior To is greater than Sequence NumberFc                4    g | ]}|j         j        k     |S ry   r   r   rW   rf   r   s     rY   
<listcomp>zBQuicConnection._handle_new_connection_id_frame.<locals>.<listcomp>  s4     
 
 
"T%??? ???r[   Tr   c                4    g | ]}|j         j        k    |S ry   r  r  s     rY   r  zBQuicConnection._handle_new_connection_id_frame.<locals>.<listcomp>  s4     $
 $
 $
"d&@@@ @@@r[   rf   r   r   r   zToo many active connection IDsr   z'Too many pending retired connection IDs)r  
pull_uint8r  r!   rt  r   r   r"   r  r   r   r  encode_new_connection_id_framer  maxr   r   r   r   r  r   r   r  r  r  r   CONNECTION_ID_LIMIT_ERRORr  minMAX_PENDING_RETIRES)r   r#  r   r  r   r  r  r  r   
change_cidretirequic_connection_ids   `           rY   rk  z.QuicConnection._handle_new_connection_id_frame  s    ++--++--!!v.. #/I J J 	M 2 25K K K%(=%N    (&--!@@"/$3$3*?	 A     _,,%(;%O    &)$:T%U%U" 

 
 
 
/
 
 

 >)O;;JMM!T^,,,$
 $
 $
 $
/$
 $
 $
  t999t'FFF$++ %$3*?     +//@@@ #) 	6 	6!!"45555  	%""$$$ s4+,,,t/UUU%(B%>    t*++c2Q68K/
 /
 
 
 &(B%G   
 
r[   c                   |                                 }|                    |          }| j        3|j                            | j                            |                     | j        st          t          j	        |d          dS )z+
        Handle a NEW_TOKEN frame.
        N)tokenz&Clients must not send NEW_TOKEN framesr   )
r  r  r   r   r  encode_new_token_framer   r   r"   r  )r   r#  r   r  r  r  s         rY   rb  z&QuicConnection._handle_new_token_frame  s     ""$$v&& (&--!88u8EE    	%(;%F   	 	r[   c                   |                                 }|                    ||j                  D ]}|r n|dz  }|                    |           | j        3|j                            | j                                                   dS dS )z)
        Handle a PADDING frame.
        r   N)r  r  r  r  r   r   r  encode_padding_frame)r   r#  r   r  posbytes         rY   r\  z$QuicConnection._handle_padding_frame/  s     hhjjNN355 	 	D 1HCC (&--d.?.T.T.V.VWWWWW )(r[   c                *   |                     d          }| j        3|j                            | j                            |                     t          |j        j                  t          k     r!|j        j                            |           dS dS )z0
        Handle a PATH_CHALLENGE frame.
        rK   Nr  )	r  r   r   r  encode_path_challenge_framert  r   r   MAX_REMOTE_CHALLENGES)r   r#  r   r  r  s        rY   rm  z+QuicConnection._handle_path_challenge_frameA  s     ~~a   (&--!==4=HH   w#5669NNN 299$????? ONr[   c                ~   |                     d          }| j        3|j                            | j                            |                     	 | j                            |          }n*# t          $ r t          t          j
        |d          w xY w| j                            d|j                   d|_        dS )z/
        Handle a PATH_RESPONSE frame.
        rK   Nr  z!Response does not match challenger   z&Network path %s validated by challengeT)r  r   r   r  encode_path_response_framer   r  KeyErrorr   r"   r  r  r  r   r   )r   r#  r   r  r  r   s         rY   rn  z*QuicConnection._handle_path_response_frameU  s     ~~a   (&--!<<$<GG  	155d;;LL 	 	 	%(;%A   	 	C\EVWWW$(!!!s   A, ,'Bc                z    | j         3|j                            | j                                                    dS dS )z&
        Handle a PING frame.
        N)r   r   r  encode_ping_framer  s       rY   r]  z!QuicConnection._handle_ping_framen  sA     (&--d.?.Q.Q.S.STTTTT )(r[   c                   |                                 }|                                 }|                                 }| j        5|j                            | j                            |||                     |                     ||           |                     ||          }||j        k    rt          t          j
        |d          t          d||j        j        z
            }| j        j        |z   | j        j        k    rt          t          j
        |d          | j                            d|||           	 |j                            ||          }	n;# t(          $ r.}
t          t          j        |t-          |
                    d}
~
ww xY w|	| j                            |	           | j        xj        |z  c_        dS )	z.
        Handle a RESET_STREAM frame.
        Nr   
final_sizerw   Over stream data limitr   r   Over connection data limitz6Stream %d reset by peer (error code %d, final size %d))r   r  )r  r   r   r  encode_reset_stream_framerT  ro  ri  r   r"   FLOW_CONTROL_ERRORr  r=  highest_offsetr   r   r   r  r  handle_resetr9   FINAL_SIZE_ERRORrP   r   )r   r#  r   r  rw   r   r  r0  newly_receivedr  r!  s              rY   r_  z)QuicConnection._handle_reset_stream_framex  s    %%''	&&((
&&((
 (&--!;;)jI <     	''
I>>> ++J	BB444%(;%6   
 Q
V_-K KLL$~58L8RRR%(;%:    	D		
 	
 	
		O00%* 1  EE  	 	 	%(9%!#hh   	 L&&&!!^3!!!!s    E 
F')FFc                   |                                 }| j        2|j                            | j                            |                     || j        k    rt          t          j        |d          t          | j
                  D ]\  }}|j        |k    r|j        |j        k    rt          t          j        |d          | j                            dt!          |j                  |j                   | j
        |= | j                            t%          j        |j                              n|                                  dS )z6
        Handle a RETIRE_CONNECTION_ID frame.
        Nz#Cannot retire unknown connection IDr   z#Cannot retire current connection IDzPeer retiring CID %s (%d)r  )r  r   r   r  !encode_retire_connection_id_framer   r   r"   r  	enumerater   r   rf   r   r  r  rm   r   r   ConnectionIdRetiredr  )r   r#  r   r  r   r  r  s          rY   rl  z1QuicConnection._handle_retire_connection_id_frame  sx    ++-- (&--!CCOTT   d000%(;%C    %.do$>$> 	 	 E=,?? $(888-#0#C#-&K   
 ""/].//!1  
 OE*##.]=NOOO   ! @& 	&&(((((r[   c                   |                                 }|                                 }| j        4|j                            | j                            ||                     |                     ||           |                     ||          }|j                            t          j
                   | j                            t          j        ||                     dS )z.
        Handle a STOP_SENDING frame.
        Nr   rw   )r   )r  r   r   r  encode_stop_sending_framerV  ro  r-  r.  r"   NO_ERRORr   r   StopSendingReceived)r   r#  r   r  rw   r   r0  s          rY   r`  z)QuicConnection._handle_stop_sending_frame  s     %%''	&&((
 (&--!;;)Y <     	$$Z;;; ++J	BB}'=>>>&*	RRR	
 	
 	
 	
 	
r[   c                t   |                                 }|dz  r|                                 }nd}|dz  r|                                 }n|j        |                                z
  }||z   t          k    rt	          t
          j        |d          t          ||                    |          t          |dz                      }| j
        4|j                            | j
                            ||	                     |                     ||           |                     ||          }||z   |j        k    rt	          t
          j        |d
          t%          d||z   |j        j        z
            }	| j        j        |	z   | j        j        k    rt	          t
          j        |d          	 |j                            |          }
n;# t2          $ r.}t	          t
          j        |t7          |                    d}~ww xY w|
| j                            |
           | j        xj        |	z  c_        dS )z(
        Handle a STREAM frame.
        r   r   r   r  r   r   )r  r  finNrz   r  r  )r  r  r  r   r   r"   r  r'   r  ra   r   r   r  encode_stream_framerT  ro  ri  r  r  r=  r  r   r   r   r  r9   r  rP   r   )r   r#  r   r  rw   r  r  r  r0  r  r  r!  s               rY   rc  z#QuicConnection._handle_stream_frame  ss    %%''	> 	&&((FFF> 	/&&((FF\CHHJJ.FF?\))%(=%F   
  v 6 6Da<P<P
 
 

 (&--!55ey5QQ  
 	''
I>>> ++J	BBF?V999%(;%6   
 Q&/2P PQQ$~58L8RRR%(;%:   	O0077EE 	 	 	%(9%!#hh   	 L&&&!!^3!!!!s   1G 
H)G??Hc                $   |                                 }|                                 }| j        4|j                            | j                            ||                     |                     ||           |                     ||           dS )z5
        Handle a STREAM_DATA_BLOCKED frame.
        N)r  rw   )r  r   r   r   encode_stream_data_blocked_framerT  ro  )r   r#  r   r  rw   r  s         rY   ri  z0QuicConnection._handle_stream_data_blocked_frame9	  s     %%''	!!## (&--!BB9 C     	''
I>>>"":y99999r[   c                   |                                 }|t          k    rt          t          j        |d          | j        D|j                            | j                            |t          j
        k    |                     dS dS )z1
        Handle a STREAMS_BLOCKED frame.
        r  r   Nr  r  )r  r  r   r"   r  r   r   r  encode_streams_blocked_framer#   STREAMS_BLOCKED_UNIr  s        rY   rj  z,QuicConnection._handle_streams_blocked_frameO	  s     !!#####%(=%B    (&--!>>&0M4U&U ?       )(r[   key_typer  c                X    | j         "| j                             dd||d           dS dS )z'
        Log a key retirement.
        Nsecuritykey_retiredr0  r  r  r   r  r   r0  r  s      rY   r  zQuicConnection._log_key_retiredf	  P     (''##"*w?? (      )(r[   c                X    | j         "| j                             dd||d           dS dS )z#
        Log a key update.
        Nr2  key_updatedr4  r  r5  r6  s      rY   r  zQuicConnection._log_key_updatedq	  r7  r[   deliveryr3   r  r8   highest_ackedc                f    |t           j        k    r |j                            d|dz              dS dS )zE
        Callback when an ACK frame is acknowledged or lost.
        r   r   N)r3   ACKEDr  subtract)r   r:  r  r;  s       rY   _on_ack_deliveryzQuicConnection._on_ack_delivery|	  s>     (...O$$Q(9::::: /.r[   r  r   c                8    |t           j        k    r	d|_        dS dS )zX
        Callback when a MAX_DATA or MAX_STREAMS frame is acknowledged or lost.
        r   N)r3   r=  r   )r   r:  r  s      rY   _on_connection_limit_deliveryz,QuicConnection._on_connection_limit_delivery	  s&     (...EJJJ /.r[   c                8    |t           j        k    r	d| _        dS dS )zO
        Callback when a HANDSHAKE_DONE frame is acknowledged or lost.
        TN)r3   r=  r  )r   r:  s     rY   _on_handshake_done_deliveryz*QuicConnection._on_handshake_done_delivery	  s)     (...+/D((( /.r[   r0  c                8    |t           j        k    r	d|_        dS dS )zP
        Callback when a MAX_STREAM_DATA frame is acknowledged or lost.
        r   N)r3   r=  max_stream_data_local_sent)r   r:  r0  s      rY   _on_max_stream_data_deliveryz+QuicConnection._on_max_stream_data_delivery	  s)     (...01F--- /.r[   r  r   c                8    |t           j        k    r	d|_        dS dS )zR
        Callback when a NEW_CONNECTION_ID frame is acknowledged or lost.
        FN)r3   r=  r   )r   r:  r  s      rY   _on_new_connection_id_deliveryz-QuicConnection._on_new_connection_id_delivery	  s)     (...%*M""" /.r[   uidsSequence[int]c                    |t           j        k    rS| j                            d|rdnd           |D ]/}| j                            t          j        |                     0dS | j        	                    |           dS )zE
        Callback when a PING frame is acknowledged or lost.
        zReceived PING%s responser  z (probe))r2  N)
r3   r=  r  r  r   r  r   PingAcknowledgedr  extend)r   r:  rI  r2  s       rY   _on_ping_deliveryz QuicConnection._on_ping_delivery	  s     (...L9;U22:VVV F F##F$;$D$D$DEEEEF F %%d+++++r[   r   c                ^    |t           j        k    r| j                            |           dS dS )zU
        Callback when a RETIRE_CONNECTION_ID frame is acknowledged or lost.
        N)r3   r=  r  r  )r   r:  r   s      rY   !_on_retire_connection_id_deliveryz0QuicConnection._on_retire_connection_id_delivery	  s8     (...'..????? /.r[   plainr  tuple[bool, bool]c                t   t          |          }d}d}d}d}|                                s)	 |                                }	n*# t          $ r t	          t
          j        dd          w xY w	 | j        |	         \  }
}n*# t          $ r t	          t
          j        |	d          w xY w|j	        |vrt	          t
          j
        |	d          	  |
||	|           n5# t          $ r t	          t
          j        |	d          t          $ r Y nw xY wd	}|	t          j        k    rd	}|	t          vrd	}|	t          vrd}n|d	}|                                )|s&t	          t
          j
        t          j        d
          |r(|s&t	          t
          j
        t          j        d          |t#          |          fS )z/
        Handle a QUIC packet payload.
        r  FNzMalformed frame typer   zUnknown frame typezUnexpected frame typezFailed to parse frameTzPacket contains no frameszPacket contains no CRYPTO frame)r   r  r  r   r   r"   r  rr  r  r   r  r;   r#   ry  r   r   r  ra   )r   r#  rQ  r  r  crypto_frame_foundframe_foundr$  r%  r   frame_handlerframe_epochss               rY   r  z QuicConnection._payload_received	  sh    %   " 
'')) 6	" ..00

"   ),A#"8   .2.CJ.O+||   ),A)"6    }L00),?)"9   
gz37777"   ),A)"9   
 '   
 K]111%)"!>>>#' !444"

#!
m '')) 6	"p  	%(;(09    ! 	); 	%(;(0?     j!1!111s)   A 'A+/B   'B'C /DDr  r$   r  c           
        | j         r| j        s|j        | j        k    r|j        t          || j        j        |j                  k    r| j	        P| j	        
                    ddg dt          |j                  t          |j                  dd|j        id	           |j        | j        _        |j        | _        | xj        d
z  c_        |j        | _        | j                            dt'          |j                   d           |                     |           dS | j	        )| j	        
                    dddd|j        id	           dS dS )z(
        Handle a retry packet.
        )r   Nr  r  retryrn   r  r  r  r  r  r   zRetrying with token (z bytes)r  r  unexpected_packetr  )r   r  r   r   integrity_tagr*   r   rf   r   r   r  rm   r  r  r  r   r  r  r  rt  r  )r   r  r  r  s       rY   r  z$QuicConnection._receive_retry_packet
  s    O*	%*	 &$-77$&""     ,!++(+"$+2$,V->$?$?$,V-C$D$D# #
 !)&*>?  ,    "(!2DN%|D"/5/@D,LQs6<7H7HQQQRRRMMcM"""""  ,!++(*#6 (&*>?  ,      -,r[   c           
     @   | j         r| j        t          j        u r| j        s| j        m| j                            ddg | j                            j                  t          j	                  t          j
                  ddj        id           | j        j        v r/| j                            dt!          | j                             dS fd	| j        j        D             }|r|d
         nd}| j        0| j                            ddj        | j        j        |d           |`| j                            d           t%          j        t(          j        t,          j        d          | _        |                                  dS d
| _        || _        d| _        | j                            dt!          | j                             |                     |           dS | j        )| j                            ddddj        id           dS dS )z
        Handle a version negotiation packet.

        This is used in "Incompatible Version Negotiation", see:
        https://datatracker.ietf.org/doc/html/rfc9368#section-2.2
        Nr  r  rZ  r  r  r  z7Version negotiation packet contains protocol version %sc                &    g | ]}|j         v |S ry   )r  )rW   xr  s     rY   r  zFQuicConnection._receive_version_negotiation_packet.<locals>.<listcomp>y
  s1       111 111r[   r   version_information)server_versionsclient_versionschosen_versionz(Could not find a common protocol versionr   Tz!Retrying with protocol version %sr  r  r[  r  )r   r	  r   r   r  r   r  rn   rm   r  r   r  r  r  r  r  r,   r   r   r  r"   r  r#   r  r   r  r   r  )r   r  r  commonrc  s    `   rY   r  z2QuicConnection._receive_version_negotiation_packetI
  s    OO	2>>>9 ?  ,!++(+"$+/+<+H+H & 2, , %-V->$?$?$,V-C$D$D# # !)&*>?
 
 ,   ( } 999""M+DM::      ,?  F +1:VAYYdN ,!++(/+1+D+/+>+Q*8  ,    %""#MNNN$*$?,;,4"L% % %!
 !!!"#D*DM48D1L3'66   MMcM"""""  ,!++(*#6 (&*>?  ,      -,r[   c           	        t          | j                  t          d| j                  k     r| j                            t          t          j        | j        j	                  | j
        t          j        d                               | xj
        dz  c_
        t          | j                  t          d| j                  k     dS dS )z.
        Generate new connection IDs.
        rK   r+  r  r   N)rt  r   r  r   r  r   rR  rS  r   rT  r   ru  s    rY   r  z(QuicConnection._replenish_connection_ids
  s     $/""SD,S%T%TTTO"" 
4#6#KLL$($6*,*R..     !# $/""SD,S%T%TTTTTTTr[   c                    | j                             dt          |j                  |j        t          | j                  dz              | j                            |j                   dS )z5
        Retire a destination connection ID.
        zRetiring CID %s (%d) [%d]r   N)r  r  rm   rf   r   rt  r  r  )r   r  s     rY   r  zQuicConnection._retire_peer_cid
  sj     	']&'')+,,q0		
 	
 	
 	#**=+HIIIIIr[   c                    | j                                         D ]D\  }}| j        |         j                            |j                   |                    d           Ed S r   )r   itemsr   r-  r9  r  r  )r   r   r  s      rY   r_  z QuicConnection._push_crypto_data
  s`    .4466 	 	JE3 '.44SX>>>HHQKKKK	 	r[   c                    d| _         d S )NT)r  ru  s    rY   r[  zQuicConnection._send_probe
  s    "r[   r  c                v   	 t          t          |                    }n4# t          $ r' t          t          j        t          j        d          w xY w| j        9|s7| j        	                    dd| j        
                    d|          	           | j        s>d
D ];}t          ||          )t          t          j        t          j        | d          <|s|j        | j        k    r&t          t          j        t          j        d          | j        r6|j        | j        k    r&t          t          j        t          j        d          | j        r6|j        | j        k    r&t          t          j        t          j        d          |j        1|j        dk     r&t          t          j        t          j        d          |j        1|j        dk    r&t          t          j        t          j        d          |j        1|j        dk    r&t          t          j        t          j        d          |j        1|j        dk     r&t          t          j        t          j        d          |j        x|j        }| j        s4|j        |j        vr&t          t          j        t          j        d          |j        | j        k    r&t          t          j        t          j        d          |si|j        | j        | _        |j        |j        dz  | j        _        | j        r(| j        j        dk    r|j         |j         | j        _         |j        | _!        |j        |j        | _"        |j#        |j#        dz  | _$        |j%        | _&        dD ]+}t          |d|z             }|tO          | d|z   |           ,dS )z
        Parse and apply remote transport parameters.

        `from_session_ticket` is `True` when restoring saved transport parameters,
        and `False` when handling received transport parameters.
        r  z)Could not parse QUIC transport parametersr   Nr  parameters_setremoteowner
parametersr  )r!  preferred_addressr"  r   z is not allowed for clientsz+initial_source_connection_id does not matchz1original_destination_connection_id does not matchz)retry_source_connection_id does not matchr   z1active_connection_id_limit must be no less than 2rC  z ack_delay_exponent must be <= 20r=   zmax_ack_delay must be < 2^14i  z$max_udp_payload_size must be >= 1200zJversion_information's chosen_version is not included in available_versionszFversion_information's chosen_version does not match the version in useg     @@r   )r,  max_stream_data_bidi_localmax_stream_data_bidi_remotemax_stream_data_unir-  r/  initial__remote_)(r/   r   r  r   r"   TRANSPORT_PARAMETER_ERRORr#   ry  r   r  encode_transport_parametersr   getattrinitial_source_connection_idr   r!  r  r"  r  active_connection_id_limitack_delay_exponentmax_ack_delaymax_udp_payload_sizer`  rc  rJ  r   VERSION_NEGOTIATION_ERRORr   r  r   r   r   r  r   max_idle_timeoutr   r  r   setattr)r   r  r  quic_transport_parametersattrr`  paramr   s           rY   rF  z*QuicConnection._parse_transport_parameters
  s   		(FD!!!) )%%  	 	 	%(B(/I   	 (1D(''$&&BB"/H C   (     	   4d;;G-#0#J#0#7)-&J&J&J    H # b	)F<= = *,F,3"O   
  )L;< < *,F,3"U   
  )D34 4 *,F,3"M    *DP-H1LL),F,3"U    *<H-@2EE),F,3"D    *7C-;uDD),F,3"@    *>J-BTII),F,3"H    )<H&?&S# +:.AB B .#0#J#0#74	    '59TTT-#0#J#0#71	    # 	(;G262Q/(6B-;fD 
( N2a77-CO .C 4 *= , %?K)D 3 %5A):VC ) &= 	,
 
	9 
	9E 5zE7IJJE j50%888
	9 
	9s	     1Ac                   t          | j        | j        t          | j        j        dz            | j        j        | j        | j	        | j
        | j        j        | j        j        | j        d| j        j        | j        j        rdnd | j        d         j        t%          | j        | j        j                            }| j        s| j        |_        | j        |_        | j        7| j                            dd| j                            d	|
                     t;          dt<          z            }t?          ||           |j         S )Ni  rH  s  QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQr   )rc  rJ  )r{  rz  r  initial_max_data"initial_max_stream_data_bidi_local#initial_max_stream_data_bidi_remoteinitial_max_stream_data_uniinitial_max_streams_bidiinitial_max_streams_uniry  r|  r  quantum_readinessr   r`  r  rk  localrm  r  rN   r  )!r(   r   r   r_   r   r  r   r   r   r   r   r   r   r   r  quantum_readiness_testr   r   r)   r  r  r   r  r!  r  r"  r   r  rw  r   r2   r1   r  )r   r  r  s      rY   rK  z.QuicConnection._serialize_transport_parameters  sc   $;#='+'M !4!AD!HII!17/3/U040W(,(G%)%A%G$($?$E)-)Q$($7$O#2ISt"&/!"4"J 6#}#'#6#I! ! !#%
 %
 %
!,  	8 &H 0 &@
 (''$&&BB!.G C   (    a/1222&s,EFFFxr[   r  r   c                j    | j                             d| j        j        |j                   || _        d S )Nz%s -> %s)r  r  r	  r   )r   r  s     rY   r  zQuicConnection._set_state  s.    :t{'7DDDr[   r  c                0   |r| j         }| j        }| j        }n| j        }| j        }| j        }|rM|d         j        dz  |k     r9|                    d          }d|_        ||_	        |r|d         j        dz  |k     9| j        s| j        sd| _
        d S d S d S )Nr   r   F)r   r  r  r   r  r  rw   r  rr  rj  r  )r   r  rj  rm  rs  r0  s         rY   r  zQuicConnection._unblock_streams  s     	9%)%E"6K"7OO%)%M"7K"8O 	C/!"4">!"Ck"Q"Q$((++F %F,BF)  	C/!"4">!"Ck"Q"Q
 ) 	2$2K 	2,1D)))	2 	2 	2 	2r[   	directiontls.Directionr~  tls.CipherSuitesecretc                   | j         rN| j        G| j        s@| j        | _        d| _        | j                            dt          | j                             | j        j        }|| j         |t          j
        j        k    k    }t          |         |j                 }|                    | d| j	        j                                         d|                                 d           |                                 | j        |         }|t          j
        j        k    r$|j                            ||| j                   dS |j                            ||| j                   dS )zj
        Callback which is invoked by the TLS engine when new traffic keys are
        available.
        NTrB   
)r~  r  r   )r   r   r  r  r  r  r,   r   secrets_log_filer   	DirectionDECRYPTSECRETS_LABELSr   r9  client_randomhexr  r   ENCRYPTr  setuprc  )	r   r  r   r~  r  r  	label_rowlabelr  s	            rY   r  z"QuicConnection._update_traffic_key  s~    O		+77 8 !7DM26D/L02I$-2X2X    .?'I9N,NOI"9-ek:E""JJ4815577JJ&**,,JJJ   ""$$$u%---K)&$-       K)&$-      r[   	challenger   c                   || j         |<   t          | j                   t          k    rZt          t	          | j                                                             }| j         |= t          | j                   t          k    Xd S d S rU   )r   rt  MAX_LOCAL_CHALLENGESnextiterr[  )r   r  r   keys       rY   _add_local_challengez#QuicConnection._add_local_challenge  s|    ,8y)$()),@@@ tD27799::;;C&s+	 $()),@@@@@@@r[   r  r4   c           
        d }| j         t          j        j                 j                                        rE| j         t          j        j                 }| j        t          j        j                 }t          j        }n^| j         t          j        j                 j                                        r)| j         t          j        j                 }t          j        }nd S | j	        t          j        j                 }	 |j
        |j
        |k    r.| j        j                            |          | _        | j        d S |                    ||           | j        r|j        sP|j        sIt'          j        d          }|                     ||           |                     ||           d|_        |j
        #|j
        |k    r|                     |||           | j        r|                     |           d| _        |j        rB|                     ||j        d	                    |j                                         |j        B| j        D ] }	|	j        s|                     ||	
           !| j         r:| j         D ]}
| !                    ||
           | j         "                                 | j#        rc| j$        r'| %                    |tL          j'        | j(                   | j)        r'| %                    |tL          j*        | j+                   d| _#        | ,                    ||           | j-        .                                D ]}| /                    |||           | j0        r4| 1                    || j0                   | j0        "                                 | j2        r| 1                    |d           d| _2        |$|j3        j4        s| 5                    |||           | j6        rn| j6                                        }	 | 7                    ||tL          j8                   n*# tr          $ r | j6        :                    |           Y nw xY w| j6        ng }g }	 | j;        D ]<}|j<        rP| j=        >                    d|j?         d           | j-        |j?        = | j@        A                    |j?                   Z|jB        jC        r| D                    ||           |j3        jE        r| F                    ||           n|jG        s|j3        j4        ss| H                    |||t          |j3        jJ        | jK        z   | jL        z
  |jM                            }| xjL        |z  c_L        |d	k    r|N                    |           '|N                    |           >	 ||d	d	<   || _;        n# ||d	d	<   || _;        w xY w|jO        rd S | j        j        P                    |           )NTr  rK   )r  r  )r  r   r  r  r  )r  Fr   )r  r  )r  r   )r  r   r  )r  r  r  r  r0  probecomment)r  r  r   rh  z
 discarded)r  r0  )r  r  r0  
max_offset)Qr   r   rr   ru   r  r  r   r%   rs   r  r  r  _pacernext_send_timer   r  r   r   r   rR  rS  _write_path_challenge_framer  _write_ack_framer  _write_handshake_done_framer   _write_path_response_framer  r   r   _write_new_connection_id_framer  !_write_retire_connection_id_frameclearr  r  _write_streams_blocked_framer#   STREAMS_BLOCKED_BIDIr  r  r/  r  _write_connection_limitsr
  rb  _write_stream_limitsr  _write_ping_framer  r-  buffer_is_empty_write_crypto_framer  _write_datagram_framer  r5   
appendleftr  is_finishedr  r  rw   r  r  r=  stop_pending_write_stop_sending_framereset_pending_write_reset_stream_framerr  _write_stream_framer  r  r   r   rj  r  packet_is_emptyupdate_after_send)r   r  r   r  crypto_streamr  rn   r  r  r  r   r0  datagram_pendingto_reshelver   r   s                   rY   r  z!QuicConnection._write_application  s    ,0=*+099;; 	]39#45F 01BCM(0KK]39-.3<<>> 	]39#56F(1KKFSY./Z	=|#u|s':':"&*"3"B"Bs"B"K"K?.E  f555' <L$1 =\5V = "
1I44 '9 5    --"+, .    9=L5 <+0C0C))'C)PPP / 944W4EEE38D0 #4 =33 '<3QRS3T 4    !2::<<<	 #4 = &*_  M(1 ;;$+= <   
 . 8+/+F  >>$+_ ?     /55777 0 :1 99$+'4'I"&"? :   
 0 99$+'4'H"&"> :   
 5:D1 --gU-KKK -..00 W W))'v)VVVV ! +&&w0BCCC"((*** " ,&&w&@@@&+# (1E1U(((#5 )   
 ) 
#'#:#B#B#D#D .. '-#0#E /    
 -   +667GHHHE ) 
 -/K%'D*+"1 !/ !/F) !**+QV5E+Q+Q+QRRR M&*:;.2263CDDD 3 W66wv6VVV}2 %66wv6VVVV#. %v}7T %#77$+"'#)'* & <"&"7!8"&"<!= !' =	( (	  8 
  
  22d:22!88 KK///$&&v....C!/P (QqS	&*## (QqS	&*#****& =
!333<<<uZ	=s   "P* *$QQ EV5 5Wc                   | j         |         }|j                                        sd S | j        |         }| j        |         }	 |t
          j        j        k    rt          j        }nt          j	        }|
                    ||           |j        |                     |||           |j        j        s|                     |||          rd| _        | j        rm| j        sf|t
          j        j	        k    s3| j         t
          j        j	                 j                                        s|                     |d           d| _        |j        rd S )NTr  r  Fr  r  )r   r  r  r   r  r   rr   rq   r%   rt   r  r  r  r-  r  r  r  r   r  r  )r   r  r   r  r  r  r  rn   s           rY   r  zQuicConnection._write_handshake  sj    u%{##%% 	F,U3U# 		))),4,6  f555 |'%%gU%LLL !'7 0++#5 ,   0 +0D' #	,0	, SY000=)<=BKKMM 1 &&w&@@@&+#& A 	r[   c                   ||j         z
  }t          |dz            | j        z	  }|                    t          j        t          | j        ||j        f          }t          ||j
        |          }d |_        | j        9|j                            | j                            |j
        |                     |dk    r'|j        dz  dk    r|                     |d           d S d S d S )	Nr  r  handlerhandler_args)rangesdelayr   rK   r   zACK-of-ACK triggerr  )r  r_   r   start_framer#   ACKACK_FRAME_CAPACITYr?  r  r0   r  r  r   r   r  r  r  r  )r   r  r  r  r  r  r  r  s           rY   r  zQuicConnection._write_ack_frame  s    %55		G 3448VV!!')!>?	 " 
 
  U_6GHH (&--!22 ?) 3     A::'/!3q88""74H"IIIII :88r[   c                   |>|t           j        j        t           j        j        fv rt          j        }t          j        }d}|                    d          }t          |          }|i|
                    t          j        t          |z             }|                    |           |                    |           |                    |           n}|
                    t          j        t           |z             }|                    |           |                    |           |                    |           |                    |           | j        7|j                            | j                            |||                     d S d S )Nr  r  r  r   )r   rr   rq   rt   r"   APPLICATION_ERRORr#   r  encodert  r  APPLICATION_CLOSE APPLICATION_CLOSE_FRAME_CAPACITYpush_uint_var
push_bytesr  TRANSPORT_CLOSE_FRAME_CAPACITYr   r   r  r  )	r   r  r   r   r   r   reason_bytesr  r  s	            rY   r  z,QuicConnection._write_connection_close_frame  s    %CI,=sy?R+S"S"S&8J&.JM$++F33L))%%/9MI &  C j)))m,,,NN<((((%%-7-G &  C j)))j)))m,,,NN<((( (&--!??))"/ @       )(r[   c                   | j         | j        | j        fD ]}|j        dz  |j        k    r6|xj        dz  c_        | j                            d|j        |j                   |j        |j        k    r|	                    |j
        t          | j        |f          }|                    |j                   |j        |_        | j        >|j                            | j                            |j
        |j                             dS )z:
        Raise MAX_DATA or MAX_STREAMS if needed.
        r   zLocal %s raised to %dr  Nr  )r   r   r   r   r   r  r  r   r   r  r   CONNECTION_LIMIT_FRAME_CAPACITYrA  r  r   r   r  r  )r   r  r  r  r  s        rY   r  z'QuicConnection._write_connection_limits  s!     ('
 	 	E
 zA~++q ""#:EJTTT{ej(())$< >"'	 *   !!%+..."[
 $0.55)GG','7$)K H    )	 	r[   c           
     T   dt          |j        j                  z   }|j                            |j        |z
            }||                    t          j        ||j        j        |j	        |j	        t          |j                  z   f          }|                    |j	                   |                    t          |j                  dz             |                    |j                   | j        2|j                            | j                            |                     dS dS )NrN   r  r=   TF)r   r-  next_offset	get_frameremaining_flight_spacer  r#   ry  on_data_deliveryr  rt  r  r  push_uint16r  r   r   r  r  )r   r  r  r0  frame_overheadr  r  s          rY   r  z"QuicConnection._write_crypto_frame>  s    ]6=+DEEE''(F(WXX%%$'6#lEL3uz??,JK	 &  C el+++OOC
OOf4555NN5:&&&  ,*11%99%@@   4ur[   r#   c                h   |t           j        k    sJ t          |          }dt          |          z   |z   }|                    ||          }|                    |           |                    |           | j        3|j        	                    | j        
                    |                     dS )zl
        Write a DATAGRAM frame.

        Returns True if the frame was processed, False otherwise.
        r   r  Nr  T)r#   r  rt  r   r  r  r  r   r   r  r  )r   r  r  r   r  
frame_sizer  s          rY   r  z$QuicConnection._write_datagram_frameW  s     ]?????Tv...7
!!*z!BB&!!!t (&--!77v7FF   tr[   c                    |                     t          j        t          | j                   | j        3|j                            | j                                                   d S d S )N)r  r  )	r  r#   HANDSHAKE_DONEHANDSHAKE_DONE_FRAME_CAPACITYrC  r   r   r  r  )r   r  s     rY   r  z*QuicConnection._write_handshake_done_frameo  sx    (24 	 	
 	
 	
 (&--!==??     )(r[   c                   d}|                     t          j        t          | j        |f          }|                    |j                   |                    |           |                    t          |j	                             |
                    |j	                   |
                    |j                   d|_        | j                            t          j        |j	                             | j        G|j                            | j                            |j	        ||j        |j                             d S d S )Nr   r  Tr  r  )r  r#   NEW_CONNECTION_ID NEW_CONNECTION_ID_FRAME_CAPACITYrH  r  r   
push_uint8rt  rf   r  r   r   r   r  r   ConnectionIdIssuedr   r   r  )r   r  r  r  r  s        rY   r  z-QuicConnection._write_new_connection_id_frame|  sD    !!+57')	 " 
 
 	-7888/***s=,--...}()))}:;;;!%F5MDUVVVWWW (&--!@@"/"3$3$1$A*7*M	 A       )(r[   c                    |                     t          j        t                    }|                    |           | j        5|j                            | j                            |                     d S d S Nr  r  )	r  r#   PATH_CHALLENGEPATH_CHALLENGE_FRAME_CAPACITYr  r   r   r  r  r   r  r  r  s       rY   r  z*QuicConnection._write_path_challenge_frame  s     !!(3P " 
 
 	y!!! (&--!==9=MM     )(r[   c                    |                     t          j        t                    }|                    |           | j        5|j                            | j                            |                     d S d S r  )	r  r#   PATH_RESPONSEPATH_RESPONSE_FRAME_CAPACITYr  r   r   r  r  r  s       rY   r  z)QuicConnection._write_path_response_frame  s     !!'2N " 
 
 	y!!! (&--!<<)<LL     )(r[   	list[int]c                B   |                     t          j        t          | j        t          |          f           | j                            d|rd| dnd|j                   | j	        3|j
                            | j	                                                   d S d S )Nr  zSending PING%s in packet %dz ()r  )r  r#   PINGPING_FRAME_CAPACITYrN  tupler  r  r  r   r   r  r  )r   r  rI  r  s       rY   r  z QuicConnection._write_ping_frame  s     	(*++	 	 	
 	
 	
 	)&.OOOOOB!	
 	
 	
 (&--d.?.Q.Q.S.STTTTT )(r[   c                   |                     t          j        t          |j        j                  }|j                                        }|                    |j                   |                    |j	                   |                    |j
                   | j        F|j                            | j                            |j	        |j
        |j                             d S d S )Nr   r  r  r  )r  r#   RESET_STREAMRESET_STREAM_FRAME_CAPACITYr-  on_reset_deliveryget_reset_framer  rw   r   r  r   r   r  r  r   r  r0  r  r  s        rY   r  z(QuicConnection._write_reset_stream_frame  s    
 !!$10M3 " 
 

 --//%/***%*+++%*+++ (&--!;;$/$/#o <       )(r[   c                   |                     t          j        t          | j        |f          }|                    |           | j        4|j                            | j        	                    |                     d S d S )Nr  )
r  r#   RETIRE_CONNECTION_IDRETIRE_CONNECTION_ID_CAPACITYrP  r  r   r   r  r  )r   r  r   r  s       rY   r  z0QuicConnection._write_retire_connection_id_frame  s     !!.2:)+	 " 
 
 	/*** (&--!CCOTT     )(r[   c                   |                     t          j        t          |j        j                  }|j                                        }|                    |j                   |                    |j	                   | j
        @|j                            | j
                            |j	        |j                             d S d S )Nr  r#  )r  r#   STOP_SENDINGSTOP_SENDING_FRAME_CAPACITYr=  on_stop_sending_deliveryget_stop_framer  rw   r   r   r   r  r$  r  s        rY   r  z(QuicConnection._write_stop_sending_frame  s    
 !!$10O< " 
 

 ..00%/***%*+++ (&--!;;$/5? <       )(r[   r  c           
     Z   dt          |j                  z   |j        j        rt          |j        j                  ndz   }|j        j        }|j                            |j        |z
  |          }|9t          j        dz  }|j	        r|dz  }|j
        r|dz  }|                    |||j        j        |j	        |j	        t          |j                  z   f          }	|	                    |j                   |j	        r|	                    |j	                   |	                    t          |j                  dz             |	                    |j                   | j        9|j                            | j                            ||j                             |j        j        |z
  S dS )	NrN   r   r   r   r   r  r=   rz   )r   rw   r-  r  r  r  r  r#   STREAM_BASEr  r(  r  r  rt  r  r  r  r  r   r   r  r)  )
r   r  r  r0  r  r  previous_send_highestr  r   r  s
             rY   r  z"QuicConnection._write_stream_frame
  s    F,--. =,fm7888 	 !' <''*^;Z
 
 &2Q6J|  a
y  a
%%'6#lEL3uz??,JK	 &  C f.///| 0!!%,///OOC
OOf4555NN5:&&&  ,*11%99)9 :     =/2GGG1r[   c                >   |j         rN|j        j        dz  |j         k    r6|xj         dz  c_         | j                            d|j        |j                    |j        |j         k    r|                    t          j	        t          | j        |f          }|                    |j                   |                    |j                    |j         |_        | j        B|j                            | j                            |j         |j                             dS dS dS )z
        Raise MAX_STREAM_DATA if needed.

        The only case where `stream.max_stream_data_local` is zero is for
        locally created unidirectional streams. We skip such streams to avoid
        spurious logging.
        r   z,Stream %d local max_stream_data raised to %dr  Nr  )ri  r=  r  r  r  rw   rE  r  r#   MAX_STREAM_DATAMAX_STREAM_DATA_FRAME_CAPACITYrF  r  r   r   r  r  )r   r  r  r0  r  s        rY   r  z#QuicConnection._write_stream_limits?  sH    (		.2V5QQQ((A-((L> ,  
 ,0LLL%%-79$Y	 &  C f.///f:;;;060LF-  ,*11%BB & <HX C       ML -,r[   c                    |                     |t                    }|                    |           | j        D|j                            | j                            |t          j        k    |                     d S d S )Nr  r-  )	r  STREAMS_BLOCKED_CAPACITYr  r   r   r  r.  r#   r/  )r   r  r   r  r  s        rY   r  z+QuicConnection._write_streams_blocked_framef  s     !!*7O!PP%    (&--!>>&0M4U&U ?       )(r[   )r%  r   r!  r&  r"  r&  r#  r'  r$  r(  rQ   r)  )rQ   r_   )rQ   r{  )rQ   r  )rQ   r  )rQ   r   )rQ   rg   )rQ   r)  )r   r_   r   r   r   rP   rQ   r)  )r   r   r  r   rQ   r)  )r  r   rQ   r  r   )rQ   r  )r  r   rQ   r)  )rQ   r  )r  rg   r   r   r  r   rQ   r)  )rw   r_   r   r_   rQ   r)  )r2  r_   rQ   r)  )r  rg   rQ   r)  )rw   r_   r  rg   r7  ra   rQ   r)  )r@  rP   rQ   r)  )r   r_   rw   r_   rQ   r)  )r  ra   r  r   rQ   r)  )r   ro   rQ   r)  )r   r   rQ   r   )r   r_   rw   r_   rQ   r:   )rw   r_   rQ   r:   )rt  ru  rQ   r)  )r  rg   rQ   r)  )r#  r   r   r_   r  r   rQ   r)  )r0  rP   r  rP   rQ   r)  )r:  r3   r  r8   r;  r_   rQ   r)  )r:  r3   r  r   rQ   r)  )r:  r3   rQ   r)  )r:  r3   r0  r:   rQ   r)  )r:  r3   r  r   rQ   r)  )r:  r3   rI  rJ  rQ   r)  )r:  r3   r   r_   rQ   r)  )r#  r   rQ  rg   r  ra   rQ   rR  )r  r$   r  rg   r  r   rQ   r)  )r  r$   r  r   rQ   r)  )r  r   rQ   r)  )r  rg   r  ra   rQ   r)  )r  r   rQ   r)  )r  ra   rQ   r)  )
r  r  r   ro   r~  r  r  rg   rQ   r)  )r  rg   r   r   )r  r4   r   r   r  r   rQ   r)  )r  r4   r   ro   r  r   rQ   r)  )r  r4   r  r8   r  r   rQ   r)  )r  r4   r   ro   r   r_   r   r   r   rP   rQ   r)  )r  r4   r  r8   rQ   r)  )r  r4   r  r8   r0  r:   rQ   ra   )r  r4   r  rg   r   r#   rQ   ra   )r  r4   rQ   r)  )r  r4   r  r   rQ   r)  )r  r4   r  rg   rQ   r)  )r  r4   rI  r  )r  r4   r0  r:   rQ   r)  )r  r4   r   r_   rQ   r)  )
r  r4   r  r8   r0  r:   r  r_   rQ   r_   )r  r4   r  r8   r0  r:   rQ   r)  )r  r4   r   r#   r  r_   rQ   r)  )kr   r   r   __doc__	__slots__r   propertyrv  rx  rz  r  r  r  r%  r!  r  r"   r%  r  r  r  r  r  r  r  r'  r*  r1  r4  r6  r:  r?  rP  rT  rV  r  r  r  r  r  r  ro  r,  rz  r  r^  ro  ra  rh  rq  rp  rd  re  rf  rg  rk  rb  r\  rm  rn  r]  r_  rl  r`  rc  ri  rj  r  r  r?  rA  rC  rF  rH  rN  rP  r  r  r  r  r  r_  r[  rF  rK  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ry   r[   rY   r   r      s        UIv <@37BFBF
 
 
 
 
 
B " " " X" - - - X- , , , X,U U U U) ) ) )/ / / / # # # X# 8 8 8 X8% % % %" (0!%	' ' ' ' ',   0I I I IV3 3 3 3 3   ,: : : :2	 	 	 	|9 |9 |9 |9|	6 6 6 6( ( ( (' ' ' '- - - - ?D9 9 9 9 9) ) ) )(6T 6T 6T 6Tp	 	 	 		 	 	 	
 
 
 
: : : :% % % %
! 
! 
! 
!1 1 1 1	% 	% 	% 	%2 2 2 2h0 0 0 0d5 5 5 5F8 F8 F8 F8P
 
 
 
B&D &D &D &DPY2 Y2 Y2 Y2v   E E E E@@ @ @ @2- - - -,< < < <>; ; ; ;:: : : ::c c c cJ   ,X X X X$@ @ @ @() ) ) )2U U U U84 84 84 84t*) *) *) *)X
 
 
 
8=4 =4 =4 =4~: : : :,   .	 	 	 		 	 	 	; ; ; ;   0 0 0 02 2 2 2+ + + +, , , ,@ @ @ @ ',	X2 X2 X2 X2 X2t0 0 0 0d] ] ] ]~$ $ $ $
J 
J 
J 
J   
# # # # 8={9 {9 {9 {9 {9z+ + + +Z   2 2 2 2$) ) ) )V, , , ,i= i= i= i=V* * * *XJ J J J8+ + + +Z   B   2   0      >       =?U U U U U&   2   "   ,3 3 3 3j% % % %N     r[   r   )rO   rP   rQ   rR   )r^   r_   r`   r_   rQ   ra   )rf   rg   rQ   rP   )rn   r%   rQ   ro   )rw   r_   rQ   ra   )r~   ra   rw   r_   rQ   ra   ry   )
__future__r   rj   loggingrR  collectionsr   dataclassesr   enumr   	functoolsr   r   typingr	   r
   r   r%  r   r5  r   r  r   _compatr   r   r   _hazmatr   r   r   r   r  r   r  r   r   r   r   r  r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   packet_builderr2   r3   r4   r5   recoveryr6   r7   r8   r0  r9   r:   r;   	getLoggerr  rr   rq   rt   rs   ru   rV   rx  r  r  r  r  STREAM_FLAGSr  r  r  r   r  r  r  r  r  r  r  r  r  r  r	  r  r  r  r]   re   rm   rv   r{   r}   r   r   r   	Exceptionr   LoggerAdapterr   r   r   r   r   r\   r   r   r   r  r   ry   r[   rY   <module>r)     s   " " " " " "   				       ! ! ! ! ! !       ( ( ( ( ( ( ( ( / / / / / / / / / / (000000''''''       G G G G G G G G G G < < < < < < < < < < 4 4 4 4 4 4       L L L L L L L L L L L L                                             .            I H H H H H H H H H C C C C C C C C C C		6	"	" 									          %    #$q+<'<#<  "#&7"7  ! !"Q):%:!: !$::=WW ! !& $  !&7"77  !$5 5 !&7"77 00 !"Q):%:!: ; ; ; ;
 
 
 
1 1 1 1! ! ! !       > > > > B B B B       
 
 
 
 
) 
 
 
? ? ? ? ?G1 ? ? ?
            '   
X 
X 
X 
X 
X 
X 
X 
X         Y#$& 
5 5 5 5 5 5 5 5 5 5r[   