
    @OOf}                       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
 d dlmZmZmZmZmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZ d
dlmZ d
dlm Z m!Z! d
dl"m#Z# d
dl$m%Z%m&Z&m'Z' d
dl(m)Z) d
dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB d
dlCmDZDmEZEmFZF d
dlGmHZHmIZI d
dlJmKZKmLZLmMZM  ej                  d      Z(dZOej                  j                  ej                  j                  ej                  j                  ej                  j                  d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   e4z   ZbdZcdZdd
Zed
d ez  z   Zfd
ez   Zgd
dez  z   Zhd
ez   Zid
d ez  z   Zjd!ekd"eej                     fd#Zld$emd"ekfd%Znd&eod"ej                  fd'Zpd(eod"ej                  fd)Zrd*eod"esfd+Ztd*eod"esfd,Zu G d- d.      Zv G d/ d0ew      Zx G d1 d2ej                        Zze G d3 d4             Z{ G d5 d6e      Z|e G d7 d8             Z}e G d9 d:             Z~eemgdf   Z ee|j                  e|j                  e|j                  g      Z G d; d<      Zy)=    N)deque)	dataclass)Enum)partial)
AnyCallableDequeDict	FrozenSetListOptionalSequenceSetTuple   )tls)UINT_VAR_MAXUINT_VAR_MAX_SIZEBufferBufferReadErrorsize_uint_var   )events)SMALLEST_MAX_DATAGRAM_SIZEQuicConfiguration)K_GRANULARITY)CryptoError
CryptoPairKeyUnavailableError)QuicLoggerTrace)CONNECTION_ID_MAX_SIZENON_ACK_ELICITING_FRAME_TYPESPACKET_TYPE_HANDSHAKEPACKET_TYPE_INITIALPACKET_TYPE_ONE_RTTPACKET_TYPE_RETRYPACKET_TYPE_ZERO_RTTPROBING_FRAME_TYPESRETRY_INTEGRITY_TAG_SIZESTATELESS_RESET_TOKEN_SIZEQuicErrorCodeQuicFrameTypeQuicProtocolVersionQuicStreamFrameQuicTransportParametersget_retry_integrity_tagget_spin_bitis_draft_versionis_long_headerpull_ack_framepull_quic_headerpull_quic_transport_parameterspush_ack_framepush_quic_transport_parameters)QuicDeliveryStateQuicPacketBuilderQuicPacketBuilderStop)QuicPacketRecoveryQuicPacketSpace)FinalSizeError
QuicStreamStreamFinishedErrorquic @  )IH01l    )NCLIENT_EARLY_TRAFFIC_SECRETCLIENT_HANDSHAKE_TRAFFIC_SECRETCLIENT_TRAFFIC_SECRET_0)NNSERVER_HANDSHAKE_TRAFFIC_SECRETSERVER_TRAFFIC_SECRET_0   l               d   @   	      shortcutreturnc                 &    t        d | D              S )Nc              3   .   K   | ]  }t         |     y wN)EPOCH_SHORTCUTS).0is     X/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/aioquic/quic/connection.py	<genexpr>zEPOCHS.<locals>.<genexpr>w   s     :A_Q':s   )	frozenset)rR   s    rZ   EPOCHSr]   v   s    ::::    cidc                 J    t        j                  |       j                  d      S )Nascii)binasciihexlifydecode)r_   s    rZ   dump_cidre   z   s    C ''00r^   packet_typec                    | t         k(  rt        j                  j                  S | t        k(  rt        j                  j
                  S | t        k(  rt        j                  j                  S t        j                  j                  S rV   )	r$   r   EpochINITIALr'   ZERO_RTTr#   	HANDSHAKEONE_RTT)rf   s    rZ   	get_epochrm   ~   s]    ))yy   	,	,yy!!!	-	-yy"""yy   r^   versionc                     t        |       rt        j                  j                  S t        j                  j                  S rV   )r2   r   ExtensionTypeQUIC_TRANSPORT_PARAMETERS_DRAFTQUIC_TRANSPORT_PARAMETERSrn   s    rZ   "get_transport_parameters_extensionrt      s.       @@@  :::r^   	stream_idc                     | dz   S )z9
    Returns True if the stream is client initiated.
    r    ru   s    rZ   stream_is_client_initiatedry      s     Ar^   c                     t        | dz        S )z7
    Returns True if the stream is unidirectional.
    r   )boolrx   s    rZ   stream_is_unidirectionalr|      s     	Ar^   c                        e Zd ZdededefdZy)Limit
frame_typenamevaluec                 J    || _         || _        || _        d| _        || _        y Nr   )r   r   sentusedr   )selfr   r   r   s       rZ   __init__zLimit.__init__   s%    $			
r^   N)__name__
__module____qualname__intstrr   rw   r^   rZ   r~   r~      s    3 c # r^   r~   c                   ,    e Zd ZdededefdZdefdZy)QuicConnectionError
error_coder   reason_phrasec                 .    || _         || _        || _        y rV   r   r   r   r   r   r   r   s       rZ   r   zQuicConnectionError.__init__   s    $$*r^   rS   c                 x    d| j                   | j                  fz  }| j                  |d| j                  z  z  }|S )NzError: %d, reason: %sz, frame_type: %s)r   r   r   )r   ss     rZ   __str__zQuicConnectionError.__str__   s>    #t8J8J&KK??&#doo55Ar^   N)r   r   r   r   r   r   r   rw   r^   rZ   r   r      s(    +3 +C + +
 r^   r   c                   *    e Zd Zdededeeef   fdZy)QuicConnectionAdaptermsgkwargsrS   c                 0    d| j                   d   d||fS )N[idz] )extra)r   r   r   s      rZ   processzQuicConnectionAdapter.process   s     JJt,c2F::r^   N)r   r   r   r   r   r   r   rw   r^   rZ   r   r      s$    ;3 ; ;c3h ;r^   r   c                   >    e Zd ZU eed<   eed<   dZeed<   dZeed<   y)QuicConnectionIdr_   sequence_numberr^   stateless_reset_tokenFwas_sentN)	r   r   r   bytes__annotations__r   r   r   r{   rw   r^   rZ   r   r      s"    	J#&5&Hdr^   r   c                        e Zd ZdZdZdZdZdZy)QuicConnectionStater   r   r   rQ      N)r   r   r   FIRSTFLIGHT	CONNECTEDCLOSINGDRAINING
TERMINATEDrw   r^   rZ   r   r      s    KIGHJr^   r   c                   z    e Zd ZU eed<   dZeed<   dZeed<   dZe	ed<   dZ
ee   ed<   dZee   ed	<   d
ede	fdZy)QuicNetworkPathaddrr   bytes_received
bytes_sentFis_validatedNlocal_challengeremote_challengesizerS   c                 \    | j                   xs | j                  |z   d| j                  z  k  S NrQ   )r   r   r   )r   r   s     rZ   can_sendzQuicNetworkPath.can_send   s,      WT__t%;DDWDW@W$WWr^   )r   r   r   NetworkAddressr   r   r   r   r   r{   r   r   r   r   r   rw   r^   rZ   r   r      sY    
NCJL$'+OXe_+(,huo,XS XT Xr^   r   c                   `    e Zd ZU ej                  ed<   eed<   eed<   ee	e
      ed<   eed<   y)QuicReceiveContextepochhost_cidnetwork_pathquic_logger_framestimeN)r   r   r   r   rh   r   r   r   r   r   r   floatrw   r^   rZ   r   r      s+    99O!! c++
Kr^   r   c                      e Zd ZdZdddddddedee   dee   deej                     deej                     d	ee
   d
dfdZed
efd       Zed
efd       ZddZej"                  ddfdedee   ded
dfdZdeded
dfdZded
eeeef      fdZdd
efdZd
ee   fdZded
dfdZd
eej>                     fdZ d
efdZ!dededed
dfdZ"ddZ#d eded
dfd!Z$d"ed
dfd#Z%ded
dfd$Z&	 dd eded%e'd
dfd&Z(d eded
dfd'Z)d(ed
dfd)Z*ded ed
dfd*Z+ded ed
dfd+Z,dd,Z-d-e'ded
dfd.Z.dd/Z/ded
dfd0Z0d1ejb                  d
dfd2Z2ded
e3fd3Z4ded ed
e5fd4Z6d ed
e5fd5Z7d6ejp                  d
dfd7Z9d8ed
dfd9Z:d:e;ded;e<d
dfd<Z=d:e;ded;e<d
dfd=Z>d:e;ded;e<d
dfd>Z?d:e;ded;e<d
dfd?Z@d:e;ded;e<d
dfd@ZAd:e;ded;e<d
dfdAZBd:e;ded;e<d
dfdBZCd:e;ded;e<d
dfdCZDd:e;ded;e<d
dfdDZEd:e;ded;e<d
dfdEZFd:e;ded;e<d
dfdFZGd:e;ded;e<d
dfdGZHd:e;ded;e<d
dfdHZId:e;ded;e<d
dfdIZJd:e;ded;e<d
dfdJZKd:e;ded;e<d
dfdKZLd:e;ded;e<d
dfdLZMd:e;ded;e<d
dfdMZNd:e;ded;e<d
dfdNZOd:e;ded;e<d
dfdOZPd:e;ded;e<d
dfdPZQd:e;ded;e<d
dfdQZRdRedSed
dfdTZSdRedSed
dfdUZTdVeUdWeVdXed
dfdYZWdVeUdZeXd
dfd[ZYdVeUd
dfd\ZZdVeUd]e5d
dfd^Z[dVeUd_e\d
dfd`Z]dVeUdae^e   d
dfdbZ_dVeUdced
dfddZ`	 dd:e;deedfe'd
ee'e'f   fdgZaddhZbd_e\d
dfdiZcddjZdddkZe	 ddedle'd
dfdmZfd
efdnZgdoehd
dfdpZid ed
e'fdqZjd ed
e'fdrZkdse'd
dfdtZlduej                  d1ejb                  dvej                  dwed
df
dxZodyepdze3ded
dfd{Zqdyepd1ejb                  ded
dfd|ZrdyepdWeVded
dfd}Zsdyepd1ejb                  dedee   ded
dfd~ZtdyepdWeVd
dfdZudyepdWeVd]e5d
e'fdZvdyepdedewd
e'fdZxdyepd
dfdZydyepd_e\d
dfdZzdyepded
dfdZ{dyepded
dfdZ|g dfdyepdaee   fdZ}dyepd]e5d
dfdZ~dyepdced
dfdZdyepd]e5d
dfdZdyepdWeVd]e5ded
ef
dZdyepdWeVd]e5d
dfdZdyepdewdZed
dfdZy)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.
    N)"original_destination_connection_idretry_source_connection_idsession_ticket_fetchersession_ticket_handlertoken_handlerconfigurationr   r   r   r   r   rS   c          	      x   |j                   t        k\  sJ dt         d       |j                  r|J d       |UJ d       |J d       |j                  dk(  sJ d       |j                  J d       |j
                  J d	       |J d
       || _        |j                  | _        t        | _	        d | _
        d | _        d| _        i | _        i | _        d| _        i | _        t#               | _        d| _        d| _        t+        t-        j.                  |j0                        d| j                  st-        j.                  d      nd d      g| _        | j2                  d   j4                  | _        d| _        d| _        d| _        | j2                  d   j4                  | _        tA        tB        jD                  d|jF                        | _$        |jJ                  | _&        |jJ                  | _'        |jJ                  | _(        tA        tB        jR                  dd      | _*        tA        tB        jV                  dd      | _,        | j                  rdnd| _-        | j                  rdnd| _.        d | _/        |j                   | _0        g | _1        d | _2        d| _3        d| _4        t+        t-        j.                  |j0                        d       | _5        g | _6        to        dg      | _8        d| _9        |j                  | _:        d | _;        d| _<        d| _=        d | _>        d | _?        d| _@        d| _A        d | _B        d| _C        d| _D        d| _E        d| _F        d| _G        d| _H        || _I        i | _J        d| _K        d| _L        t        j                  | _O        i | _P        g | _Q        g | _R        g | _S        to               | _T        d | _U        d| _V        | j                  r| jj                  j4                  | _W        n|| _W        t        t        dt        | j                        i      | _[        |j                  r6|j                  j                  |j                  | j                        | _;        t        |j                  |j                  | j`                  | j                   | jv                  | j                  | j                        | _b        d| _c        t#               | _d        d| _e        g | _f        d| _g        g | _h        d| _i        || _j        || _k        || _l        i d| j                  t        d      fd| j                  t        d      fd| j                  t        d      fd| j                  t        d      fd| j                  t        d       fd!| j                  t        d       fd"| j                  t        d      fd#| j                  t        d$      fd| j                  t        d       fd%| j                  t        d       fd&| j                  t        d       fd'| j                  t        d       fd(| j                  t        d       fd)| j                  t        d       fd*| j                  t        d       fd+| j                  t        d       fd| j                  t        d       fi d,| j                  t        d       fd-| j                  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d9| j                  t        d$      fd:| j                  t        d       fd;| j                  t        d       f| _        y )<Nz.The smallest allowed maximum datagram size is z bytesz:Cannot set original_destination_connection_id for a clientz2Cannot set retry_source_connection_id for a clientz'Cannot set `token_handler` for a serverr^   z-Cannot set `configuration.token` for a serverz(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)r_   r   r   r   r   rQ   rM   max_data)r   r   r   max_streams_bidi   max_streams_unir   )r_   r   r   )	is_clientodcid)congestion_control_algorithminitial_rttmax_datagram_size!peer_completed_address_validationquic_logger
