MCPcopy Index your code
hub / github.com/masterking32/MasterHttpRelayVPN / __init__

Method __init__

src/proxy/proxy_server.py:76–257  ·  view source on GitHub ↗
(self, config: dict)

Source from the content-addressed store, hash-verified

74 )
75
76 def __init__(self, config: dict):
77 self.host = config.get("listen_host", "127.0.0.1")
78 # Prefer the new key (http_port) but keep listen_port for old configs.
79 self.port = config.get("http_port", config.get("listen_port", 8080))
80 self.socks_enabled = True
81 self.socks_host = config.get("socks5_host", self.host)
82 self.socks_port = config.get("socks5_port", 1080)
83 if self.socks_enabled and self.socks_host == self.host \
84 and int(self.socks_port) == int(self.port):
85 raise ValueError(
86 f"http_port and socks5_port must differ on the same host "
87 f"(both set to {self.port} on {self.host}). "
88 f"Change one of them in config.json."
89 )
90 self.fronter = DomainFronter(config)
91 self.mitm = None
92 self._cache = ResponseCache(max_mb=CACHE_MAX_MB)
93 self._direct_fail_until: dict[str, float] = {}
94 self._servers: list[asyncio.base_events.Server] = []
95 self._client_tasks: set[asyncio.Task] = set()
96 self._tcp_connect_timeout = self._cfg_float(
97 config, "tcp_connect_timeout", TCP_CONNECT_TIMEOUT, minimum=1.0,
98 )
99 self._download_min_size = self._cfg_int(
100 config, "chunked_download_min_size", 5 * 1024 * 1024, minimum=0,
101 )
102 self._download_chunk_size = self._cfg_int(
103 config, "chunked_download_chunk_size", 512 * 1024, minimum=64 * 1024,
104 )
105 self._download_max_parallel = self._cfg_int(
106 config, "chunked_download_max_parallel", 8, minimum=1,
107 )
108 self._download_max_chunks = self._cfg_int(
109 config, "chunked_download_max_chunks", 256, minimum=1,
110 )
111 self._warmup_before_listen = True
112 self._warmup_timeout = 20.0
113 self._download_extensions, self._download_any_extension = (
114 self._normalize_download_extensions(
115 config.get(
116 "chunked_download_extensions",
117 list(self._DOWNLOAD_DEFAULT_EXTS),
118 )
119 )
120 )
121
122 # hosts override — DNS fake-map: domain/suffix → IP
123 # Checked before any real DNS lookup; supports exact and suffix matching.
124 self._hosts: dict[str, str] = config.get("hosts", {})
125 configured_direct_exclude = config.get("direct_google_exclude", [])
126 self._direct_google_exclude = {
127 h.lower().rstrip(".")
128 for h in (
129 list(self._GOOGLE_DIRECT_EXACT_EXCLUDE) +
130 list(configured_direct_exclude)
131 )
132 }
133 configured_direct_allow = config.get("direct_google_allow", [])

Callers

nothing calls this directly

Calls 9

_cfg_floatMethod · 0.95
_cfg_intMethod · 0.95
DomainFronterClass · 0.90
load_allFunction · 0.90
ResponseCacheClass · 0.85
load_host_rulesFunction · 0.85
MITMCertManagerClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected