
    kj                       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'm(Z( d
dl)m*Z* d
dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d
dlAmBZBmCZCmDZD d
dlEmFZFmGZG d
dlHmIZImJZJmKZK  ej                  d      Z)dZMej                  j                  ej                  j                  ej                  j                  ej                  j                  dZSdZTdZUdZVg dg dgZWdZXdZYdZZdZ[dZ\eZ]d Z^d
dez  z   Z_d
ez   Z`d
Zad
dez  z   Zbd
dez  z   d
z   e,z   e0z   Zcd!Zdd!Zed
Zfd
d"ez  z   Zgd
ez   Zhd
dez  z   Zid
ez   Zjd
d"ez  z   Zkd#eld$eej                     fd%Zmd&end'end$eofd(Zpd)eqd$elfd*Zrd+e4d$ej                  fd,Zsd-end$eofd.Ztd-end$eofd/Zu G d0 d1      Zv G d2 d3ew      Zx G d4 d5ej                        Zze G d6 d7             Z{ G d8 d9e      Z| G d: d;      Z}e G d< d=             Z~eeqg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
NoCallback)QuicLoggerTrace)CONNECTION_ID_MAX_SIZENON_ACK_ELICITING_FRAME_TYPESPROBING_FRAME_TYPESRETRY_INTEGRITY_TAG_SIZESTATELESS_RESET_TOKEN_SIZEQuicErrorCodeQuicFrameType
QuicHeaderQuicPacketTypeQuicProtocolVersionQuicStreamFrameQuicTransportParametersQuicVersionInformationget_retry_integrity_tagget_spin_bitpretty_protocol_versionpull_ack_framepull_quic_headerpull_quic_transport_parameterspush_ack_framepush_quic_transport_parameters)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   i   @   	      shortcutreturnc                 &    t        d | D              S )Nc              3   .   K   | ]  }t         |     y wN)EPOCH_SHORTCUTS).0is     `/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/aioquic/quic/connection.py	<genexpr>zEPOCHS.<locals>.<genexpr>s   s     :A_Q':s   )	frozenset)rQ   s    rY   EPOCHSr\   r   s    ::::    from_version
to_versionc                 p    t        | |g      t        t        j                  t        j                  g      k(  S )zz
    Return whether it is possible to perform compatible version negotiation
    from `from_version` to `to_version`.
    )setr+   	VERSION_1	VERSION_2)r^   r_   s     rY   is_version_compatiblerd   v   s7     j)*c		&	&(;(E(EF/  r]   cidc                 J    t        j                  |       j                  d      S )Nascii)binasciihexlifydecode)re   s    rY   dump_cidrk      s    C ''00r]   packet_typec                 D   | t         j                  k(  rt        j                  j                  S | t         j                  k(  rt        j                  j                  S | t         j
                  k(  rt        j                  j
                  S t        j                  j                  S rU   )r*   INITIALr   EpochZERO_RTT	HANDSHAKEONE_RTT)rl   s    rY   	get_epochrs      sl    n,,,yy   	//	/yy!!!	00	0yy"""yy   r]   	stream_idc                     | dz   S )z9
    Returns True if the stream is client initiated.
    r    rt   s    rY   stream_is_client_initiatedrx      s     Ar]   c                     t        | dz        S )z7
    Returns True if the stream is unidirectional.
    r   )boolrw   s    rY   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       rY   __init__zLimit.__init__   s%    $			
r]   N)__name__
__module____qualname__intstrr   rv   r]   rY   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 rU   r   r~   r   r   r   r~   r   s       rY   r   zQuicConnectionError.__init__   s    $$*r]   rR   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     rY   __str__zQuicConnectionError.__str__   s>    #t8J8J&KK??&#doo55Ar]   N)r   r   r   r   r   r   r   rv   r]   rY   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kwargsrR   c                 0    d| j                   d   d||fS )N[idz] )extra)r   r   r   s      rY   processzQuicConnectionAdapter.process   s     JJt,c2F::r]   N)r   r   r   r   r   r   r   rv   r]   rY   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)QuicConnectionIdre   sequence_numberr]   stateless_reset_tokenFwas_sentN)	r   r   r   bytes__annotations__r   r   r   rz   rv   r]   rY   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   rP      N)r   r   r   FIRSTFLIGHT	CONNECTEDCLOSINGDRAINING
TERMINATEDrv   r]   rY   r   r      s    KIGHJr]   r   c                   .    e Zd ZddedefdZdedefdZy)	QuicNetworkPathaddris_validatedc                 h    || _         d| _        d| _        || _        d| _        t               | _        y )Nr   F)r   bytes_received
bytes_sentr   local_challenge_sentr   remote_challenges)r   r   r   s      rY   r   zQuicNetworkPath.__init__   s2    $(	#$ ".*/!/4wr]   sizerR   c                 \    | j                   xs | j                  |z   d| j                  z  k  S NrP   )r   r   r   )r   r   s     rY   can_sendzQuicNetworkPath.can_send   s,      WT__t%;DDWDW@W$WWr]   NF)r   r   r   NetworkAddressrz   r   r   r   rv   r]   rY   r   r      s+    7^ 74 7XS XT Xr]   r   c                   p    e Zd ZU ej                  ed<   eed<   eed<   ee	e
      ed<   eed<   ee   ed<   y)QuicReceiveContextepochhost_cidnetwork_pathquic_logger_framestimeversionN)r   r   r   r   ro   r   r   r   r   r   r   floatr   rv   r]   rY   r   r      s5    99O!! c++
