2015-07-24 16:29:13 +00:00
|
|
|
from __future__ import (absolute_import, print_function, division, unicode_literals)
|
|
|
|
|
|
|
|
from ..proxy import ProxyError, Socks5ProxyMode, ProxyError2
|
2015-07-25 11:31:55 +00:00
|
|
|
from .layer import Layer, ServerConnectionMixin
|
2015-07-25 12:48:50 +00:00
|
|
|
from .auto import AutoLayer
|
2015-07-24 16:29:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Socks5IncomingLayer(Layer, ServerConnectionMixin):
|
|
|
|
def __call__(self):
|
|
|
|
try:
|
|
|
|
s5mode = Socks5ProxyMode(self.config.ssl_ports)
|
|
|
|
address = s5mode.get_upstream_server(self.client_conn)[2:]
|
|
|
|
except ProxyError as e:
|
|
|
|
# TODO: Unmonkeypatch
|
|
|
|
raise ProxyError2(str(e), e)
|
|
|
|
|
|
|
|
self._set_address(address)
|
|
|
|
|
2015-07-25 12:48:50 +00:00
|
|
|
layer = AutoLayer(self)
|
2015-07-24 16:29:13 +00:00
|
|
|
for message in layer():
|
|
|
|
if not self._handle_server_message(message):
|
|
|
|
yield message
|