mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-28 23:40:30 +00:00
feat: Surfboard 支持 TUIC v5
This commit is contained in:
3 files changed
+73
-1
No files matched your search
@@ -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') ||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user