U mfr@sddlZddlZddlZddlZddlZddlmZmZddlZ ddl Z ddl Z dZ dZedZGdddeZGdd d ZGd d d ZGd d d ZGdddeZGdddZGdddeZdS)N)AnyOptionalic@s eZdZdS) UnexpectedEOFN)__name__ __module__ __qualname__r r >/opt/hc_python/lib/python3.8/site-packages/dns/quic/_common.pyrsrc@s4eZdZddZddZddZddZd d Zd S) BuffercCsd|_d|_dS)NF)_buffer _seen_endselfr r r __init__szBuffer.__init__cCs&|jr dS|j|7_|r"d|_dS)NT)rrrdataZis_endr r r puts z Buffer.putcCs t|j|krdS|jrtdS)NTF)lenrrr)ramountr r r have&s z Buffer.havecCs|jSN)rrr r r seen_end-szBuffer.seen_endcCs0||st|jd|}|j|d|_|Sr)rAssertionErrorr)rrrr r r get0sz Buffer.getN)rrr rrrrrr r r r r s r c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)BaseQuicStreamcCs||_||_t|_d|_dSNr) _connection _stream_idr r _expecting)r connection stream_idr r r r8szBaseQuicStream.__init__cCs|jSr)r rr r r id>szBaseQuicStream.idcCs|dk rt|}nd}|Sr)time)rtimeout expirationr r r _expiration_from_timeoutAsz'BaseQuicStream._expiration_from_timeoutcCs$|dk rt|td}nd}|S)Ng)maxr%)rr'r&r r r _timeout_from_expirationHsz'BaseQuicStream._timeout_from_expirationcCst|}td||S)Nz!H)rstructpack)rZdatagramlr r r _encapsulateRszBaseQuicStream._encapsulatecCsD|j||z|jdko&|j|jWStk r>YdSXdS)NrT)rrr!rrrr r r _common_add_inputVs z BaseQuicStream._common_add_inputcCs |j|j|jdddS)Nr T)r close_streamr rrrr r r _close]szBaseQuicStream._closeN) rrr rr$r(r*r.r/r1r r r r r7s rc@s0eZdZd ddZddZd dd Zd d ZdS)BaseQuicConnectionNrcCsd|_||_||_||_d|_||_i|_tj ||_ tj ||f|_ |dkr|dkr|j t jkrld}n|j t jkr~d}nt|r||f|_nd|_dS)NFrz0.0.0.0z::)Z_donerZ_addressZ_port_closed_manager_streamsdnsinetZaf_for_addressZ_aflow_level_address_tupleZ_peersocketAF_INETAF_INET6NotImplementedError_source)rr"addressportsource source_portmanagerr r r rcs$   zBaseQuicConnection.__init__cCs |j|=dSr)r5)rr#r r r r0{szBaseQuicConnection.close_streamTcCsLt}|j}|dkr"|d}t||d}|jrD|rDt|d}||fS)Nirg?)r%rZ get_timerr)r3min)rZclosed_is_specialnowr'intervalr r r _get_timer_values~s   z$BaseQuicConnection._get_timer_valuescCs t}||kr|j|dSr)r%rZ handle_timer)rr'rDr r r _handle_timersz BaseQuicConnection._handle_timer)NrN)T)rrr rr0rFrGr r r r r2bs  r2c@s"eZdZdeeedddZdS)AsyncQuicConnectionN)r&returncsdSrr )rr&r r r make_streamszAsyncQuicConnection.make_stream)N)rrr rfloatrrJr r r r rHsrHc@s0eZdZd ddZdddZd d Zd d ZdS)BaseQuicManagerNcCsdi|_||_i|_|dkrZd}t|tr0|}d}tjjjddg||d}|dk rZ| |||_ dS)NTZdoqzdoq-i03)alpn_protocols verify_mode server_name) _connections_connection_factory_session_tickets isinstancestraioquicquic configurationZQuicConfigurationload_verify_locations_conf)rconfrNconnection_factoryrOZ verify_pathr r r rs   zBaseQuicManager.__init__UrTc Cs|j||f}|dk r |dfS|j}|rvz$|j||f}t|}||_Wntk rbYnXt |j ||} nd} t j j j|| d} tj||f} | | t|| |||||}||j||f<|dfS)NF)rWsession_ticket_handlerT)rPrrYrRpopcopysession_ticketKeyError functoolspartialsave_session_ticketrUrVr"ZQuicConnectionr6r7r8connectr%rQ) rr>r?r@rAZwant_session_ticketr"rZr`r]ZqconnZ lladdressr r r _connectsB  zBaseQuicManager._connectcCs*z|j||f=Wntk r$YnXdSr)rPra)rr>r?r r r closedszBaseQuicManager.closedcCsLt|j}|tkr:t|jdt}|D] }|j|=q,||j||f<dSr)rrRMAX_SESSION_TICKETSlistkeysSESSIONS_TO_DELETE)rr>r?ticketr-Zkeys_to_deletekeyr r r rds   z#BaseQuicManager.save_session_ticket)N)r\NrT)rrr rrfrgrdr r r r rLs  #rLc@seZdZdddZdS)AsyncQuicManagerr\NrcCstdSr)r<)rr>r?r@rAr r r reszAsyncQuicManager.connect)r\Nr)rrr rer r r r rnsrn)r_rbr9r+r%typingrrZaioquic.quic.configurationrUZaioquic.quic.connectionZdns.inetr6ZQUIC_MAX_DATAGRAMrhrk Exceptionrr rr2rHrLrnr r r r s$+/H