mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-30 08:28:10 +00:00
feat: 优化 sing-box network 转换逻辑, 兼容 UDP 开关, 区分不支持协议
- 调整 sing-box 的 network 解析:`_network` 显式为 `tcp/udp` 时直接生效,并提高优先级,避免和 `udp` 冲突。 - 增加 Mihomo 风格兼容:当节点配置 `udp: false` 时,对支持 `network` 的协议写入 `network: "tcp"`。 - 为 shadowTLS 与 SSR 补齐 network 解析,确保这两类协议也能应用 UDP/TCP 映射规则。 - 移除 anytls、tailscale、wireguard 的 network 映射,避免输出不支持的字段导致配置不合法。 - 新增结构化产物测试,验证: - `udp: true/false` 与 `_network` 的行为差异与优先级; - 不支持 network 的协议不会被误加 `network` 字段。 - 更新 demo 注释说明 `_network` 生效协议列表、`udp` 与 `_network` 的关系。
This commit is contained in:
4 files changed
+101
-5
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.23.6",
|
||||
"version": "2.23.7",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -50,8 +50,13 @@ const detourParser = (proxy, parsedProxy) => {
|
||||
parsedProxy.detour = proxy['dialer-proxy'] || proxy.detour;
|
||||
};
|
||||
const networkParser = (proxy, parsedProxy) => {
|
||||
if (['tcp', 'udp'].includes(proxy._network))
|
||||
if (['tcp', 'udp'].includes(proxy._network)) {
|
||||
parsedProxy.network = proxy._network;
|
||||
return;
|
||||
}
|
||||
if (proxy.udp === false) {
|
||||
parsedProxy.network = 'tcp';
|
||||
}
|
||||
};
|
||||
const tfoParser = (proxy, parsedProxy) => {
|
||||
parsedProxy.tcp_fast_open = false;
|
||||
@@ -503,6 +508,7 @@ const shadowTLSParser = (proxy = {}) => {
|
||||
if (proxy['fast-open'] === true) stPart.udp_fragment = true;
|
||||
tfoParser(proxy, stPart);
|
||||
detourParser(proxy, stPart);
|
||||
networkParser(proxy, ssPart);
|
||||
smuxParser(proxy.smux, ssPart);
|
||||
ipVersionParser(proxy, stPart);
|
||||
domainResolverParser(proxy, stPart);
|
||||
@@ -616,6 +622,7 @@ const ssrParser = (proxy = {}) => {
|
||||
if (proxy['protocol-param'] && proxy['protocol-param'] !== '')
|
||||
parsedProxy.protocol_param = proxy['protocol-param'];
|
||||
if (proxy['fast-open']) parsedProxy.udp_fragment = true;
|
||||
networkParser(proxy, parsedProxy);
|
||||
tfoParser(proxy, parsedProxy);
|
||||
detourParser(proxy, parsedProxy);
|
||||
smuxParser(proxy.smux, parsedProxy);
|
||||
@@ -912,7 +919,6 @@ const anytlsParser = (proxy = {}) => {
|
||||
`${proxy['min-idle-session']}`,
|
||||
10,
|
||||
);
|
||||
networkParser(proxy, parsedProxy);
|
||||
detourParser(proxy, parsedProxy);
|
||||
tlsParser(proxy, parsedProxy);
|
||||
ipVersionParser(proxy, parsedProxy);
|
||||
@@ -959,7 +965,6 @@ const tailscaleParser = (proxy = {}) => {
|
||||
`${proxy['relay-server-port']}`,
|
||||
10,
|
||||
);
|
||||
networkParser(proxy, parsedProxy);
|
||||
if (!useControlHTTPClient) {
|
||||
detourParser(proxy, parsedProxy);
|
||||
ipVersionParser(proxy, parsedProxy);
|
||||
@@ -1051,7 +1056,6 @@ const wireguardParser = (proxy = {}) => {
|
||||
parsedProxy.peers.push(peer);
|
||||
}
|
||||
}
|
||||
networkParser(proxy, parsedProxy);
|
||||
tfoParser(proxy, parsedProxy);
|
||||
detourParser(proxy, parsedProxy);
|
||||
smuxParser(proxy.smux, parsedProxy);
|
||||
|
||||
@@ -2289,6 +2289,96 @@ describe('Proxy structured producers', function () {
|
||||
expect(outbound.plugin_opts).to.include('mux=0');
|
||||
});
|
||||
|
||||
it('maps mihomo udp capability flags to sing-box network only when disabling UDP', function () {
|
||||
const output = loadProducedJson('sing-box', [
|
||||
{
|
||||
type: 'ss',
|
||||
name: 'SS UDP On',
|
||||
server: 'ss-on.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
udp: true,
|
||||
},
|
||||
{
|
||||
type: 'ss',
|
||||
name: 'SS UDP Off',
|
||||
server: 'ss-off.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
udp: false,
|
||||
},
|
||||
{
|
||||
type: 'ss',
|
||||
name: 'SS Network Override',
|
||||
server: 'ss-override.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
udp: false,
|
||||
_network: 'udp',
|
||||
},
|
||||
]);
|
||||
|
||||
const udpOn = output.outbounds.find((item) => item.tag === 'SS UDP On');
|
||||
const udpOff = output.outbounds.find(
|
||||
(item) => item.tag === 'SS UDP Off',
|
||||
);
|
||||
const networkOverride = output.outbounds.find(
|
||||
(item) => item.tag === 'SS Network Override',
|
||||
);
|
||||
|
||||
expect(udpOn).to.not.have.property('network');
|
||||
expect(udpOff).to.have.property('network', 'tcp');
|
||||
expect(networkOverride).to.have.property('network', 'udp');
|
||||
});
|
||||
|
||||
it('does not emit sing-box network for protocols without sing-box network options', function () {
|
||||
const output = loadProducedJson('sing-box', [
|
||||
{
|
||||
type: 'anytls',
|
||||
name: 'AnyTLS No Network',
|
||||
server: 'anytls.example.com',
|
||||
port: 443,
|
||||
password: 'secret',
|
||||
udp: false,
|
||||
_network: 'udp',
|
||||
},
|
||||
{
|
||||
type: 'tailscale',
|
||||
name: 'Tailscale No Network',
|
||||
udp: false,
|
||||
_network: 'udp',
|
||||
},
|
||||
{
|
||||
type: 'wireguard',
|
||||
name: 'WireGuard No Network',
|
||||
server: 'wg.example.com',
|
||||
port: 51820,
|
||||
'private-key': 'private-key',
|
||||
'public-key': 'public-key',
|
||||
ip: '10.0.0.2',
|
||||
udp: false,
|
||||
_network: 'udp',
|
||||
},
|
||||
]);
|
||||
|
||||
const anytls = output.outbounds.find(
|
||||
(item) => item.tag === 'AnyTLS No Network',
|
||||
);
|
||||
const tailscale = output.endpoints.find(
|
||||
(item) => item.tag === 'Tailscale No Network',
|
||||
);
|
||||
const wireguard = output.endpoints.find(
|
||||
(item) => item.tag === 'WireGuard No Network',
|
||||
);
|
||||
|
||||
expect(anytls).to.not.have.property('network');
|
||||
expect(tailscale).to.not.have.property('network');
|
||||
expect(wireguard).to.not.have.property('network');
|
||||
});
|
||||
|
||||
it('emits sing-box outbounds with reality tls and websocket transport', function () {
|
||||
const output = loadProducedJson('sing-box', {
|
||||
type: 'vless',
|
||||
|
||||
@@ -27,6 +27,8 @@ function operator(proxies = [], targetPlatform, context) {
|
||||
// 14. `ports` 为端口跳跃, `hop-interval` 变换端口号的时间间隔
|
||||
// 15. `ip-version` 设置节点使用 IP 版本,兼容各家的值. 会进行内部转换. sing-box 以外: 若无法匹配则使用原始值. sing-box: 需有匹配且节点上设置 `_dns_server` 字段, 将自动设置 `domain_resolver.server`. 同时, `sing-box` 支持使用完整的 `_domain_resolver` 结构设置 `domain_resolver` 字段
|
||||
// 16. `sing-box` 支持使用 `_network` 来设置 `network`, 例如 `tcp`, `udp`
|
||||
// 仅对 sing-box 源码里有 `network` 字段的协议生效: `ss`, `ssr`, `socks5`, `vmess`, `vless`, `trojan`, `hysteria`, `hysteria2`, `tuic`.
|
||||
// 注意: mihomo 风格的 `udp: true` 表示节点支持 UDP, 不会转换成 sing-box 的 `network: "udp"`; sing-box 默认就是 TCP+UDP. `udp: false` 会转换成 `network: "tcp"`. `_network` 是显式覆盖, 优先级高于 `udp`.
|
||||
// 17. `block-quic` 支持 `auto`, `on`, `off`. 不同的平台不一定都支持, 会自动转换
|
||||
// 18. `sing-box` 支持 `_fragment`, `_fragment_fallback_delay`, `_record_fragment` 设置 `tls` 的 `fragment`, `fragment_fallback_delay`, `record_fragment`
|
||||
// 19. `sing-box` 支持 `_certificate`, `_certificate_path`, `_certificate_public_key_sha256`, `_client_certificate`, `_client_certificate_path`, `_client_key`, `_client_key_path` 设置 `tls` 的 `certificate`, `certificate_path`, `certificate_public_key_sha256`, `client_certificate`, `client_certificate_path`, `client_key`, `client_key_path`
|
||||
|
||||
Reference in new issue
Block a user