Kc]r]   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Zadhebdieded
dfdjZcdhebded
dfdkZdddlZed_e\d
dfdmZfddnZgddoZh	 ddedpe'd
dfdqZid
efdrZjdsekd
dfdtZld ed
e'fduZmd ed
e'fdvZndwe'd
dfdxZodyej                  d1ejb                  dzej                  d{ed
df
d|Zrd}ed~e3fdZsdetd~e3ded
dfdZudetd1ejb                  ded
dfdZvdetdWeVded
dfdZwdetd1ejb                  dedee   ded
dfdZxdetdWeVd
dfdZydetdWeVd]e5d
e'fdZzdetdede{d
e'fdZ|detd
dfdZ}detd_e\d
dfdZ~detd}ed
dfdZdetd}ed
dfdZg dfdetdaee   fdZdetd]e5d
dfdZdetdced
dfdZdetd]e5d
dfdZdetdWeVd]e5ded
ef
dZdetdWeVd]e5d
dfdZdetde{dZe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   rR   c          	         |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 | _        i | _        d | _        d | _        d| _        i | _        t)               | _        d| _        d| _        t1        t3        j4                  |j6                        d| j                  st3        j4                  d      nd d      g| _        | j8                  d   j:                  | _        d| _        d| _         d| _!        i | _"        | j8                  d   j:                  | _#        tI        tJ        jL                  d|jN                        | _(        |jR                  | _*        |jR                  | _+        |jR                  | _,        tI        tJ        jZ                  dd      | _.        tI        tJ        j^                  dd      | _0        | j                  rdnd| _1        | j                  rdnd| _2        d | _3        |j                   | _4        g | _5        d | _6        d| _7        t1        t3        j4                  |j6                        d       | _8        g | _9        tu        dg      | _;        d| _<        |j                  | _=        d | _>        d| _?        d| _@        d | _A        d | _B        d| _C        d| _D        d | _E        d| _F        d| _G        d| _H        d| _I        d| _J        d | _K        d| _L        || _M        i | _N        d| _O        d| _P        t        j                  | _S        i | _T        g | _U        g | _V        g | _W        tu               | _X        d | _Y        d| _Z        d| _[        | j                  r| jp                  j:                  | _\        n|| _\        t        t        dt        | j                        i      | _`        |j                  r6|j                  j                  |j                  | j                        | _>        t        |j                  |j                  | jh                  | j                   | j|                  | j                  | j                        | _g        d| _h        t)               | _i        d| _j        g | _k        d| _l        g | _m        d| _n        || _o        || _p        || _q        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)re   r   r   r   r   rP   rL   max_data)r~   r   r   max_streams_bidi   max_streams_unir   )re   r   r   )	is_clientodcid)congestion_control_algorithminitial_rttmax_datagram_size!peer_completed_address_validationquic_logger
send_probeloggerIH01IH1r   01rE      rK   rD   rO   
                                                            0   1   )r   r   r   tokencertificateprivate_key_configuration
