File: _proxy_async.py

package info (click to toggle)
electrum 4.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 35,248 kB
  • sloc: python: 222,785; sh: 165; java: 73; javascript: 10; makefile: 9
file content (74 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ._proto_socks5_async import Socks5Proto
from ._proto_http_async import HttpProto
from ._proto_socks4_async import Socks4Proto
from ._stream_async import AsyncSocketStream


class AsyncProxy:
    async def connect(self, dest_host, dest_port,
                      timeout=None, _socket=None):
        raise NotImplementedError()  # pragma: no cover

    @property
    def proxy_host(self):
        raise NotImplementedError()  # pragma: no cover

    @property
    def proxy_port(self):
        raise NotImplementedError()  # pragma: no cover


class Socks5ProxyNegotiator:
    _stream: AsyncSocketStream
    _dest_host: str
    _dest_port: int
    _username: str
    _password: str
    _rdns: str

    async def negotiate(self):
        proto = Socks5Proto(
            stream=self._stream,
            dest_host=self._dest_host,
            dest_port=self._dest_port,
            username=self._username,
            password=self._password,
            rdns=self._rdns
        )
        await proto.negotiate()


class Socks4ProxyNegotiator:
    _stream: AsyncSocketStream
    _dest_host: str
    _dest_port: int
    _user_id: str
    _rdns: str

    async def negotiate(self):
        proto = Socks4Proto(
            stream=self._stream,
            dest_host=self._dest_host,
            dest_port=self._dest_port,
            user_id=self._user_id,
            rdns=self._rdns
        )
        await proto.negotiate()


class HttpProxyNegotiator:
    _stream: AsyncSocketStream
    _dest_host: str
    _dest_port: int
    _username: str
    _password: str

    async def negotiate(self):
        proto = HttpProto(
            stream=self._stream,
            dest_host=self._dest_host,
            dest_port=self._dest_port,
            username=self._username,
            password=self._password
        )
        await proto.negotiate()