
    RPf                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z
d dlZ
d dlmZ d dlmZmZmZmZmZ  G d de      Z G d de      Z G d d	e      Zy)
    N)NullContext)QUIC_MAX_DATAGRAMAsyncQuicConnectionAsyncQuicManagerBaseQuicStreamUnexpectedEOFc                   L     e Zd Z fdZd Zd	dZd
dZd Zd Zd Z	d Z
 xZS )TrioQuicStreamc                 X    t         |   ||       t        j                         | _        y N)super__init__trio	Condition_wake_up)self
connection	stream_id	__class__s      H/var/www/fastapitest/venv/lib/python3.12/site-packages/dns/quic/_trio.pyr   zTrioQuicStream.__init__   s     Y/(    c                 &  K   	 | j                   j                  |      ry || _        | j                  4 d {    | j                  j	                          d {    d d d       d {    d| _        r7 >7 7 # 1 d {  7  sw Y    xY ww)Nr   )_bufferhave
_expectingr   wait)r   amounts     r   wait_forzTrioQuicStream.wait_for   s     ||  ($DO}} + +mm((***+ +DO +*+ + + +sV   5BA6BA<A8A<B)A:*B8A<:B<BBB
Bc                   K   |t        d       }nt        j                  |      }|5  | j                  d       d {    t	        j
                  d| j                  j                  d            \  }| j                  |       d {    | j                  j                  |      cd d d        S 7 r7 *# 1 sw Y   t        j                  j                  xY ww)N   z!H)r   r   move_on_afterr   structunpackr   getdns	exceptionTimeout)r   timeoutcontextsizes       r   receivezTrioQuicStream.receive'   s     ?!$'G((1G 	*--"""mmD$,,*:*:1*=>GT--%%%<<##D)		* 	*"%	*
 mm###s?   &CB4B0A	B4B2B4&
C0B42B44C9 Cc                    K   | j                  |      }| j                  j                  | j                  ||       d {    y 7 wr   )_encapsulate_connectionwrite
_stream_id)r   datagramis_enddatas       r   sendzTrioQuicStream.send3   s8       *$$T__dFCCCs   <AAAc                    K   | j                  ||      r@| j                  4 d {    | j                  j                          d d d       d {    y y 7 07 # 1 d {  7  sw Y   y xY wwr   )_common_add_inputr   notify)r   r3   r2   s      r   
_add_inputzTrioQuicStream._add_input7   sf     !!$/}} ' '$$&' ' ' 0' ' ' ' 'sD   #A/AA/AA/AA/A/A, A#!A,(A/c                 ,   K   | j                          y wr   )_closer   s    r   closezTrioQuicStream.close<   s     s   c                    K   | S wr    r;   s    r   
__aenter__zTrioQuicStream.__aenter__A           c                    K   | j                          d {    | j                  4 d {    | j                  j                          d d d       d {    y7 D7 17 	# 1 d {  7  sw Y   yxY wwNF)r<   r   r7   )r   exc_typeexc_valexc_tbs       r   	__aexit__zTrioQuicStream.__aexit__D   sg     jjl== 	# 	#MM  "	# 	# 		# 	# 	# 	# 	#sT   A6AA6AA6A!
A6AA6A6A6!A3'A*(A3/A6r   F)__name__
__module____qualname__r   r   r+   r4   r8   r<   r?   rG   __classcell__r   s   @r   r
   r
      s,    ) 
$D'

r   r
   c                   H     e Zd Zd fd	Zd Zd Zd	dZd ZddZd Z	 xZ
S )
TrioQuicConnectionc                 *   t         |   ||||||       t        j                  j                  | j                  t        j
                  d      | _        t        j                         | _        t        j                         | _	        d | _
        d| _        y )Nr   F)r   r   r   socket_af
SOCK_DGRAM_socketEvent_handshake_complete	_run_done_worker_scope_send_pending)r   r   addressportsourcesource_portmanagerr   s          r   r   zTrioQuicConnection.__init__L   si    WdFKQ{{))$((F4E4EqI#'::< !"r   c                   K   	 | j                   rU| j                  j                  t        j                  j                  | j                   | j                               d {    | j                  j                  | j                         d {    | j                  sZ| j                  d      \  }}| j                  rd}t        j                  t        j                         |z         5 | _        | j                  j!                  t"               d {   }| j$                  j'                  || j                  t)        j(                                d d d        d | _        | j+                  |       | j-                          d {    d| _        | j$                  j/                  t)        j(                               }|D ](  \  }}| j                  j1                  |       d {    * | j                  sZd| _	        | j2                  j5                          y 7 7 7 # 1 sw Y   xY w7 7 M# d| _	        | j2                  j5                          w xY ww)NFg        )deadlineT)_sourcerT   bindr%   inetlow_level_address_tuplerR   connect_peer_done_get_timer_valuesrY   r   CancelScopecurrent_timerX   recvr   r.   receive_datagramtime_handle_timer_handle_eventsdatagrams_to_sendr4   rV   set)r   
expirationintervalr1   	datagrams_s         r   _workerzTrioQuicConnection._workerT   s    !	+||ll''HH44T\\488L   ,,&&tzz222jj)-)?)?)F&X%%  #H%%!..08; Y'%)\\%6%67H%IIH$$55h

