aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol2/socks.py
blob: 7835b1a4bdda7c7b168c57d1a2b95bf91a4f178c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from __future__ import (absolute_import, print_function, division, unicode_literals)

from ..proxy import ProxyError, Socks5ProxyMode, ProxyError2
from .layer import Layer, ServerConnectionMixin
from .auto import AutoLayer


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)

        layer = AutoLayer(self)
        for message in layer():
            if not self._handle_server_message(message):
                yield message