mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-05-17 00:25:51 +03:00
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import os
|
|
import socket as _socket
|
|
|
|
from typing import Dict, List
|
|
from dataclasses import dataclass, field
|
|
|
|
|
|
@dataclass
|
|
class ProxyConfig:
|
|
port: int = 1443
|
|
host: str = '127.0.0.1'
|
|
secret: str = field(default_factory=lambda: os.urandom(16).hex())
|
|
dc_redirects: Dict[int, str] = field(default_factory=lambda: {2: '149.154.167.220', 4: '149.154.167.220'})
|
|
buffer_size: int = 256 * 1024
|
|
pool_size: int = 4
|
|
fallback_cfproxy: bool = True
|
|
fallback_cfproxy_priority: bool = True
|
|
fallback_cfproxy_domain: str = 'pclead.co.uk'
|
|
|
|
|
|
proxy_config = ProxyConfig()
|
|
|
|
|
|
def parse_dc_ip_list(dc_ip_list: List[str]) -> Dict[int, str]:
|
|
dc_redirects: Dict[int, str] = {}
|
|
for entry in dc_ip_list:
|
|
if ':' not in entry:
|
|
raise ValueError(
|
|
f"Invalid --dc-ip format {entry!r}, expected DC:IP")
|
|
dc_s, ip_s = entry.split(':', 1)
|
|
try:
|
|
dc_n = int(dc_s)
|
|
_socket.inet_aton(ip_s)
|
|
except (ValueError, OSError):
|
|
raise ValueError(f"Invalid --dc-ip {entry!r}")
|
|
dc_redirects[dc_n] = ip_s
|
|
return dc_redirects |