Skip to content

Commit

Permalink
feat: Add support for TUIC protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
7Sageer committed Jul 31, 2024
1 parent cccc9a5 commit 309062a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## 功能特点

- 支持协议:SS、VMess、VLESS、Hysteria2, Trojan
- 支持协议:SS、VMess、VLESS、Hysteria2, Trojan, TUIC
- 支持导入Base64订阅链接
- [一键部署](#最近更新), 无需后端
- 支持客户端:
Expand All @@ -22,9 +22,13 @@

## 最近更新

### 31/7

- 支持 TUIC

### 30/7

- 简化逆天路由规则
- 简化路由逻辑
- 修复了一些小问题

### 28/7
Expand Down
11 changes: 11 additions & 0 deletions src/ClashConfigBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 32 additions & 3 deletions src/ProxyParsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
1 change: 0 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 309062a

Please sign in to comment.