From 309062a8f5c6dc22f529c617242e7f314b05f0f7 Mon Sep 17 00:00:00 2001 From: 7Sageer <125936732+7Sageer@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:30:37 +0800 Subject: [PATCH] feat: Add support for TUIC protocol --- README.md | 8 ++++++-- src/ClashConfigBuilder.js | 11 +++++++++++ src/ProxyParsers.js | 35 ++++++++++++++++++++++++++++++++--- src/config.js | 6 +----- wrangler.toml | 1 - 5 files changed, 50 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ea53aac5..7dc7adf7 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## 功能特点 -- 支持协议:SS、VMess、VLESS、Hysteria2, Trojan +- 支持协议:SS、VMess、VLESS、Hysteria2, Trojan, TUIC - 支持导入Base64订阅链接 - [一键部署](#最近更新), 无需后端 - 支持客户端: @@ -22,9 +22,13 @@ ## 最近更新 +### 31/7 + +- 支持 TUIC + ### 30/7 -- 简化逆天路由规则 +- 简化路由逻辑 - 修复了一些小问题 ### 28/7 diff --git a/src/ClashConfigBuilder.js b/src/ClashConfigBuilder.js index 343a6739..9a1c6baf 100644 --- a/src/ClashConfigBuilder.js +++ b/src/ClashConfigBuilder.js @@ -158,6 +158,17 @@ export class ClashConfigBuilder { 'skip-cert-verify': proxy.tls.insecure, 'flow': proxy.flow ?? undefined, } + case 'tuic': + return { + name: proxy.tag, + type: proxy.type, + server: proxy.server, + port: proxy.server_port, + uuid: proxy.uuid, + password: proxy.password, + 'congestion-controller': proxy.congestion, + 'skip-cert-verify': proxy.tls.insecure, + }; default: return proxy; // Return as-is if no specific conversion is defined } diff --git a/src/ProxyParsers.js b/src/ProxyParsers.js index 04e374de..7eb5ca21 100644 --- a/src/ProxyParsers.js +++ b/src/ProxyParsers.js @@ -9,8 +9,11 @@ export class ProxyParser { case 'vmess': return new VmessParser().parse(url); case 'vless': return new VlessParser().parse(url); case 'hysteria2': return new Hysteria2Parser().parse(url); - case 'http' || 'https': return HttpParser.parse(url); + case 'http': + case 'https': + return HttpParser.parse(url); case 'trojan': return new TrojanParser().parse(url); + case 'tuic': return new TuicParser().parse(url); } } } @@ -137,7 +140,6 @@ export class ProxyParser { class TrojanParser { parse(url) { - // trojan://8jxfHkRdEV@diylink.qhr.icu:31190?security=reality&sni=yahoo.com&fp=random&pbk=KlaUGzBvKlBX0GqI7hCPioRZvDuLP3O5wozg-L8nCiw&sid=a9d30b07&spx=%2F&type=tcp&headerType=none#trojan-test-nuu4xgxm const { addressPart, params, name } = parseUrlParams(url); const [password, serverInfo] = addressPart.split('@'); const { host, port } = parseServerInfo(serverInfo); @@ -159,7 +161,34 @@ export class ProxyParser { }; } } - // + + class TuicParser { + parse(url) { + const { addressPart, params, name } = parseUrlParams(url); + const [userinfo, serverInfo] = addressPart.split('@'); + const { host, port } = parseServerInfo(serverInfo); + + const tls = { + enabled: true, + server_name: params.sni, + alpn: [params.alpn], + }; + + return { + tag: name, + type: "tuic", + server: host, + server_port: port, + uuid: userinfo.split(':')[0], + password: userinfo.split(':')[1], + congestion_control: params.congestion_control, + tls: tls, + flow: params.flow ?? undefined + }; + } + } + + class HttpParser { static async parse(url) { try { diff --git a/src/config.js b/src/config.js index a9a1fe4f..e2262253 100644 --- a/src/config.js +++ b/src/config.js @@ -269,10 +269,6 @@ export const CLASH_CONFIG = { fallback: ['8.8.8.8', '8.8.4.4', 'tls://1.0.0.1:853', 'tls://dns.google:853'], }, proxies: [], - 'proxy-groups': [ - // 'name': '🐟 漏网之鱼', - // 'type': 'select', - // 'proxies': ['🚀 节点选择','DIRECT','REJECT'] - ], + 'proxy-groups': [], rules: parsedRules, }; diff --git a/wrangler.toml b/wrangler.toml index 21db48a8..13f4a09f 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,6 +1,5 @@ #:schema node_modules/wrangler/config-schema.json name = "sublink-worker" -type = "javascript" usage_model = "bundled" main = "src/index.js" compatibility_date = "2024-07-24"