feat: Loon Hysteria 2 支持 server-ports, hop-interval

This commit is contained in:
xream committed 2026-05-19 23:05:09 +08:00
1 parent 0111766a2e
commit 049f468200
7 files changed
+185 -20

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.23.14",
"version": "2.23.15",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -72,7 +72,7 @@ anytls = tag equals "anytls"i address password (transport/transport_host/transpo
proxy.type = "anytls";
handleTransport();
}
hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/udp_relay/fast_open/download_bandwidth/salamander_password/ecn/ip_mode/block_quic/others)* {
hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/udp_relay/fast_open/download_bandwidth/server_ports/hop_interval/salamander_password/ecn/ip_mode/block_quic/others)* {
proxy.type = "hysteria2";
}
https = tag equals "https"i address (username password)? (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/others)* {
@@ -195,6 +195,8 @@ ip_mode = comma "ip-mode" equals match:[^,]+ { proxy["ip-version"] = match.join(
ecn = comma "ecn" equals flag:bool { proxy.ecn = flag; }
download_bandwidth = comma "download-bandwidth" equals match:[^,]+ { proxy.down = match.join(""); }
server_ports = comma "server-ports" equals '"' match:$[^"]+ '"' { proxy.ports = match.trim().replace(/\s*-\s*/g, "-").replace(/\s*,\s*/g, ","); }
hop_interval = comma "hop-interval" equals match:$[0-9]+ { proxy["hop-interval"] = parseInt(match, 10); }
salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['obfs-password'] = match.join(""); proxy.obfs = 'salamander'; }
block_quic = comma "block-quic" equals flag:bool { if(flag) proxy["block-quic"] = "on"; else proxy["block-quic"] = "off"; }
@@ -749,6 +749,17 @@ function hysteria2(proxy) {
result.appendIfPresent(`,"${proxy.password}"`, 'password');
if (isPresent(proxy, 'ports') && `${proxy.ports}`.trim().length > 0) {
result.append(`,server-ports="${proxy.ports}"`);
}
if (
isPresent(proxy, 'hop-interval') &&
`${proxy['hop-interval']}`.trim().length > 0
) {
result.append(`,hop-interval=${proxy['hop-interval']}`);
}
// sni
result.appendIfPresent(`,tls-name=${proxy.sni}`, 'sni');
result.appendIfPresent(
@@ -4,6 +4,10 @@ import { isNotBlank } from '@/utils';
const targetPlatform = 'Surfboard';
function hasNonBlankValue(value) {
return value != null && `${value}`.trim().length > 0;
}
export default function Surfboard_Producer() {
const produce = (proxy) => {
if (
@@ -62,14 +66,15 @@ function hysteria2(proxy) {
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
if (isPresent(proxy, 'ports')) {
result.append(`,port-hopping="${proxy.ports.replace(/,/g, ';')}"`);
if (hasNonBlankValue(proxy.ports)) {
result.append(
`,port-hopping="${String(proxy.ports).replace(/,/g, ';')}"`,
);
}
result.appendIfPresent(
`,port-hopping-interval=${proxy['hop-interval']}`,
'hop-interval',
);
if (hasNonBlankValue(proxy['hop-interval'])) {
result.append(`,port-hopping-interval=${proxy['hop-interval']}`);
}
// tls verification
result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni');
+18 -12
View File
@@ -44,6 +44,10 @@ function quoteSurgeValue(value) {
.replace(/"/g, '\\"')}"`;
}
function hasNonBlankValue(value) {
return value != null && `${value}`.trim().length > 0;
}
function appendClientCert(result, proxy) {
const clientCert = isPresent(proxy, 'keystore-client-cert')
? proxy['keystore-client-cert']
@@ -1076,14 +1080,15 @@ function tuic(proxy) {
'alpn',
);
if (isPresent(proxy, 'ports')) {
result.append(`,port-hopping="${proxy.ports.replace(/,/g, ';')}"`);
if (hasNonBlankValue(proxy.ports)) {
result.append(
`,port-hopping="${String(proxy.ports).replace(/,/g, ';')}"`,
);
}
result.appendIfPresent(
`,port-hopping-interval=${proxy['hop-interval']}`,
'hop-interval',
);
if (hasNonBlankValue(proxy['hop-interval'])) {
result.append(`,port-hopping-interval=${proxy['hop-interval']}`);
}
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
result.appendIfPresent(`,ip-version=${ip_version}`, 'ip-version');
@@ -1348,14 +1353,15 @@ function hysteria2(proxy) {
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
if (isPresent(proxy, 'ports')) {
result.append(`,port-hopping="${proxy.ports.replace(/,/g, ';')}"`);
if (hasNonBlankValue(proxy.ports)) {
result.append(
`,port-hopping="${String(proxy.ports).replace(/,/g, ';')}"`,
);
}
result.appendIfPresent(
`,port-hopping-interval=${proxy['hop-interval']}`,
'hop-interval',
);
if (hasNonBlankValue(proxy['hop-interval'])) {
result.append(`,port-hopping-interval=${proxy['hop-interval']}`);
}
if (proxy['obfs-password'] && proxy.obfs == 'salamander') {
result.append(`,salamander-password="${proxy['obfs-password']}"`);
@@ -2559,6 +2559,7 @@ describe('Platform raw-format parser coverage', function () {
},
},
]);
});
describe('Loon raw inputs', function () {
@@ -2709,6 +2710,21 @@ describe('Platform raw-format parser coverage', function () {
ecn: true,
},
},
{
title: 'parses hysteria2 port hopping lines',
input: 'Loon Hysteria2 Port Hopping=hysteria2,loon-hy2.example.com,443,"secret",server-ports="1000,2000-3000,5000",hop-interval=30,tls-name=peer.example.com,skip-cert-verify=true',
expected: {
type: 'hysteria2',
name: 'Loon Hysteria2 Port Hopping',
server: 'loon-hy2.example.com',
port: 443,
ports: '1000,2000-3000,5000',
'hop-interval': 30,
password: 'secret',
sni: 'peer.example.com',
'skip-cert-verify': true,
},
},
{
title: 'parses https auth lines',
input: 'Loon HTTPS=https,loon-http.example.com,8443,user,"pass",tls-name=sni.example.com,skip-cert-verify=true',
@@ -2829,6 +2845,14 @@ describe('Platform raw-format parser coverage', function () {
},
},
]);
it('rejects hysteria2 hop interval ranges', function () {
expect(
parseAll(
'Loon Hysteria2 Hop Range=hysteria2,loon-hy2.example.com,443,"secret",hop-interval=15-30',
),
).to.have.length(0);
});
});
describe('Surge raw inputs', function () {
@@ -433,6 +433,53 @@ describe('Proxy text producers', function () {
);
});
it('produces Loon Hysteria2 lines with port hopping', function () {
const output = produceExternal('Loon', {
type: 'hysteria2',
name: 'Loon Hysteria2',
server: 'hy2.example.com',
port: 443,
password: 'secret',
ports: '1000,2000-3000,5000',
'hop-interval': 30,
sni: 'peer.example.com',
'skip-cert-verify': true,
});
expect(output).to.equal(
'Loon Hysteria2=Hysteria2,hy2.example.com,443,"secret",server-ports="1000,2000-3000,5000",hop-interval=30,tls-name=peer.example.com,skip-cert-verify=true',
);
});
it('does not emit empty Loon Hysteria2 port hopping fields', function () {
const output = produceExternal('Loon', {
type: 'hysteria2',
name: 'Loon Hysteria2 Plain',
server: 'hy2.example.com',
port: 443,
password: 'secret',
ports: '',
'hop-interval': ' ',
sni: 'peer.example.com',
'skip-cert-verify': true,
});
expect(output).to.equal(
'Loon Hysteria2 Plain=Hysteria2,hy2.example.com,443,"secret",tls-name=peer.example.com,skip-cert-verify=true',
);
});
it('exports URI Hysteria2 port hopping nodes to Loon fields', function () {
const [proxy] = ProxyUtils.parse(
'hy2://secret@hy2.example.com:443?mport=1000,2000-3000,5000&hop-interval=30#URI%20Hysteria2',
);
const output = produceExternal('Loon', proxy);
expect(output).to.equal(
'URI Hysteria2=Hysteria2,hy2.example.com,443,"secret",server-ports="1000,2000-3000,5000",hop-interval=30,tls-name=hy2.example.com,skip-cert-verify=false,fast-open=false',
);
});
it('produces Surge TUIC v5 lines with port hopping', function () {
const output = produceExternal('Surge', {
type: 'tuic',
@@ -453,6 +500,58 @@ describe('Proxy text producers', function () {
);
});
it('does not emit empty Surge port hopping fields', function () {
const output = produceExternal('Surge', [
{
type: 'tuic',
name: 'Surge TUIC Plain',
server: 'tuic.example.com',
port: 443,
uuid: UUID,
password: 'secret',
ports: '',
'hop-interval': ' ',
sni: 'sni.example.com',
'skip-cert-verify': true,
alpn: ['h3'],
},
{
type: 'hysteria2',
name: 'Surge Hysteria2 Plain',
server: 'hy2.example.com',
port: 443,
password: 'secret',
ports: '',
'hop-interval': ' ',
sni: 'peer.example.com',
'skip-cert-verify': true,
},
]);
expect(output).to.equal(
`Surge TUIC Plain=tuic-v5,tuic.example.com,443,uuid=${UUID},password="secret",alpn=h3,sni="sni.example.com",skip-cert-verify=true\nSurge Hysteria2 Plain=hysteria2,hy2.example.com,443,password="secret",sni="peer.example.com",skip-cert-verify=true`,
);
});
it('produces Surge Hysteria2 lines with port hopping', function () {
const output = produceExternal('Surge', {
type: 'hysteria2',
name: 'Surge 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',
});
expect(output).to.equal(
'Surge 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',
);
});
it('quotes Surge SSH private-key and TLS client-cert keystore values', function () {
const output = ProxyUtils.produce(
[
@@ -818,6 +917,24 @@ describe('Proxy text producers', function () {
);
});
it('does not emit empty Surfboard Hysteria2 port hopping fields', function () {
const output = produceExternal('Surfboard', {
type: 'hysteria2',
name: 'Surfboard Hysteria2 Plain',
server: 'hy2.example.com',
port: 443,
password: 'secret',
ports: '',
'hop-interval': ' ',
sni: 'peer.example.com',
'skip-cert-verify': true,
});
expect(output).to.equal(
'Surfboard Hysteria2 Plain=hysteria2,hy2.example.com,443,password="secret",sni="peer.example.com",skip-cert-verify=true',
);
});
it('omits Surfboard Hysteria2 lines when obfs is present', function () {
const output = ProxyUtils.produce(
[