From db7ad0a2843d48ed5b9b7c17c9e2a86a7b02aa09 Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 30 Mar 2026 10:13:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Surfboard=20=E6=94=AF=E6=8C=81=20Hyster?= =?UTF-8?q?ia=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../core/proxy-utils/producers/surfboard.js | 39 ++++++++++++++++++ backend/src/test/proxy-producers/text.spec.js | 41 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 8c4d9a66..6ce9e013 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.63", + "version": "2.21.64", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/producers/surfboard.js b/backend/src/core/proxy-utils/producers/surfboard.js index 29759520..ee9d8b0d 100644 --- a/backend/src/core/proxy-utils/producers/surfboard.js +++ b/backend/src/core/proxy-utils/producers/surfboard.js @@ -30,6 +30,8 @@ export default function Surfboard_Producer() { return socks5(proxy); case 'anytls': return anytls(proxy); + case 'hysteria2': + return hysteria2(proxy); case 'wireguard-surge': return wireguard(proxy); } @@ -39,6 +41,43 @@ export default function Surfboard_Producer() { }; return { produce }; } +function hysteria2(proxy) { + if (proxy.obfs || proxy['obfs-password']) { + throw new Error(`Surfboard Hysteria2 does not support obfs`); + } + + const result = new Result(proxy); + result.append(`${proxy.name}=hysteria2,${proxy.server},${proxy.port}`); + + result.appendIfPresent(`,password="${proxy.password}"`, 'password'); + + if (isPresent(proxy, 'ports')) { + result.append(`,port-hopping="${proxy.ports.replace(/,/g, ';')}"`); + } + + result.appendIfPresent( + `,port-hopping-interval=${proxy['hop-interval']}`, + 'hop-interval', + ); + + // tls verification + result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni'); + result.appendIfPresent( + `,skip-cert-verify=${proxy['skip-cert-verify']}`, + 'skip-cert-verify', + ); + + // download-bandwidth + result.appendIfPresent( + `,download-bandwidth=${`${proxy['down']}`.match(/\d+/)?.[0] || 0}`, + 'down', + ); + + // udp + result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp'); + + return result.toString(); +} function anytls(proxy) { const result = new Result(proxy); result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`); diff --git a/backend/src/test/proxy-producers/text.spec.js b/backend/src/test/proxy-producers/text.spec.js index 44755d02..526a928a 100644 --- a/backend/src/test/proxy-producers/text.spec.js +++ b/backend/src/test/proxy-producers/text.spec.js @@ -2,6 +2,7 @@ import { expect } from 'chai'; import { Base64 } from 'js-base64'; import { describe, it } from 'mocha'; +import { ProxyUtils } from '@/core/proxy-utils'; import { produceExternal, UUID } from './helpers'; describe('Proxy text producers', function () { @@ -131,6 +132,46 @@ describe('Proxy text producers', function () { ); }); + it('produces Surfboard Hysteria2 lines', function () { + const output = produceExternal('Surfboard', { + type: 'hysteria2', + name: 'Surfboard Hysteria2', + server: 'hy2.example.com', + port: 443, + password: 'secret', + ports: '8443,8445-8447', + 'hop-interval': 30, + sni: 'peer.example.com', + 'skip-cert-verify': true, + down: '100 Mbps', + udp: true, + }); + + expect(output).to.equal( + 'Surfboard Hysteria2=hysteria2,hy2.example.com,443,password="secret",port-hopping="8443;8445-8447",port-hopping-interval=30,sni="peer.example.com",skip-cert-verify=true,download-bandwidth=100,udp-relay=true', + ); + }); + + it('omits Surfboard Hysteria2 lines when obfs is present', function () { + const output = ProxyUtils.produce( + [ + { + type: 'hysteria2', + name: 'Surfboard Hysteria2 Obfs', + server: 'hy2.example.com', + port: 443, + password: 'secret', + obfs: 'salamander', + 'obfs-password': 'mask', + }, + ], + 'Surfboard', + 'external', + ); + + expect(output).to.equal(''); + }); + it('produces SurgeMac external lines', function () { const output = produceExternal('SurgeMac', { type: 'external',