_is_clientr   
_ack_delay	_close_at_close_event_connect_called_cryptos_cryptos_initial_crypto_buffers_crypto_frame_type_crypto_packet_version_crypto_retransmitted_crypto_streamsr   _events_handshake_complete_handshake_confirmedr   osurandomconnection_id_length
_host_cidsre   r   _host_cid_seq_local_ack_delay_exponent!_local_active_connection_id_limit_local_challenges#_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	_peer_cid_peer_cid_availablera   _peer_cid_sequence_numbers_peer_retire_prior_to_peer_token_quic_logger_remote_ack_delay_exponent"_remote_active_connection_id_limit$_remote_initial_source_connection_id_remote_max_idle_timeout_remote_max_data_remote_max_data_used_remote_max_datagram_frame_size"_remote_max_stream_data_bidi_local#_remote_max_stream_data_bidi_remote_remote_max_stream_data_uni_remote_max_streams_bidi_remote_max_streams_uni_remote_version_information_retry_count_retry_source_connection_id_spaces	_spin_bit_spin_highest_pnr   r   _state_streams_streams_queue_streams_blocked_bidi_streams_blocked_uni_streams_finished_version_version_negotiated_compatible _version_negotiated_incompatible#_original_destination_connection_idr   r   rk   _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          rY   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798:1559#%*"<>05#( $)!JJ}AAB !<@OObjjnQU	
 *..)*&12.?A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+,(()%'($MQ(+E(9; !)55/10279"68!+.5'+.3+05-??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 rU   )r   r   s    rY   r   zQuicConnection.configuration  s    """r]   c                     | j                   S rU   )rE  rl  s    rY   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_cidrl  s    rY   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   r<  
END_STATESr   ConnectionTerminatedrJ  r   s       rY   closezQuicConnection.close  sJ      $J)F & ; ;%%+!D
 #'D *G$r]   r   nowc                 :   | j                   r| j                  rJ d       d| _        t        |d      g| _        | j                  j
                  | j                  j
                  | _        n| 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   Nr   rw  )	r   r   r   r!  r   original_versionrB  supported_versions_connect)r   r   rw  s      rY   connectzQuicConnection.connect  s     OOD$8$8	HG	H8#.t$GH//; //@@DM //BB1EDM#r]   c                 
   | j                   d   }| j                  t        v rg S t        | j                  | j
                  | j                  | j                  | j                  j                  | j                  | j                  | j                  | j                  	      }| j                  rg }| j                  sW|t         j"                  j$                  t&        j$                  ft         j"                  j(                  t&        j(                  fgz  }|j+                  t         j"                  j,                  t&        j,                  f       |D ]  \  }}| j.                  |   }|j0                  j3                         s0|j5                  ||       | j7                  ||| j8                  j:                  | j8                  j<                  | j8                  j>                          | j@                  jC                  d| j8                  j:                  | j8                  j>                         d| _        | jE                  d|       n| jF                  jH                  | jF                  jJ                  z
  |_&        | jN                  r*|jL                  | j                  k  r| j                  |_&        |jP                  s!|jR                  dz  |jT                  z
  |_+        	 | j                  sLt         j"                  j$                  t         j"                  j(                  fD ]  }| jY                  |||        | j[                  |||       |j_                         \  }}	|r}|j`                  | _        d}
|	D ]-  }||_1        | jF                  je                  || jf                  |jh                     	       |jh                  t         j"                  j(                  k(  rd}
| j                  u| j                  jk                  d
d|jl                  |j`                  | j                  jo                  |jn                        |jn                  t&        j,                  k(  rdntq        | j                        tq        | j                  j                        dd|jr                  id       0 |
r5| j
                  r)| ju                  t         j"                  j$                         g }|D ]x  }tw        |      }|xjT                  |z  c_*        |j+                  ||jx                  f       | j                  M| j                  jk                  d
ddtz        |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_bitr   )builderr   r   r~   r   z,Connection close sent (code 0x%X, reason %s)FTis_initiatorrw  rP   )packetspace	transportpacket_sentrr  )r  rl   sciddcidlengthframesheaderrawcategoryeventdatadatagrams_sentr   r  payload_lengthcountr  )>r!  r<  rt  r8   r   r   r   r#  r$  re   r(  r)  r:  rB  rJ  r	  r   ro   rn   r*   rq   appendrr   r   sendis_validstart_packet_write_connection_close_framer   r   r~   r   rF  info_close_beginrI  congestion_windowbytes_in_flightmax_flight_bytesrN  r   r   r   max_total_bytes_write_handshake_write_applicationr9   flushr  	sent_timeon_packet_sentr9  r   	log_eventr   rl   rk   
sent_bytes_discard_epochlenr   UDP_HEADER_SIZE)r   rw  r   r  epoch_packet_typesr   rl   crypto	datagramspacketssent_handshaker  retdatagramr  s                  rY   datagrams_to_sendz QuicConnection.datagrams_to_send  s    **1-;;*$I $]]oo"55--^^''''))^^MM

 !#,,"YY&&(>(>?YY((.*B*BC' " %%syy'8'8.:P:P&QR&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"
 (.'9'9^=S=S'S %')1$--)@(01C1C(D' %-f.?.?#@ 0 @ $//##CII$5$56 ! 	H ]N##~5#JJ,"3"345  ,!!++(*!" +:N*J2@  , 	& 
E ) s   A+U 	U"!U"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     rY   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   r<  rt  rI  spacesack_atget_loss_detection_timer  r"  )r   timer_atr  s      rY   	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 triggeredry  )r   r   r   ru  r'   INTERNAL_ERRORr(   PADDING
_close_endr  rF  debugrI  on_loss_detection_timeoutr   rw  s     rY   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
IndexErrorrl  s    rY   
next_eventzQuicConnection.next_event  s,    	<<'')) 		s    	((c                     | j                   j                  }| j                  t        || j                        }t	        |d| j
                  j                         z        S r   )r   idle_timeoutr-  minmaxrI  get_probe_timeout)r   r  s     rY   _idle_timeoutzQuicConnection._idle_timeout  sR     **77((4|T-J-JKL<TZZ%A%A%C!CDDr]   r  c                    t        |      }| j                  t        v ry| j                  ,| j                  j	                  dddt
        |z   |dgd       | j                  |      }|j                  s|xj                  |z  c_        | j                  || j                         z   | _	        t        |      }|j                         s|j                         }	 t        || j                  j                   	      }| j&                  s`|j(                  t*        j,                  k(  rC|t.        k  r:| j                  -| j                  j	                  dd
dd|j0                  id       yd}	| j2                  D ])  }
|j4                  |
j6                  k(  s|
j8                  }	 n | j&                  s|j(                  t*        j:                  k(  r<|	:| j                  -| j                  j	                  dd
dd|j0                  id       y|j(                  t*        j<                  k(  r| j?                  ||       y|j@                  \|j@                  | j                  jB                  vr:| j                  -| j                  j	                  dd
dd|j0                  id       y|j(                  t*        jD                  k(  r:| jG                  ||jI                  ||j                         tJ        z
        |       yd}| j&                  sw| j                  tL        jN                  k(  rZ|j(                  t*        j,                  k(  sJ d       d}|g| _(        |j@                  | _)        | jU                  |j4                         tW        |j(                        }|tX        jZ                  j,                  k(  r| j\                  |j@                     }n| j^                  |   }|tX        jZ                  j`                  k(  r(| jb                  tX        jZ                  jd                     }n| jb                  |   }|j                         |z
  }||j0                  z   }|jg                  |       	 |ji                  ||| ||jj                        \  }}}|j(                  t*        jd                  k(  rd}nd}|d   |z  r1| j{                  t|        j~                  t        j                  d       yd}| j                  ~g }| j                  j	                  dd||| j                  j)                  |j(                        t        |j4                        t        |j                        dd|j0                  id        ||jj                  kD  r
|dz   |_5        | j&                  sF|tX        jZ                  j:                  k(  r)| j                  tX        jZ                  j,                         | j                  j8                  ,|j                  | j                  _        d| j                  _        | j                  tL        jN                  k(  r0|j                  | _F        | j                  tL        j                         |j(                  t*        jd                  k(  rv|| j                  kD  rgt        |d         }| j&                  r	| | _K        n|| _K        || _I        | j                  *| j                  j	                  d!d"d#| j                  i       t        ||j4                  ||||j@                  $      }	 | j                  |||%      \  }}| j                  t        v s| j                  ry|| j                         z   | _	        | j&                  s|j                  | j                  k7  rn|tX        jZ                  jd                  k(  rQ| jn                  jq                  d&t        |j                        |	       |j                  | _T        | j                          |j                  sJ|tX        jZ                  j:                  k(  r-| jn                  jq                  d'|j                         d|_        || jP                  vr| jP                  j                  |       | jP                  j                  |      }|rnsl||j                  kD  r]| jn                  jq                  d(|j                         | jP                  j                  |       | jP                  j                  d|       |j                  sZ||j                  kD  r||_Y        ||_]        |j                  j                  |       r |j                  || j                  z   |_`        |j                         syy# t"        $ r? | j                  0| j                  j	                  dd
dd|j$                  |z
  id       Y yw xY w# tl        $ r}| jn                  jq                  |       | j                  -| j                  j	                  dd
dd|j0                  id       | j&                  re|tX        jZ                  j:                  tX        jZ                  jd                  fv r/| jr                  s#| jt                  jw                  |       d| _9        Y d}~	d}~wtx        $ r_}| jn                  jq                  |       | j                  -| j                  j	                  dd
dd|j0                  id       Y d}~
Nd}~ww xY w# t        $ rX}| jn                  j                  |       | j{                  |j                  |j                  |j                         Y d}~7d}~ww xY w))z
        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_smallunknown_connection_id)r  rw  unsupported_version)r  packet_without_tagrw  Fzfirst packet must be INITIALTkey_unavailablery  payload_decrypt_errorr   r   r   zReserved bits must be zeror   packet_received)r  rl   r  r  r  connectivityspin_bit_updatedstate)r   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)br  r<  rt  r)  r  r  _find_network_pathr   r   r   r  r   eoftellr3   r   r  
ValueErrorcapacityr   rl   r*   rn   r   packet_lengthr  destination_cidre   r   rq   VERSION_NEGOTIATION#_receive_version_negotiation_packetr   r{  RETRY_receive_retry_packet
data_slicer%   r   r   r!  rB  _initializers   r   ro   r  r   rp   r9  rr   seekdecrypt_packetexpected_packet_numberr   rF  r  r  rI  reschedule_datar   rv  r'   PROTOCOL_VIOLATIONr(   r  rk   
source_cidr  r$  r,  
_set_stater   r;  r0   r:  r   _payload_receivedr   warningr   r~   r   rJ  r   rq  r   r  indexlargest_received_packetpopinsert	discardedlargest_received_time	ack_queueaddr  r   )r   r  r   rw  r  r   buf	start_offr  destination_cid_seqconnection_idr  r   r  r  encrypted_offend_offplain_headerplain_payloadr  excreserved_maskr   r  contextis_ack_eliciting
is_probingidxs                               rY   receive_datagramzQuicConnection.receive_datagram  sO
    T ;;*$ (''$* '6&F.< ( 0 ..t4((''>9' >>! 4#5#5#77DN$'')
I))<)<)Q)Q$ OO&&.*@*@@"%??$$0%%//!,.'J$,f.B.B#C 0   26!% ))]->->>*7*G*G'
 6#5#59Q9Q#Q%-$$0%%//!,.'>$,f.B.B#C 0   !!^%G%GG88C8P *NN$*=*=*P*PP$$0%%//!,.'<$,f.B.B#C 0   !!^%9%99**!'*~~!388:0H#H(  +  $)! ??t{{6I6U6U'U&&.*@*@@212@(,%'3n# &  !7!78 f001E		)))..v~~>u-		***SYY%6%67U+  HHJ2M&"6"66GHHW%=C=R=R7+]E<X<X>:m]N !!^%;%;; $ $A.

,??,44">  
  8<  ,%'"!!++(+"4-:+/+<+<+H+H & 2 2, %-V-C-C$D$,V->->$?# !)&*>*>? , $ u;;;/<q/@, ??u		0C0C'C##CII$5$56 ~~--5%+%6%6"12.{{1===<B<M<M9 3 = => ""n&<&<<!D$9$99'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)4#6#66##**<8%%++L9C:-%:W:W*W""#=|?P?PQ##'',##**1l; ?? 5#@#@@4AE125E/##M2#(<#&#8EL} ''))  
$$0%%//!,.';$,cllY.F#G 0  
d ' ""3'$$0%%//!,.'8$,f.B.B#C 0  OO#))"5"5syy7H7H!II 66JJ..3.715D. ""3'$$0%%//!,.'>$,f.B.B#C 0  @ ' $$S)

"~~"~~"%"3"3   sR   !f $g l Ag
	g
	lCj!!l-All	m0Am++m0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   ro   rr   
update_keyrl  s    rY   request_key_updatez!QuicConnection.request_key_update=  s8     ''W)WW'cii''(335r]   rt   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   rt   r   streams       rY   reset_streamzQuicConnection.reset_streamF  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)rM  r  )r   r  s     rY   	send_pingzQuicConnection.send_pingR  s     	!!#&r]   c                 :    | j                   j                  |       y)zr
        Send a DATAGRAM frame.

        .. aioquic_transmit::

        :param data: The data to be sent.
        N)rK  r  )r   r  s     rY   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   rt   r  r!  r  s        rY   send_stream_datazQuicConnection.send_stream_dataf  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  r=  getreceiverstopr  s       rY   stop_streamzQuicConnection.stop_streamu  s]     ''	2R  ""9d3>IJJZ(r]   alpn_protocolc                    | j                   j                  D ]5  \  }}|t         j                  j                  k(  s$| j	                  |        nB t        t        j                  t         j                  j                  z   | j                  d      | j                  s!| j                  s| j                  | j                  j                  D ]  }|| j                  k(  r n|| j                   j"                  v s-t%        | j                  |      sD|| _        | j&                  |   | j(                  t         j*                  j,                  <   t         j                  j                  | j/                         fg| j                   _         n d| _        | j2                  j5                  dt7        | j                               | j8                  j;                  t=        j>                  |             y)z
        Callback which is invoked by the TLS engine at most once, when the
        ALPN negotiation completes.

        At this point, TLS extensions have been received so we can parse the
        transport parameters.
        z%No QUIC transport parameters receivedr   NTNegotiated protocol version %s)r+  ) r   received_extensionsExtensionTypeQUIC_TRANSPORT_PARAMETERS_parse_transport_parametersr   r'   CRYPTO_ERRORAlertDescriptionmissing_extensionr  r   rC  r6  available_versionsrB  r   r{  rd   r  r   ro   rn   _serialize_transport_parametershandshake_extensionsrF  r  r1   r  r  r   ProtocolNegotiated)r   r+  ext_typeext_datar   s        rY   _alpn_handlerzQuicConnection._alpn_handler  s    #'((">"> 
	Hh3,,FFF00:
	
 &(55&&88922E	  t'J'J//;  $??RR G$--/4#6#6#I#II1$--I )0;?;P;P#<cii&7&78 !$ 1 1 K K $ D D F95 +, 37D/LL02I$--2X
 	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~   rt   s      rY   _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'   r=  r>  s      rY   _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$  rF  r  rk   re   r   rl  s    rY   rp  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.
        rP   N)rI  r  r   r  r   r   r   )r   r  rw  s      rY   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   r9  keysr  r  r  r   r  r   r   r)  r   r   	end_trace)r   r   s     rY   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  version_information)client_versionschosen_versionr  alpn_informationclient_alpnsr]   )r   r)  r  r   r{  rB  alpn_protocolsr  r   r  r$  re   r   handle_messager  _push_crypto_datar  s     rY   r|  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                  s| j                  j                  d|       | j                  |   j                          |t        j                  j                  k(  rY| j                  j                         D ]<  }t        |j                  _        t        |j                  _        |j                          > | j                  j!                  | j                   |          d| j                   |   _        y y )NzDiscarding epoch %sT)r9  r  rF  r  r   teardownr   ro   rn   r  valuesr    recv_teardown_cbr  rI  discard_space)r   r   r  s      rY   r  zQuicConnection._discard_epoch  s    ||E",,LL4e<MM% ))+		))) #33::< &F/9FKK,/9FKK,OO%& 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   rF  r  )r   r   r  r   s       rY   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)rt   max_stream_data_localmax_stream_data_remotewritable)rA  r>   r=  r'  rx   r   r   r'   r=  r{   r  r  r  r1  r  r   STREAM_LIMIT_ERRORr   rF  r  r=   r>  r  )r   r~   rt   r  rZ  r[  max_streamsstream_counts           rY   _get_or_create_streamz$QuicConnection._get_or_create_stream3  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   )rt   rZ  r[  readabler   T)rA  r  r=  r'  rx   r   r{   r3  r5  r@  r  r2  r4  r?  r=   r>  r  r  r  
is_blockedrP  )r   rt   r  rZ  r[  r^  streams_blockedr  s           rY   r  z-QuicConnection._get_or_create_stream_for_sende  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(   CRYPTOrR  )r   re  s     rY   _handle_session_ticketz%QuicConnection._handle_session_ticket  s\    ..:22nD%(;;(//? 445  	$$^4r]   r  c                 
    t        j                   j                  j                   j                  j                   j                  j
                   j                  j                   j                  j                   j                   j                   j                  rd nt         j                  j                   j                  j                  
       _          j                  j                   j                   _         j                  j                   j                   _         j                  j                    j                   _        t         j$                  j&                   j)                         fg j                   _         j                  j,                  } j                  r||j.                  r|j                   j                  j                  k(  r~ j                  j,                   j                   _        |j0                  t        k(  rF|j2                  D ]7  \  }}|t         j$                  j&                  k(  s$ j5                  |d        n  j6                   j                   _         j:                   j:                   j                   _         j>                   j@                   j                   _!         jD                   j                   _#        dt         jH                  dtJ        f fdi  _&         j                  jN                  D ]9  }tK               }|jQ                  | j                  |       | jL                  |<   ; tS        fdt         jH                  jT                  t         jH                  jV                  t         jH                  jX                  fD               _-         jL                   j\                      jZ                  t         jH                  j^                  <   t         jH                  j^                  ta        tb        	      t         jH                  jV                  ta        tb        	      t         jH                  jX                  ta        tb        	      i _2        t         jH                  j^                  tg               t         jH                  jV                  tg               t         jH                  jX                  tg               i _4        t         jH                  j^                  tk               t         jH                  jV                  tk               t         jH                  jX                  tk               i _6        to         jl                  jq                                jr                  _:        y )
N)
rN  cadatacafilecapathcipher_suitesr   r   max_early_dataserver_nameverify_modeT)from_session_ticketr   rR   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        rY   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]   )re   r   r   c              3   2   K   | ]  }| |      f  y wrU   rv   )rW   r   r  s     rY   rZ   z-QuicConnection._initialize.<locals>.<genexpr>  s$      
 &u-.
s   r  );r   Contextr   rN  rl  rm  rn  r   ro  r   rF  rh  rq  rr  r   certificate_chainr   certificate_private_keyr/  r0  r6  r7  re  r  rg  other_extensionsr1  r;  alpn_cbrQ  get_session_ticket_cbrR  rj  new_session_ticket_cb_update_traffic_keyupdate_traffic_key_cbro   r   r  r{  setup_initialdictrp   rq   rr   r   rB  rn   r   CRYPTO_BUFFER_SIZEr  r=   r  r;   r9  listrS  rI  r  )r   r  re  r9  r:  r   pairr  s   `      @rY   r  zQuicConnection._initialize  s   ;;..==&&--&&--&&--,,::oo<<#'??4++77++77
  $22>>%)%8%8%J%J"+/+>+>+J+J( !!;;446)
% ,,;;OO*''**d.A.A.M.MM&*&9&9&H&HDHH# 11^C*8*I*I &Hh3#4#4#N#NN88$$ 9    --''3-1-I-IDHH*''3-1-H-HDHH*)-)A)A&	cii 	J 	" !#**== 	2G<D8tPWX-1D!!'*	2
  
 		""		##		!!
 
 ,0+@+@+Ocii''( IIv/ABII1C!DIIv/AB 
 IIz|IIIIz| 
 II0II!2II0

 !!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_delayrw  r  )r2   r(   ACK_ECNpull_uint_varr*  r)  r   r  encode_ack_framerI  r   r   r   ro   rq   rr   on_ack_receivedr   r9  )r   r  r~   r  r  ack_delay_encodedr  s          rY   rV  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utf8rr  r   z0Connection close received (code 0x%X, reason %s)Fr  )r  r(   TRANSPORT_CLOSE
pull_bytesrj   UnicodeDecodeErrorr)  r   r  encode_connection_close_framerF  r  r   r   ru  r  r   )r   r  r~   r  r   reason_lengthr   s          rY   rg  z-QuicConnection._handle_connection_close_frame)  s    &&(
666**,JJ))+	NN=9@@HM
 (&&--!!??))"/ @  	>	

 $ & ; ;%%+!D
 5gllC %% " 	M	s    D DDc                    |j                         }|j                         }||z   t        kD  rt        t        j                  |d      t        ||j                  |            }| j                  4|j                  j                  | j                  j                  |             | j                  |j                     }||z   |j                  j                         z
  }|t        kD  rt        t        j                   |d      |j                  j#                  |      }	|	|| _        |j&                  | _        	 | j*                  j-                  |	j.                  | j0                         | j3                          | j>                  sh| j*                  j@                  t*        jB                  jD                  t*        jB                  jF                  fv rd| _        | jH                  s7| jK                  t*        jL                  jN                         d| _(        d| _)        | jU                          | jV                  j                  tY        jZ                  | j*                  j\                  | j*                  j^                  | j*                  j`                               | jc                  d	       | jc                  d	       | jd                  jg                  d
| j*                  j\                         yyy| jd                  jg                  d|j                         | jH                  sc|j                  t*        jL                  jh                  k(  r;| jj                  s.| jl                  jo                  |jp                         d| _5        yyyy# t*        j4                  $ r@}
t        t        j6                  t9        |
j:                        z   |t=        |
            d}
~
ww xY w)z(
        Handle a CRYPTO frame.
        &offset + length cannot exceed 2^62 - 1r   )offsetr  Nztoo much crypto bufferingT)r+  early_data_acceptedsession_resumedFr  zALPN negotiated protocol %sz+Duplicate CRYPTO data received for epoch %sry  )9r  r   r   r'   FRAME_ENCODING_ERRORr,   r  r)  r   r  encode_crypto_framer  r   r(  starting_offsetMAX_PENDING_CRYPTOCRYPTO_BUFFER_EXCEEDEDhandle_framer  r   r  r   rO  r  r  rP  Alertr2  r   descriptionr   r  r  StateCLIENT_POST_HANDSHAKESERVER_POST_HANDSHAKEr   r  ro   rq   r	  rL  _replenish_connection_idsr  r   HandshakeCompletedalpn_negotiatedr  r  _unblock_streamsrF  r  rn   r  rI  r  r   )r   r  r~   r  r  r  framer  pendingr  r  s              rY   rY  z#QuicConnection._handle_crypto_frameQ  s    ""$""$F?\)%(==%F 
  vCNN64JK (&&--!!55e< %%gmm46/FOO$C$C$EE''%(??%9 
 ,,U3 '1D#*1//D'''

D4H4HI&&( ++		//		//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 $S 99 ),99C<PP)"%c( s   :A N O;OO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        rY   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          rY   ri  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   ro   rq   rI  r   r   r  r~   r  s       rY   rh  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.  rF  r  )r   r  r~   r  r   s        rY   r\  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  rt   z-Stream %d remote max_stream_data raised to %d)
r  r)  r   r  encode_max_stream_data_framerB  r`  r[  rF  r  )r   r  r~   r  rt   r  r  s          rY   r]  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  r4  rF  r  r  r   r  r~   r  r^  s        rY   r^  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  r5  rF  r  r  r  s        rY   r_  z,QuicConnection._handle_max_streams_uni_frameB  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   re   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  ro  rp  r  CONNECTION_ID_LIMIT_ERRORrO  r  MAX_PENDING_RETIRES)r   r  r~   r  r   r  r  r  r   
change_cidre   retirequic_connection_ids                rY   rc  z.QuicConnection._handle_new_connection_id_frame_  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  rS  )r   r  r~   r  r  r   s         rY   rZ  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         rY   rT  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
                  j                  j                  |       y)z0
        Handle a PATH_CHALLENGE frame.
        rL   Nr  )r  r)  r   r  encode_path_challenge_framer   r   )r   r  r~   r  r  s        rY   re  z+QuicConnection._handle_path_challenge_frame  sg     ~~a  (&&--!!==4=H 	..55d;r]   c                    |j                  d      }| j                  5|j                  j                  | j                  j	                  |             	 | j
                  j                  |      }| j                  j                  d|j                         d|_        y# t        $ r t        t        j                  |d      w xY w)z/
        Handle a PATH_RESPONSE frame.
        rL   Nr  z!Response does not match challenger   z&Network path %s validated by challengeT)r  r)  r   r  encode_path_response_framer  r  KeyErrorr   r'   r  rF  r  r   r   )r   r  r~   r  r  r   s         rY   rf  z*QuicConnection._handle_path_response_frame  s     ~~a  (&&--!!<<$<G	1155d;L 	C\EVEVW$(!  	%(;;%A 	s   B &Cc                     | j                   4|j                  j                  | j                   j                                yy)z&
        Handle a PING frame.
        N)r)  r   r  encode_ping_framer  s       rY   rU  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_sizert   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_framer?  r`  rZ  r   r'   FLOW_CONTROL_ERRORr  r(  highest_offsetr  r   r   rF  r  handle_resetr<   FINAL_SIZE_ERRORr   r  )r   r  r~   r  rt   r   r  r  newly_receivedr  r  s              rY   rW  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  rX  r  r   re   r   rF  r  rk   r  r   ConnectionIdRetiredr  )r   r  r~   r  r   r  r  s          rY   rd  z1QuicConnection._handle_retire_connection_id_frame\  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   rt   )r   )r  r)  r   r  encode_stop_sending_framerB  r`  r  r  r'   NO_ERRORr  r   StopSendingReceived)r   r  r~   r  rt   r   r  s          rY   rX  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  finNrw   r  r  )r  r  r  r   r   r'   r  r,   r  rz   r)  r   r  encode_stream_framer?  r`  rZ  r  r  r(  r  r  r   r   r  r<   r  r   r  )r   r  r~   r  rt   r  r  r  r  r  r  r  s               rY   r[  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  rt   )r  r)  r   r   encode_stream_data_blocked_framer?  r`  )r   r  r~   r  rt   r  s         rY   ra  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        rY   rb  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      rY   r~  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      rY   r}  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)r7   ACKEDr  subtract)r   r  r  r  s       rY   _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)r7   r  r   )r   r  r  s      rY   _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)r7   r  rL  )r   r  s     rY   _on_handshake_done_deliveryz*QuicConnection._on_handshake_done_delivery8	  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)r7   r  max_stream_data_local_sent)r   r  r  s      rY   _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)r7   r  r   )r   r  r  s      rY   _on_new_connection_id_deliveryz-QuicConnection._on_new_connection_id_deliveryH	  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 responserr  z (probe))r  N)
r7   r  rF  r  r  r  r   PingAcknowledgedrM  extend)r   r  r#  r  s       rY   _on_ping_deliveryz QuicConnection._on_ping_deliveryQ	  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)r7   r  rO  r  )r   r  r   s      rY   !_on_retire_connection_id_deliveryz0QuicConnection._on_retire_connection_id_delivery^	  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  rj  r  r   r  r>   r(   ri  r#   r$   r  rz   )r   r  r*  r  r  crypto_frame_foundframe_foundr  r  r~   frame_handlerframe_epochss               rY   r  z QuicConnection._payload_receivedg	  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)r  r  c           
      F   | j                   rZ| j                  sM|j                  | j                  k(  r3|j                  t        || j                  j                  |j                        k(  r| j                  X| j                  j                  ddg dt        |j                        t        |j                        dd|j                  id	       |j                  | j                  _        |j                  | _        | xj                  d
z  c_        |j                  | _        | j"                  j%                  dt'        |j                        z         | j)                  |       y| j                  .| j                  j                  dddd|j                  id	       yy)z(
        Handle a retry packet.
        )r   Nr  r  retryrl   r  r  r  r  r  r   zRetrying with token (%d bytes)ry  r  unexpected_packetr  )r   r7  r  r   integrity_tagr/   r$  re   r   r)  r  rk   r  r  r   r(  r8  rF  r  r  r|  )r   r  r  rw  s       rY   r  z$QuicConnection._receive_retry_packet	  sr    OO%%&&$--7$$&"""   ,!!++(+"$+2$,V->->$?$,V-C-C$D#
 !)&*>*>? ,  "(!2!2DNN%||D"/5/@/@D,LL>V\\ARRSMMcM"   ,!!++(*#6 (&*>*>? ,  -r]   c           
         | j                   r>| j                  t        j                  k(  r | j                  s| j
                  {| j
                  j                  ddg | j
                  j                  |j                        t        |j                        t        |j                        dd|j                  id       | j                  |j                  v r0| j                  j                  dt!        | j                               y| j"                  j                  D cg c]  }||j                  v r| }}|r|d	   nd}| j
                  @| j
                  j                  dd
|j                  | j"                  j                  |d       |e| j                  j%                  d       t'        j(                  t*        j,                  t.        j0                  d      | _        | j5                          yd	| _        || _        d| _        | j                  j9                  dt!        | j                               | j;                  |       y| j
                  .| j
                  j                  dddd|j                  id       yyc c}w )z
        Handle a version negotiation packet.

        This is used in "Incompatible Version Negotiation", see:
        https://datatracker.ietf.org/doc/html/rfc9368#section-2.2
        Nr  r  r2  r  r  r  z7Version negotiation packet contains protocol version %sr   rI  )server_versionsrJ  rK  z(Could not find a common protocol versionr   Tz!Retrying with protocol version %sry  r  r3  r  )r   r<  r   r   rD  r)  r  rl   rk   r  r  r  rB  r{  rF  r  r1   r   errorr   ru  r'   r  r(   r  r   r  r#  r  r|  )r   r  rw  xcommonrK  s         rY   r  z2QuicConnection._receive_version_negotiation_packet	  s_    OO2>>>99  ,!!++(+"$+/+<+<+H+H & 2 2, %-V->->$?$,V-C-C$D# !)&*>*>?
 , ( }} 9 99$$M+DMM: 
 ,,??111 F  +1VAYdN  ,!!++(/+1+D+D+/+>+>+Q+Q*8 ,  %""#MN$*$?$?,;;,44"L%!
 !"#D*DM48D1LL3'6 MMcM"   ,!!++(*#6 (&*>*>? ,  -Ks    J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.
        rL   r   r  r   N)r  r  r  r+  r  r   r
  r  r   r  r  rl  s    rY   r  z(QuicConnection._replenish_connection_idsQ
  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)rF  r  rk   re   r   r  rO  r  )r   r  s     rY   ro  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      rY   rP  z QuicConnection._push_crypto_datak
  sR    ..446 	JE3  '..44SXX>HHQK	r]   c                     d| _         y )NT)rN  rl  s    rY   rH  zQuicConnection._send_probep
  s
    "r]   rs  c                 V	   	 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.               |j0                  |j0                  }| j                  sB|j2                  |j4                  vr*t        t        j
                  t        j                  d      |j2                  | j6                  k7  r*t        t        j8                  t        j                  d      |s|j(                  | j:                  | _        |j*                  |j*                  dz  | j<                  _        | j                  r@| j>                  j@                  dk(  r'|jB                  |jB                  | j>                  _!        |j0                  | _"        |j&                  |j&                  | _#        |jH                  |jH                  dz  | _%        |jL                  | _'        dD ]$  }t        |d|z         }|tQ        | 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 <= 20r@   zmax_ack_delay must be < 2^14z max_udp_payload_size must be >= zJversion_information's chosen_version is not included in available_versionszFversion_information's chosen_version does not match the version in useg     @@r   )r   max_stream_data_bidi_localmax_stream_data_bidi_remotemax_stream_data_unir   r   initial__remote_))r4   r   r  r   r'   TRANSPORT_PARAMETER_ERRORr(   ri  r)  r  encode_transport_parametersr   getattrinitial_source_connection_idr,  r   rE  r   r8  active_connection_id_limitack_delay_exponentmax_ack_delaymax_udp_payload_sizer   rI  rK  r5  r  VERSION_NEGOTIATION_ERRORr*  rI  r$  r   r   r6  r+  max_idle_timeoutr-  r  r0  setattr)r   r  rs  quic_transport_parametersattrrI  paramr   s           rY   r1  z*QuicConnection._parse_transport_parameterss
  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	  )<<H&?&S&S# +::.AAB .#0#J#J#0#7#74	  '559T9TT-#0#J#J#0#7#71	  #(;;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
	9K  	%(BB(//I 	s   Q4 44R(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$                  t'        | j(                  | j                  j*                              }| j,                  s"| j.                  |_        | j2                  |_        | j6                  9| j6                  j9                  dd| j6                  j;                  d	|
             t=        d| j>                  z        }tA        ||       |jB                  S )Ni  r      Qr   )rK  r5  )rP  rO  rT  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_unirN  rQ  r  quantum_readinessr   rI  r  r@  localrB  r  rP   r  )"r-   r  r  r   r   r  r  r   r  r  r  r  r  r  r  quantum_readiness_testr   r  r   r.   rB  r{  r   rE  r   r8  r   r)  r  rL  r   r   r6   r  )r   rV  r  s      rY   r6  z.QuicConnection._serialize_transport_parameters2  s   $;#=='+'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 6#}}#'#6#6#I#I!'%
