o
    �õ±j~  ã                   @   sŽ   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ G dd	„ d	eƒZG d
d„ dƒZdS )é    N)Úlogger)Úconnect)ÚQuicConnectionProtocol)ÚQuicConfiguration)ÚConnectionTerminatedÚ	QuicEventÚStreamDataReceived)ÚOptionalÚcastc                       sX   e Zd Z‡ fdd„Zdejddf‡ fdd„Zdeddfd	d
„Zde	ddfdd„Z
‡  ZS )ÚQuicTransportClientc                    s.   t ƒ j|i |¤Ž d | _d | _d | _d | _d S ©N)ÚsuperÚ__init__Ú_ack_waiterÚin_queueÚdisconnected_evtÚ	stream_id)ÚselfÚargsÚkwargs©Ú	__class__© ú‘/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asysocks/unicomm/protocol/quic.pyr      s
   
zQuicTransportClient.__init__Ú	transportÚreturnNc                    s   t dƒ tƒ  |¡S )Nz
Connected!)Úprintr   Úconnection_made)r   r   r   r   r   r      s   z#QuicTransportClient.connection_madeÚdatac                 Ã   s:   �| j d u r| j ¡ | _ d}| j | j ||¡ |  ¡  d S )NF)r   Ú_quicÚget_next_available_stream_idÚsend_stream_dataÚtransmit)r   r   Ú
end_streamr   r   r   Úsend   s   €
zQuicTransportClient.sendÚeventc                 C   s:   t |tƒr| j |jd f¡ t |tƒr| j d¡ d S d S )N©NN)Ú
isinstancer   r   Ú
put_nowaitr   r   )r   r%   r   r   r   Úquic_event_received$   s
   

ÿz'QuicTransportClient.quic_event_received)Ú__name__Ú
__module__Ú__qualname__r   ÚasyncioÚBaseTransportr   Úbytesr$   r   r)   Ú__classcell__r   r   r   r   r      s
    
r   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )Ú
QUICSocketz”
	Generic asynchronous TCP socket class, nothing SMB related.
	Creates the connection and channels incoming/outgoing bytes via asynchonous queues.
	Nc                 C   s.   || _ || _t ¡ | _t ¡ | _t ¡ | _d S r   )ÚsettingsÚsocketr-   ÚQueueÚ	out_queuer   ÚEventr   )r   r3   Útargetr   r   r   r   1   s
   

zQUICSocket.__init__c                 Ã   s   �| j  ¡ rdS | j  ¡  dS )zI
		Disconnects from the socket.
		Stops the reader and writer streams.
		N)ÚdisconnectedÚis_setÚset)r   r   r   r   Ú
disconnect:   s   €
zQUICSocket.disconnectc              
   Ã   sü   �zSt | jj| jj| jtd�4 I d H š4}tt|ƒ}| j|_| j|_| j	 
¡ s;| j ¡ I d H }| |¡I d H  | j	 
¡ r&W d   ƒI d H  W d S 1 I d H sMw   Y  W d S  tjy_   Y d S  ty} } zt d¡ |  ¡ I d H  W Y d }~d S d }~ww )N)ÚconfigurationÚcreate_protocolz[QUICSocket] handle_outgoing)r   r2   ÚhostnameÚportr<   r   r
   r   r   r8   r9   r5   Úgetr$   r-   ÚCancelledErrorÚ	Exceptionr   Ú	exceptionr;   )r   Úclientr   Úer   r   r   Ú	run_innerC   s$   €$

þ2ü
€þzQUICSocket.run_innerc              
   Ã   sf   �zt dgddtjd�| _t |  ¡ ¡| _W dS  ty2 } zt	 
d¡ d|fW  Y d}~S d}~ww )	zk
		Main function to be called, connects to the target specified in settings, and starts reading/writing.
		ÚsmbTi   )Úalpn_protocolsÚ	is_clientÚmax_datagram_frame_sizeÚverify_mode)TNz[QUICSocket] mainFN)r   ÚsslÚ	CERT_NONEr<   r-   Úcreate_taskrF   rD   rB   r   rC   )r   rE   r   r   r   r   W   s   €ü
€þzQUICSocket.connectr&   )r*   r+   r,   Ú__doc__r   r;   rF   r   r   r   r   r   r1   ,   s    
		r1   )Úenumr-   rL   Úasysocks.unicommr   Úaioquic.asyncio.clientr   Úaioquic.asyncio.protocolr   Úaioquic.quic.configurationr   Úaioquic.quic.eventsr   r   r   Útypingr	   r
   r   r1   r   r   r   r   Ú<module>   s    