feat: Surge ECN 逻辑调整

This commit is contained in:
xream committed 2026-11-24 02:24:31 +08:00
1 parent 85948dcf96
commit 8edb26fe54
7 files changed
+112 -21

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.44.27",
"version": "2.44.28",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"packageManager": "pnpm@11.0.9",
@@ -424,7 +424,7 @@ start = (masque/anytls/shadowsocks/vmess/vless/trojan/h2_connect/https/http/snel
return proxy;
}
shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/udp_port/others)* {
shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/udp_port/others)* {
proxy.type = "ss";
// handle obfs
if (obfs.type == "http" || obfs.type === "tls") {
@@ -435,7 +435,7 @@ shadowsocks = tag equals "ss" address (method/passwordk/obfs/obfs_host/obfs_uri/
}
handleShadowTLS();
}
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_path/ws_headers/vmess_method/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_path/ws_headers/vmess_method/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "vmess";
proxy.cipher = proxy.cipher || "auto";
// Surfboard 与 Surge 默认不一致, 不管 Surfboard https://getsurfboard.com/docs/profile-format/proxy/external-proxy/vmess
@@ -447,7 +447,7 @@ vmess = tag equals "vmess" address (vmess_uuid/vmess_aead/ws/ws_http_upgrade/ws_
handleWebsocket();
handleShadowTLS();
}
vless = tag equals vless_address (vless_username/vless_option/reality_option/ws/ws_http_upgrade/ws_path/ws_headers/grpc/grpc_service_name/grpc_mode/grpc_authority/xhttp/xhttp_headers/xhttp_option/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
vless = tag equals vless_address (vless_username/vless_option/reality_option/ws/ws_http_upgrade/ws_path/ws_headers/grpc/grpc_service_name/grpc_mode/grpc_authority/xhttp/xhttp_headers/xhttp_option/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy["packet-encoding"] = "xudp";
if (proxy["reality-opts"] && proxy["reality-opts"]["public-key"]) proxy.tls = true;
if (xhttpEnabled) {
@@ -459,30 +459,30 @@ vless = tag equals vless_address (vless_username/vless_option/reality_option/ws/
handleShadowTLS();
}
vless_address = "vless" address { proxy.type = "vless"; }
trojan = tag equals "trojan" address (passwordk/ws/ws_http_upgrade/ws_path/ws_headers/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
trojan = tag equals "trojan" address (passwordk/ws/ws_http_upgrade/ws_path/ws_headers/tls/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "trojan";
handleWebsocket();
handleShadowTLS();
}
https = tag equals "https" address (username password)? (usernamek passwordk)? (headers/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
https = tag equals "https" address (username password)? (usernamek passwordk)? (headers/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "http";
proxy.tls = true;
handleShadowTLS();
}
h2_connect = tag equals "h2-connect" address (username password)? (usernamek passwordk)? (headers/max_streams/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
h2_connect = tag equals "h2-connect" address (username password)? (usernamek passwordk)? (headers/max_streams/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "h2-connect";
proxy.tls = true;
handleShadowTLS();
}
http = tag equals "http" address (username password)? (usernamek passwordk)? (headers/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
http = tag equals "http" address (username password)? (usernamek passwordk)? (headers/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "http";
handleShadowTLS();
}
ssh = tag equals "ssh" address (username password)? (usernamek passwordk)? (server_fingerprint/idle_timeout/private_key/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
ssh = tag equals "ssh" address (username password)? (usernamek passwordk)? (server_fingerprint/idle_timeout/private_key/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "ssh";
handleShadowTLS();
}
snell = tag equals ("snell"i/"opensnell"i) address (snell_version/snell_mode/snell_psk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/reuse/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
snell = tag equals ("snell"i/"opensnell"i) address (snell_version/snell_mode/snell_psk/obfs/obfs_host/obfs_uri/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/fast_open/tfo/udp_relay/reuse/alpn/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "snell";
// handle obfs
if (obfs.type == "http" || obfs.type === "tls") {
@@ -501,7 +501,7 @@ tuic_v5 = tag equals "tuic-v5" address (alpn/passwordk/uuidk/ip_version/underlyi
proxy.version = 5;
handleShadowTLS();
}
wireguard = tag equals "wireguard" (section_name/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
wireguard = tag equals "wireguard" (section_name/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "wireguard-surge";
handleShadowTLS();
}
@@ -509,20 +509,20 @@ hysteria2 = tag equals "hysteria2" address (no_error_alert/ip_version/underlying
proxy.type = "hysteria2";
handleShadowTLS();
}
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
socks5 = tag equals "socks5" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "socks5";
handleShadowTLS();
}
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/others)* {
socks5_tls = tag equals "socks5-tls" address (username password)? (usernamek passwordk)? (udp_relay/no_error_alert/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/sni/cert_verify_name/alpn/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/fast_open/tfo/shadow_tls_version/shadow_tls_sni/shadow_tls_password/block_quic/ecn/others)* {
proxy.type = "socks5";
proxy.tls = true;
handleShadowTLS();
}
anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/sni/cert_verify_name/alpn/fast_open/tfo/block_quic/others)* {
anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/sni/cert_verify_name/alpn/fast_open/tfo/block_quic/ecn/others)* {
proxy.type = "anytls";
proxy.tls = true;
}
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/client_random_auth_key/headers/max_streams/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/sni/cert_verify_name/alpn/h3/fast_open/tfo/block_quic/others)* {
trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/client_random_auth_key/headers/max_streams/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/client_fingerprint/tls_verification/client_cert/ech_config/sni/cert_verify_name/alpn/h3/fast_open/tfo/block_quic/ecn/others)* {
proxy.type = "trusttunnel";
proxy.tls = true;
}
@@ -680,7 +680,7 @@ uri = $[^,]+
udp_relay = comma "udp-relay" equals flag:bool { proxy.udp = flag; }
fast_open = comma "fast-open" equals flag:bool { proxy.tfo = flag; }
reuse = comma "reuse" equals flag:bool { proxy.reuse = flag; }
ecn = comma "ecn" equals flag:bool { proxy.ecn = flag; }
ecn = comma "ecn" equals mode:("auto" / "on" / "off" / bool) &(_ ("," / !.)) { proxy.ecn = mode; }
tfo = comma "tfo" equals flag:bool { proxy.tfo = flag; }
ip_version = comma "ip-version" equals match:[^,]+ { proxy["ip-version"] = match.join(""); }
section_name = comma "section-name" equals match:[^,]+ { proxy["section-name"] = match.join(""); }
@@ -144,6 +144,7 @@ function QuickSettingOperator(args) {
);
}
const ecn = getSwitchMode(args.ecn, get(args.ecn));
return proxies.map((proxy) => {
proxy.udp = get(args.udp, proxy.udp);
proxy.tfo = get(args.tfo, proxy.tfo);
@@ -158,10 +159,14 @@ function QuickSettingOperator(args) {
if (['snell', 'anytls', 'trusttunnel'].includes(proxy.type)) {
proxy.reuse = get(args.reuse, proxy.reuse);
}
if (['tuic', 'hysteria2'].includes(proxy.type)) {
proxy.ecn = get(args.ecn, proxy.ecn);
if (
ecn !== undefined &&
proxy.type !== 'direct' &&
proxy.type !== 'external'
) {
proxy.ecn = ecn;
}
proxy['block-quic'] = getBlockQuic(
proxy['block-quic'] = getSwitchMode(
args['block-quic'],
proxy['block-quic'],
);
@@ -185,7 +190,7 @@ function QuickSettingOperator(args) {
}
}
function getBlockQuic(value, defaultValue) {
function getSwitchMode(value, defaultValue) {
switch (value) {
case 'auto':
case 'on':
@@ -1189,7 +1189,11 @@ function hysteria2(proxy) {
'down',
);
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
if ([true, 'true', 'on'].includes(proxy.ecn)) {
result.append(',ecn=true');
} else if ([false, 'false', 'off'].includes(proxy.ecn)) {
result.append(',ecn=false');
}
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
result.appendIfPresent(`,ip-mode=${ip_version}`, 'ip-version');
@@ -390,6 +390,7 @@ function shadowsocks(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -448,6 +449,7 @@ function trojan(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -498,6 +500,7 @@ function anytls(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -567,6 +570,7 @@ function trusttunnel(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -681,6 +685,7 @@ function h2Connect(proxy) {
appendShadowTLS(result, proxy);
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
result.appendIfPresent(
`,underlying-proxy=${proxy['underlying-proxy']}`,
'underlying-proxy',
@@ -747,6 +752,7 @@ function v2ray(proxy, includeUnsupportedProxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -898,6 +904,7 @@ function ssh(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -952,6 +959,7 @@ function http(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -1057,6 +1065,7 @@ function socks5(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -1153,6 +1162,7 @@ function snell(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -1296,6 +1306,7 @@ function wireguard(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -1385,6 +1396,7 @@ function wireguard_surge(proxy) {
// block-quic
result.appendIfPresent(`,block-quic=${proxy['block-quic']}`, 'block-quic');
result.appendIfPresent(`,ecn=${proxy.ecn}`, 'ecn');
// underlying-proxy
result.appendIfPresent(
@@ -215,6 +215,14 @@ export function getWireGuardAddressWithCIDR(proxy = {}, family = 'ipv4') {
}
export function produceProxyListOutput(list, type, opts = {}) {
// These formats have no per-proxy ECN setting.
list = list.map((proxy) => {
if (!Object.hasOwn(proxy, 'ecn')) return proxy;
const config = { ...proxy };
delete config.ecn;
return config;
});
if (type === 'internal') return list;
if (opts.prettyYaml || opts['pretty-yaml']) {
@@ -38,6 +38,68 @@ function captureErrors(fn) {
}
describe('Proxy text producers', function () {
it('round-trips Surge ECN modes and converts them to Loon booleans', function () {
for (const [input, mode, loonEcn] of [
['auto', 'auto', undefined],
['on', 'on', true],
['off', 'off', false],
['true', true, true],
['false', false, false],
]) {
const proxies = ProxyUtils.parse(
`TCP=ss,example.com,443,encrypt-method=aes-128-gcm,password=secret,ecn=${input} ,tfo=true\n` +
`QUIC=hysteria2,example.com,443,password=secret,ecn=${input}`,
);
expect(proxies.map((proxy) => proxy.ecn)).to.deep.equal([
mode,
mode,
]);
expect(proxies[0].tfo).to.equal(true);
for (const target of ['Surge', 'SurgeMac']) {
const output = produceExternal(target, proxies);
expect(
ProxyUtils.parse(output).map((proxy) => proxy.ecn),
).to.deep.equal([mode, mode]);
}
const [tcp, quic] = produceExternal('Loon', proxies).split('\n');
expect(tcp).not.to.include(',ecn=');
if (loonEcn === undefined) {
expect(quic).not.to.include(',ecn=');
} else {
expect(quic).to.include(`,ecn=${loonEcn}`);
}
const mihomo = produceInternal('Mihomo', proxies);
expect(mihomo).to.have.lengthOf(2);
for (const proxy of mihomo) {
expect(proxy).not.to.have.property('ecn');
}
}
});
it('applies ECN quick settings to TCP proxies and accepts saved toggles', async function () {
const raw =
'TCP=ss,example.com,443,encrypt-method=aes-128-gcm,password=secret,ecn=off';
for (const [ecn, expected] of [
['DEFAULT', 'off'],
['auto', 'auto'],
['on', 'on'],
['off', 'off'],
['ENABLED', true],
['DISABLED', false],
]) {
const [proxy] = await ProxyUtils.process(
ProxyUtils.parse(raw),
[{ type: 'Quick Setting Operator', args: { ecn } }],
'Surge',
);
expect(produceExternal('Surge', proxy)).to.include(
`,ecn=${expected}`,
);
}
});
it('decodes and preserves Quantumult X tls-alpn forms', function () {
for (const tlsAlpn of [
'02683208687474702f312e31',