U mÃfßã@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__©ú?/opt/hc_python/lib/python3.8/site-packages/dns/quic/_asyncio.pyr szAsyncioQuicStream.__init__c Ãs4|j4IdHš|j ¡IdHW5QIdHRXdSr)r Úwait©rrrrÚ_wait_for_wake_upsz#AsyncioQuicStream._wait_for_wake_upcÃsd| |¡}|j |¡rdS||_zt | ¡|¡IdHWntk rVtj j ‚YnXd|_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 Ãs:| ||¡r6|j4IdHš|j ¡W5QIdHRXdSr)Z_common_add_inputr Únotify)rr+r*rrrÚ _add_input9s zAsyncioQuicStream._add_inputcÃs | ¡dSr)Ú_closerrrrÚclose>szAsyncioQuicStream.closecÃs|SrrrrrrÚ __aenter__CszAsyncioQuicStream.__aenter__c Ãs<| ¡IdH|j4IdHš|j ¡W5QIdHRXdS©NF)r0r r-)rÚexc_typeÚexc_valÚexc_tbrrrÚ __aexit__FszAsyncioQuicStream.__aexit__)N)F) Ú__name__Ú __module__Ú __qualname__r rrr&r,r.r0r1r6Ú __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_portÚmanagerrrrr Ns   zAsyncioQuicConnection.__init__cÃsZzzútj |j¡}tj   d¡}|  |t j d|j|jd|jdf¡IdH|_|j ¡|j4IdHšŠ|jsì|j td¡IdH\}}|d|jdksh|d|jdkr¬qh|j ||t ¡¡|j4IdHš|j ¡W5QIdHRXqhW5QIdHRXWntk rYnXW5d|_|j4IdHš|j ¡W5QIdHRX|j ¡XdS)NTr ré)Ú_doner@Ú notify_allr>ÚsetrZinetZaf_for_addressZ_addressZ asyncbackendÚ get_backendZ make_socketÚsocketÚ SOCK_DGRAMÚ_sourceÚ_peerr<r?Úrecvfromrr'Zreceive_datagramÚtimeÚ Exception)rÚafÚbackendr)rCrrrÚ _receiverWs8 ÿ  ÿ$0 zAsyncioQuicConnection._receiverc Ãs4|j4IdHš|j ¡IdHW5QIdHRXdSr)r@rrrrrÚ_wait_for_wake_timerusz*AsyncioQuicConnection._wait_for_wake_timercÃs´|j ¡IdH|js°|j t ¡¡}|D].\}}||jks@t‚|j  ||jd¡IdHq*|  ¡\}}zt   |  ¡|¡IdHWntk r”YnX| |¡| ¡IdHqdSr)r?rrIr'Zdatagrams_to_sendrRrPÚAssertionErrorr<ÚsendtoZ_get_timer_valuesr rrWrSZ _handle_timerÚ_handle_events)rZ datagramsr)rCrÚintervalrrrÚ_senderys   zAsyncioQuicConnection._sendercÃsðd}|j ¡}|dkrdSt|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órHé )r'Z next_eventÚ isinstanceÚaioquicZquicÚeventsZStreamDataReceivedÚ_streamsr$rr.r+Z end_streamZHandshakeCompletedr>rKZConnectionTerminatedrIrAÚcancelZ StreamResetr Úsleep)rÚcountÚeventÚstreamrrrrZˆs*   z$AsyncioQuicConnection._handle_eventsFc Ãs>|j |||¡|j4IdHš|j ¡W5QIdHRXdSr)r'Zsend_stream_datar@rJ)rrgr+r*rrrr(¢szAsyncioQuicConnection.writecCs.|jr dSt | ¡¡|_t | ¡¡|_dSr)Ú_closedr ÚTaskrVrAr\rBrrrrÚrun§szAsyncioQuicConnection.runcÃshzt |j ¡|¡IdHWntk r8tjj‚YnX|jrDt ‚|j   d¡}t ||ƒ}||j |<|Sr2)r rr>rrrrrrIrr'Zget_next_available_stream_idrrb)rr rrgrrrÚ make_stream­s   z!AsyncioQuicConnection.make_streamc ÃsÈ|jsÄ|j |jd|jd¡d|_|j ¡|j ¡|j4IdHš|j  ¡W5QIdHRXz|j IdHWnt j k rŠYnXz|j IdHWnt j k r²YnX|j ¡IdHdS)NrrHT)rhÚ_managerÚclosedrPr'r0r?rKr@rJrAr ZCancelledErrorrBr<rrrrr0¹s   zAsyncioQuicConnection.close)N)F)N) r7r8r9r rVrWr\rZr(rjrkr0r:rrrrr;Ms   r;cs@eZdZdejdf‡fdd„ Zd dd„Zd d „Zd d „Z‡Z S)ÚAsyncioQuicManagerNcstƒ ||t|¡dSr)r r r;)rZconfÚ verify_modeZ server_namerrrr ÎszAsyncioQuicManager.__init__éUrTcCs&| |||||¡\}}|r"| ¡|Sr)Ú_connectrj)rrCrDrErFZwant_session_ticketrÚstartrrrÚconnectÑsÿzAsyncioQuicManager.connectcÃs|Srrrrrrr1ÛszAsyncioQuicManager.__aenter__cÃs*t|j ¡ƒ}|D]}| ¡IdHqdSr2)ÚlistZ _connectionsÚvaluesr0)rr3r4r5Ú connectionsrrrrr6ÞszAsyncioQuicManager.__aexit__)rpNrT) r7r8r9ÚsslÚ CERT_REQUIREDr rsr1r6r:rrrrrnÍsÿ rn)r rMrwr"rRZaioquic.quic.configurationr`Zaioquic.quic.connectionZaioquic.quic.eventsZdns.asyncbackendrZ dns.exceptionZdns.inetZdns.quic._commonrrrrrrr;rnrrrrÚs 4