
    vKg                       % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJrJrJrJrJrJrJr  S SK	JrJr  S SKrS SKrSSKJrJr  \(       a&  S SKJr  S S	KJ q   S S
K!J"r"J#r#J$r$J%r%  S SK&J'r'  \$" S5      r(Sr)SIS jr*SIS jr+SIS jr, " S S\RZ                  5      r. " S S\RZ                  5      r/ " S S5      r0Sr1 " S S\25      r3SJS jr4SJS jr5\Rl                  " S5      r7SKS jr8\Rr                   " S S5      5       r:SLS  jr;SMS! jr<\Rl                  " S"5      r=\Rr                   " S# S$5      5       r>SNS% jr?SOS& jr@SPS' jrA\Rr                   " S( S)5      5       rB\Rr                   " S* S+5      5       rC\Rr                   " S, S-5      5       rD\\B\C\D4   rES.\FS/'       SQS0 jrG " S1 S25      rHS3rIS4rJS5rKS6rLS4rMSRS7 jrNSSS8 jrO            STS9 jrP          SUS: jrQ          SVS; jrR\" S<5      rS " S= S>\\S   5      rTSWS? jrU        SXSA jrV      SYSB jrW\Rr                   " SC SD5      5       rX\ " SE SF\R                  R                  \[   \SG95       r\\ " SH S@5      5       r]g)Z    )annotationsN)count)	TYPE_CHECKINGAny	AwaitableCallableGenericIterableIteratorTypeVarUnion)ReferenceTypeWeakValueDictionary   )NoPublicConstructorfinal)TracebackTypeSSL)Self	TypeAliasTypeVarTupleUnpack)
SocketTypePosArgsTi  c                V    U R                   [        R                  R                  :X  a  gg)N   0   )familytriosocketAF_INETsocks    J/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/trio/_dtls.pypacket_header_overheadr&   5   s    {{dkk)))    c                    U R                   [        R                  R                  :X  a  S[	        U 5      -
  $ S[	        U 5      -
  $ )Ni@  i   )r   r    r!   r"   r&   r#   s    r%   worst_case_mtur)   <   s:    {{dkk)))+D111,T222r'   c                    S[        U 5      -
  $ )Ni  )r&   r#   s    r%   best_guess_mtur+   C   s    (...r'   c                  (    \ rS rSrSrSrSrSrSrSr	g)	ContentTypeJ                   N)
__name__
__module____qualname____firstlineno__change_cipher_specalert	handshakeapplication_data	heartbeat__static_attributes__r4   r'   r%   r-   r-   J   s    EIIr'   r-   c                  h    \ rS rSrSrSrSrSrSrSr	Sr
SrS	rS
rSrSrSrSrSrSrSrSrSrSrSrSrg)HandshakeTypeR   r   r                                 r/   r0   r1   r2   r3            r4   N)r5   r6   r7   r8   hello_requestclient_helloserver_hellohello_verify_requestnew_session_ticketend_of_early_dataencrypted_extensionscertificateserver_key_exchangecertificate_requestserver_hello_donecertificate_verifyclient_key_exchangefinishedcertificate_urlcertificate_statussupplemental_data
key_updatecompressed_certificateekt_keymessage_hashr>   r4   r'   r%   r@   r@   R   sw    MLLKHOJGLr'   r@   c                  <    \ rS rSr\" SS/5      r\" SS/5      rSrg)ProtocolVersionj   rN         r4   N)r5   r6   r7   r8   bytesDTLS10DTLS12r>   r4   r'   r%   re   re   j   s    C:FC:Fr'   re   l          c                      \ rS rSrSrg)	BadPacketw   r4   N)r5   r6   r7   r8   r>   r4   r'   r%   rm   rm   w   s    r'   rm   c                    U SS S:H  $ )NrC      s     r4   packets    r%   part_of_handshake_untrustedrs      s     !A;+%%r'   c                     U S   [         R                  :H  =(       a    U S   [        R                  :H  $ ! [         a     gf = f)Nr   rH   F)r-   r;   r@   rP   
IndexErrorrq   s    r%   is_client_hello_untrustedrv      sI    1I... 9r
m888	
  s   25 
