From 2b28e1b522c7bcd8052704506c0bc6e299532622 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 19 Jul 2026 06:43:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Surfboard=20=E6=94=AF=E6=8C=81=20TUIC?= =?UTF-8?q?=20v5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/proxy-utils/producers/surfboard.js | 31 ++++++++++++++ .../src/core/proxy-utils/producers/surge.js | 2 +- backend/src/test/proxy-producers/text.spec.js | 41 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/backend/src/core/proxy-utils/producers/surfboard.js b/backend/src/core/proxy-utils/producers/surfboard.js index de702d68..8bb9d9aa 100644 --- a/backend/src/core/proxy-utils/producers/surfboard.js +++ b/backend/src/core/proxy-utils/producers/surfboard.js @@ -46,6 +46,8 @@ export default function Surfboard_Producer() { return http(proxy); case 'snell': return snell(proxy); + case 'tuic': + return tuic(proxy); case 'socks5': return socks5(proxy); case 'hysteria2': @@ -72,6 +74,35 @@ export default function Surfboard_Producer() { }; return { produce }; } +function tuic(proxy) { + if (proxy.token?.length) { + throw new Error( + `Platform ${targetPlatform} does not support proxy type ${proxy.type} v4`, + ); + } + const result = new Result(proxy); + result.append(`${proxy.name}=tuic-v5,${proxy.server},${proxy.port}`); + result.appendIfPresent(`,uuid=${proxy.uuid}`, 'uuid'); + result.appendIfPresent(`,password="${proxy.password}"`, 'password'); + if (hasNonBlankValue(proxy.alpn)) { + result.append( + `,alpn="${ + Array.isArray(proxy.alpn) ? proxy.alpn.join(',') : proxy.alpn + }"`, + ); + } + if (hasNonBlankValue(proxy.ports)) { + result.append( + `,port-hopping="${String(proxy.ports).replace(/,/g, ';')}"`, + ); + } + if (hasNonBlankValue(proxy['hop-interval'])) { + result.append(`,port-hopping-interval=${proxy['hop-interval']}`); + } + appendTlsProxyParams(result, proxy); + result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp'); + return result.toString(); +} function hysteria2(proxy) { if ( (proxy.obfs && proxy.obfs !== 'salamander') || diff --git a/backend/src/core/proxy-utils/producers/surge.js b/backend/src/core/proxy-utils/producers/surge.js index c422873d..7e6925df 100644 --- a/backend/src/core/proxy-utils/producers/surge.js +++ b/backend/src/core/proxy-utils/producers/surge.js @@ -973,7 +973,7 @@ function snell(proxy) { function tuic(proxy) { const result = new Result(proxy); - // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/adapter/outbound/tuic.go#L197 + // https://github.com/MetaCubeX/mihomo/blob/e26714a181ac0e2fa803453c0a8e9a9ce94e31cb/adapter/outbound/tuic.go#L271 let type = proxy.type; if (!proxy.token || proxy.token.length === 0) { type = 'tuic-v5'; diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index f733d840..12429acc 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -1635,6 +1635,47 @@ describe('Proxy text producers', function () { ); }); + it('produces Surfboard TUIC v5 lines', function () { + const output = produceExternal('Surfboard', { + type: 'tuic', + name: 'ProxyTuic', + server: '1.2.3.4', + port: 443, + uuid: UUID, + password: 'pwd', + alpn: ['h3'], + ports: '1234,5000-6000', + 'hop-interval': 30, + 'skip-cert-verify': true, + sni: 'example.com', + 'tls-fingerprint': + 'fac26f65c034829da42d740d23c4a7202475a3834f0ebaecae5f934adbbfd640', + udp: true, + }); + + expect(output).to.equal( + `ProxyTuic=tuic-v5,1.2.3.4,443,uuid=${UUID},password="pwd",alpn="h3",port-hopping="1234;5000-6000",port-hopping-interval=30,server-cert-fingerprint-sha256=fac26f65c034829da42d740d23c4a7202475a3834f0ebaecae5f934adbbfd640,sni="example.com",skip-cert-verify=true,udp-relay=true`, + ); + }); + + it('does not produce legacy TUIC as Surfboard TUIC v5', function () { + const output = ProxyUtils.produce( + [ + { + type: 'tuic', + name: 'Legacy TUIC', + server: 'tuic.example.com', + port: 443, + token: 'secret', + }, + ], + 'Surfboard', + 'external', + ); + + expect(output).to.equal(''); + }); + it('does not emit empty Surfboard Hysteria2 port hopping fields', function () { const output = produceExternal('Surfboard', { type: 'hysteria2',