!0 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)rF  r  r<  )r   r  s     rY   r  zQuicConnection._set_statea  s#    :t{{E:r]   c                 N    t        |      | j                  k7  xs t        |       S rU   rx   r   r{   r   rt   s     rY   r&  z"QuicConnection._stream_can_receivee  0    )
__ H$<Y$G G	Hr]   c                 N    t        |      | j                  k(  xs t        |       S rU   rf  rg  s     rY   rA  zQuicConnection._stream_can_sendj  rh  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)r3  r5  r@  r2  r4  r?  rt   r  rc  r[  rP  )r   r  r[  r^  rd  r  s         rY   r  zQuicConnection._unblock_streamso  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                 8   | j                   r_| j                  S| j                  sG| j                  | _        d| _        | j                  j                  dt        | j                               | 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.
        NTr-   
)rl  rm  r   )r   r  rC  rB  rF  r  r1   r   secrets_log_filer   	DirectionDECRYPTSECRETS_LABELSr   r#  client_randomhexr  r   ENCRYPTr  setuprT  )	r   rk  r   rl  rm  rq  	label_rowlabelr  s	            rY   r  z"QuicConnection._update_traffic_key  sE    OO++777 77DM26D/LL02I$--2X  ..??'I9N9N,NOI"9-ekk:E"" %txx'='='A'A'CVZZ\R ""$u%---KK)&$--   KK)&$--  r]   	challenger   c                    || j                   |<   t        | j                         t        kD  rWt        t	        | j                   j                                     }| j                   |= t        | j                         t        kD  rVy y rU   )r  r  MAX_LOCAL_CHALLENGESnextiterrF  )r   r{  r   keys       rY   _add_local_challengez#QuicConnection._add_local_challenge  sj    ,8y)$((),@@ tD22779:;C&&s+	 $((),@@r]   r  c           
         d }| j                   t        j                  j                     j                  j                         r_| j                   t        j                  j                     }| j                  t        j                  j                     }t        j                  }nx| j                   t        j                  j                     j                  j                         r8| j                   t        j                  j                     }t        j                  }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(                  sN|j*                  sBt-        j.                  d      }| j1                  ||       | j3                  ||       d|_        t5        |j6                        d	kD  rF|j6                  j9                         }| j;                  ||       t5        |j6                        d	kD  rF| j<                  D ]"  }	|	j>                  r| jA                  ||	
       $ | jB                  d d  D ]0  }
