U
    f                     @   s   d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlZ	dZ
G dd deZG dd dZG dd	 d	ZG d
d dZG dd deZG dd dZG dd deZdS )    N)Anyi   c                   @   s   e Zd ZdS )UnexpectedEOFN)__name__
__module____qualname__ r   r   ^/home/www/findmeahotel.co.uk/times_travel/venv/lib/python3.8/site-packages/dns/quic/_common.pyr      s   r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )Bufferc                 C   s   d| _ d| _d S )N    F)_buffer	_seen_endselfr   r   r   __init__   s    zBuffer.__init__c                 C   s&   | j r
d S |  j|7  _|r"d| _ d S )NT)r   r   r   dataZis_endr   r   r   put   s
    z
Buffer.putc                 C   s    t | j|krdS | jrtdS )NTF)lenr   r   r   )r   amountr   r   r   have!   s
    zBuffer.havec                 C   s   | j S N)r   r   r   r   r   seen_end(   s    zBuffer.seen_endc                 C   s0   |  |st| jd | }| j|d  | _|S r   )r   AssertionErrorr   )r   r   r   r   r   r   get+   s    z
Buffer.getN)r   r   r   r   r   r   r   r   r   r   r   r   r	      s
   r	   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )BaseQuicStreamc                 C   s   || _ || _t | _d| _d S Nr   )_connection
_stream_idr	   r   
_expecting)r   
connection	stream_idr   r   r   r   3   s    zBaseQuicStream.__init__c                 C   s   | j S r   )r   r   r   r   r   id9   s    zBaseQuicStream.idc                 C   s   |d k	rt   | }nd }|S r   )time)r   timeout
expirationr   r   r   _expiration_from_timeout<   s    z'BaseQuicStream._expiration_from_timeoutc                 C   s$   |d k	rt |t  d}nd }|S )Ng        )maxr"   )r   r$   r#   r   r   r   _timeout_from_expirationC   s    z'BaseQuicStream._timeout_from_expirationc                 C   s   t |}td|| S )Nz!H)r   structpack)r   Zdatagramlr   r   r   _encapsulateM   s    zBaseQuicStream._encapsulatec                 C   s&   | j || | jdko$| j | jS r   )r   r   r   r   r   r   r   r   _common_add_inputQ   s    z BaseQuicStream._common_add_inputc                 C   s    | j | j | jdd d S )Nr
   T)r   close_streamr   r   r   r   r   r   r   _closeU   s    zBaseQuicStream._closeN)
r   r   r   r   r!   r%   r'   r+   r,   r.   r   r   r   r   r   2   s   
r   c                   @   s0   e Zd ZdddZdd Zddd	Zd
d ZdS )BaseQuicConnectionNr   c                 C   s   d| _ || _|| _|| _d| _|| _i | _tj	|| _
tj||f| _|d kr|dkr| j
tjkrld}n| j
tjkr~d}nt|r||f| _nd | _d S )NFr   z0.0.0.0z::)_doner   _addressZ_port_closed_manager_streamsdnsZinetZaf_for_addressZ_afZlow_level_address_tupleZ_peersocketAF_INETAF_INET6NotImplementedError_source)r   r   addressportsourcesource_portmanagerr   r   r   r   [   s$    zBaseQuicConnection.__init__c                 C   s   | j |= d S r   )r4   )r   r    r   r   r   r-   s   s    zBaseQuicConnection.close_streamTc                 C   sL   t   }| j }|d kr"|d }t|| d}| jrD|rDt|d}||fS )Ni  r   g?)r"   r   Z	get_timerr&   r2   min)r   Zclosed_is_specialnowr$   intervalr   r   r   _get_timer_valuesv   s    


z$BaseQuicConnection._get_timer_valuesc                 C   s    t   }||kr| j| d S r   )r"   r   Zhandle_timer)r   r$   rA   r   r   r   _handle_timer   s    z BaseQuicConnection._handle_timer)Nr   N)T)r   r   r   r   r-   rC   rD   r   r   r   r   r/   Z   s        

r/   c                   @   s   e Zd ZedddZdS )AsyncQuicConnection)returnc                    s   d S r   r   r   r   r   r   make_stream   s    zAsyncQuicConnection.make_streamN)r   r   r   r   rG   r   r   r   r   rE      s   rE   c                   @   s&   e Zd Zdd Zd
ddZdd	 ZdS )BaseQuicManagerc                 C   s\   i | _ || _|d krRd }t|tr*|}d}tjjjddg|d}|d k	rR|| || _	d S )NTZdoqzdoq-i03)alpn_protocolsverify_mode)
_connections_connection_factory
isinstancestraioquicquicconfigurationZQuicConfigurationload_verify_locations_conf)r   confrJ   connection_factoryZverify_pathr   r   r   r      s    

zBaseQuicManager.__init__U  Nr   c                 C   sl   | j ||f}|d k	r |dfS tjjj| jd}||t  | 	|||||| }|| j ||f< |dfS )NF)rQ   T)
rK   r   rO   rP   r   ZQuicConnectionrS   connectr"   rL   )r   r;   r<   r=   r>   r   Zqconnr   r   r   _connect   s         zBaseQuicManager._connectc                 C   s*   z| j ||f= W n tk
r$   Y nX d S r   )rK   KeyError)r   r;   r<   r   r   r   closed   s    zBaseQuicManager.closed)rV   Nr   )r   r   r   r   rX   rZ   r   r   r   r   rH      s   
rH   c                   @   s   e Zd ZdddZdS )AsyncQuicManagerrV   Nr   c                 C   s   t d S r   )r9   )r   r;   r<   r=   r>   r   r   r   rW      s    zAsyncQuicManager.connect)rV   Nr   )r   r   r   rW   r   r   r   r   r[      s   r[   )r6   r(   r"   typingr   Zaioquic.quic.configurationrO   Zaioquic.quic.connectionZdns.inetr5   ZQUIC_MAX_DATAGRAM	Exceptionr   r	   r   r/   rE   rH   r[   r   r   r   r   <module>   s   (/$