mirror of
https://github.com/alexbers/mtprotoproxy.git
synced 2026-03-14 07:13:09 +00:00
Compare commits
3 Commits
1f7ce9e977
...
0614c35020
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0614c35020 | ||
|
|
368669a546 | ||
|
|
949ee12ed2 |
@@ -139,8 +139,8 @@ def init_config():
|
||||
# use middle proxy, necessary to show ad
|
||||
conf_dict.setdefault("USE_MIDDLE_PROXY", len(conf_dict["AD_TAG"]) == 16)
|
||||
|
||||
# if IPv6 available, use it by default
|
||||
conf_dict.setdefault("PREFER_IPV6", socket.has_ipv6)
|
||||
# if IPv6 available, use it by default, IPv6 with middle proxies is unstable now
|
||||
conf_dict.setdefault("PREFER_IPV6", socket.has_ipv6 and not conf_dict["USE_MIDDLE_PROXY"])
|
||||
|
||||
# disables tg->client traffic reencryption, faster but less secure
|
||||
conf_dict.setdefault("FAST_MODE", True)
|
||||
@@ -264,6 +264,9 @@ def init_config():
|
||||
# telegram servers connect timeout in seconds
|
||||
conf_dict.setdefault("TG_CONNECT_TIMEOUT", 10)
|
||||
|
||||
# drop connection if no data from telegram server for this many seconds
|
||||
conf_dict.setdefault("TG_READ_TIMEOUT", 60)
|
||||
|
||||
# listen address for IPv4
|
||||
conf_dict.setdefault("LISTEN_ADDR_IPV4", "0.0.0.0")
|
||||
|
||||
@@ -1584,7 +1587,11 @@ async def do_middleproxy_handshake(proto_tag, dc_idx, cl_ip, cl_port):
|
||||
async def tg_connect_reader_to_writer(rd, wr, user, rd_buf_size, is_upstream):
|
||||
try:
|
||||
while True:
|
||||
data = await rd.read(rd_buf_size)
|
||||
if not is_upstream:
|
||||
data = await asyncio.wait_for(rd.read(rd_buf_size),
|
||||
timeout=config.TG_READ_TIMEOUT)
|
||||
else:
|
||||
data = await rd.read(rd_buf_size)
|
||||
if isinstance(data, tuple):
|
||||
data, extra = data
|
||||
else:
|
||||
@@ -1605,7 +1612,7 @@ async def tg_connect_reader_to_writer(rd, wr, user, rd_buf_size, is_upstream):
|
||||
|
||||
wr.write(data, extra)
|
||||
await wr.drain()
|
||||
except (OSError, asyncio.IncompleteReadError) as e:
|
||||
except (OSError, asyncio.IncompleteReadError, asyncio.TimeoutError) as e:
|
||||
# print_err(e)
|
||||
pass
|
||||
|
||||
@@ -2011,6 +2018,7 @@ async def get_srv_time():
|
||||
continue
|
||||
line = line[len("Date: "):].decode()
|
||||
srv_time = datetime.datetime.strptime(line, "%a, %d %b %Y %H:%M:%S %Z")
|
||||
srv_time = srv_time.replace(tzinfo=datetime.timezone.utc)
|
||||
now_time = datetime.datetime.now(datetime.timezone.utc)
|
||||
is_time_skewed = (now_time-srv_time).total_seconds() > MAX_TIME_SKEW
|
||||
if is_time_skewed and config.USE_MIDDLE_PROXY and not disable_middle_proxy:
|
||||
|
||||
Reference in New Issue
Block a user