a àMÒeßã@s¨ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl mZmZmZmZmZGdd„deƒZGdd„deƒZGdd„deƒZdS) éN)ÚQUIC_MAX_DATAGRAMÚAsyncQuicConnectionÚAsyncQuicManagerÚBaseQuicStreamÚ UnexpectedEOFcs`eZdZ‡fdd„Zdd„Zdd„Zddd „Zdd d „Zd d„Zdd„Z dd„Z dd„Z ‡Z S)ÚAsyncioQuicStreamcstƒ ||¡t ¡|_dS©N)ÚsuperÚ__init__ÚasyncioÚ ConditionÚ_wake_up)ÚselfÚ connectionÚ stream_id©Ú __class__©ú5/usr/lib/python3.9/site-packages/dns/quic/_asyncio.pyr szAsyncioQuicStream.__init__c ÃsN|j4IdHš&|j ¡IdHWdƒIdHqJ1IdHs@0YdSr)r Úwait©rrrrÚ_wait_for_wake_upsz#AsyncioQuicStream._wait_for_wake_upcÃsb| |¡}|j |¡rdS||_zt | ¡|¡IdHWntyTtj j ‚Yn0d|_qdS)Nr) Z_timeout_from_expirationÚ_bufferZhaveZ _expectingr Úwait_forrÚ TimeoutErrorÚdnsÚ exceptionÚTimeout)rÚamountÚ expirationÚtimeoutrrrr"s   zAsyncioQuicStream.wait_forNcÃsP| |¡}| d|¡IdHt d|j d¡¡\}| ||¡IdH|j |¡S)Néz!H)Z_expiration_from_timeoutrÚstructÚunpackrÚget)rr rÚsizerrrÚreceive.s  zAsyncioQuicStream.receiveFcÃs&| |¡}|j |j||¡IdHdSr)Z _encapsulateÚ _connectionÚwriteZ _stream_id)rÚdatagramÚis_endÚdatarrrÚsend5s zAsyncioQuicStream.sendc ÃsT| ||¡rP|j4IdHš |j ¡WdƒIdHqP1IdHsF0YdSr)Z_common_add_inputr Únotify)rr+r*rrrÚ _add_input9s zAsyncioQuicStream._add_inputcÃs | ¡dSr)Z_closerrrrÚclose>szAsyncioQuicStream.closecÃs|SrrrrrrÚ __aenter__CszAsyncioQuicStream.__aenter__c ÃsV| ¡IdH|j4IdHš |j ¡WdƒIdHqR1IdHsH0YdS©NF)r/r r-)rÚexc_typeÚexc_valÚexc_tbrrrÚ __aexit__Fs4zAsyncioQuicStream.__aexit__)N)F) Ú__name__Ú __module__Ú __qualname__r rrr&r,r.r/r0r5Ú __classcell__rrrrrs   rcsbeZdZd‡fdd„ Zdd„Zdd„Zdd „Zd d „Zdd d„Zdd„Z ddd„Z dd„Z ‡Z S)ÚAsyncioQuicConnectionNcsJtƒ ||||||¡d|_t ¡|_t ¡|_t ¡|_d|_ d|_ dSr) r r Ú_socketr ÚEventÚ_handshake_completeÚ_socket_createdr Ú _wake_timerÚ_receiver_taskÚ _sender_task)rrÚaddressÚportÚsourceÚ source_portZmanagerrrrr Ns   zAsyncioQuicConnection.__init__cÃs zªz6tj |j¡}tj d¡}| |tjd|j |j d|j df¡IdH|_ |j   ¡|j 4IdHšº|js |j  td¡IdH\}}|d|j dksj|d|j dkr°qj|j ||t ¡¡|j4IdHš |j ¡WdƒIdHqj1IdHs0YqjWdƒIdHq:1IdHs00YWntyPYn0Wd|_|j4IdHš"|j ¡WdƒIdHq¢1IdHs˜0Y|j  ¡nZd|_|j4IdHš"|j ¡WdƒIdHqü1IdHsò0Y|j  ¡0dS)Nr réT)rZinetZaf_for_addressZ_addressZ asyncbackendZ get_backendZ make_socketÚsocketZ SOCK_DGRAMÚ_sourceÚ_peerr;r>ÚsetÚ_doneZrecvfromrr'Zreceive_datagramÚtimer?Ú notify_allÚ Exceptionr=)rÚafZbackendr)rBrrrÚ _receiverWs6 ÿ  ÿ$j8 ý8zAsyncioQuicConnection._receiverc ÃsN|j4IdHš&|j ¡IdHWdƒIdHqJ1IdHs@0YdSr)r?rrrrrÚ_wait_for_wake_timerusz*AsyncioQuicConnection._wait_for_wake_timercÃs²|j ¡IdH|js®|j t ¡¡}|D].\}}||jks@J‚|j ||jd¡IdHq*|  ¡\}}zt   |  ¡|¡IdHWnt y’Yn0| |¡| ¡IdHqdSr)r>rrKr'Zdatagrams_to_sendrLrIr;ZsendtoZ_get_timer_valuesr rrQrNZ _handle_timerÚ_handle_events)rZ datagramsr)rBrÚintervalrrrÚ_senderys    zAsyncioQuicConnection._sendercÃsðd}|j ¡}|durdSt|tjjjƒrT|j |j ¡}|rÆ|  |j |j ¡IdHnrt|tjjj ƒrp|j ¡nVt|tjjjƒr’d|_|j ¡n4t|tjjjƒrÆ|j |j ¡}|rÆ|  dd¡IdH|d7}|dkrd}t d¡IdHqdS)NrTórFé )r'Z next_eventÚ isinstanceÚaioquicZquicZeventsZStreamDataReceivedÚ_streamsr$rr.r+Z end_streamZHandshakeCompletedr=rJZConnectionTerminatedrKr@ÚcancelZ StreamResetr Úsleep)rÚcountZeventÚstreamrrrrRˆs*   z$AsyncioQuicConnection._handle_eventsFc ÃsX|j |||¡|j4IdHš |j ¡WdƒIdHqT1IdHsJ0YdSr)r'Zsend_stream_datar?rM)rr]r+r*rrrr(¢szAsyncioQuicConnection.writecCs.|jr dSt | ¡¡|_t | ¡¡|_dSr)Ú_closedr ZTaskrPr@rTrArrrrÚrun§szAsyncioQuicConnection.runcÃsfzt |j ¡|¡IdHWnty6tjj‚Yn0|jrBt ‚|j   d¡}t ||ƒ}||j |<|Sr1)r rr=rrrrrrKrr'Zget_next_available_stream_idrrY)rr rr]rrrÚ make_stream­s    z!AsyncioQuicConnection.make_streamc ÃsÞ|jsÚ|j |jd|jd¡d|_|j ¡|j ¡|j4IdHš |j  ¡WdƒIdHq~1IdHst0Yz|j IdHWnt j y¢Yn0z|j IdHWnt j yÈYn0|j ¡IdHdS)NrrFT)r^Z_managerÚclosedrIr'r/r>rJr?rMr@r ZCancelledErrorrAr;rrrrr/¹s   4zAsyncioQuicConnection.close)N)F)N) r6r7r8r rPrQrTrRr(r_r`r/r9rrrrr:Ms   r:cs@eZdZdejdf‡fdd„ Zd dd„Zd d „Zd d „Z‡Z S)ÚAsyncioQuicManagerNcstƒ ||t|¡dSr)r r r:)rZconfZ verify_modeZ server_namerrrr ÎszAsyncioQuicManager.__init__éUrTcCs&| |||||¡\}}|r"| ¡|Sr)Z_connectr_)rrBrCrDrEZwant_session_ticketrÚstartrrrÚconnectÑs  ÿzAsyncioQuicManager.connectcÃs|Srrrrrrr0ÛszAsyncioQuicManager.__aenter__cÃs*t|j ¡ƒ}|D]}| ¡IdHqdSr1)ÚlistZ _connectionsÚvaluesr/)rr2r3r4Z connectionsrrrrr5ÞszAsyncioQuicManager.__aexit__)rcNrT) r6r7r8ÚsslZ CERT_REQUIREDr rer0r5r9rrrrrbÍs ÿ rb)r rGrhr"rLZaioquic.quic.configurationrXZaioquic.quic.connectionZaioquic.quic.eventsZdns.asyncbackendrZ dns.exceptionZdns.inetZdns.quic._commonrrrrrrr:rbrrrrÚs 4