feat: cahining + stats
This commit is contained in:
28 files changed
+898
-72
No files matched your search
@@ -419,6 +419,44 @@ def parse_tuic(url: str, tag: str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def parse_anytls(url: str, tag: str) -> dict:
|
||||
# anytls://password@host:port?sni=example.com&insecure=1&fp=chrome&alpn=h2
|
||||
userinfo, host, port, params = _parse_url_parts(url, "anytls")
|
||||
if not userinfo:
|
||||
raise ValueError("anytls link is missing the password")
|
||||
tls = _mk_tls(params.get("sni") or params.get("peer") or host, params.get("fp"), params.get("alpn"))
|
||||
if params.get("insecure", params.get("allowInsecure", "0")) == "1":
|
||||
tls["insecure"] = True
|
||||
return {
|
||||
"type": "anytls",
|
||||
"tag": tag,
|
||||
"server": host,
|
||||
"server_port": int(port),
|
||||
"password": urllib.parse.unquote(userinfo),
|
||||
"tls": tls,
|
||||
}
|
||||
|
||||
|
||||
def parse_naive(url: str, tag: str) -> dict:
|
||||
# naive+https://user:pass@host:port, or naive+quic:// for HTTP/3 (NekoBox's form).
|
||||
scheme = url.split("://", 1)[0].lower()
|
||||
userinfo, host, port, params = _parse_url_parts(url, scheme)
|
||||
ob: dict = {
|
||||
"type": "naive",
|
||||
"tag": tag,
|
||||
"server": host,
|
||||
"server_port": int(port),
|
||||
"tls": {"enabled": True, "server_name": params.get("sni") or host},
|
||||
}
|
||||
username, password = _mk_auth(userinfo)
|
||||
if username is not None:
|
||||
ob["username"] = username
|
||||
ob["password"] = password
|
||||
if scheme == "naive+quic":
|
||||
ob["quic"] = True
|
||||
return ob
|
||||
|
||||
|
||||
def parse_socks(url: str, tag: str) -> dict:
|
||||
scheme = url.split("://")[0].lower()
|
||||
version = "4" if scheme.startswith("socks4") else "5"
|
||||
@@ -461,6 +499,9 @@ PARSERS = {
|
||||
"hysteria2": parse_hysteria2,
|
||||
"hy2": parse_hysteria2,
|
||||
"tuic": parse_tuic,
|
||||
"anytls": parse_anytls,
|
||||
"naive+https": parse_naive,
|
||||
"naive+quic": parse_naive,
|
||||
"socks5": parse_socks,
|
||||
"socks5h": parse_socks,
|
||||
"socks4": parse_socks,
|
||||
|
||||
@@ -274,6 +274,22 @@ class BuildOutboundTests(unittest.TestCase):
|
||||
self.assertEqual(ob["type"], "tuic")
|
||||
self.assertEqual(ob["tls"]["alpn"], ["h3", "hq-29"])
|
||||
|
||||
def test_anytls(self):
|
||||
ob = run_parser("anytls://p%40ss@example.com:443?sni=a.example.com&insecure=1&fp=chrome#name")
|
||||
self.assertEqual(ob["type"], "anytls")
|
||||
self.assertEqual(ob["password"], "p@ss")
|
||||
self.assertEqual(ob["tls"], {"enabled": True, "server_name": "a.example.com", "insecure": True,
|
||||
"utls": {"enabled": True, "fingerprint": "chrome"}})
|
||||
with self.assertRaisesRegex(ValueError, "unsupported XRay outbound type"):
|
||||
run_xray_parser("anytls://pw@example.com:443")
|
||||
|
||||
def test_naive(self):
|
||||
ob = run_parser("naive+https://user:pass@example.com:443#name")
|
||||
self.assertEqual((ob["type"], ob["username"], ob["password"]), ("naive", "user", "pass"))
|
||||
self.assertEqual(ob["tls"]["server_name"], "example.com")
|
||||
self.assertNotIn("quic", ob)
|
||||
self.assertTrue(run_parser("naive+quic://user:pass@example.com:443")["quic"])
|
||||
|
||||
def test_socks5(self):
|
||||
ob = run_parser("socks5://user:pass@example.com:1080")
|
||||
self.assertEqual(ob["type"], "socks")
|
||||
|
||||
Reference in new issue
Block a user