| jE                  ||
       | jB                  jG                  d	       2 | jH                  rw| jJ                  r,| jM                  |tN        jP                  | jR                         | jT                  r,| jM                  |tN        jV                  | jX                         d| _$        | j[                  ||       | j\                  j_                         D ]  }| ja                  |||        | jb                  r6| je                  || jb                         | jb                  jg                          | jh                  r| je                  |d       d| _4        |*|jj                  jl                  s| jo                  |||       | jp                  rW	 | js                  || jp                  d	   tN        jt                         | jp                  j9                          | jp                  rWty               }ty               }	 | jz                  D ]  }|j|                  r| j~                  j                  d|j                         | j\                  jG                  |j                         | j                  j                  |j                         |j                  |       |j                  j                  r| j                  ||       |jj                  j                  r| j                  ||       |j                  r|jj                  jl                  r
| j                  |||t        |jj                  j                  | j                  z   | j                  z
  |j                              }| xj                  |z  c_N        |d	kD  s}|j                  |        	 | jz                  D cg c]  }||v s||v s| c}| _=        | jz                  j                  |       |j                  ry | j                  j                  j                  |       # tv        $ r Y 6w xY wc c}w # | jz                  D cg c]  }||v s||v s| nc c}w c}| _=        | jz                  j                  |       w xY w)NTry  r  r  rw  )r  FrL   )r{  r   )r  r{  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)Sr   r   ro   rr   r  r  r  r*   rp   r9  r  rI  _pacernext_send_timer"  r  r  _write_ack_framerL  _write_handshake_done_framer   r   r
  r  r  _write_path_challenge_framer  r   r  _write_path_response_framer  r   _write_new_connection_id_framerO  !_write_retire_connection_id_framer  rP  r?  _write_streams_blocked_framer(   STREAMS_BLOCKED_BIDIr4  r@  r	  r5  _write_connection_limitsr=  rS  _write_stream_limitsrM  _write_ping_frameclearrN  r  buffer_is_empty_write_crypto_framerK  _write_datagram_framer  r9   ra   r>  is_finishedrF  r  rt   rA  r  r(  stop_pending_write_stop_sending_framereset_pending_write_reset_stream_framerc  _write_stream_framer  r  r.  r/  r[  r&  packet_is_emptyupdate_after_send)r   r  r   rw  crypto_streamr  rl   r  r{  r  r   r  r   r  r   s                  rY   r  z!QuicConnection._write_application  s    /3==**+0099;]]399#4#45F 001B1BCM(00K]]399--.33<<>]]399#5#56F(11KSYY../||#u||s':"&**"3"3"B"Bs"B"K??.  f5''<<+0C))'C)P //44W4E38D0 %11\5V5V "

1I--"+, .  44 '9 5  9=L5 ,889A= , > > F F HI33 '9 4  ,889A= &*__ 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	\ C=\1 \1 A1\1 \1 3\,	\)(\)1]; ]*];c                    | j                   |   }|j                  j                         sy | j                  |   }| j                  |   }	 |t
        j                  j                  k(  rt        j                  }nt        j                  }|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 >)Nr  r  Fr  r  )r   r  r  r  r9  r   ro   rn   r*   rq   r  r  r  r  r  r  rN  r  r  r  )r   r  r   rw  r  r  r  rl   s           rY   r  zQuicConnection._write_handshake]  sM    u%{{##%,,U3U#		))),44,66  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   rL   r   zACK-of-ACK triggerr  )r   r   r  start_framer(   ACKACK_FRAME_CAPACITYr  r  r5   r  r  r)  r   r  r  r  r  )r   r  r  rw  r  r  r  r  s           rY   r  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 )Nrr  r  r  r   )r   ro   rn   rq   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	            rY   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   rF  r  r   r   r  r~   CONNECTION_LIMIT_FRAME_CAPACITYr  r  r)  r   r  r  )r   r  r  r  r  s        rY   r  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)NrP   Fr  r@   T)r   r  next_offset	get_frameremaining_flight_spacer  r(   ri  on_data_deliveryr  r  r  r  push_uint16r  r)  r   r  r  )r   r  r  r  frame_overheadr  r  s          rY   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   r  r  T)r(   r  r  r   r  r  r  r)  r   r  r  )r   r  r  r~   r  
frame_sizer  s          rY   r  z$QuicConnection._write_datagram_frame  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     rY   r  z*QuicConnection._write_handshake_done_frame#  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  re   r  r   r   r  r  r   ConnectionIdIssuedr)  r   r  )r   r  r  r  r  s        rY   r  z-QuicConnection._write_new_connection_id_frame0  s"    !!++577')	 " 
 	-778/*s=,,-.}(()}::;!%F55MDUDUVW (&&--!!@@"/"3"3$3$1$A$A*7*M*M	 A  )r]   c                     |j                  t        j                  t              }|j	                  |       | j
                  6|j                  j                  | j
                  j                  |             y y Nr  r  )	r  r(   PATH_CHALLENGEPATH_CHALLENGE_FRAME_CAPACITYr  r)  r   r  r  r   r  r{  r  s       rY   r  z*QuicConnection._write_path_challenge_frameO  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       rY   r  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)rr  )r  r(   PINGPING_FRAME_CAPACITYr'  tuplerF  r  r  r)  r   r  r  )r   r  r#  r  s       rY   r  z QuicConnection._write_ping_framek  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  rt   r   r  r)  r   r  r  r   r  r  r  r  s        rY   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       rY   r  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  rt   r   r)  r   r  r  r  s        rY   r  z(QuicConnection._write_stop_sending_frame  s    
 !!$110OO<< " 

 ..0%//*%**+ (&&--!!;;$//5?? <  )r]   r  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)	NrP   r   r   r   r   r  r@   rw   )r   rt   r  r  r  r  r  r(   STREAM_BASEr  r  r  r  r  r  r  r  r  r)  r   r  r  )
r   r  r  r  r  r  previous_send_highestr  r~   r  s
             rY   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  )rZ  r(  r  rF  r  rt   r  r  r(   MAX_STREAM_DATAMAX_STREAM_DATA_FRAME_CAPACITYr   r  r)  r   r  r  )r   r  r  r  r  s        rY   r  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 )Nr  r  )	r  STREAMS_BLOCKED_CAPACITYr  r)  r   r  r  r(   r	  )r   r  r~   r  r  s        rY   r  z+QuicConnection._write_streams_blocked_frame  sy     !!*7O!P%  (&&--!!>>&0M4U4U&U ?  )r]   )rR   Nr   )r   r   r   __doc__r   r   r   r   SessionTicketFetcherSessionTicketHandlerQuicTokenHandlerr   propertyr   r   rq  r'   r  r   r   rv  r   r   r}  r   r   r  r  r  r  r   	QuicEventr  r  r  r  r  r  r   rz   r$  r*  r;  r?  rB  rp  r  r  r|  ro   r  r   r  r=   r`  r  SessionTicketrj  r  r   r   rV  rg  rY  r`  ri  rh  r\  r]  r^  r_  rc  rZ  rT  re  rf  rU  rW  rd  rX  r[  ra  rb  r~  r}  r7   r;   r  r}   r  r  r   r   r"  r   r'  r)  r  r)   r  r  r  ro  rP  rH  r1  r6  r   r  r&  rA  r  rr  CipherSuiter  r  r8   r  r  r  r  r  r  r(   r  r  r  r  r  r  r  r  r  r  r  r  rv   r]   rY   r   r      s   $ ?C6:EIEI48L
 )L
 -5UO	L

 %-UOL
 !))A)A BL
 !))A)A BL
   01L
 
L
\ #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Q9U Q9. Q9u Q9QU Q9f
6
(c 
(s 
(t 
('S 'T '- -$ - ?D99$)97;9	9)S )c )d ),6T3 6T4 6Tp	S 	S 	T 		# 	# 	$ 	
: :E :d :%!E !d !61CII 1$ 1	~ 	/ 	0 0 0
 0d. .
 .`5S5F5F 54 5d8E d8d d8L
)
7:
AG
	
B&D)&D7:&DAG&D	&DPV2)V27:V2AGV2	V2p)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$<)<7:<AG<	< )))7:)AG)	)2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0 06;0BG0	0d] ]',]	]~$
J.> 
J4 
J
# 8=}9}904}9	}9~- -^ 3  HS HT H
H# H$ H
2$ 24 2$(==( yy( oo	(
 ( 
(T,e ,? ,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   )rh   loggingr
  collectionsr   dataclassesr   enumr   	functoolsr   typingr   r   r	   r
   r   r   r   r   r   r   rr  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   packet_builderr7   r8   r9   recoveryr:   r;   r  r<   r=   r>   	getLoggerr  ro   rn   rq   rp   rr   rV   rh  MAX_REMOTE_CHALLENGESr}  rt  STREAM_FLAGSr  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r\   r   rz   rd   r   rk   rs   rx   r{   r}   	Exceptionr   LoggerAdapterr   r   r   r   r   r  r[   r   r   r   rt  r   rv   r]   rY   <module>r     s     	  !        H * L L #     . X W 9 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!> !cii !# $    
) 
;G11 ;
   $ 
X 
X    UGTM* ##$$&&
{4 {4r]   