AAz!B2sQHc                "    U R                  5       $ N)hex)datas    r%   to_hexr{      s    88:r'   c                  ~    \ rS rSr% S\S'   \R                  " \S9rS\S'   S\S'   \R                  " \S9r	S\S'   S	r
g
)Record   intcontent_typereprri   versionepoch_seqnopayloadr4   N)r5   r6   r7   r8   __annotations__attrsfieldr{   r   r   r>   r4   r'   r%   r}   r}      s4    [[f-GU-[[f-GU-r'   r}   c              #  ^  #    SnU[        U 5      :  ap   [        R                  X5      u  p#pEU[        R                  -  nXX-    n[        U5      U:w  a  [        S5      eX-  n[        X#XG5      v   U[        U 5      :  a  Mo  g g ! [        R                   a  n[        S5      UeS nAff = f7f)Nr   zinvalid record headerzshort record)lenRECORD_HEADERunpack_fromstructerrorrm   sizer}   )rr   ictr   r   payload_lenexcr   s           r%   records_untrustedr      s     	A
c&k/	>4A4M4Mf4X1B 	
]Q_-w<;&N++	R+77 c&k/ || 	>34#=	>s.   B-B AB-B-B*B%%B**B-c                    [         R                  U R                  U R                  U R                  [        U R                  5      5      nXR                  -   $ rx   )r   packr   r   r   r   r   )recordheaders     r%   encode_recordr      sF    FNN	F NN""r'   z	!B3sH3s3sc                  r    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S'   \R                  " \S9rS	\S
'   Sr	g)HandshakeFragment   r   msg_typemsg_lenmsg_seqfrag_offsetfrag_lenr   ri   fragr4   N)
r5   r6   r7   r8   r   r   r   r{   r   r>   r4   r'   r%   r   r      s/    MLLM++6*D%*r'   r   c                    [         R                  U 5      u  nnnnn[
        R                  US5      n[
        R                  US5      n[
        R                  US5      n	U [         R                  S  n
[        U
5      U	:w  a  [	        S5      e[        UUUUU	U
5      $ ! [        R                   a  n[	        S5      UeS nAff = f)Nzbad handshake message headerbigz5handshake fragment length doesn't match record length)
HANDSHAKE_MESSAGE_HEADERr   r   r   rm   r   
from_bytesr   r   r   )r   r   msg_len_bytesr   frag_offset_bytesfrag_len_bytesr   r   r   r   r   s              r%   #decode_handshake_fragment_untrustedr      s    	A %009	
 nn]E2G..!2E:K~~ne4H+0023D
4yHOPP  << A67S@As   B C0B<<Cc           
        [         R                  U R                  U R                  R	                  SS5      U R
                  U R                  R	                  SS5      U R                  R	                  SS5      5      nXR                  -   $ )NrC   r   )	r   r   r   r   to_bytesr   r   r   r   )hsf	hs_headers     r%   encode_handshake_fragmentr      sk    (--Q&  E*a'I xxr'   c                    [        [        U 5      5      nUR                  [        R                  :w  a  [        S5      e[        UR                  5      nUR                  [        R                  :w  a  [        S5      eUR                  S:w  a  [        S5      eUR                  UR                  :w  a  [        S5      eUR                  nUS   nSU-   nX5   nUS-   nXv-   nUS U n	X7U n
X8S  n[        U
5      U:w  a  [        S5      eUR                   XU-   4$ ! ["        R$                  [&        4 a  n[        S	5      UeS nAff = f)
Nznot a handshake recordznot a ClientHellor   zfragmented ClientHello"   #   r   zshort cookiezbad ClientHello)nextr   r   r-   r;   rm   r   r   r   r@   rP   r   r   r   r   r   r   r   r   ru   )rr   r   fragmentbodysession_id_lencookie_len_offset
cookie_lencookie_start
cookie_endbefore_cookiecookieafter_cookier   s                r%   decode_client_hello_untrustedr     sT   >4'/0 +"7"774556v~~F : ::/00 1$455 0 00455  }} f&7,
(1,!.
//0:.K(v;*$N++""FL,HIILL*% 4)*34s   DD E2D>>Ec                  ~    \ rS rSr% \R
                  " \S9rS\S'   S\S'   S\S'   \R
                  " \S9r	S	\S
'   Sr
g)HandshakeMessageiH  r   ri   record_versionr@   r   r   r   	bytearrayr   r4   N)r5   r6   r7   r8   r   r   r{   r   r   r   r>   r4   r'   r%   r   r   H  s3    !KKV4NE4Lkkv.D).r'   r   c                  t    \ rS rSr% \R
                  " \S9rS\S'   S\S'   \R
                  " \S9r	S\S'   Sr
g	)
PseudoHandshakeMessageiR  r   ri   r   r   r   r   r4   N)r5   r6   r7   r8   r   r   r{   r   r   r   r>   r4   r'   r%   r   r   R  s.    !KKV4NE4[[f-GU-r'   r   c                       \ rS rSr% S\S'   Srg)OpaqueHandshakeMessagei^  r}   r   r4   N)r5   r6   r7   r8   r   r>   r4   r'   r%   r   r   ^  s    Nr'   r   r   _AnyHandshakeMessagec           	        / n0 n[        U 5       GH  nUR                  [        -  (       a  UR                  [	        U5      5        M8  UR
                  [        R                  [        R                  4;   a<  UR                  [        UR                  UR
                  UR                  5      5        M  UR
                  [        R                  :X  d   e[        UR                  5      n[        UR                  5      nUR                   U;  aU  [#        UR                  UUR                   [%        UR&                  5      5      nUR                  U5        XbUR                   '   OX$R                      nUR                  UR                  :X  d   eUR                   UR                   :X  d   e[)        UR*                  5      UR&                  :X  d   eUR,                  UR*                  UR.                  UR.                  UR0                  -   & GM     U$ rx   )r   r   
EPOCH_MASKappendr   r   r-   r9   r:   r   r   r   r;   r   r@   r   r   r   r   r   r   r   r   r   r   )volleymessagesmessages_by_seqr   r   r   msgs          r%   decode_volley_trustedr   n  s    ,.HO#F+ 
*OO26:;  [%C%C[EVEV$WWOO&NN''NN &&+*?*????:6>>JH$X%6%67H6&NN$$h../	 $47 0 01%&6&67<<8#4#4444;;("2"2222sxx=H$4$4444  HH$$x';';h>O>O'OI ,P Or'   c                  >    \ rS rSrSS jrSS jr      S	S jrSrg)
RecordEncoderi  c                "    [        5       U l        g rx   r   _record_seqselfs    r%   __init__RecordEncoder.__init__  s     7r'   c                $    [        U5      U l        g rx   r   )r   ns     r%   set_first_record_number%RecordEncoder.set_first_record_number  s     8r'   c                   / n[        5       nU GH  n[        U[        5      (       ae  [        UR                  5      nU[        U5      -
  [        U5      -
  S::  a  UR                  U5        [        5       nXF-  n[        U5      U::  d   eM~  [        U[        5      (       a  U[        U5      -
  [        R                  -
  [        UR                  5      -
  nUS::  a  UR                  U5        [        5       nU[        R                  UR                  UR                  [        U R                  5      [        UR                  5      5      -  nXER                  -  n[        U5      U::  d   eGM`  [        UR                   5      R#                  SS5      nSn	Sn
U	[        UR                   5      :  d
  U
(       a  GM  U[        U5      -
  [        R                  -
  [$        R                  -
  nUS::  a  UR                  U5        [        5       nMv  UR                   XU-    nU	R#                  SS5      n[        U5      R#                  SS5      nU	[        U5      -  n	U[        R                  [&        R(                  UR                  [        U R                  5      [$        R                  [        U5      -   5      -  nU[$        R                  UR*                  UUR,                  UU5      -  nXK-  nU
S-  n
[        U5      U::  d   eU	[        UR                   5      :  a  GMe  U
(       d  GMo  GM     U(       a  UR                  U5        U$ )Nr   rC   r   r   )r   
isinstancer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r;   r   r   )r   r   mtupacketsrr   messageencodedspacer   r   frags_encodedr   r   r   s                 r%   encode_volleyRecordEncoder.encode_volley  s   
 G'#9::'7V$s7|3q8NN6*&[F!6{c)))G%;<<c&k)M,>,>>W__AUUA:NN6*&[F-,,((**))*(	  //)6{c))) #GLL 1 : :1e D ! "C$55]]f+&',,- 3778  zv.!* "<<E6IJD(3(<(<Q(F%%(Y%7%75%AN3t9,Km00#--..T--.055D	A	 F 6;;((%)& F NF!Q&Mv;#---E "C$55]]7  ~ NN6"r'   )r   NreturnNone)r   r   r   r   )r   zIterable[_AnyHandshakeMessage]r   r   r   zlist[bytearray])r5   r6   r7   r8   r   r   r   r>   r4   r'   r%   r   r     s1    #$I0I I 
	Ir'   r          sha256rE   c                 L    [        [        R                  " 5       [        -  5      $ rx   )r   r    current_timeCOOKIE_REFRESH_INTERVALr4   r'   r%   _current_cookie_tickr   -  s    t  "%<<==r'   c            	         / nU  HC  nUR                  [        R                  " S[        U5      5      5        UR                  U5        ME     SR	                  U5      $ )N!Qr'   )r   r   r   r   join)fieldsoutr   s      r%   	_signabler   3  sH    
C

6;;tSZ01

5  88C=r'   c                    [        U5      [        :X  d   e[        U 5      [        :X  d   e[        U[        R
                  " SU5      [        S U 5       6 U5      nU[        R                  " X[        5      -   S [         $ )Nr   c              3  R   #    U H  n[        U5      R                  5       v   M      g 7frx   )strencode).0parts     r%   	<genexpr>_make_cookie.<locals>.<genexpr>J  s      ;74CI$$&&7s   %')
r   
SALT_BYTES	KEY_BYTESr   r   r   hmacdigestCOOKIE_HASHCOOKIE_LENGTH)keysalttickaddressclient_hello_bitssignable_datas         r%   _make_cookier  ;  su     t9
"""s8y   D$ 	;7;<M 4;;s;??-PPr'   c                    [        U5      [        :  aj  US [         n[        5       n[        XXRU5      n[        U U[	        US-
  S5      UU5      n[
        R                  " X5      [
        R                  " UU5      -  $ g)Nr   r   F)r   r   r   r  maxr  compare_digest)r  r   r  r	  r  r  
cur_cookie
old_cookies           r%   valid_cookier  Q  s     6{Zkz"#%!#T<MN
!q!

 ""669L9L:
 
 	

 r'   c           	        [         R                  " [        5      n[        5       n[	        XXQU5      n[
        R                  [        [        U5      /5      -   U-   n[        [        R                  [        U5      SS[        U5      US9n[        U5      n	[        [        [        R                   [
        R                  X)5      5      n
U
$ )Nr   )r   r   r   r   r   r   )osurandomr   r   r  re   rj   ri   r   r   r@   rR   r   r   r}   r-   r;   )r  r  r   r	  r  r  r   r   hsr   rr   s              r%   challenge_forr  o  s     ::j!D!D#T4EFF !!E3v;-$886AD 
33D	T
B (+G{$$o&<&<kSF Mr'   _Tc                      \ rS rSrSS jrSrg)_Queuei  c                X    [         R                  [           " U5      u  U l        U l        g rx   )r    open_memory_channelr  sr)r   incoming_packets_buffers     r%   r   _Queue.__init__  s     11"56MNr'   )r  r  N)r  zint | float)r5   r6   r7   r8   r   r>   r4   r'   r%   r  r    s    Or'   r  c                    / n  U " S5      nUR                  U5        M  ! [         R                   a     Of = fSR                  U5      $ )Ni @  r'   )r   WantReadErrorr   r   )read_fnchunkschunks      r%   
_read_loopr%    sV    F
	ENE 	e     		 88Fs     77DTLSEndpointc                  #    U R                   c  g  [        U5      u  p4nU R                  c  [        R
                  " [        5      U l        [        U R                  XAU5      (       db  [        U R                  UUU5      n U R                   IS h  vN   U R                  R                  Xa5      I S h  vN   S S S 5      IS h  vN   g [        R!                  XU R                   5      nUR"                  R%                  U5         UR&                  R)                  U5        UR&                  R+                  5         UR&                  R)                  U5        U R0                  R3                  U5      nUb"  UR4                  XE4:X  a  g UR7                  5         XE4Ul        XpR0                  U'   U R8                  R:                  R=                  U5        g ! [         a     g f = f GNQ GN1 GN$! , IS h  vN  (       d  f       g = f! [        [        R                  4 a     g f = f! [,        R.                   a     g f = f7frx   )_listening_contextr   rm   _listening_keyr  r  r   r  r  
_send_lockr!   sendtoOSErrorr    ClosedResourceErrorDTLSChannel_create_record_encoderr   _ssl	bio_writeDTLSv1_listenr   Error_streamsget_client_hello_set_replaced_incoming_connections_qr  send_nowait)	endpointr  rr   r   r   bitschallenge_packetstream
old_streams	            r%   handle_client_hello_untrustedr@    s     ""*$A&$I!T &"$**Y"7//$GG(##	
	***oo,,-=GGG +** $$X8S8ST 	66{C	KK!!&)KK%%'* 	f% &&**73
!''F>9 ((* &~%+'"((**66v>G   +G +***112 		$ yy 	 	s   H?G A H?H G"H G+4G%5G+9H G(H 	<H?5H% ;BH?
GH?GH?"H %G+(H +H1G42H>H H?H H"H?!H""H?%H<9H?;H<<H?c                V  #       UR                  [        5      I S h  vN u  p#U " 5       n Uc   Ag [        U5      (       a  [        XSU5      I S h  vN   OX5R                  ;   ap  UR                  U   nUR                  (       a)  [        U5      (       a  UR                  5       I S h  vN   O( UR                  R                  R                  U5        O AM   N! [         a+  nUR                  [        R                  :X  a   S nAGM  e S nAff = f N Nl! [        R                   a    U=R                   S-  sl         Nlf = f! Af = f! [        R"                   a     g [         a9  nUR                  [        R$                  [        R&                  4;   a   S nAg e S nAff = f7f)Nr   )recvfromMAX_UDP_PACKET_SIZEr,  errno
ECONNRESETrv   r@  r5  _did_handshakers   _resend_final_volley_qr  r:  r    
WouldBlock_packets_dropped_in_trior-  EBADFENOTSOCK)endpoint_refr$   rr   r  r   r;  r>  s          r%   dtls_receive_looprN    ss    4(,6I(J"J $~H#0 / -V4476RRR 1 11%..w7F,,1LV1T1T %99;;;A"IIKK33F;
 S "J 
99 0 00 
  S <
  $ A";;q@;A ##  99enn55 s   F)E C CC E E E F)E DAE *D+E 1%D E E C 
D'DE DDE E E )EE EE EE F&"F)$	F&-.F!F) F!!F&&F)c                  $    \ rS rSr% SrS\S'   Srg)DTLSChannelStatisticsi?  a  Currently this has only one attribute:

- ``incoming_packets_dropped_in_trio`` (``int``): Gives a count of the number of
  incoming packets from this peer that Trio successfully received from the
  network, but then got dropped because the internal channel buffer was full. If
  this is non-zero, then you might want to call ``receive`` more often, or use a
  larger ``incoming_packets_buffer``, or just not worry about it because your
  UDP-based protocol should be able to handle the occasional lost packet, right?

r    incoming_packets_dropped_in_trior4   N)r5   r6   r7   r8   __doc__r   r>   r4   r'   r%   rP  rP  ?  s    	 '*)r'   rP  c                      \ rS rSrSr        SS jrSS jrSS jrSS jrSS jr	        SS jr
SS	 jrSS
 jrSS jrSS.SS jjrSS jrSS jrSS jrSS jrS S jrSrg)!r.  iO  uD  A DTLS connection.

This class has no public constructor – you get instances by calling
`DTLSEndpoint.serve` or `~DTLSEndpoint.connect`.

.. attribute:: endpoint

   The `DTLSEndpoint` that this connection is using.

.. attribute:: peer_address

   The IP/port of the remote peer that this connection is associated with.

c                   Xl         X l        SU l        S U l        SU l        UR                  [        R                  [        R                  -  5        [        R                  " U5      U l
        SU l        U R                  [        U R                   R                  5      5        SU l        SU l        ["        [$           " UR&                  5      U l        [*        R,                  " 5       U l        [1        5       U l        / U l        g )Nr   F)r;  peer_addressrJ  r7  rF  set_optionsr   OP_NO_QUERY_MTUOP_NO_RENEGOTIATION
Connectionr1  _handshake_mtuset_ciphertext_mtur+   r!   	_replaced_closedr  ri   r  rH  r    Lock_handshake_lockr   r0  _final_volley)r   r;  rU  ctxs       r%   r   DTLSChannel.__init__`  s     !(()%!# 	#"9"99	
 NN3'	 	t}}/C/C DE- @ @A#yy{.;o9;r'   c                Z    SU l         U R                  R                  R                  5         g NT)r\  rH  r  closer   s    r%   r8  DTLSChannel._set_replaced  s     			r'   c                R    U R                   (       a  [        R                  " S5      eg )Nz1peer tore down this connection to start a new one)r\  r    BrokenResourceErrorr   s    r%   _check_replacedDTLSChannel._check_replaced  s$    >>**C  r'   c                $   U R                   (       a  gSU l         U R                  R                  R                  U R                  5      U L a!  U R                  R                  U R                  	 U R
                  R                  R                  5         g)u  Close this connection.

`DTLSChannel`\s don't actually own any OS-level resources – the
socket is owned by the `DTLSEndpoint`, not the individual connections. So
you don't really *have* to call this. But it will interrupt any other tasks
calling `receive` with a `ClosedResourceError`, and cause future attempts to use
this connection to fail.

You can also use this object as a synchronous or asynchronous context manager.

NT)r]  r;  r5  r6  rU  rH  r  re  r   s    r%   re  DTLSChannel.close  sd     <<==!!%%d&7&78D@&&t'8'89 			r'   c                    U $ rx   r4   r   s    r%   	__enter__DTLSChannel.__enter__      r'   c                "    U R                  5       $ rx   re  r   exc_type	exc_value	tracebacks       r%   __exit__DTLSChannel.__exit__       zz|r'   c                |   #    U R                  5         [        R                  R                  5       I Sh  vN   g N7f)zClose this connection, but asynchronously.

This is included to satisfy the `trio.abc.Channel` contract. It's
identical to `close`, but async.

N)re  r    lowlevel
checkpointr   s    r%   acloseDTLSChannel.aclose  s&      	

mm&&(((s   2<:<c                x  #    U R                   R                  UU R                  5      nU Hi  nU R                  R                   IS h  vN   U R                  R
                  R                  X0R                  5      I S h  vN   S S S 5      IS h  vN   Mk     g  NP N N! , IS h  vN  (       d  f       M  = f7frx   )r0  r   rZ  r;  r*  r!   r+  rU  )r   volley_messagesr   rr   s       r%   _send_volleyDTLSChannel._send_volley  s     &&44
 F}}///mm**11&:K:KLLL 0// /L 0///sZ   AB:B	B:3B?B BB:B
B:BB:B7	%B(&B7	2B:c                V   #    U R                  U R                  5      I S h  vN   g  N7frx   )r  r`  r   s    r%   rG   DTLSChannel._resend_final_volley  s      2 2333s   )')g      ?)initial_retransmit_timeoutc               |  ^ ^#    T R                    ISh  vN   T R                  (       a   SSS5      ISh  vN   gUn/ mSnS	U U4S jjn[        R                  " [        R
                  5         T R                  R                  5         SSS5        U" 5       mT(       d  [        R                  " S5      e T(       d   eT R                  5         T R                  T5      I Sh  vN   T R                  R                  5         [        R                  " U5       nT R                  R                     Sh  vN nT R                  R#                  U5         T R                  R                  5         ST l        U" 5       T l        T R                  T R$                  5      I Sh  vN     SSS5        SSS5      ISh  vN   g GN GN! , (       d  f       GNB= f N N N: N#! [        R
                  [        R                  4 a     Of = fU" 5       nU(       d  M  ['        US   [(        5      (       a>  US   R*                  [,        R.                  :X  a  T R                  U5      I Sh  vN    GM?  UmUS:X  a  UnSn  O$
 T R0                  (       d   eT R                  5         SSS5        O! , (       d  f       O= fWR2                  (       aR  [5        SU-  S5      nUS-  nUS:X  a8  [5        T R6                  [9        T R                  R:                  5      5      T l        GMj  ! , ISh  vN  (       d  f       g= f7f)
u   Perform the handshake.

Calling this is optional – if you don't, then it will be automatically called
the first time you call `send` or `receive`. But calling it explicitly can be
useful in case you want to control the retransmit timeout, use a cancel scope to
place an overall timeout on the handshake, or catch errors from the handshake
specifically.

It's safe to call this multiple times, or call it simultaneously from multiple
tasks – the first call will perform the handshake, and the rest will be no-ops.

Args:

  initial_retransmit_timeout (float): Since UDP is an unreliable protocol, it's
    possible that some of the packets we send during the handshake will get
    lost. To handle this, DTLS uses a timer to automatically retransmit
    handshake packets that don't receive a response. This lets you set the
    timeout we use to detect packet loss. Ideally, it should be set to ~1.5
    times the round-trip time to your peer, but 1 second is a reasonable
    default. There's `some useful guidance here
    <https://tlswg.org/dtls13-spec/draft-ietf-tls-dtls13.html#name-timer-values>`__.

    This is the *initial* timeout, because if packets keep being lost then Trio
    will automatically back off to longer values, to avoid overloading the
    network.

Nr   c                   > [        TR                  R                  5      n [        U 5      nU(       aY  T(       aR  [	        US   [
        5      (       a:  [	        TS   [
        5      (       a"  US   R                  TS   R                  :X  a  / $ U$ )Nr   )r%  r1  bio_readr   r   r   r   )volley_bytesnew_volley_messagesr   r  s     r%   read_volley-DTLSChannel.do_handshake.<locals>.read_volley  sz    )$))*<*<=&;L&I#''"#6q#9;KLL"?1#57GHH+A.66/!:L:T:TT I..r'   z'something wrong with peer's ClientHelloTrB   g      N@r   )r   list[_AnyHandshakeMessage])r_  rF  
contextlibsuppressr   r!  r1  do_handshaker4  ri  r  r;  _ensure_receive_loopr    move_on_afterrH  r  r2  r`  r   r   r   r-   r:   r\  cancelled_caughtminrZ  r)   r!   )	r   r  timeoutvolley_failed_sendsr  cscoperr   maybe_volleyr  s	   `       @r%   r  DTLSChannel.do_handshake  s    8 '''"" ('' 1G:<O"#/ /& $$S%6%67		&&( 8)mO #ii IJJ&&$$&''888224''0F(,		 */f		++F3# II224 37D/ 2=D."&"3"3D4F4F"GGG"# 1W (''6 87 9*/ Hw (d !$ 1 1399= ! ! (3}'< *<?<R S S$0O$@$@KDUDU$U '+&7&7&E E E
 3? $7!#;.HG67 3 %O )2R  $~~-~,,.W 100X ** "!g+t4G'1,'*a/ /2 //*4==+?+?@/+{ I (''s	  L<G L<L"L<GL<3L"0GAL"%G&4L"J+1I>5G
6I>9J+G 01J+!G
"J+'L"/L<:G;L<L<
G		L"I>J+L< $H	J+H	J+AJ+'I*
(:J+"	L"+
J9	5A-L""L9(L+)L95L<c                f  #    U R                   (       a  [        R                  eU(       d  [        S5      eU R                  (       d  U R                  5       I Sh  vN   U R                  5         U R                  R                  U5        U R                  R                   ISh  vN   U R                  R                  R                  [        U R                  R                  5      U R                  5      I Sh  vN   SSS5      ISh  vN   g N Nl N N! , ISh  vN  (       d  f       g= f7f)z Send a packet of data, securely.z2openssl doesn't support sending empty DTLS packetsN)r]  r    r-  
ValueErrorrF  r  ri  r1  writer;  r*  r!   r+  r%  r  rU  )r   rz   s     r%   sendDTLSChannel.sendK  s      <<***QRR""##%%%		==+++--&&--499--.!!   ,++ & , ,+++sn   AD1DA	D1$D%D1(AD9D:D>D1	D
D1D1DD1D.D D.*D1c                  #    U R                   (       d  U R                  5       I Sh  vN     U R                  R                  R	                  5       I Sh  vN nU R                  R                  W5        [        U R                  R                  5      nU(       a  U$ Mr   Nw NK! [
        R                   a&    U R                  (       d   eU R                  5          Nf = f7f)aZ  Fetch the next packet of data from this connection's peer, waiting if
necessary.

This is safe to call from multiple tasks simultaneously, in case you have some
reason to do that. And more importantly, it's cancellation-safe, meaning that
cancelling a call to `receive` will never cause a packet to be lost or corrupt
the underlying connection.

N)rF  r  rH  r  receiver    EndOfChannelr\  ri  r1  r2  r%  read)r   rr   	cleartexts      r%   r  DTLSChannel.receive\  s      ""##%%% '#wwyy0022 II'"499>>2I   	 & 3$$ '~~%~$$&'sE   %C BC 'B# B!B# AC !B# #7CC CC c                F    Xl         U R                  R                  U5        g)u  Tells Trio the `largest amount of data that can be sent in a single packet to
this peer <https://en.wikipedia.org/wiki/Maximum_transmission_unit>`__.

Trio doesn't actually enforce this limit – if you pass a huge packet to `send`,
then we'll dutifully encrypt it and attempt to send it. But calling this method
does have two useful effects:

- If called before the handshake is performed, then Trio will automatically
  fragment handshake messages to fit within the given MTU. It also might
  fragment them even smaller, if it detects signs of packet loss, so setting
  this should never be necessary to make a successful connection. But, the
  packet loss detection only happens after multiple timeouts have expired, so if
  you have reason to believe that a smaller MTU is required, then you can set
  this to skip those timeouts and establish the connection more quickly.

- It changes the value returned from `get_cleartext_mtu`. So if you have some
  kind of estimate of the network-level MTU, then you can use this to figure out
  how much overhead DTLS will need for hashes/padding/etc., and how much space
  you have left for your application data.

The MTU here is measuring the largest UDP *payload* you think can be sent, the
amount of encrypted data that can be handed to the operating system in a single
call to `send`. It should *not* include IP/UDP headers. Note that OS estimates
of the MTU often are link-layer MTUs, so you have to subtract off 28 bytes on
IPv4 and 48 bytes on IPv6 to get the ciphertext MTU.

By default, Trio assumes an MTU of 1472 bytes on IPv4, and 1452 bytes on IPv6,
which correspond to the common Ethernet MTU of 1500 bytes after accounting for
IP/UDP overhead.

N)rZ  r1  r[  )r   new_mtus     r%   r[  DTLSChannel.set_ciphertext_mtuv  s    @ &		$$W-r'   c                x    U R                   (       d  [        R                  eU R                  R	                  5       $ )zReturns the largest number of bytes that you can pass in a single call to
`send` while still fitting within the network-level MTU.

See `set_ciphertext_mtu` for more details.

)rF  r    NeedHandshakeErrorr1  get_cleartext_mtur   s    r%   r  DTLSChannel.get_cleartext_mtu  s,     "")))yy**,,r'   c                ,    [        U R                  5      $ )zOReturns a `DTLSChannelStatistics` object with statistics about this connection.)rP  rJ  r   s    r%   
statisticsDTLSChannel.statistics  s    $T%B%BCCr'   )r7  r]  rF  r`  r_  rZ  rJ  rH  r0  r\  r1  r;  rU  N)r;  r&  rU  r   ra  SSL.Contextr   r   r   r   r   rt  ztype[BaseException] | Noneru  zBaseException | Nonerv  zTracebackType | Noner   r   )r  r  r   r   )r  floatr   r   )rz   ri   r   r   )r   ri   )r  r   r   r   r   r   )r   rP  )r5   r6   r7   r8   rR  r   r8  ri  re  rn  rw  r}  r  rG  r  r  r  r[  r  r  r>   r4   r'   r%   r.  r.  O  s    << < 	<
 
<@*, ( (	
 
)M4 IL @D"!4!.F	-Dr'   r.  )	metaclassc                      \ rS rSrSrSS.     SS jjrSS jrSS jrSS jrSS	 jr	        SS
 jr
SS jr\R                  S.         SS jjr      SS jrSrg)r&  i  a  A DTLS endpoint.

A single UDP socket can handle arbitrarily many DTLS connections simultaneously,
acting as a client or server as needed. A `DTLSEndpoint` object holds a UDP socket
and manages these connections, which are represented as `DTLSChannel` objects.

Args:
  socket: (trio.socket.SocketType): A ``SOCK_DGRAM`` socket. If you want to accept
    incoming connections in server mode, then you should probably bind the socket to
    some known port.
  incoming_packets_buffer (int): Each `DTLSChannel` using this socket has its own
    buffer that holds incoming packets until you call `~DTLSChannel.receive` to read
    them. This lets you adjust the size of this buffer. `~DTLSChannel.statistics`
    lets you check if the buffer has overflowed.

.. attribute:: socket
               incoming_packets_buffer

   Both constructor arguments are also exposed as attributes, in case you need to
   access them later.


   )r  c                  SSK Jq  SU l        UR                  [        R
                  R                  :w  a  [        S5      eSU l        Xl        X l        [        R                  R                  5       U l        [        5       U l        S U l        S U l        [         ["           " [%        S5      5      U l        [        R(                  " 5       U l        SU l        SU l        g )Nr   r   Fz!DTLS requires a SOCK_DGRAM socketTinf)OpenSSLr   _initializedtyper    r!   
SOCK_DGRAMr  r  r{  current_trio_token_tokenr   r5  r(  r)  r  r.  r  r9  r^  r*  r]  _receive_loop_spawned)r   r!   r  s      r%   r   DTLSEndpoint.__init__  s     	  #(;;$++000@AA "('>$mm668 @S?T6:,0'-k':5<'H$))+%*"r'   c                    U R                   (       dK  [        R                  R                  [        [
        R                  " U 5      U R                  5        SU l         g g rd  )r  r    r{  spawn_system_taskrN  weakrefrefr!   r   s    r%   r  !DTLSEndpoint._ensure_receive_loop  sD     ))MM++!D!
 *.D& *r'   c                <   U R                   (       d  g U R                  (       dh  [        R                  " [        5         U R
                  R                  U R                  5        S S S 5        [        R                  " SU < 3[        U SS9  g g ! , (       d  f       N/= f)Nzunclosed DTLS endpoint r   )source
stacklevel)r  r]  r  r  RuntimeErrorr  run_sync_soonre  warningswarnResourceWarningr   s    r%   __del__DTLSEndpoint.__del__  sm       ||$$\2))$**5 3 MM)$2		 22s   &B
Bc                   SU l         U R                  R                  5         [        U R                  R                  5       5       H  nUR                  5         M     U R                  R                  R                  5         g)zmClose this socket, and all associated DTLS connections.

This object can also be used as a context manager.

TN)r]  r!   re  listr5  valuesr9  r  )r   r>  s     r%   re  DTLSEndpoint.close   sX     4==//12FLLN 3$$&&,,.r'   c                    U $ rx   r4   r   s    r%   rn  DTLSEndpoint.__enter__  rp  r'   c                "    U R                  5       $ rx   rr  rs  s       r%   rw  DTLSEndpoint.__exit__  ry  r'   c                F    U R                   (       a  [        R                  eg rx   )r]  r    r-  r   s    r%   _check_closedDTLSEndpoint._check_closed  s    <<*** r'   )task_statusc                 ^^#    U R                  5         U R                  b  [        R                  " S5      e U R                  R                  5         U R                  5         UR                  S 5         Xl        UR                  5         SUU4S jjn[        R                  " 5        ISh  vN nU R                  R                    Sh  vN nUR                  XW5        M  ! [         a    [        S5      Sef = f NP N3
 SSS5      ISh  vN    O! , ISh  vN  (       d  f       O= fSU l        g! SU l        f = f7f)a5  Listen for incoming connections, and spawn a handler for each using an
internal nursery.

Similar to `~trio.serve_tcp`, this function never returns until cancelled, or
the `DTLSEndpoint` is closed and all handlers have exited.

Usage commonly looks like::

    async def handler(dtls_channel):
        ...

    async with trio.open_nursery() as nursery:
        await nursery.start(dtls_endpoint.serve, ssl_context, handler)
        # ... do other things here ...

The ``dtls_channel`` passed into the handler function has already performed the
"cookie exchange" part of the DTLS handshake, so the peer address is
trustworthy. But the actual cryptographic handshake doesn't happen until you
start using it, giving you a chance for any last minute configuration, and the
option to catch and handle handshake errors.

Args:
  ssl_context (OpenSSL.SSL.Context): The PyOpenSSL context object to use for
    incoming connections.
  async_fn: The handler function that will be invoked for each incoming
    connection.
  *args: Additional arguments to pass to the handler function.

Nz!another task is already listeningz-DTLS socket must be bound before it can servec                     grd  r4   )_s    r%   <lambda>$DTLSEndpoint.serve.<locals>.<lambda>L  s    $r'   c                l   >#    U    T" U /TQ76 I S h  vN   S S S 5        g  N! , (       d  f       g = f7frx   r4   )r>  argsasync_fns    r%   handler_wrapper+DTLSEndpoint.serve.<locals>.handler_wrapperQ  s-     "61D111 V1 Vs    4#!#	4#
14)r>  r.  r   r   )r  r(  r    BusyResourceErrorr!   getsocknamer,  r  r  set_cookie_verify_callbackstartedopen_nurseryr9  r  
start_soon)r   ssl_contextr  r  r  r  nurseryr>  s     ` `   r%   serveDTLSEndpoint.serve  s    H 	"".(()LMM	KK##% 	!!# 	..?	+&1#!2 2 ((**g$($@$@$B$B @&&&?'  	?	" +@$B +***** '+D#dD#s   4EC% "E68D8 .C?/D8 2D	DDDD%C<<E?D8 DDD8 DD8 D-DD-)D8 0E8	EEc                    U R                  5         [        R                  XU5      nUR                  R	                  5         U R
                  R                  U5      nUb  UR                  5         X0R
                  U'   U$ )u7  Initiate an outgoing DTLS connection.

Notice that this is a synchronous method. That's because it doesn't actually
initiate any I/O – it just sets up a `DTLSChannel` object. The actual handshake
doesn't occur until you start using the `DTLSChannel`. This gives you a chance
to do further configuration first, like setting MTU etc.

Args:
  address: The address to connect to. Usually a (host, port) tuple, like
    ``("127.0.0.1", 12345)``.
  ssl_context (OpenSSL.SSL.Context): The PyOpenSSL context object to use for
    this connection.

Returns:
  DTLSChannel

)r  r.  r/  r1  set_connect_stater5  r6  r8  )r   r  r  channelold_channels        r%   connectDTLSEndpoint.connect[  si    2 	%%d[A&&(mm''0"%%'!(gr'   )r]  r9  r  r(  r)  r  r*  r5  r  r  r!   N)r!   r   r  r   r   r   r   r  r  )
r  r  r  z<Callable[[DTLSChannel, Unpack[PosArgsT]], Awaitable[object]]r  zUnpack[PosArgsT]r  ztrio.TaskStatus[None]r   r   )r  ztuple[str, int]r  r  r   r.  )r5   r6   r7   r8   rR  r   r  r  re  rn  rw  r  r    TASK_STATUS_IGNOREDr  r  r>   r4   r'   r%   r&  r&    s    6 (*	++ "%	+
 
+B
."
/, ( (	
 
+ .2-E-E>+ >+ O>+  	>+
 +>+ 
>+@    !  
	 r'   )r$   r   r   r   )rr   ri   r   bool)rz   ri   r   r   )rr   ri   r   zIterator[Record])r   r}   r   ri   )r   ri   r   r   )r   r   r   ri   )rr   ri   r   ztuple[int, bytes, bytes])r   ri   r   r  r  )r   ri   r   ri   )r  ri   r  ri   r  r   r  r   r	  ri   r   ri   )
r  ri   r   ri   r  r   r	  ri   r   r  )
r  ri   r  r   r   r   r	  ri   r   ri   )r"  zCallable[[int], bytes]r   ri   )r;  r&  r  r   rr   ri   r   r   )rM  zReferenceType[DTLSEndpoint]r$   r   r   r   )^
__future__r   r  enumrD  r  r  r   r  r  	itertoolsr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r    _utilr   r   typesr   r  r   typing_extensionsr   r   r   r   trio.socketr   r   rC  r&   r)   r+   IntEnumr-   r@   re   r   	Exceptionrm   rs   rv   Structr   r{   frozenr}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   r  r  r  r  r  r%  r@  rN  rP  abcChannelri   r.  r&  r4   r'   r%   <module>r     s   #     	    
 
 
 7   -# GG&J'H 3/$,, DLL 0 
 
		 	&( h' . . .8$#  "==5  + + +< B4J / / / . . .    #(# i ---`P P@  	
 >Q	Q
Q Q 	Q
 Q Q,	  	
 
<*	** * 	*
 *Z T]OWR[ O
R?R?R? R? 
	R?j8-8
8 
8v * * * VD$((""5)5H VD VDr
 Q Q Qr'   