send_probeloggerIH01IH1r   01      rL   rF   rP   
                                                            0   1   )r   r   r   tokencertificateprivate_key_configuration
_is_clientr   
_ack_delay	_close_at_close_event_connect_called_cryptos_crypto_buffers_crypto_retransmitted_crypto_streamsr   _events_handshake_complete_handshake_confirmedr   osurandomconnection_id_length
_host_cidsr_   r   _host_cid_seq_local_ack_delay_exponent!_local_active_connection_id_limit#_local_initial_source_connection_idr~   r,   MAX_DATAr   _local_max_datamax_stream_data!_local_max_stream_data_bidi_local"_local_max_stream_data_bidi_remote_local_max_stream_data_uniMAX_STREAMS_BIDI_local_max_streams_bidiMAX_STREAMS_UNI_local_max_streams_uni_local_next_stream_id_bidi_local_next_stream_id_uni_loss_at_max_datagram_size_network_paths
_pacing_at_packet_number_parameters_received	_peer_cid_peer_cid_availableset_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_retry_count_retry_source_connection_id_spaces	_spin_bit_spin_highest_pnr   r   _state_streams_streams_queue_streams_blocked_bidi_streams_blocked_uni_streams_finished_version_version_negotiation_count#_original_destination_connection_idr   r   re   _loggerr   start_tracer<   r   r   _send_probe_loss_close_pending_datagrams_pending_handshake_done_pending_ping_pending_probe_pending_retire_connection_ids_streams_blocked_pending_session_ticket_fetcher_session_ticket_handler_token_handler_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   r   s          rZ   r   zQuicConnection.__init__   s    ..2LL 	
<)*&2	
L ""2:LKL: +2DCD2 !(S*SS(##s*?>?* ))5:9:5 ))5:9:5 3>MLM> ,'11'*.CG$578:%*"<>05#( $)!JJ}AAB !<@OObjjnQU	
 *..)*&12.37??13E3I3I0$$--(( 

 2?1N1N.2?2O2O/*7*G*G'',$55#(
$
 ',$44;LTW'
# 04!A'.2oo1&)-"/"A"A57+/$)!)

===>PT
 <> 47H'%&"(..7;*+'23/EI19=% !%&">B,23/340+,(()%'($+E(9; !)55/10279"68!+.5'+*+'??7;~~7I7ID4 3 4
 -T8D$L$LMN
 $$ - 9 9 E E'11>> !F !D ()6)S)S%11"5526//.A))''<<

 $05',$(*#13#(-% (>$'=$+"!
4--vf~>"!
4**F6N;"!
 4))6%=9"!
 4))6%=9	"!

 422F4LA"!
 422F4LA"!
 4,,fUm<"!
 4//="!
 4,,fTl;"!
 4,,fTl;"!
 4,,fTl;"!
 4,,fTl;"!
 4,,fTl;"!
 4,,fTl;"!
 4,,fTl;"!
  4,,fTl;!"!
" 4..t=#"!
$ 455vd|D%"!
& 466tE'"!
( 455vd|D)"!
* 422F4LA+"!
, 4996$<H-"!
. 455vd|D/"!
0 455vd|D1"!
2 477F3"!
4 4::F4LI5"!
6 444fTlC7"!
8 433VD\B9"!
: 466vG;"!
< 466tE="!
> 444fSkB?"!
@ 4..t=A"!
B 4..t=C"!
r^   c                     | j                   S rV   )r   r   s    rZ   r   zQuicConnection.configuration  s    """r^   c                     | j                   S rV   )r@  rg  s    rZ   r   z1QuicConnection.original_destination_connection_id  s    777r^   c                 t    | j                   r,| j                  | j                         | j                          yy)z
        Switch to the next available connection ID and retire
        the previous one.

        .. aioquic_transmit::
        N)r!  _retire_peer_cidr   _consume_peer_cidrg  s    rZ   change_connection_idz#QuicConnection.change_connection_id  s2     ##!!$..1 ""$ $r^    r   r   r   c                     | j                   8| j                  t        vr%t        j                  |||      | _         d| _        yyy)a:  
        Close the connection.

        .. aioquic_transmit::

        :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   r8  
END_STATESr   ConnectionTerminatedrE  r   s       rZ   closezQuicConnection.close  sJ      $J)F & ; ;%%+!D
 #'D *G$r^   r   nowc                     | j                   r| j                  rJ d       d| _        t        |d      g| _        | j                  j
                  d   | _        | j                  |       y)z
        Initiate the TLS handshake.

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

        .. aioquic_transmit::

        :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   r   rr  N)r   r   r   r  r   supported_versionsr>  _connect)r   r   rr  s      rZ   connectzQuicConnection.connect  se     OOD$8$8	HG	H8#.t$GH++>>qA#r^   c                 ~
   | j                   d   }| j                  t        v rg S t        | j                  | j
                  | j                  | j                  | j                  j                  | j                  | j                  | j                  | j                  	      }| j                  ryg }| j                  sC|t         j"                  j$                  t&        ft         j"                  j(                  t*        fgz  }|j-                  t         j"                  j.                  t0        f       |D ]  \  }}| j2                  |   }|j4                  j7                         s0|j9                  ||       | j;                  ||| j<                  j>                  | j<                  j@                  | j<                  jB                          | jD                  jG                  d| j<                  j>                  | j<                  jB                         d| _        | jI                  d|       n| jJ                  jL                  | jJ                  jN                  z
  |_(        | jR                  r*|jP                  | j                  k  r| j                  |_(        |jT                  s!|jV                  dz  |jX                  z
  |_-        	 | j                  sLt         j"                  j$                  t         j"                  j(                  fD ]  }| j]                  |||        | j_                  |||       |jc                         \  }}	|ru|jd                  | _        d}
|	D ]%  }||_3        | jJ                  ji                  || jj                  |jl                     	       |jl                  t         j"                  j(                  k(  rd}
| j                  u| j                  jo                  d
d|jp                  |jd                  | j                  js                  |jr                        tu        |jr                        rtw        | j                        ndtw        | j                  j                        dd|jx                  id       ( |
r5| j
                  r)| j{                  t         j"                  j$                         g }|D ]x  }t}        |      }|xjX                  |z  c_,        |j-                  ||j~                  f       | j                  M| j                  jo                  d
ddt        |z   |dgd       z |S # t`        $ r Y w xY w)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   r   packet_numberpeer_cid
peer_tokenr   spin_bitrn   )builderr   r   r   r   z,Connection close sent (code 0x%X, reason %s)FTis_initiatorrr  rQ   )packetspace	transportpacket_sentrm  )ry  rf   sciddcidlengthframesheaderrawcategoryeventdatadatagrams_sentr   r  payload_lengthcountr  )Ar  r8  ro  r:   r   r   r  r  r   r_   r%  r&  r6  r>  rE  r  r   rh   ri   r$   rk   r#   appendrl   r%   r   sendis_validstart_packet_write_connection_close_framer   r   r   r   rA  info_close_beginrD  congestion_windowbytes_in_flightmax_flight_bytesrI  r   r   r   max_total_bytes_write_handshake_write_applicationr;   flushry  	sent_timeon_packet_sentr5  r   	log_eventr   rf   r3   re   
sent_bytes_discard_epochlenr   UDP_HEADER_SIZE)r   rr  r   r}  epoch_packet_typesr   rf   crypto	datagramspacketssent_handshaker  retdatagramr  s                  rZ   datagrams_to_sendz QuicConnection.datagrams_to_send  s    **1-;;*$I $]]oo"55--^^''''))^^MM

 !#,,"YY&&(;<YY((*?@' " %%syy'8'8:M&NO&8 
"{u-;;'')((f=66 '##'#4#4#?#?#'#4#4#?#?&*&7&7&E&E 7 	
 LL>!!,,!!//
 #(D4S9 

,,tzz/I/II $ ##,,t/F/FF+/+B+B(  ,, //!3l6M6MM '00"%))"3"3SYY5H5H!I C--gucBC''sC %]]_	7")"7"7D #N! #& 

))!fll)C *  <<399#6#66%)N $$0%%//!,+&,&?&?171E1E/3/@/@/L/L$*$6$60"
 (6f6H6H'I %-T]]$;)+(01C1C(D' %-f.?.?#@ 0 @ $//##CII$5$56 ! 	H ]N##~5#JJ,"3"345  ,!!++(*!" +:N*J2@  , 	& 
E ) s   8A+T/ /	T<;T<c                 6    |r| j                   S | j                  S )zT
        Return the stream ID for the next stream created by this endpoint.
        )r  r  )r   is_unidirectionals     rZ   get_next_available_stream_idz+QuicConnection.get_next_available_stream_id  s     111222r^   c                    | j                   }| j                  t        vr| j                  j                  D ]+  }|j
                  |j
                  |k  s |j
                  }- | 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   r8  ro  rD  spacesack_atget_loss_detection_timer  r  )r   timer_atr  s      rZ   	get_timerzQuicConnection.get_timer  s     >>;;j(** ,<<+x0G$||H,
 !JJ>>@DM}}(T]]X-E== *t/I??r^   c                 v   || j                   k\  rV| j                  9t        j                  t        j
                  t        j                  d      | _        | j                          y| j                  H|| j                  k\  r8| j                  j                  d       | j                  j                  |       yyy)zi
        Handle the timer.

        .. aioquic_transmit::

        :param now: The current time.
        NzIdle timeoutr   zLoss detection triggeredrt  )r   r   r   rp  r+   INTERNAL_ERRORr,   PADDING
_close_endr  rA  debugrD  on_loss_detection_timeoutr   rr  s     rZ   handle_timerzQuicConnection.handle_timer  s     $..   ($*$?$?,;;,44"0%!
 OO ==$)=LL9:JJ00S09 *>$r^   c                 V    	 | j                   j                         S # t        $ r Y yw xY w)zy
        Retrieve the next event from the event buffer.

        Returns `None` if there are no buffered events.
        N)r  popleft
IndexErrorrg  s    rZ   
next_eventzQuicConnection.next_event  s,    	<<'')) 		s    	((c                     | j                   j                  }| j                  t        || j                        }t	        |d| j
                  j                         z        S r   )r   idle_timeoutr*  minmaxrD  get_probe_timeout)r   r  s     rZ   _idle_timeoutzQuicConnection._idle_timeout  sR     **77((4|T-J-JKL<TZZ%A%A%C!CDDr^   r  c                 6   | j                   t        v ry| j                  7t        |      }| j                  j	                  dddt
        |z   |dgd       | j                  || j                         z   | _        t        |      }|j                         s&|j                         }	 t        || j                  j                  	      }| j                   sb|j"                  t$        k(  rOt        |      t&        k  r=| j                  0| j                  j	                  dd
dd|j                  |z
  id       yd}| j(                  D ])  }	|j*                  |	j,                  k(  s|	j.                  } n | j                   s|j"                  t0        k(  r/|-| j                   | j                  j	                  dd
ddi       y| j                   rl| j                   t2        j4                  k(  rN|j6                  t8        j:                  k(  r0| j<                  s#g }
|j                         s0|
j?                  |jA                                |j                         s0| j                  _| j                  j	                  ddg dtC        |jD                        tC        |j*                        dd|j                         |z
  id       | jF                  |
v r)| jH                  jK                  d| jF                  z         y| j                  jL                  D cg c]	  }||
v s| }}|r|d   nd}| j                  6| j                  j	                  dd|
| j                  jL                  |d       |e| jH                  jO                  d       tQ        jR                  tT        jV                  tX        jZ                  d      | _.        | j_                          yd| _0        t9        |      | _#        | xj<                  dz  c_        | jH                  jc                  d| jF                         | je                  |       y|j6                  O|j6                  | j                  jL                  vr-| j                   | j                  j	                  dd
ddi       y|j"                  tf        k(  r| j                   r| jh                  sz|j*                  | jj                  k(  r`|jl                  to        |jq                  ||j                         tr        z
        | jt                  j,                  |j6                        k(  r| j                  _| j                  j	                  ddg dtC        |jD                        tC        |j*                        dd|j                         |z
  id       |jD                  | jt                  _        |jv                  | _<        | xjh                  dz  c_4        |jD                  | _=        | jH                  jc                  d t        |jv                        z         | je                  |       y| j                   | j                  j	                  dd
dd!i       yd"}| j}                  |      }| j                   sv| j                   t2        j4                  k(  rY|j"                  t$        k(  sJ d#       d$}|g| _?        t9        |j6                        | _#        | j                  |j*                         t        |j"                        }| j                  |   }|t        j                  j                  k(  r(| j                  t        j                  j                     }n| j                  |   }|j                         |z
  }|j                         |j                  z   }|j                  |       	 |j                  ||| ||j                        \  }}}|j                  rd'}nd(}|d   |z  r1| j                  tT        j                  tX        jZ                  d)       yd}| j                  wg }| j                  j	                  dd||| j                  j#                  |j"                        tC        |j*                        tC        |jD                        d*d||z
  id       ||j                  kD  r
|dz   |_K        | j                   sF|t        j                  j                  k(  r)| j                  t        j                  j                         | jt                  j.                  ,|jD                  | jt                  _        d| jt                  _        | j                   t2        j4                  k(  r0|jD                  | _X        | j                  t2        j                         |j                  sv|| j                  kD  rgt        |d         }| j                   r	| | _]        n|| _]        || _[        | j                  *| j                  j	                  d+d,d-| j                  i       t        ||j*                  |||.      }	 | j                  |||/      \  }}| j                   t        v s| j                  ry|| j                         z   | _        | j                   s|jj                  | jj                  k7  rn|t        j                  j                  k(  rQ| jH                  j                  d0tC        |jj                        |       |jj                  | _5        | j                          |j                  sJ|t        j                  j                  k(  r-| jH                  j                  d1|j                         d$|_f        |xj                  ||z
  z  c_h        || j~                  vr| j~                  j?                  |       | j~                  j                  |      }|rnsl||j                  kD  r]| jH                  j                  d2|j                         | j~                  j                  |       | j~                  j                  d|       |j                  sZ||j                  kD  r||_j        ||_n        |j                  j                  |       r |j                  || j                  z   |_q        |j                         s%yy# t        $ r? | j                  0| j                  j	                  dd
dd|j                  |z
  id       Y yw xY wc c}w # t        $ r}| jH                  j                  |       | j                   | j                  j	                  dd
dd%i       | j                   re|t        j                  j                  t        j                  j                  fv r/| j                  s#| j                  j                  |       d$| _O        Y d}~Od}~wt        $ rR}| jH                  j                  |       | j                   | j                  j	                  dd
dd&i       Y d}~d}~ww xY w# t        $ rX}| jH                  jK                  |       | j                  |j                  |j                  |j                         Y d}~:d}~ww xY w)3z
        Handle an incoming datagram.

        .. aioquic_transmit::

        :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  !initial_packet_datagram_too_smallr  unknown_connection_idpacket_receivedversion_negotiation)rf   r  r  r  z&Version negotiation packet contains %sr   version_information)server_versionsclient_versionschosen_versionz(Could not find a common protocol versionr   zRetrying with %srt  unsupported_versionrs   retryzRetrying with token (%d bytes)unexpected_packetFzfirst packet must be INITIALTkey_unavailablepayload_decrypt_errorr   r   zReserved bits must be zero)ry  rf   r  r  connectivityspin_bit_updatedstate)r   r   r   r   r   )crypto_frame_requiredzPeer switching to CID %s (%d)z&Network path %s validated by handshakezNetwork path %s promoted)sr8  ro  r&  r  r  r  r   r  r   eoftellr5   r   r  
ValueErrorcapacityr   rf   r$   r   r	  destination_cidr_   r   r#   r   r   rn   r-   NEGOTIATIONr?  r  pull_uint32re   
source_cidr>  rA  warningru  errorr   rp  r+   r  r,   r  r   r  r  r  rv  r&   r3  r   integrity_tagr0   
data_slicer)   r   r   r%  r4  _find_network_pathr  _initializerm   r   r   rh   rj   r5  rl   rest_lengthseekdecrypt_packetexpected_packet_numberr   r  rk   r  rD  reschedule_datar   r3   rq  PROTOCOL_VIOLATIONr  ri   r)  
_set_stater   r7  r1   r6  r   _payload_receivedr   r   r   r   rE  rl  r   r   r   indexlargest_received_packetpopinsert	discardedlargest_received_time	ack_queueaddr  r   ) r   r  r   rr  r  buf	start_offr  destination_cid_seqconnection_idversionsxcommonr  r  r   r   r  r  encrypted_offend_offplain_headerplain_payloadry  excreserved_maskr   r|  contextis_ack_eliciting
is_probingidxs                                    rZ   receive_datagramzQuicConnection.receive_datagram  s    ;;*$ ( YN''$* '6&F.< (  >>! 4#5#5#77DN$'')
I))<)<)Q)Q$ OO&&*==I ::$$0%%//!,.'J$,cllY.F#G 0   26!% ))]->->>*7*G*G'
 6#5#59N#N%-$$0%%//!,.')@A 0 
  KK#6#B#BBNN&9&E&EE77 '')OOCOO$56 '')$$0%%//!,/&(/D(01B1B(C(01G1G(H'
 %-chhj9.D#E 0  ==H,LL((@4==P #22EEhA  /5$$$0%%//!,3/7/3/B/B/U/U.< 0  ")LL&&'QR(.(C(C#0#?#?#0#8#8&P)D%
 OO%&'# 3N C//14/!!"4dmmD#&*NN$*=*=*P*PP $$0%%//!,.')>? 0 
  !!%66OO --..$--?,,.%sxxz4L'L ** & ((4))33%0"3*,3:,4V5F5F,G,4V5K5K,L+"
 )1#((*y2H'I" 4  *0):):DNN&'-||D$%%*%7=7H7HD4LL%%83v||;LL MMcM*  ((4))33%0"2"+-@!A 4 
 $)!2248L ??t{{6I6U6U'U&&*==212=(,%'3n# 3FNN C  !7!78 f001E]]5)F		***SYY%6%67U+  HHJ2Mhhj6#5#55GHHW=C=R=R7+]E<X<X>:m]B $$ $ $A.

,??,44">  
  8<  ,%'"!!++(+"4-:+/+<+<+H+H & 2 2, %-V-C-C$D$,V->->$?# !)'I*=> , $ u;;;/<q/@, ??u		0C0C'C##CII$5$56 ~~--5%+%6%6"12.{{1===<B<M<M9 3 = => ((]T=R=R-R'Q8??)1\DN%-DN(5%$$0%%//!/0%t~~6 0  )//)#5G
/3/E/E]BW 0F 0, * {{j(D,?,? !4#5#5#77DN OO$$5SYY...""3W--.'
 !( 0 0))+  ,,#)):M:M1M""<l>O>O -1)''7Y+>>'4#6#66##**<8%%++L9C:-%:W:W*W""#=|?P?PQ##'',##**1l; ?? 5#@#@@4AE125E/##M2#(<#&#8ELQ ''))  
$$0%%//!,.';$,cllY.F#G 0  
Zp ' ""3'$$0%%//!,.'):; 0  OO#))"5"5syy7H7H!II 66JJ..3.715D. ""3'$$0%%//!,.')@A 0 
 r ' $$S)

"~~"~~"%"3"3   s^   )!r? 	t
t
8$t x7 ?Att	x4B8wx4"Ax//x47	z Azzc                     | j                   sJ d       | j                  t        j                  j                     j                          y)zZ
        Request an update of the encryption keys.

        .. aioquic_transmit::
        z,cannot change key before handshake completesN)r  r   r   rh   rl   
update_keyrg  s    rZ   request_key_updatez!QuicConnection.request_key_updaten  s8     ''W)WW'cii''(335r^   ru   c                 \    | j                  |      }|j                  j                  |       y)z
        Abruptly terminate the sending part of a stream.

        .. aioquic_transmit::

        :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   ru   r   streams       rZ   reset_streamzQuicConnection.reset_streamw  s&     44Y?J'r^   uidc                 :    | j                   j                  |       y)z
        Send a PING frame to the peer.

        .. aioquic_transmit::

        :param uid: A unique ID for this PING.
        N)rH  r  )r   r  s     rZ   	send_pingzQuicConnection.send_ping  s     	!!#&r^   c                 :    | j                   j                  |       y)zr
        Send a DATAGRAM frame.

        .. aioquic_transmit::

        :param data: The data to be sent.
        N)rF  r  )r   r  s     rZ   send_datagram_framez"QuicConnection.send_datagram_frame  s     	&&t,r^   
end_streamc                 `    | j                  |      }|j                  j                  ||       y)z
        Send data on the specific stream.

        .. aioquic_transmit::

        :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.
        )r#  N)r  r  write)r   ru   r  r#  r  s        rZ   send_stream_datazQuicConnection.send_stream_data  s+     44Y?DZ8r^   c                     | j                  |      st        d      | j                  j                  |d      }|t        d      |j                  j                  |       y)z
        Request termination of the receiving part of a stream.

        .. aioquic_transmit::

        :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)_stream_can_receiver  r9  getreceiverstopr  s       rZ   stop_streamzQuicConnection.stop_stream  s]     ''	2R  ""9d3>IJJZ(r^   alpn_protocolc                 b    | j                   j                  t        j                  |             y)z^
        Callback which is invoked by the TLS engine when ALPN negotiation completes.
        )r-  N)r  r  r   ProtocolNegotiated)r   r-  s     rZ   _alpn_handlerzQuicConnection._alpn_handler  s!     	F55MRSr^   c                 ^    | j                  |      st        t        j                  |d      y)z^
        Check the specified stream can receive data or raises a QuicConnectionError.
        zStream is send-onlyr   N)r(  r   r+   STREAM_STATE_ERRORr   r   ru   s      rZ   _assert_stream_can_receivez)QuicConnection._assert_stream_can_receive  s3     ''	2%(;;%3  3r^   c                 ^    | j                  |      st        t        j                  |d      y)z[
        Check the specified stream can send data or raises a QuicConnectionError.
        zStream is receive-onlyr   N)_stream_can_sendr   r+   r2  r3  s      rZ   _assert_stream_can_sendz&QuicConnection._assert_stream_can_send  s3     $$Y/%(;;%6  0r^   c                     | j                   j                  d      | _        | j                  j	                  dt        | j                  j                        | j                  j                         y)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   rA  r  re   r_   r   rg  s    rZ   rk  z QuicConnection._consume_peer_cid  sP     1155a8&T^^''(NN**	
r^   r  c                     |d| j                   j                         z  z   | _        |r | j                  t        j
                         y| j                  t        j                         y)z,
        Begin the close procedure.
        rQ   N)rD  r  r   r  r   r   r   )r   r  rr  s      rZ   r  zQuicConnection._close_begin  sK     q4::#?#?#AAAOO/778OO/889r^   c                    d| _         | j                  j                         D ]  }| j                  |        | j                  j                  | j                         | j                  t        j                         | j                  7| j                  j                  j                  | j                         d| _
        yy)z*
        End the close procedure.
        N)r   r5  keysr  r  r  r   r  r   r   r&  r   r   	end_tracer   r   s     rZ   r  zQuicConnection._close_end  s     \\&&( 	'E&	'D--.+667 (++55d6G6GH $D )r^   c                    | j                   sJ | j                  s| j                  j                  dd| j                  j                  | j
                  d       | j                  j                  ddd| j                  j                  i       || j                         z   | _        | j                  | j                  j                         | j                  j                  d| j                         | j                          y)	z-
        Start the client handshake.
        Nr  r  )r  r  r  alpn_informationclient_alpnsr^   )r   r&  r  r   ru  r>  alpn_protocolsr  r   r  r   r_   r   handle_messager   _push_crypto_datar  s     rZ   rv  zQuicConnection._connect  s     (''$+'+':':'M'M&*mm (  ''$($d&9&9&H&HI (  t1133++,T%9%9: r^   r   c                 "   | j                   |   j                  sv| j                  j                  d|       | j                  |   j                          | j                  j                  | j                   |          d| j                   |   _        y y )NzDiscarding epoch %sT)r5  r  rA  r  r   teardownrD  discard_spacer=  s     rZ   r  zQuicConnection._discard_epoch  so    ||E",,LL4e<MM% ))+JJ$$T\\%%89,0DLL)	 -r^   c                     t        | j                        D ]  \  }}|j                  |k(  s|c S  t        |      }| j                  j                  d|j                         |S )NzNetwork path %s discovered)	enumerater  r   r   rA  r  )r   r   r  r   s       rZ   r  z!QuicConnection._find_network_path   sb    !*4+>+>!? 	$C  D(##	$
 't,79J9JKr^   c                    || j                   v rt        | j                  j                  |d      }|(t	        |      | j
                  k(  rt        t        j                  |d      t        |      r| j                  }d}| j                  }n$| j                  }| j                  }| j                  }|dz  dz   }||j                  kD  rt        t        j                   |d      ||j"                  kD  r||_        | j$                  j'                  d|z         t)        |||t        |       	      x}| j                  |<   | 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 openzStream %d created by peer)ru   max_stream_data_localmax_stream_data_remotewritable)r=  r@   r9  r)  ry   r   r   r+   r2  r|   r  r  r  r.  r  r   STREAM_LIMIT_ERRORr   rA  r  r?   r:  r  )r   r   ru   r  rJ  rK  max_streamsstream_counts           rZ   _get_or_create_streamz$QuicConnection._get_or_create_stream+  s_    ...%%""9d3>))4G),??)":  (	2(,(G(G%)*&"99(,(O(O%)-)P)P&":: &Na/Lk///),??)"9 
  0 00#/  LL:YFG0:#&;'=5i@@	1 FT]]9- &&v.r^   c                    | j                  |      st        d      | j                  j                  |d      }|t	        |      | j
                  k7  rt        d      t        |      r'd}| j                  }| j                  }| j                  }n0| j                  }| j                  }| j                  }| j                  }t        |      }t        ||||       x}| j                  |<   | j                  j!                  |       |r|dz   | _        n
|dz   | _        |dz  |k\  rd|_        |j!                  |       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   )ru   rJ  rK  readabler   T)r6  r  r9  r)  ry   r   r|   r0  r2  r<  r  r/  r1  r;  r?   r:  r  r  r  
is_blockedrK  )r   ru   r  rJ  rK  rN  streams_blockedr  s           rZ   r  z-QuicConnection._get_or_create_stream_for_send]  sN    $$Y/WXX""9d3>))4G !TUU (	2()%)-)I)I&"::"&";";(,(N(N%)-)Q)Q&";;"&"<"< !9 C0:#&;'=..	1 FT]]9- &&v. 1:Q.2;a-/ A~,$(!&&v.04-r^   session_ticketc                     |j                   J|j                   t        k7  r7t        t        j                  t
        j                  d|j                   z        | j                  |       y )NzInvalid max_early_data value %sr   )max_early_data_sizeMAX_EARLY_DATAr   r+   r  r,   CRYPTOrM  )r   rU  s     rZ   _handle_session_ticketz%QuicConnection._handle_session_ticket  s\    ..:22nD%(;;(//? 445  	$$^4r^   rz  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                    j                   _        t%         j&                         j)                         fg j                   _         j                  j,                  } j                  r||j.                  r|j                   j                  j                  k(  ry j                  j,                   j                   _        |j0                  t        k(  rA|j2                  D ]2  \  }}|t%         j&                        k(  s j5                  |d        n  j6                   j                   _         j:                   j:                   j                   _         j>                   j@                   j                   _!         jD                   j                   _#        dt         jH                  dtJ        f fdtM        fdt         jH                  jN                  t         jH                  jP                  t         jH                  jR                  t         jH                  jT                  fD               _+        t         jH                  jN                  tY        tZ              t         jH                  jR                  tY        tZ              t         jH                  jT                  tY        tZ              i _.        t         jH                  jN                  t_               t         jH                  jR                  t_               t         jH                  jT                  t_               i _0        t         jH                  jN                  tc               t         jH                  jR                  tc               t         jH                  jT                  tc               i _2         jV                  t         jH                  jN                     jg                  | j                   j&                  	       ti         jd                  jk                                jl                  _7        y )
N)
rA  cadatacafilecapathcipher_suitesr   r   max_early_dataserver_nameverify_modeT)from_session_ticketr   rS   c           	      6   g d| j                      }d|z  d|z  g}|j                      }|j                     }t        t        j                  |      t        j
                  |      t        j                  |      t        j
                  |            S )N)initial0rtt	handshake1rttzserver_%s_secretzclient_%s_secret)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        rZ   create_crypto_pairz6QuicConnection._initialize.<locals>.create_crypto_pair  s    A%++NJ"Z/"Z/L  ,,?@+DOO<%d&;&;=MN!()>)>@P!Q%d&;&;=MN!()>)>@P!Q	 r^   c              3   2   K   | ]  }| |      f  y wrV   rw   )rX   r   rs  s     rZ   r[   z-QuicConnection._initialize.<locals>.<genexpr>  s$      
 &u-.
s   r  )r_   r   rn   )8r   Contextr   rA  r\  r]  r^  r   r_  r   rA  rX  ra  rb  r   certificate_chainr   certificate_private_keyrt   r>  _serialize_transport_parametershandshake_extensionsrU  r  rW  other_extensions_parse_transport_parametersr0  alpn_cbrL  get_session_ticket_cbrM  rZ  new_session_ticket_cb_update_traffic_keyupdate_traffic_key_cbrh   r   dictri   rj   rk   rl   r   r   CRYPTO_BUFFER_SIZEr   r?   r  r=   r5  setup_initiallistvaluesrD  r  )r   rz  rU  ext_typeext_datars  s   `    @rZ   r  zQuicConnection._initialize  s   ;;..==&&--&&--&&--,,::oo<<#'??4++77++77
  $22>>%)%8%8%J%J"+/+>+>+J+J( 34==A446)
% ,,;;OO*''**d.A.A.M.MM&*&9&9&H&HDHH# 11^C*8*I*I &Hh#Edmm#TT88$$ 9    --''3-1-I-IDHH*''3-1-H-HDHH*)-)A)A&	cii 	J 	  
 		!!		""		##		!!	
 
 IIv/ABII1C!DIIv/AB 
 IIz|IIIIz| 
 II0II!2II0
 	cii''(66DOOT]] 	7 	
 !!4!4!67

r^   r  r  c                    t        |      \  }}|t        j                  k(  r0|j                          |j                          |j                          || j                  z  dz  }| j
                  5|j                  j                  | j
                  j                  ||             | j                  j                  sQ|j                  t        j                  j                  t        j                  j                  fv rd| j                  _
        | j                  j!                  |||j"                  | j$                  |j                            y)z&
        Handle an ACK frame.
        @B NT)ack_rangeset	ack_delayrr  r  )r4   r,   ACK_ECNpull_uint_varr'  r&  r   r  encode_ack_framerD  r   r   r   rh   rk   rl   on_ack_receivedr   r5  )r   r  r   r  r  ack_delay_encodedr  s          rZ   rQ  z QuicConnection._handle_ack_frame  s    +9*=''...&$*I*IIWT	 (&&--!!22<K
 zz;;IIIIR
 A
 <@DJJ8

""%,,w}}-	 	# 	
r^   c                 B   |j                         }|t        j                  k(  r|j                         }nd}|j                         }	 |j                  |      j	                  d      }| j                  7|j                  j                  | j                  j                  |||             | j                  j                  d||       | j                  ;t        j                  |||      | _        | j                  d|j                          yy# t
        $ r d}Y w xY w)z2
        Handle a CONNECTION_CLOSE frame.
        Nutf8rm  r   z0Connection close received (code 0x%X, reason %s)Fr~  )r  r,   TRANSPORT_CLOSE
pull_bytesrd   UnicodeDecodeErrorr&  r   r  encode_connection_close_framerA  r  r   r   rp  r  r   )r   r  r   r  r   reason_lengthr   s          rZ   rb  z-QuicConnection._handle_connection_close_frame  s    &&(
666**,JJ))+	NN=9@@HM
 (&&--!!??))"/ @  	>	

 $ & ; ;%%+!D
 5gllC %% " 	M	s    D DDc                 h   |j                         }|j                         }||z   t        kD  rt        t        j                  |d      t        ||j                  |            }| j                  4|j                  j                  | j                  j                  |             | j                  |j                     }|j                  j                  |      }|l	 | j                  j!                  |j"                  | j$                         | j'                          | j2                  s| j                  j4                  | j                  j4                  D ]7  \  }
}|
t7        | j8                        k(  s| j;                  |       d| _         n | j2                  s7t        t        j*                  t        j<                  j>                  z   |d      | j@                  sh| j                  jB                  t        jD                  jF                  t        jD                  jH                  fv rd| _         | jJ                  s7| jM                  t        jN                  jP                         d| _)        d| _*        | jW                          | jX                  j                  t[        j\                  | j                  j^                  | j                  j`                  | j                  jb                               | je                  d	       | je                  d	       | jf                  ji                  d
| j                  j^                         yyy| jf                  ji                  d|j                         | jJ                  sc|j                  t        jN                  jj                  k(  r;| jl                  s.| jn                  jq                  |jr                         d| _6        yyyy# t        j(                  $ r@}	t        t        j*                  t-        |	j.                        z   |t1        |	            d}	~	ww xY w)z(
        Handle a CRYPTO frame.
        &offset + length cannot exceed 2^62 - 1r   )offsetr  NTz%No QUIC transport parameters received)r-  early_data_acceptedsession_resumedFr  zALPN negotiated protocol %sz+Duplicate CRYPTO data received for epoch %srt  ):r  r   r   r+   FRAME_ENCODING_ERRORr.   r  r&  r   r  encode_crypto_framer  r   r*  handle_framer   rB  r  r   rC  AlertCRYPTO_ERRORr   descriptionr   r  received_extensionsrt   r>  r|  AlertDescriptionmissing_extensionr  r  StateCLIENT_POST_HANDSHAKESERVER_POST_HANDSHAKEr   r  rh   rk   r  rG  _replenish_connection_idsr  r   HandshakeCompletedalpn_negotiatedr  r  _unblock_streamsrA  r  ri   r  rD  r  r   )r   r  r   r  r  r  framer  r  r  r  r  s               rZ   rT  z#QuicConnection._handle_crypto_frameE  sc    ""$""$F?\)%(==%F 
  vCNN64JK (&&--!!55e< %%gmm4,,U3''

D4H4HI&&( --HH00<*.((*F*F &Hh#Edmm#TT88B481	
 00-#0#=#=..@@$A#-&M	  ++		//		//C 1 ,0( ''		(;(;<04D-37D0..0##--&*hh&>&>,0HH,H,H(,(@(@ %%%>%%%=!!14883K3K-1+4 LL=w}} OOMMSYY%6%6622

**w||*<-1* 3 7 $w 99 ),99C<PP)"%c( s   A O P11;P,,P1c                     |j                         }| j                  6|j                  j                  | j                  j	                  |             yy)z.
        Handle a DATA_BLOCKED frame.
        N)limit)r  r&  r   r  encode_data_blocked_framer   r  r   r  r  s        rZ   r[  z)QuicConnection._handle_data_blocked_frame  sP     !!# (&&--!!;;%;H )r^   c                 D   |j                         }|t        j                  k(  r|j                         }n|j                  |z
  }|j                  |      }| j                  5|j                  j                  | j                  j                  |             | j                  j                  *|j                         |z
  | j                  j                  k\  rt        t        j                  |d      | j                  j                  t!        j"                  |             y)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          rZ   rd  z%QuicConnection._handle_datagram_frame  s     
;;;&&(F\\E)F~~f% (&&--!!77v7F 77?xxzE!T%8%8%P%PP%(;;%9  	F88dCDr^   c                 n   | j                   3|j                  j                  | j                   j                                | j                  st        t        j                  |d      | j                  sB| j                  t        j                  j                         d| _        d| j                  _        yy)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   rh   rk   rD  r   r   r  r   r  s       rZ   rc  z+QuicConnection._handle_handshake_done_frame  s     (&&--!!==? %(;;%K  ((		 3 34(,D%;?DJJ8 )r^   c                    |j                         }| j                  6|j                  j                  | j                  j	                  ||             || j
                  kD  r$| j                  j                  d|       || _        yy)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+  rA  r  )r   r  r   r  r   s        rZ   rW  z%QuicConnection._handle_max_data_frame  s     $$& (&&--!!??)8 @  d+++LL=xH$,D! ,r^   c                 x   |j                         }|j                         }| j                  6|j                  j                  | j                  j	                  ||             | j                  ||       | j                  ||      }||j                  kD  r%| j                  j                  d||       ||_        yy)z|
        Handle a MAX_STREAM_DATA frame.

        This adjusts the amount of data we can send on a specific stream.
        Nr  ru   z-Stream %d remote max_stream_data raised to %d)
r  r&  r   r  encode_max_stream_data_framer7  rP  rK  rA  r  )r   r  r   r  ru   r  r  s          rZ   rX  z,QuicConnection._handle_max_stream_data_frame  s     %%'	++- (&&--!!>>+y ?  	$$Z;++J	BV:::LL?
 -<F) ;r^   c                 |   |j                         }|t        kD  rt        t        j                  |d      | j
                  6|j                  j                  | j
                  j                  ||             || j                  kD  r6| j                  j                  d|       || _	        | j                  d       yy)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  r1  rA  r  r  r   r  r   r  rN  s        rZ   rY  z-QuicConnection._handle_max_streams_bidi_frame   s     '')))%(==%B  (&&--!!??); @  666LLE{S,7D)!!E!: 7r^   c                 |   |j                         }|t        kD  rt        t        j                  |d      | j
                  6|j                  j                  | j
                  j                  ||             || j                  kD  r6| j                  j                  d|       || _	        | j                  d       yy)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  r2  rA  r  r  r  s        rZ   rZ  z,QuicConnection._handle_max_streams_uni_frame=  s     '')))%(==%B  (&&--!!??); @  555LLDkR+6D(!!D!9 6r^   c                    |j                         }|j                         }|j                         }|j                  |      }|j                  t              }|rt	        |      t
        kD  rt        t        j                  |d      | j                  8|j                  j                  | j                  j                  ||||             ||kD  rt        t        j                  |d      t        || j                        | _        d}	| j                   D 
cg c]  }
|
j"                  | j                  k  r|
 }}
| j$                  j"                  | j                  k  rd}	|j'                  d| j$                         | j                   D 
cg c]  }
|
j"                  | j                  k\  r|
 c}
| _        || j                  k\  rP|| j(                  vrB| j                   j                  t+        |||	             | j(                  j-                  |       |D ]  }| j/                  |        |	r| j1                          d
t	        | j                         z   | j2                  kD  rt        t        j4                  |d      t	        | j6                        t9        | j2                  dz  t:              kD  rt        t        j4                  |d      yc c}
w c c}
w )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 NumberFTr   r_   r   r   r   zToo many active connection IDsr   z'Too many pending retired connection IDs)r  
pull_uint8r  r*   r  r!   r   r+   r  r&  r   r  encode_new_connection_id_framer  r  r$  r!  r   r   r  r#  r   r  rj  rk  r  CONNECTION_ID_LIMIT_ERRORrJ  r  MAX_PENDING_RETIRES)r   r  r   r  r   r  r  r  r   
change_cidr_   retirequic_connection_ids                rZ   r^  z.QuicConnection._handle_new_connection_id_frameZ  s    ++-++-!v. #/I JM 25K K%(==%N  (&&--!!@@"/$3$3*?	 A  _,%(;;%O  &)$:T:T%U" 
 //
""T%?%?? 
 

 >>))D,F,FFJMM!T^^,
 //$
""d&@&@@ $
  t999t'F'FF$$++ %$3*? ++//@ #) 	6!!"45	6 ""$ s4++,,t/U/UU%(BB%>  t**+c22Q68K/
 
 &(BB%G 
e
$
s   "K
"Kc                 T   |j                         }|j                  |      }| j                  5|j                  j	                  | j                  j                  |             | j                  st        t        j                  |d      | j                  | j                  |       yy)z+
        Handle a NEW_TOKEN frame.
        N)r   z&Clients must not send NEW_TOKEN framesr   )r  r  r&  r   r  encode_new_token_framer   r   r+   r  rN  )r   r  r   r  r  r   s         rZ   rU  z&QuicConnection._handle_new_token_frame  s     ""$v& (&&--!!88u8E %(;;%F  *& +r^   c                    |j                         }|j                  ||j                        D ]  }|r n|dz  } |j                  |       | j                  4|j
                  j                  | j                  j                                yy)z)
        Handle a PADDING frame.
        r   N)r  r  r  r  r&  r   r  encode_padding_frame)r   r  r   r  posbytes         rZ   rO  z$QuicConnection._handle_padding_frame  s     hhjNN35 	D1HC	 	 (&&--d.?.?.T.T.VW )r^   c                     |j                  d      }| j                  5|j                  j                  | j                  j	                  |             ||j
                  _        y)z0
        Handle a PATH_CHALLENGE frame.
        rM   Nr  )r  r&  r   r  encode_path_challenge_framer   r   r   r  r   r  r  s        rZ   r`  z+QuicConnection._handle_path_challenge_frame  s[     ~~a  (&&--!!==4=H 15-r^   c                    |j                  d      }| j                  5|j                  j                  | j                  j	                  |             ||j
                  j                  k7  rt        t        j                  |d      | j                  j                  d|j
                  j                         d|j
                  _        y)z/
        Handle a PATH_RESPONSE frame.
        rM   Nr  z!Response does not match challenger   z&Network path %s validated by challengeT)r  r&  r   r  encode_path_response_framer   r   r   r+   r  rA  r  r   r   r  s        rZ   ra  z*QuicConnection._handle_path_response_frame  s     ~~a  (&&--!!<<$<G 7''777%(;;%A 
 	4g6J6J6O6O	
 -1)r^   c                     | j                   4|j                  j                  | j                   j                                yy)z&
        Handle a PING frame.
        N)r&  r   r  encode_ping_framer  s       rZ   rP  z!QuicConnection._handle_ping_frame  s8     (&&--d.?.?.Q.Q.ST )r^   c                    |j                         }|j                         }|j                         }| j                  7|j                  j                  | j                  j	                  |||             | j                  ||       | j                  ||      }||j                  kD  rt        t        j                  |d      t        d||j                  j                  z
        }| j                  j                  |z   | j                  j                   kD  rt        t        j                  |d      | j"                  j%                  d|||       	 |j                  j'                  ||      }	|	| j.                  j                  |	       | j                  xj                  |z  c_        y# t(        $ r*}
t        t        j*                  |t-        |
            d}
~
ww xY w)	z.
        Handle a RESET_STREAM frame.
        Nr   
final_sizeru   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_framer4  rP  rJ  r   r+   FLOW_CONTROL_ERRORr  r*  highest_offsetr  r   r   rA  r  handle_resetr>   FINAL_SIZE_ERRORr   r  )r   r  r   r  ru   r   r  r  newly_receivedr  r  s              rZ   rR  z)QuicConnection._handle_reset_stream_frame  s    %%'	&&(
&&(
 (&&--!!;;)jI <  	''
I> ++J	B444%(;;%6 
 Q
V__-K-K KL$$~58L8L8R8RR%(;;%:  	D		
		OO00%* 1 E LL&!!^3!  	%(99%!#h 	s   F+ +	G4%GGc                    |j                         }| j                  4|j                  j                  | j                  j	                  |             || j
                  k\  rt        t        j                  |d      t        | j                        D ]  \  }}|j                  |k(  s|j                  |j                  k(  rt        t        j                  |d      | j                  j                  dt!        |j                        |j                         | j                  |= | j"                  j                  t%        j&                  |j                                n | j)                          y)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  rH  r	  r   r_   r   rA  r  re   r  r   ConnectionIdRetiredr  )r   r  r   r  r   r  r  s          rZ   r_  z1QuicConnection._handle_retire_connection_id_frameW  sF    ++- (&&--!!CCOT d000%(;;%C  %.doo$> 	 E=,,? $$(8(88-#0#C#C#-&K 
 ""/]../!11
 OOE*##..]=N=NO #	( 	&&(r^   c                    |j                         }|j                         }| j                  6|j                  j                  | j                  j	                  ||             | j                  ||       | j                  ||      }|j                  j                  t        j                         | j                  j                  t        j                  ||             y)z.
        Handle a STOP_SENDING frame.
        Nr   ru   )r   )r  r&  r   r  encode_stop_sending_framer7  rP  r  r  r+   NO_ERRORr  r   StopSendingReceived)r   r  r   r  ru   r   r  s          rZ   rS  z)QuicConnection._handle_stop_sending_frame  s     %%'	&&(
 (&&--!!;;)Y <  	$$Z; ++J	B}'='=>&&*	R	
r^   c                    |j                         }|dz  r|j                         }nd}|dz  r|j                         }n|j                  |j                         z
  }||z   t        kD  rt	        t
        j                  |d      t        ||j                  |      t        |dz              }| j                  6|j                  j                  | j                  j                  ||	             | j                  ||       | j                  ||      }||z   |j                   kD  rt	        t
        j"                  |d
      t%        d||z   |j&                  j(                  z
        }	| j*                  j,                  |	z   | j*                  j.                  kD  rt	        t
        j"                  |d      	 |j&                  j1                  |      }
|
| j8                  j                  |
       | j*                  xj,                  |	z  c_        y# t2        $ r*}t	        t
        j4                  |t7        |            d}~ww xY w)z(
        Handle a STREAM frame.
        r   r   r   r  r   r   )r  r  finNrx   r  r  )r  r  r  r   r   r+   r  r.   r  r{   r&  r   r  encode_stream_framer4  rP  rJ  r  r  r*  r  r  r   r   r  r>   r  r   r  )r   r  r   r  ru   r  r  r  r  r  r  r  s               rZ   rV  z#QuicConnection._handle_stream_frame  s    %%'	>&&(FF>&&(F\\CHHJ.FF?\)%(==%F 
  v 6Da<P

 (&&--!!55ey5Q
 	''
I> ++J	BF?V999%(;;%6 
 Q&//2P2P PQ$$~58L8L8R8RR%(;;%: 	OO007E LL&!!^3!  	%(99%!#h 	s   4H 	H?%H::H?c                    |j                         }|j                         }| j                  6|j                  j                  | j                  j	                  ||             | j                  ||       | j                  ||       y)z5
        Handle a STREAM_DATA_BLOCKED frame.
        N)r  ru   )r  r&  r   r   encode_stream_data_blocked_framer4  rP  )r   r  r   r  ru   r  s         rZ   r\  z0QuicConnection._handle_stream_data_blocked_frame  s     %%'	!!# (&&--!!BB9 C  	''
I>"":y9r^   c                    |j                         }|t        kD  rt        t        j                  |d      | j
                  H|j                  j                  | j
                  j                  |t        j                  k(  |             yy)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        rZ   r]  z,QuicConnection._handle_streams_blocked_frame  s     !!###%(==%B  (&&--!!>>&0M4U4U&U ?  )r^   key_typer  c                 `    | j                   "| j                   j                  dd||d       yy)z'
        Log a key retirement.
        Nsecuritykey_retiredr  r  r  r&  r  r   r  r  s      rZ   rn  zQuicConnection._log_key_retired	  <     (''##"*w? (  )r^   c                 `    | j                   "| j                   j                  dd||d       yy)z#
        Log a key update.
        Nr  key_updatedr  r  r  r  s      rZ   rm  zQuicConnection._log_key_updated	  r  r^   deliveryr  highest_ackedc                 j    |t         j                  k(  r |j                  j                  d|dz          yy)zE
        Callback when an ACK frame is acknowledged or lost.
        r   r   N)r9   ACKEDr   subtract)r   r	  r  r
  s       rZ   _on_ack_deliveryzQuicConnection._on_ack_delivery!	  s1     (...OO$$Q(9: /r^   r  c                 :    |t         j                  k7  rd|_        yy)zX
        Callback when a MAX_DATA or MAX_STREAMS frame is acknowledged or lost.
        r   N)r9   r  r   )r   r	  r  s      rZ   _on_connection_limit_deliveryz,QuicConnection._on_connection_limit_delivery*	  s     (...EJ /r^   c                 :    |t         j                  k7  rd| _        yy)zO
        Callback when a HANDSHAKE_DONE frame is acknowledged or lost.
        TN)r9   r  rG  )r   r	  s     rZ   _on_handshake_done_deliveryz*QuicConnection._on_handshake_done_delivery3	  s      (...+/D( /r^   r  c                 :    |t         j                  k7  rd|_        yy)zP
        Callback when a MAX_STREAM_DATA frame is acknowledged or lost.
        r   N)r9   r  max_stream_data_local_sent)r   r	  r  s      rZ   _on_max_stream_data_deliveryz+QuicConnection._on_max_stream_data_delivery:	  s      (...01F- /r^   r  c                 :    |t         j                  k7  rd|_        yy)zR
        Callback when a NEW_CONNECTION_ID frame is acknowledged or lost.
        FN)r9   r  r   )r   r	  r  s      rZ   _on_new_connection_id_deliveryz-QuicConnection._on_new_connection_id_deliveryC	  s      (...%*M" /r^   uidsc                    |t         j                  k(  rW| j                  j                  d|rdnd       |D ]1  }| j                  j                  t        j                  |             3 y| j                  j                  |       y)zE
        Callback when a PING frame is acknowledged or lost.
        zReceived PING%s responserm  z (probe))r  N)
r9   r  rA  r  r  r  r   PingAcknowledgedrH  extend)r   r	  r  r  s       rZ   _on_ping_deliveryz QuicConnection._on_ping_deliveryL	  sp     (...LL92:V F##F$;$;$DEF %%d+r^   r   c                 b    |t         j                  k7  r| j                  j                  |       yy)zU
        Callback when a RETIRE_CONNECTION_ID frame is acknowledged or lost.
        N)r9   r  rJ  r  )r   r	  r   s      rZ   !_on_retire_connection_id_deliveryz0QuicConnection._on_retire_connection_id_deliveryY	  s,     (...''..? /r^   plainr  c                 X   t        |      }d}d}d}d}|j                         s	 |j                         }		 | j                  |	   \  }
}|j                  |vrt	        t
        j                  |	d      	  |
||	|       d	}|	t        j                  k(  rd	}|	t        vrd	}|	t        vrd}n|d	}|j                         s|s*t	        t
        j                  t        j                   d
      |r,|s*t	        t
        j                  t        j                   d      |t#        |      fS # t        $ r t	        t
        j                  dd      w xY w# t        $ r t	        t
        j                  |	d      w xY w# t        $ r t	        t
        j                  |	d      t        $ r Y *w xY w)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  re  KeyErrorr   r  r@   r,   rY  r"   r(   r  r{   )r   r  r  r  r  crypto_frame_foundframe_foundr  r  r   frame_handlerframe_epochss               rZ   r  z QuicConnection._payload_receivedb	  s    % " 
'') ..0
.2.C.CJ.O+| }}L0),??)"9 
gz37 K]111%)"!>>#' !44"
#!
m '')p %(;;(009  !);%(;;(00?   j!111I # ),AA#"8   ),AA)"6 $ # ),AA)"9 
 ' s(   D& E 4
E8 &&E&E58-F)(F)c           	         t        | j                        t        d| j                        k  r| j                  j	                  t        t        j                  | j                  j                        | j                  t        j                  d                   | xj                  dz  c_
        t        | j                        t        d| j                        k  ryy)z.
        Generate new connection IDs.
        rM   r   r  r   N)r  r	  r  r(  r  r   r  r  r   r  r
  rg  s    rZ   r  z(QuicConnection._replenish_connection_ids	  s     $//"SD,S,S%TTOO"" 

4#6#6#K#KL$($6$6*,**R. !# $//"SD,S,S%TTr^   c                     | j                   j                  dt        |j                        |j                  t        | j                        dz          | j                  j                  |j                         y)z5
        Retire a destination connection ID.
        zRetiring CID %s (%d) [%d]r   N)rA  r  re   r_   r   r  rJ  r  )r   r  s     rZ   rj  zQuicConnection._retire_peer_cid	  s_     	']&&'))++,q0		
 	##**=+H+HIr^   c                     | j                   j                         D ]H  \  }}| j                  |   j                  j	                  |j
                         |j                  d       J y r   )r   itemsr  r  r%  r  r  )r   r   r  s      rZ   rC  z QuicConnection._push_crypto_data	  sR    ..446 	JE3  '..44SXX>HHQK	r^   c                     d| _         y )NT)rI  rg  s    rZ   rC  zQuicConnection._send_probe	  s
    "r^   rc  c                    	 t        t        |            }| j                  ;|s9| j                  j                  dd| j                  j                  d|      	       | j                  s@d
D ];  }t        ||      t        t        j
                  t        j                  d|z         |s |j                  | j                  k7  r*t        t        j
                  t        j                  d      | j                  rC|j                  | j                   k7  r*t        t        j
                  t        j                  d      | j                  rC|j"                  | j$                  k7  r*t        t        j
                  t        j                  d      |j&                  9|j&                  dk  r*t        t        j
                  t        j                  d      |j(                  9|j(                  dkD  r*t        t        j
                  t        j                  d      |j*                  9|j*                  dk\  r*t        t        j
                  t        j                  d      |j,                  D|j,                  t.        k  r1t        t        j
                  t        j                  dt.               |s|j(                  | j0                  | _        |j*                  |j*                  dz  | j2                  _        | j                  r@| j4                  j6                  dk(  r'|j8                  |j8                  | j4                  _        |j&                  |j&                  | _        |j<                  |j<                  dz  | _        |j@                  | _!        dD ]$  }t        |d|z         }|tE        | d|z   |       & y# t        $ r+ t        t        j
                  t        j                  d      w xY w)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%s 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 2r   z ack_delay_exponent must be <= 20rB   zmax_ack_delay must be < 2^14z max_udp_payload_size must be >= g     @@r   )r   max_stream_data_bidi_localmax_stream_data_bidi_remotemax_stream_data_unir   r   initial__remote_)#r6   r   r  r   r+   TRANSPORT_PARAMETER_ERRORr,   rY  r&  r  encode_transport_parametersr   getattrinitial_source_connection_idr)  r   r@  r   r4  active_connection_id_limitack_delay_exponentmax_ack_delaymax_udp_payload_sizer   r'  rD  r   r   r   r(  max_idle_timeoutr*  r  r-  setattr)r   r  rc  quic_transport_parametersattrparamr   s          rZ   r|  z*QuicConnection._parse_transport_parameters	  s   		(FD!)% (1D''$&&&BB"/H C  (    4d;G-#0#J#J#0#7#7&E&L  #)FF<<= *,FF,33"O 
 )LL;;< *,FF,33"U 
 )DD334 *,FF,33"M  *DDP-HH1L),FF,33"U  *<<H-@@2E),FF,33"D  *77C-;;uD),FF,33"@ 
 )==I)>>,- *,FF,33:;U:VW	  #(;;G262Q2Q/(66B-;;fD 

( NN22a7-CCO .CC 4 %??K)DD 3 %55A)::VC ) &== 	,
 
	9E 5zE7IJE j50%8
	9  	%(BB(//I 	s   N: :4O.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t         z  nd | j"                  d   j$                        }| j&                  s"| j(                  |_        | j,                  |_        | j0                  9| j0                  j3                  dd| j0                  j5                  d|	      
       t7        d| j8                  z        }t;        ||       |j<                  S )Ni  r      Qr   )r<  r;  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_unir:  r=  r  quantum_readinessr   r  r,  localr.  r  rQ   ru  )r/   r  r  r   r   r  r  r   r  r  r  r  r  r  r  quantum_readiness_testr   r	  r   r   r@  r   r4  r   r&  r  r8  r   r  r8   r  )r   rA  r  s      rZ   ry  z.QuicConnection._serialize_transport_parametersv
  sq   $;#=='+'M'M !4!4!A!AD!HI!1177/3/U/U040W0W(,(G(G%)%A%A%G%G$($?$?$E$E)-)Q)Q$($7$7$O$O &&== 11"&//!"4"J"J%%
!( 88 &H 00 &@
 (''$&&&BB!.G C  (  a$"9"99:&s,EFxxr^   r  c                 `    | j                   j                  d| j                  |       || _        y )Nz%s -> %s)rA  r  r8  )r   r  s     rZ   r  zQuicConnection._set_state
  s#    :t{{E:r^   c                 N    t        |      | j                  k7  xs t        |       S rV   ry   r   r|   r   ru   s     rZ   r(  z"QuicConnection._stream_can_receive
  0    )
__ H$<Y$G G	Hr^   c                 N    t        |      | j                  k(  xs t        |       S rV   rQ  rR  s     rZ   r6  zQuicConnection._stream_can_send
  rS  r^   r  c                 x   |r%| j                   }| j                  }| j                  }n$| j                  }| j                  }| j
                  }|rL|d   j                  dz  |k  r7|j                  d      }d|_        ||_	        |r|d   j                  dz  |k  r7| j
                  s| j                  sd| _
        y y y )Nr   r   F)r0  r2  r<  r/  r1  r;  ru   r  rS  rK  rK  )r   r  rK  rN  rT  r  s         rZ   r  zQuicConnection._unblock_streams
  s    %)%E%E"66K"77O%)%M%M"77K"88O/!"4">">!"Ck"Q$((+F %F,BF) /!"4">">!"Ck"Q
 ))$2K2K,1D) 3L)r^   	directioncipher_suitesecretc                 b   | j                   j                  }|| j                  |t        j                  j
                  k(  k(  }t        |   |j                     }|j                  |d| j                  j                  j                         d|j                         d       |j                          | j                  |   }|t        j                  j                  k(  r)|j                  j                  ||| j                          y|j"                  j                  ||| j                          y)zj
        Callback which is invoked by the TLS engine when new traffic keys are
        available.
        N 
)rW  rX  rn   )r   secrets_log_filer   r   	DirectionDECRYPTSECRETS_LABELSr   r%  client_randomhexr  r   ENCRYPTr  setupr>  recv)	r   rV  r   rW  rX  r\  	label_rowlabelr  s	            rZ   r  z"QuicConnection._update_traffic_key
  s      ..??'I9N9N,NOI"9-ekk:E"" %txx'='='A'A'CVZZ\R ""$u%---KK)&$--   KK)&$--  r^   r}  r   c           
      R   d }| j                   t        j                  j                     j                  j                         rU| j                   t        j                  j                     }| j                  t        j                  j                     }t        }nn| j                   t        j                  j                     j                  j                         r.| j                   t        j                  j                     }t        }ny | j                  t        j                  j                     }	 |j                  |j                  |k\  r8| j                  j                  j                  |      | _        | j                  y |j!                  ||       | j"                  r|j                  #|j                  |k  r| j%                  |||       | j&                  r| j)                  |       d| _        |j*                  s;|j,                  /t/        j0                  d      }| j3                  ||       ||_        |j4                  $| j7                  ||j4                         d |_        | j8                  D ]"  }	|	j:                  r| j=                  ||	       $ | j>                  d d  D ]0  }
| jA                  ||
       | j>                  jC                  d	       2 | jD                  rw| jF                  r,| jI                  |tJ        jL                  | jN                  
       | jP                  r,| jI                  |tJ        jR                  | jT                  
       d| _"        | jW                  ||       | jX                  j[                         D ]  }| j]                  |||        | j^                  r6| ja                  || j^                         | j^                  jc                          | jd                  r| ja                  |d       d| _2        |*|jf                  jh                  s| jk                  |||       | jl                  rW	 | jo                  || jl                  d	   tJ        jp                         | jl                  js                          | jl                  rWtw               }tw               }	 | jx                  D ]  }|jz                  r| j|                  j                  d|j                         | jX                  jC                  |j                         | j                  j                  |j                         |j                  |       |j                  j                  r| j                  ||       |jf                  j                  r| j                  ||       |j                  r|jf                  jh                  r
| j                  |||t        |jf                  j                  | j                  z   | j                  z
  |j                              }| xj                  |z  c_M        |d	kD  s}|j                  |        	 | jx                  D cg c]  }||v s||v s| c}| _<        | jx                  j                  |       |j                  ry | j                  j                  j                  |       # tt        $ r Y 6w xY wc c}w # | jx                  D cg c]  }||v s||v s| nc c}w c}| _<        | jx                  j                  |       w xY w)Nrt  r}  r  rr  )r}  FrM   )r}  	challenge)r}  r  )r}  r   r   )r}  r   r  )r}  r  r}  r  r  probecomment)r}  r  r   zStream %d discarded)r}  r  )r}  r  r  
max_offset)Rr   r   rh   rl   r  r  r  r%   rj   r'   r5  r  rD  _pacernext_send_timer  r  r  _write_ack_framerG  _write_handshake_done_framer   r   r  r  _write_path_challenge_framer   _write_path_response_framer	  r   _write_new_connection_id_framerJ  !_write_retire_connection_id_framer  rK  r;  _write_streams_blocked_framer,   STREAMS_BLOCKED_BIDIr1  r<  r  r2  _write_connection_limitsr9  r  _write_stream_limitsrH  _write_ping_frameclearrI  r  buffer_is_empty_write_crypto_framerF  _write_datagram_framer  r  r;   r"  r:  is_finishedrA  r  ru   r=  r  r*  stop_pending_write_stop_sending_framereset_pending_write_reset_stream_framerS  _write_stream_framer  r  r+  r,  rK  r  packet_is_emptyupdate_after_send)r   r}  r   rr  crypto_streamr  rf   r  ri  r  r   r  r   r  r   s                  rZ   r  z!QuicConnection._write_application
  sP    /3==**+0099;]]399#4#45F 001B1BCM-K]]399--.33<<>]]399#5#56F.KSYY../||#u||s':"&**"3"3"B"Bs"B"K??.  f5''<<+0C))'C)P //44W4E38D0 %11$44< "

1I44 '9 5  4=L0  00<33 '<3P3P 4  59L1 &*__ M(11;;$+= <  (,'B'B1'E 7O:: ' ;  //33A6	7 001199$+'4'I'I"&"?"? : 
 0099$+'4'H'H"&">"> : 
 5:D1 --gU-K --..0 W))'v)VW !!&&w0B0BC""((* ""&&w&@&+# (1E1E1U1U((#5 ) 
 )).. '!44Q7#0#E#E / 
 ++335 )) %(ED),I-1"11 -F))**+@&BRBRS))&*:*:;..2263C3CD!f- 3366wv6V}}2266wv6V#..v}}7T7T#77$+"'#)'* & < <"&"7"7!8"&"<"<!= !' = =	(	  8 
  22d:2!8 HHV,?-R #'"5"5'"i/6T> '#
 ##**40&&

!!333<s D - Z'"&"5"5'"i/6T> ' '#
 ##**40sE   A	[ 2C=[ 0[ A1[ ;[ [	[[\&+[=<*\&c                    | j                   |   }|j                  j                         sy | j                  |   }| j                  |   }	 |t
        j                  j                  k(  rt        }nt        }|j                  ||       |j                  | j                  |||       |j                  j                  s| j                  |||      rd| _        | j                   r| j"                  sv|t
        j                  j$                  k(  s?| j                   t
        j                  j$                     j                  j                         s| j'                  |d       d| _        |j(                  ry *)Nrh  rj  Frk  rl  )r   r  r  r  r5  r   rh   ri   r$   r#   r  r  rq  r  r}  r~  rI  r  rk   r{  r  )r   r}  r   rr  r  r  r  rf   s           rZ   r  zQuicConnection._write_handshake  sA    u%{{##%,,U3U#		)))13  f5 ||'%%gU%L !''77++#5 ,  +0D' ##00SYY000==)<)<=BBKKM &&w&@&+#&&? r^   c                    ||j                   z
  }t        |dz        | j                  z	  }|j                  t        j
                  t        | j                  ||j                  f      }t        ||j                  |      }d |_        | j                  @|j                  j                  | j                  j                  |j                  |             |dkD  r'|j                   dz  dk(  r| j#                  |d       y y y )	Nr  r  handlerhandler_args)rangesdelayr   rM   r   zACK-of-ACK triggerrl  )r  r   r  start_framer,   ACKACK_FRAME_CAPACITYr  r  r7   r   r  r&  r   r  r  ry  r{  )r   r}  r  rr  r  r  r  r  s           rZ   rq  zQuicConnection._write_ack_frame  s     %555		G 348V8VV!!'))!>!>?	 " 
  U__6GH (&&--!!22 ??) 3  A:'//!3q8""74H"I 9:r^   c                    |X|t         j                  j                  t         j                  j                  fv r"t        j
                  }t        j                  }d}|j                  d      }t        |      }|\|j                  t        j                  t        |z         }|j                  |       |j                  |       |j                  |       nl|j                  t        j                  t         |z         }|j                  |       |j                  |       |j                  |       |j                  |       | j"                  8|j$                  j'                  | j"                  j)                  |||             y y )Nrm  r  ru  r   )r   rh   ri   rk   r+   APPLICATION_ERRORr,   r  encoder  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	            rZ   r  z,QuicConnection._write_connection_close_frame  s]    %CII,=,=syy?R?R+S"S&88J&..JM$++F3L)%%//9MI & C j)m,NN<(%%--7-G & C j)j)m,NN<( (&&--!!??))"/ @  )r^   c                    | j                   | j                  | j                  fD ]0  }|j                  dz  |j                  kD  rF|xj                  dz  c_        | j
                  j                  d|j                  |j                         |j                  |j                  k7  s|j                  |j                  t        | j                  |f      }|j                  |j                         |j                  |_        | j                  |j                  j!                  | j                  j#                  |j                  |j                               3 y)z:
        Raise MAX_DATA or MAX_STREAMS if needed.
        r   zLocal %s raised to %dr  Nr  )r  r  r  r   r   rA  r  r   r   r  r   CONNECTION_LIMIT_FRAME_CAPACITYr  r  r&  r   r  r  )r   r}  r  r  r  s        rZ   ry  z'QuicConnection._write_connection_limits  s      ((''
 	E
 zzA~+q ""#:EJJT{{ejj())$$< >>"'	 *  !!%++."[[
 $$0..55))GG','7'7$)KK H )	r^   c           
         dt        |j                  j                        z   }|j                  j                  |j                  |z
        }||j                  t        j                  ||j                  j                  |j                  |j                  t        |j                        z   df      }|j                  |j                         |j                  t        |j                        dz         |j                  |j                         | j                  4|j                   j#                  | j                  j%                  |             yy)NrQ   Fr  rB   T)r   r  next_offset	get_frameremaining_flight_spacer  r,   rY  on_data_deliveryr  r  r  r  push_uint16r  r&  r   r  r  )r   r}  r  r  frame_overheadr  r  s          rZ   r~  z"QuicConnection._write_crypto_frame  s
    ]6==+D+DEE''(F(F(WX%%$$'66#llELL3uzz?,JER	 & C ell+OOC

Of45NN5::&   ,**11%%99%@ r^   c                 R   |t         j                  k(  sJ t        |      }dt        |      z   |z   }|j	                  ||      }|j                  |       |j                  |       | j                  5|j                  j                  | j                  j                  |             y)zl
        Write a DATAGRAM frame.

        Returns True if the frame was processed, False otherwise.
        r   ru  r  T)r,   r  r  r   r  r  r  r&  r   r  r  )r   r}  r  r   r  
frame_sizer  s          rZ   r  z$QuicConnection._write_datagram_frame7  s     ]?????Tv..7
!!*z!B&!t (&&--!!77v7F r^   c                     |j                  t        j                  t        | j                         | j
                  4|j                  j                  | j
                  j                                y y )N)r  r  )	r  r,   HANDSHAKE_DONEHANDSHAKE_DONE_FRAME_CAPACITYr  r&  r   r  r  )r   r}  s     rZ   rr  z*QuicConnection._write_handshake_done_frameO  sc    ((244 	 	
 (&&--!!==? )r^   c                    d}|j                  t        j                  t        | j                  |f      }|j                  |j                         |j                  |       |j                  t        |j                               |j                  |j                         |j                  |j                         d|_        | j                  j                  t        j                   |j                               | j"                  W|j$                  j                  | j"                  j'                  |j                  ||j                  |j                               y y )Nr   r  Tr  r  )r  r,   NEW_CONNECTION_ID NEW_CONNECTION_ID_FRAME_CAPACITYr  r  r   
push_uint8r  r_   r  r   r   r  r  r   ConnectionIdIssuedr&  r   r  )r   r}  r  r  r  s        rZ   ru  z-QuicConnection._write_new_connection_id_frame\  s"    !!++577')	 " 
 	-778/*s=,,-.}(()}::;!%F55MDUDUVW (&&--!!@@"/"3"3$3$1$A$A*7*M*M	 A  )r^   ri  c                     |j                  t        j                  t              }|j	                  |       | j
                  6|j                  j                  | j
                  j                  |             y y Nru  r  )	r  r,   PATH_CHALLENGEPATH_CHALLENGE_FRAME_CAPACITYr  r&  r   r  r  r   r}  ri  r  s       rZ   rs  z*QuicConnection._write_path_challenge_frame{  sq     !!((3P " 
 	y! (&&--!!==9=M )r^   c                     |j                  t        j                  t              }|j	                  |       | j
                  6|j                  j                  | j
                  j                  |             y y r  )	r  r,   PATH_RESPONSEPATH_RESPONSE_FRAME_CAPACITYr  r&  r   r  r  r  s       rZ   rt  z)QuicConnection._write_path_response_frame  sq     !!''2N " 
 	y! (&&--!!<<)<L )r^   c                 V   |j                  t        j                  t        | j                  t        |      f       | j                  j                  d|rd|z  nd|j                         | j                  4|j                  j                  | j                  j                                y y )Nr  zSending PING%s in packet %dz (%s)rm  )r  r,   PINGPING_FRAME_CAPACITYr  tuplerA  r  ry  r&  r   r  r  )r   r}  r  rm  s       rZ   r{  z QuicConnection._write_ping_frame  s     	(**+	 	 	
 	)!(Ggb!!	
 (&&--d.?.?.Q.Q.ST )r^   c                    |j                  t        j                  t        |j                  j
                        }|j                  j                         }|j                  |j                         |j                  |j                         |j                  |j                         | j                  V|j                  j                  | j                  j                  |j                  |j                  |j                               y y )Nr   r  r  r  )r  r,   RESET_STREAMRESET_STREAM_FRAME_CAPACITYr  on_reset_deliveryget_reset_framer  ru   r   r  r&  r   r  r  r   r}  r  r  r  s        rZ   r  z(QuicConnection._write_reset_stream_frame  s    
 !!$110MM33 " 

 --/%//*%**+%**+ (&&--!!;;$//$//#oo <  )r^   c                    |j                  t        j                  t        | j                  |f      }|j                  |       | j                  5|j                  j                  | j                  j                  |             y y )Nr  )
r  r,   RETIRE_CONNECTION_IDRETIRE_CONNECTION_ID_CAPACITYr  r  r&  r   r  r  )r   r}  r   r  s       rZ   rv  z0QuicConnection._write_retire_connection_id_frame  s     !!..2::)+	 " 
 	/* (&&--!!CCOT )r^   c                    |j                  t        j                  t        |j                  j
                        }|j                  j                         }|j                  |j                         |j                  |j                         | j                  K|j                  j                  | j                  j                  |j                  |j                               y y )Nr  r  )r  r,   STOP_SENDINGSTOP_SENDING_FRAME_CAPACITYr*  on_stop_sending_deliveryget_stop_framer  ru   r   r&  r   r  r  r  s        rZ   r  z(QuicConnection._write_stop_sending_frame  s    
 !!$110OO<< " 

 ..0%//*%**+ (&&--!!;;$//5?? <  )r^   rn  c           
      $   dt        |j                        z   |j                  j                  rt        |j                  j                        ndz   }|j                  j                  }|j                  j                  |j                  |z
  |      }|~t        j                  dz  }|j                  r|dz  }|j                  r|dz  }|j                  |||j                  j                  |j                  |j                  t        |j                        z   |j                  f      }	|	j                  |j                         |j                  r|	j                  |j                         |	j!                  t        |j                        dz         |	j#                  |j                         | j$                  @|j&                  j)                  | j$                  j+                  ||j                               |j                  j                  |z
  S y)	NrQ   r   r   r   r   r  rB   rx   )r   ru   r  r  r  r  r  r,   STREAM_BASEr  r  r  r  r  r  r  r  r  r&  r   r  r  )
r   r}  r  r  rn  r  previous_send_highestr  r   r  s
             rZ   r  z"QuicConnection._write_stream_frame  s    F,,-. ==,, fmm778 	 !' < <''**^;Z
 &22Q6J||a
yya
%%'66#llELL3uzz?,JEIIV	 & C f../||!!%,,/OOC

Of45NN5::&   ,**11%%99)9)9 :  ==//2GGGr^   c                    |j                   rl|j                  j                  dz  |j                   kD  rF|xj                   dz  c_         | j                  j	                  d|j
                  |j                          |j                  |j                   k7  r|j                  t        j                  t        | j                  |f      }|j                  |j
                         |j                  |j                          |j                   |_        | j                  K|j                  j                  | j                  j!                  |j                   |j
                               yyy)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  )rJ  r*  r  rA  r  ru   r  r  r,   MAX_STREAM_DATAMAX_STREAM_DATA_FRAME_CAPACITYr  r  r&  r   r  r  )r   r}  r  r  r  s        rZ   rz  z#QuicConnection._write_stream_limits  s7    ((..2V5Q5QQ((A-(LL>  ,,
 ,,0L0LL%%--799$Y	 & C f../f::;060L0LF-   ,**11%%BB & < <HXHX C  - Mr^   c                     |j                  |t              }|j                  |       | j                  H|j                  j                  | j                  j                  |t        j                  k(  |             y y )Nru  r  )	r  STREAMS_BLOCKED_CAPACITYr  r&  r   r  r  r,   r  )r   r}  r   r  r  s        rZ   rw  z+QuicConnection._write_streams_blocked_frameF  sy     !!*7O!P%  (&&--!!>>&0M4U4U&U ?  )r^   )rS   N)F)r   r   r   __doc__r   r   r   r   SessionTicketFetcherSessionTicketHandlerQuicTokenHandlerr   propertyr   r   rl  r+   r  r   r   rq  r   r   rw  r   r   r  r  r  r  r   	QuicEventr  r  r  r  r  r   r"  r{   r&  r,  r0  r4  r7  rk  r  r  rv  rh   r  r   r  r?   rP  r  SessionTicketrZ  r  r   r   rQ  rb  rT  r[  rd  rc  rW  rX  rY  rZ  r^  rU  rO  r`  ra  rP  rR  r_  rS  rV  r\  r]  rn  rm  r9   r=   r  r~   r  r  r  r   r  r   r  r  r  r  rj  rC  rC  r|  ry  r   r  r(  r6  r  r]  CipherSuiter  r:   r  r  rq  r  ry  r~  r,   r  rr  ru  rs  rt  r{  r  rv  r  r  rz  rw  rw   r^   rZ   r   r      s   $ ?C6:EIEI48G
 )G
 -5UO	G

 %-UOG
 !))A)A BG
 !))A)A BG
   01G
 
G
R #0 # # 8E 8 8%  (00$(	'' SM' 	'
 
'0N  4 (MU MtE%:O4P/Q M^3s 38E? ,: :$ :0	HV%5%56 		Eu 	EL9U L9. L9u L9QU L9\6
(c 
(s 
(t 
('S 'T '- -$ - ?D99$)97;9	9)S )c )d ),T3 T4 T	S 	S 	T 		# 	# 	$ 	
: :E :d :%!E !d !61CII 1$ 1	~ 	/ 	0 0 0
 0d. .
 .`5S5F5F 54 5`8E `8d `8D
)
7:
AG
	
B&D)&D7:&DAG&D	&DP]2)]27:]2AG]2	]2~)7:AG	E)E7:EAGE	E@@)@7:@AG@	@2-)-7:-AG-	-,<)<7:<AG<	<>;);7:;AG;	;::):7::AG:	::c)c7:cAGc	cJ')'7:'AG'	'2X)X7:XAGX	X$5)57:5AG5	5 1)17:1AG1	12U)U7:UAGU	U84)847:84AG84	84t*))*)7:*)AG*)	*)X
)
7:
AG
	
8=4)=47:=4AG=4	=4~:):7::AG:	:,)7:AG	.	 	s 	t 		 	s 	t 	;);2A;RU;	;)27	04E 0$ 02)23=2	2+)+:J+	+,),19#,	,@)@<?@	@ ',	W2#W2 W2  $	W2
 
tTz	W2r$
J.> 
J4 
J
# 8=W9W904W9	W9r) )V 3  HS HT H
H# H$ H
2$ 24 2$== yy oo	
  
<h=(h=8Gh=NSh=	h=T)()14)AF)	)VJ(J1@JGLJ	J8+"+ yy+ 	+
 SM+ + 
+Z(1@	B(1@JT	2(05CP	03D  (9I	>(5:	(5:	 =?U(U04S	U&"  
	2(;>	""  
	,3"3 3 	3
 3 
3j%(%1@%JT%	%N(6CLO	r^   r   )rb   loggingr  collectionsr   dataclassesr   enumr   	functoolsr   typingr   r   r	   r
   r   r   r   r   r   r   rm  r   bufferr   r   r   r   r   r   r   r   r   congestion.baser   r  r   r   r   r   r    r  r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   packet_builderr9   r:   r;   recoveryr<   r=   r  r>   r?   r@   	getLoggerr  rh   ri   rk   rj   rl   rW   rX  r_  STREAM_FLAGSr  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r]   r   re   r   rm   rp   rt   r{   ry   r|   r~   	Exceptionr   LoggerAdapterr   r   r   r   r   r  r\   r   r   r   ro  r   rw   r^   rZ   <module>r     s     	  !        H * @ @ #      4 
 : C C			6	" 													  %    #$q+<'<#<  "#&7"7  ! !"Q):%:!: !$::=WW ! !& $  !&7"77  !$5 5 !&7"77 00 !"Q):%:!: ;S ;Ysyy1 ;1% 1C 1!3 !399 !; ;8I8I ;# $    
) 
;G11 ;
   $  	X 	X 	X    UGTM* ##$$&&
i1 i1r^   