o
    ¯bC	  ã                   @   sv   d Z ddlmZ ddlmZ G dd„ dejƒZG dd„ deƒZG dd	„ d	ejƒZ	G d
d„ deƒZ
G dd„ dejƒZdS )z
A simple port forwarder.
é    )Úprotocol)Úlogc                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ ZdS )	ÚProxyTNc                 C   ó
   || _ d S ©N)Úpeer)Úselfr   © r	   ú?/usr/lib/python3/dist-packages/twisted/protocols/portforward.pyÚsetPeer   ó   
zProxy.setPeerc                 C   s>   | j d ur| j j ¡  d | _ d S | jrt d|› �¡ d S d S )NzUnable to connect to peer: )r   Ú	transportÚloseConnectionÚnoisyr   Úmsg)r   Úreasonr	   r	   r
   ÚconnectionLost   s   

ÿzProxy.connectionLostc                 C   s   | j j |¡ d S r   )r   r   Úwrite)r   Údatar	   r	   r
   ÚdataReceived   s   zProxy.dataReceived)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r	   r	   r	   r
   r      s    r   c                   @   s   e Zd Zdd„ ZdS )ÚProxyClientc                 C   s@   | j  | ¡ | j | j jd¡ | j j | jd¡ | j j ¡  d S )NT)r   r   r   ÚregisterProducerÚresumeProducing)r   r	   r	   r
   ÚconnectionMade!   s   zProxyClient.connectionMadeN)r   r   r   r   r	   r	   r	   r
   r       s    r   c                   @   s(   e Zd ZeZdd„ Zdd„ Zdd„ ZdS )ÚProxyClientFactoryc                 C   r   r   )Úserver)r   r   r	   r	   r
   Ú	setServer3   r   zProxyClientFactory.setServerc                 O   s*   t jj| g|¢R i |¤Ž}| | j¡ |S r   )r   ÚClientFactoryÚbuildProtocolr   r   )r   ÚargsÚkwÚprotr	   r	   r
   r!   6   s   z ProxyClientFactory.buildProtocolc                 C   s   | j j ¡  d S r   )r   r   r   )r   Ú	connectorr   r	   r	   r
   ÚclientConnectionFailed;   s   z)ProxyClientFactory.clientConnectionFailedN)r   r   r   r   r   r   r!   r&   r	   r	   r	   r
   r   /   s
    r   c                   @   s   e Zd ZeZdZdd„ ZdS )ÚProxyServerNc                 C   sT   | j  ¡  |  ¡ }| | ¡ | jd u rddlm} || _| j | jj| jj	|¡ d S )Nr   )Úreactor)
r   ÚpauseProducingÚclientProtocolFactoryr   r(   Útwisted.internetÚ
connectTCPÚfactoryÚhostÚport)r   Úclientr(   r	   r	   r
   r   D   s   


zProxyServer.connectionMade)r   r   r   r   r*   r(   r   r	   r	   r	   r
   r'   ?   s    r'   c                   @   s   e Zd ZdZeZdd„ ZdS )ÚProxyFactoryz%
    Factory for port forwarder.
    c                 C   s   || _ || _d S r   )r.   r/   )r   r.   r/   r	   r	   r
   Ú__init__Z   s   
zProxyFactory.__init__N)r   r   r   Ú__doc__r'   r   r2   r	   r	   r	   r
   r1   S   s    r1   N)r3   r+   r   Útwisted.pythonr   ÚProtocolr   r   r    r   r'   ÚFactoryr1   r	   r	   r	   r
   Ú<module>   s   