DIIKX	Y
 &*""":.))+++ &+" ,,>>tyy{K	#, 6KHa,,++H5556/ jj4 DJ$$((*? 3  JY Y , 6DJ$$((*s   IAH4  H!,H4 HAH4 ,(H$H!=H$3H4 H0AH4 $H2%H4 9"IH4 H4 !H$$H-)H4 2H4 4#IIc                   K   d}	 | j                   j                         }|y t        |t        j                  j
                  j                        rX| j                  j                  |j                        }|r8|j                  |j                  |j                         d {    nt        |t        j                  j
                  j                        r| j                  j                          nt        |t        j                  j
                  j                         r"d| _        | j$                  j'                          not        |t        j                  j
                  j(                        rA| j                  j                  |j                        }|r|j                  dd       d {    |dz  }|dkD  rd}t+        j,                  d       d {    7 :7 27 w)Nr   Tr      
   )r.   
next_event
isinstanceaioquicquiceventsStreamDataReceived_streamsr$   r   r8   r3   
end_streamHandshakeCompletedrV   rq   ConnectionTerminatedrg   rT   r<   StreamResetr   sleep)r   counteventstreams       r   ro   z!TrioQuicConnection._handle_eventsx   sd    $$//1E}%!4!4!G!GH**5??; ++EJJ8H8HIIIE7<<#6#6#I#IJ((,,.E7<<#6#6#K#KL!
""$E7<<#6#6#B#BC**5??; ++C666QJErzjjm##+  J 7
 $s7   B G#"G#D	G#,G-(G#G!G#G#!G#c                    K   | j                   j                  |||       d| _        | j                  | j                  j	                          y y w)NT)r.   send_stream_datarY   rX   cancel)r   r   r3   r2   s       r   r/   zTrioQuicConnection.write   sI     ))&$?!)%%' *s   AAc                   K   | j                   ry t        j                         4 d {   }|j                  | j                         d d d       d {    | j
                  j                          y 7 J7 !# 1 d {  7  sw Y   1xY wwr   )_closedr   open_nursery
start_soonrv   rW   rq   )r   nurserys     r   runzTrioQuicConnection.run   so     <<$$& 	- 	-'t||,	- 	-	- 	- 	- 	- 	-sD   &BA3BA7BA5 B5B7B	=B >B	Bc                   K   |t        d       }nt        j                  |      }|5  | j                  j	                          d {    | j
                  rt        | j                  j                  d      }t        | |      }|| j                  |<   |cd d d        S 7 W# 1 sw Y   t        j                  j                  xY wwrC   )r   r   r!   rV   r   rg   r   r.   get_next_available_stream_idr
   r   r%   r&   r'   )r   r(   r)   r   r   s        r   make_streamzTrioQuicConnection.make_stream   s     ?!$'G((1G 	**//111zz##((EEeLI#D)4F'-DMM)$	 	1	 mm###s/   &CB BAB 
CB  C% Cc                 v  K   | j                   s| j                  j                  | j                  d   | j                  d          d| _         | j                  j                          d| _        | j                  | j                  j                          | j                  j                          d {    y y 7 w)Nr   rx   T)r   _managerclosedrf   r.   r<   rY   rX   r   rW   r   r;   s    r   r<   zTrioQuicConnection.close   s     ||MM  A

1>DL""$!%D!!-""))+..%%'''  (s   B.B90B71B9r   rH   )rI   rJ   rK   r   rv   ro   r/   r   r   r<   rL   rM   s   @r   rO   rO   K   s'    #"+H$2($(r   rO   c                   P     e Zd Zdej                  df fd	Z	 ddZd Zd Z xZ	S )TrioQuicManagerNc                 @    t         |   ||t        |       || _        y r   )r   r   rO   _nursery)r   r   confverify_modeserver_namer   s        r   r   zTrioQuicManager.__init__   s      	{,>Lr   c                     | j                  |||||      \  }}|r%| j                  j                  |j                         |S r   )_connectr   r   r   )r   rZ   r[   r\   r]   want_session_ticketr   starts           r   re   zTrioQuicManager.connect   sD     #mmT6;0C
U MM$$Z^^4r   c                    K   | S wr   r>   r;   s    r   r?   zTrioQuicManager.__aenter__   r@   rA   c                    K   t        | j                  j                               }|D ]  }|j                          d {     y7 wrC   )list_connectionsvaluesr<   )r   rD   rE   rF   connectionsr   s         r   rG   zTrioQuicManager.__aexit__   sJ      4,,3356% 	%J""$$$	% %s   <AAA)iU  Nr   T)
rI   rJ   rK   sslCERT_REQUIREDr   re   r?   rG   rL   rM   s   @r   r   r      s+     c.?.?T  RVr   r   )rQ   r   r"   rm   aioquic.quic.configurationr|   aioquic.quic.connectionaioquic.quic.eventsr   dns.exceptionr%   dns.inetdns._asyncbackendr   dns.quic._commonr   r   r   r   r   r
   rO   r   r>   r   r   <module>r      s\     
   !      ) /^ /dj(, j(Z& r   