mirror of
https://github.com/alexbers/mtprotoproxy.git
synced 2026-03-22 02:25:49 +00:00
use ipv6 for external communications by default if available
This commit is contained in:
@@ -53,7 +53,7 @@ PORT = getattr(config, "PORT")
|
|||||||
USERS = getattr(config, "USERS")
|
USERS = getattr(config, "USERS")
|
||||||
|
|
||||||
# load advanced settings
|
# load advanced settings
|
||||||
PREFER_IPV6 = getattr(config, "PREFER_IPV6", False)
|
PREFER_IPV6 = getattr(config, "PREFER_IPV6", socket.has_ipv6)
|
||||||
# disables tg->client trafic reencryption, faster but less secure
|
# disables tg->client trafic reencryption, faster but less secure
|
||||||
FAST_MODE = getattr(config, "FAST_MODE", True)
|
FAST_MODE = getattr(config, "FAST_MODE", True)
|
||||||
STATS_PRINT_PERIOD = getattr(config, "STATS_PRINT_PERIOD", 600)
|
STATS_PRINT_PERIOD = getattr(config, "STATS_PRINT_PERIOD", 600)
|
||||||
@@ -427,10 +427,10 @@ async def do_direct_handshake(dc_idx, dec_key_and_iv=None):
|
|||||||
try:
|
try:
|
||||||
reader_tgt, writer_tgt = await asyncio.open_connection(dc, TG_DATACENTER_PORT)
|
reader_tgt, writer_tgt = await asyncio.open_connection(dc, TG_DATACENTER_PORT)
|
||||||
except ConnectionRefusedError as E:
|
except ConnectionRefusedError as E:
|
||||||
print_err("Got connection refused while trying to connect to", addr, port)
|
print_err("Got connection refused while trying to connect to", dc, TG_DATACENTER_PORT)
|
||||||
return False
|
return False
|
||||||
except OSError as E:
|
except OSError as E:
|
||||||
print_err("Unable to connect to", addr, port)
|
print_err("Unable to connect to", dc, TG_DATACENTER_PORT)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -522,7 +522,7 @@ async def do_middleproxy_handshake(dc_idx, cl_ip, cl_port):
|
|||||||
use_ipv6_tg = PREFER_IPV6
|
use_ipv6_tg = PREFER_IPV6
|
||||||
use_ipv6_clt = (":" in cl_ip)
|
use_ipv6_clt = (":" in cl_ip)
|
||||||
|
|
||||||
if use_ipv6_tg: # commented out because they aren't work yet
|
if use_ipv6_tg:
|
||||||
if not 0 <= dc_idx < len(TG_MIDDLE_PROXIES_V6):
|
if not 0 <= dc_idx < len(TG_MIDDLE_PROXIES_V6):
|
||||||
return False
|
return False
|
||||||
addr, port = TG_MIDDLE_PROXIES_V6[dc_idx]
|
addr, port = TG_MIDDLE_PROXIES_V6[dc_idx]
|
||||||
@@ -722,9 +722,10 @@ async def stats_printer():
|
|||||||
|
|
||||||
|
|
||||||
def init_ip_info():
|
def init_ip_info():
|
||||||
TIMEOUT = 5
|
|
||||||
global USE_MIDDLE_PROXY
|
global USE_MIDDLE_PROXY
|
||||||
|
global PREFER_IPV6
|
||||||
global my_ip_info
|
global my_ip_info
|
||||||
|
TIMEOUT = 5
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen('https://v4.ifconfig.co/ip', timeout=TIMEOUT) as f:
|
with urllib.request.urlopen('https://v4.ifconfig.co/ip', timeout=TIMEOUT) as f:
|
||||||
@@ -734,17 +735,22 @@ def init_ip_info():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
if PREFER_IPV6:
|
||||||
with urllib.request.urlopen('https://v6.ifconfig.co/ip', timeout=TIMEOUT) as f:
|
try:
|
||||||
if f.status != 200:
|
with urllib.request.urlopen('https://v6.ifconfig.co/ip', timeout=TIMEOUT) as f:
|
||||||
raise Exception("Invalid status code")
|
if f.status != 200:
|
||||||
my_ip_info["ipv6"] = f.read().decode().strip()
|
raise Exception("Invalid status code")
|
||||||
except Exception:
|
my_ip_info["ipv6"] = f.read().decode().strip()
|
||||||
pass
|
except Exception:
|
||||||
|
PREFER_IPV6 = False
|
||||||
|
else:
|
||||||
|
print_err("IPv6 found, using it for external communication")
|
||||||
|
|
||||||
if USE_MIDDLE_PROXY and not my_ip_info["ipv4"]: # and not my_ip_info["ipv6"]:
|
if USE_MIDDLE_PROXY:
|
||||||
print_err("Failed to determine your ip, advertising disabled")
|
if ((not PREFER_IPV6 and not my_ip_info["ipv4"]) or
|
||||||
USE_MIDDLE_PROXY = False
|
(PREFER_IPV6 and not my_ip_info["ipv6"])):
|
||||||
|
print_err("Failed to determine your ip, advertising disabled")
|
||||||
|
USE_MIDDLE_PROXY = False
|
||||||
|
|
||||||
|
|
||||||
def print_tg_info():
|
def print_tg_info():
|
||||||
|
|||||||
Reference in New Issue
Block a user