dsh-mobile-plugin 0.5.143 → 0.5.145

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +2 -2
  2. package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +4 -2
  3. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/harmonyos.md +27 -0
  4. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network-guide.md +1 -1
  5. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +1 -1
  6. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay-server.md +1 -1
  7. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +8 -9
  8. package/docs/extension-authoring.md +28 -0
  9. package/dsh-mobile-credentials/lib/credentials.js +74 -6
  10. package/lib/cloudflared/wiring.cjs +14 -1
  11. package/lib/frpc/runner.cjs +14 -5
  12. package/lib/impl.js +21 -6
  13. package/lib/mobile/activity.cjs +107 -11
  14. package/lib/mobile/feedback.js +19 -0
  15. package/lib/mobile/mux.js +2 -1
  16. package/lib/mobile/pairing.js +19 -24
  17. package/lib/mobile/permissions.js +13 -10
  18. package/lib/mobile/relay-control.js +7 -0
  19. package/lib/mobile/schedule-edit.js +9 -8
  20. package/lib/mobile/send-continuation.js +2 -2
  21. package/lib/mobile/session-send.js +3 -4
  22. package/lib/p2p/session.cjs +21 -38
  23. package/lib/panel/index.html +18 -19
  24. package/lib/relay/config-store.js +5 -0
  25. package/lib/relay/core.js +6 -43
  26. package/lib/relay/ipv6-lifetime.cjs +89 -0
  27. package/lib/relay/lan-discovery.cjs +4 -7
  28. package/lib/relay/lan-network.cjs +16 -6
  29. package/lib/relay/lan-port-policy.cjs +6 -14
  30. package/lib/relay/lan-proxy.js +16 -30
  31. package/lib/relay/pairing-payload.cjs +76 -2
  32. package/lib/remote/host-control.cjs +14 -8
  33. package/lib/routes/control-plane.js +11 -1
  34. package/lib/routes/mobile-api.js +4 -1
  35. package/lib/shared/device-headers.js +1 -3
  36. package/lib/sidecar-facade-worker.cjs +15 -4
  37. package/lib/tailcat/host-process.cjs +17 -25
  38. package/lib/zeronews/account.cjs +8 -4
  39. package/lib/zeronews/probe.cjs +22 -14
  40. package/lib/zeronews/runner.cjs +26 -5
  41. package/package.json +14 -13
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:局域网 Bonjour 广播单独开关进 schema,老状态缺项按开。
1
2
  // 2026-11-27:零讯客户端身份两格进 schema(连上时落盘,复用本机客户端前比对,手机配置口不开放)。
2
3
  // 2026-11-25:专属回环入口端口进 schema(worker 绑定后落盘、手机配置口不开放),兜底期间的手填地址备份同属运行时字段。
3
4
  // 固定端口设置随远程连接配置一并保存和投影。
@@ -44,6 +45,8 @@ const RemoteControlSettingsSchema = z.object({
44
45
  // 宿主从列表选择并注册一条线路,中选地址写回首项;手机只跟随当前注册线路。
45
46
  relayUrls: z.array(z.string()).default([]),
46
47
  lanEnabled: z.boolean().default(true),
48
+ // Bonjour 广播的单独开关,默认开;关掉只停发布,不动局域网监听与配对。
49
+ lanDiscoveryEnabled: z.boolean().default(true),
47
50
  lanPort: z.number().step(1).min(1024).max(65535).default(51887),
48
51
  // 外部穿透软件的固定目标由用户声明;插件内配置的穿透另外自动锁定。
49
52
  lanPortFixed: z.boolean().default(false),
@@ -134,6 +137,8 @@ function configOf(state) {
134
137
  relayUrl: relay.relayUrl,
135
138
  relayUrls: relay.relayUrls,
136
139
  lanEnabled: Boolean(state.lanEnabled),
140
+ // 只有显式 false 才算关;老状态文件没这一格、坏值都按开(与历史行为一致)。
141
+ lanDiscoveryEnabled: state.lanDiscoveryEnabled !== false,
137
142
  lanPort: Number.isInteger(state.lanPort) ? state.lanPort : 51887,
138
143
  lanPortFixed: state.lanPortFixed === true,
139
144
  // 专属入口还没分配时按 0(worker 绑好之后才有值),坏值不能冒充已就绪。
package/lib/relay/core.js CHANGED
@@ -1,6 +1,7 @@
1
+ // 2026-11-30:局域网 Bonjour 广播单独开关进默认状态,老配置缺项按开。
1
2
  // 2026-11-27:零讯客户端身份两格进默认状态(连上时落盘,复用本机客户端前比对)。
2
3
  // 2026-11-25:专属回环入口端口与兜底期手填地址备份进默认状态(运行时字段,手机配置口不开放)。
3
- // 中转地址的废弃内置项在读盘与落盘时统一清理;配置收敛保持两格自洽。
4
+ // 配置收敛保持两格自洽;不再按域名清理废弃内置中转地址(2026-11-29:退役清单清完,自建同名域名照常保留)。
4
5
  // 通用线路引擎的运行时线路清单(customRoutes)随状态落盘,默认空:没接第三方线路时上报清单逐字不变。
5
6
  // 2026-11-22:ZeroNews 本机隧道地址独立一格 zeroNewsUrl,由插件自己读、作为第一条通用线路上报。
6
7
  /**
@@ -61,6 +62,9 @@ function defaultState() {
61
62
  // 老状态文件没这一格时靠这里兜底,别在别处再判一次「没有就拒绝」。
62
63
  pairingTier: 'full',
63
64
  lanEnabled: true, lanPort: 51887, lanSecret: crypto.randomBytes(32).toString('hex'), enabled: false,
65
+ // Bonjour 广播单独开关:关掉只停发布,局域网监听 / 地址候选 / 配对 / 二维码都不变。
66
+ // 老状态文件没这一格时按开,与历史行为一致。
67
+ lanDiscoveryEnabled: true,
64
68
  // 专属回环入口端口(默认 0 = 还没分配):worker 启动时绑定、宿主写回,手机配置口不开放。
65
69
  // 局域网默认 51887 与 0.0.0.0 绑定都不动,它是另外一条只听 127.0.0.1 的入口。
66
70
  tunnelIngressPort: 0,
@@ -143,8 +147,6 @@ function loadState() {
143
147
  // 「明确没有中转」,地址当场被清空。所以先把这一格撤掉,交给收敛函数从 relayUrl 生出来。
144
148
  if (!Object.prototype.hasOwnProperty.call(raw, 'relayUrls')) delete merged.relayUrls;
145
149
  const state = normalizeRelayAddresses(merged);
146
- // 废弃的内置中转地址在老配置里按残留数据直接清掉(纯清理,不写任何停用/回补语义)。
147
- stripDeprecatedBuiltinRelays(state);
148
150
  return state;
149
151
  } catch {
150
152
  const state = defaultState();
@@ -194,7 +196,6 @@ function rotateIdentity(state) {
194
196
 
195
197
  function saveState(state) {
196
198
  normalizeRelayAddresses(state);
197
- stripDeprecatedBuiltinRelays(state);
198
199
  fs.mkdirSync(path.dirname(STATE_FILE), { recursive: true });
199
200
  const tmp = `${STATE_FILE}.tmp`;
200
201
  fs.writeFileSync(tmp, JSON.stringify(state, null, 2), { mode: 0o600 });
@@ -334,46 +335,8 @@ function tunnelWsUrl(relayUrl) {
334
335
  function signLanToken(secret, instanceId, ttlSec = MOBILE_TOKEN_TTL_SEC) { return sharedToken.signLanToken(secret, instanceId, ttlSec); }
335
336
  function verifyLanToken(secret, token, instanceId) { return sharedToken.verifyLanToken(secret, token, instanceId); }
336
337
 
337
- /**
338
- * 曾经内置、现已废弃的中转 host。
339
- *
340
- * 这几台前几版作为内置地址发给过用户(dsh.iouf.cn / dsh.yfyidc.cn / ai-hub-jd-1 是更早的
341
- * 面板项,ai-hub-de-1 是最后一版内置地址),现已全部停止提供。老配置里残留的按废弃地址
342
- * 直接清掉:纯数据清理,不保留识别或回补语义,也不据此判断用户是否配了自己的线路。
343
- */
344
- const DEPRECATED_BUILTIN_RELAY_HOSTS = new Set([
345
- 'ai-hub-de-1.wnluo.com',
346
- 'ai-hub-jd-1.wnluo.com',
347
- 'dsh.iouf.cn',
348
- 'dsh.yfyidc.cn',
349
- ]);
350
- function isDeprecatedBuiltinRelayUrl(url) {
351
- try {
352
- return DEPRECATED_BUILTIN_RELAY_HOSTS.has(new URL(String(url).trim()).host.toLowerCase());
353
- } catch {
354
- return false;
355
- }
356
- }
357
-
358
- /**
359
- * 把废弃的内置中转地址从配置两格里剔掉(就地改 `state`,返回有没有改动)。
360
- *
361
- * 读盘与落盘都无条件调用:命中即删,不判断列表里还有没有别的地址,也不写任何
362
- * 「停用 / 回补」标记。删空了就让 `relayUrl` 也空,`relayUrls[0] === relayUrl` 的不变式
363
- * 在这里一并维持。
364
- */
365
- function stripDeprecatedBuiltinRelays(state) {
366
- if (!state || typeof state !== 'object') return false;
367
- const relay = relayAddressesOf(state);
368
- const kept = relay.relayUrls.filter((url) => !isDeprecatedBuiltinRelayUrl(url));
369
- if (kept.length === relay.relayUrls.length) return false;
370
- state.relayUrls = kept;
371
- state.relayUrl = kept.length ? kept[0] : '';
372
- return true;
373
- }
374
-
375
338
  module.exports = {
376
339
  STATE_FILE, MOBILE_TOKEN_TTL_SEC, MOBILE_BEARER_TTL_SEC, defaultState, loadState, saveState, rotatePairing, rotateIdentity, genInstanceId, genPairingCode, genPairingTicket, genHistoryKey, ensureHistoryKey,
377
340
  tunnelWsUrl, normalizeRelayUrl, normalizeRelayUrlList, normalizeRelayAddresses, relayAddressesOf, applyRelayAddressPatch, signLanToken, verifyLanToken,
378
- isDeprecatedBuiltinRelayUrl, stripDeprecatedBuiltinRelays, DEPRECATED_BUILTIN_RELAY_HOSTS, MAX_RELAY_ADDRESSES,
341
+ MAX_RELAY_ADDRESSES,
379
342
  };
@@ -0,0 +1,89 @@
1
+ // IPv6 候选的本机「退休地址」探测:读系统网卡详情,把 preferred_lft 归零 / 标了 deprecated
2
+ // 的地址认出来,供候选生成直接过滤。Node 的 os.networkInterfaces() 不带这个状态,只能问系统。
3
+ //
4
+ // 这是旁路优化,不是可达性保证:任何读不到、解析不出、命令不存在的情况都退化成空集合(不过滤),
5
+ // 绝不让候选生成抛错或断链;真正的可达性由 ipv6-liveness 那层和手机侧实测兜底。
6
+ // 电信 PPPoE 重拨换前缀后,旧地址会先进入 deprecated 再消失 —— 这段窗口里它仍挂在网卡上、
7
+ // 看起来像正常全球单播,却已经收不到外面的连接,正是手机白等一次超时的来源。
8
+ 'use strict'
9
+
10
+ const { execFileSync } = require('node:child_process')
11
+
12
+ const CACHE_TTL_MS = 5 * 1000
13
+ const PROBE_TIMEOUT_MS = 3000
14
+
15
+ /** 模块级缓存:同一批候选生成(二维码 / connection-info / 总控上报)共用一次系统读取。 */
16
+ let cached = null
17
+
18
+ /**
19
+ * 从 ifconfig / ip -6 addr 的输出里认退休地址。
20
+ *
21
+ * macOS:`inet6 240e:... prefixlen 64 autoconf deprecated pltime 0 vltime ...`
22
+ * Linux:`inet6 240e:.../64 scope global deprecated ...` 下一行 `valid_lft ... preferred_lft 0sec`
23
+ * 只认 inet6 行上的 deprecated / pltime 0,以及紧跟其后的 preferred_lft 0sec。别的文本一律不算
24
+ * 答案 —— 读不出就当没有,宁可多报一条让手机探一次,也不能把还在用的地址误踢。
25
+ */
26
+ function parseRetiredAddresses(text) {
27
+ const out = []
28
+ const seen = new Set()
29
+ let lastAddress = null
30
+ const retire = (address) => {
31
+ const key = address.toLowerCase()
32
+ if (!seen.has(key)) {
33
+ seen.add(key)
34
+ out.push(key)
35
+ }
36
+ }
37
+ for (const line of String(text || '').split(/\r?\n/)) {
38
+ const hit = /^\s*inet6\s+([0-9a-fA-F:]+)(?:\/\d+)?\s*(.*)$/.exec(line)
39
+ if (hit) {
40
+ lastAddress = hit[1]
41
+ const rest = hit[2]
42
+ // macOS 把 deprecated / pltime 0 写在 inet6 行上;有就直接收。
43
+ if (/\bdeprecated\b/i.test(rest) || /\bpltime\s+0\b/i.test(rest)) retire(lastAddress)
44
+ continue
45
+ }
46
+ // Linux 把 lifetime 写在 inet6 的下一行:preferred_lft 归零就是退休。
47
+ if (lastAddress && /\bpreferred_lft\s+0sec\b/i.test(line)) retire(lastAddress)
48
+ }
49
+ return out
50
+ }
51
+
52
+ function commandFor(platform) {
53
+ if (platform === 'darwin') return { cmd: 'ifconfig', args: ['-a'] }
54
+ if (platform === 'linux') return { cmd: 'ip', args: ['-6', 'addr', 'show'] }
55
+ // Windows 的 netsh 输出形态随版本/语言变,读不出就不过滤(还有 liveness 与手机实测兜底)。
56
+ return null
57
+ }
58
+
59
+ /**
60
+ * 当前退休的 IPv6 地址(裸地址字符串)。`platform` / `execFileSync` / `now` 可注入,守卫不用真 fork 进程。
61
+ * 读不到一律回空数组,并按 TTL 缓存,避免每次取候选都 fork 一次。
62
+ */
63
+ function retiredAddresses(options = {}) {
64
+ const platform = typeof options.platform === 'string' ? options.platform : process.platform
65
+ const now = typeof options.now === 'function' ? options.now() : Date.now()
66
+ const ttlMs = Number(options.ttlMs) > 0 ? Number(options.ttlMs) : CACHE_TTL_MS
67
+ if (cached && cached.platform === platform && now - cached.at < ttlMs) return cached.value
68
+ let value = []
69
+ const command = commandFor(platform)
70
+ const exec = typeof options.execFileSync === 'function' ? options.execFileSync : (cmd, args) => execFileSync(cmd, args, {
71
+ encoding: 'utf8',
72
+ timeout: PROBE_TIMEOUT_MS,
73
+ stdio: ['ignore', 'pipe', 'ignore'],
74
+ maxBuffer: 1 << 20,
75
+ })
76
+ if (command) {
77
+ try {
78
+ value = parseRetiredAddresses(exec(command.cmd, command.args))
79
+ } catch {
80
+ value = []
81
+ }
82
+ }
83
+ cached = { platform, at: now, value }
84
+ return value
85
+ }
86
+
87
+ function reset() { cached = null }
88
+
89
+ module.exports = { parseRetiredAddresses, retiredAddresses, reset }
@@ -1,7 +1,7 @@
1
+ // 2026-11-29:端口被占即换号,只有显式固定端口才保留;去掉发现能力拦截。
1
2
  // 短暂占用先重试原端口;发现重发等待退订结束,失败保留底层原因。
2
3
  'use strict';
3
4
  // 只发布已监听入口;发布失败时停止换号,现有固定入口仍可使用。
4
- const { canChangeLanPort } = require('./lan-port-policy.cjs');
5
5
 
6
6
  const SERVICE_TYPE = 'dsh-mobile';
7
7
 
@@ -91,8 +91,8 @@ function createLanDiscovery({ instanceId, onChange = () => {}, makeBonjour = onE
91
91
  return { publish, stop, snapshot: () => ({ ...view }) };
92
92
  }
93
93
 
94
- /** 短暂占用先重试原入口;固定穿透与旧手机始终保留原端口。 */
95
- async function bindLanEndpoint({ requestedPort, createProxy, discovery, store, instanceId, lockReason = '', isCurrent = () => true,
94
+ /** 短暂占用先重试原入口;只有显式固定端口才保留原端口,其余占用即换号。 */
95
+ async function bindLanEndpoint({ requestedPort, createProxy, discovery, lockReason = '', isCurrent = () => true,
96
96
  retryDelays = [250, 750], wait = ms => new Promise(resolve => setTimeout(resolve, ms)) }) {
97
97
  let proxy;
98
98
  let changed = false;
@@ -104,10 +104,7 @@ async function bindLanEndpoint({ requestedPort, createProxy, discovery, store, i
104
104
  await proxy.stop();
105
105
  if (error?.code !== 'EADDRINUSE') throw error;
106
106
  if (attempt < retryDelays.length) { await wait(retryDelays[attempt]); continue; }
107
- if (lockReason) throw new Error(`端口 ${requestedPort} 已被占用;${lockReason === 'fixed' ? '已开启固定端口' : '穿透或固定地址依赖此端口'},未自动换端口。请释放占用后重试。`);
108
- if (!canChangeLanPort(store, instanceId)) {
109
- throw new Error(`端口 ${requestedPort} 已被占用;为保留旧版或未知能力手机的连接地址,未自动换端口。请释放占用后重试。`);
110
- }
107
+ if (lockReason) throw new Error(`端口 ${requestedPort} 已被占用;已开启固定端口,未自动换端口。请释放占用后重试。`);
111
108
  if (!isCurrent()) throw new Error('局域网配置已更新');
112
109
  proxy = createProxy(0);
113
110
  try { await proxy.start(); } catch (retryError) { await proxy.stop(); throw retryError; }
@@ -1,4 +1,5 @@
1
1
  // 反馈 1569:插件跑在容器里时容器内网 eth0 不进局域网候选(按容器标记判,不按 172 地址段)。
2
+ // 反馈 N1(IPv6 地址变化):退休 / deprecated 的全球单播地址不进候选,避免手机拨一条已经收不到连接的旧地址。
2
3
  // 反馈 1012:172.17/16 是真实 Wi-Fi 可用的私网段,容器 / 虚拟网卡改由网卡名黑名单挡。
3
4
  // 反馈 1562:节点小宝 NodeBabyLink 是第三方穿透 VPN 虚拟网卡,按网卡名挡,不进局域网候选。
4
5
  // 没有已监听端口时不产出可连接候选。
@@ -19,6 +20,7 @@ const os = require('node:os')
19
20
  const { isPrivateLanAddress } = require('../shared/private-address.js')
20
21
  const { normalizeIpVersionPolicy, allowsIpv6Candidates } = require('./net-family.cjs')
21
22
  const ipv6Liveness = require('./ipv6-liveness.cjs')
23
+ const ipv6Lifetime = require('./ipv6-lifetime.cjs')
22
24
 
23
25
  // 出站协议族策略与 IPv6 候选活性账都放在模块级:同一进程里所有取候选的入口共用一份。
24
26
  // 每个进程(宿主 / worker)各自把自己那份配置口径设进来即可,见 `setIpVersionPolicy`。
@@ -291,24 +293,32 @@ function isGlobalUnicastV6(address) {
291
293
  * ——候选是随二维码一起带走的,条数一多二维码就密到扫不动。
292
294
  */
293
295
  const IPV6_CANDIDATE_MAX = 4
294
- function ipv6Interfaces(port, interfaces = os.networkInterfaces()) {
296
+ /**
297
+ * @param {object} [opts] `opts.retired` 可注入退休地址名单(函数或数组),供守卫不必真读系统网卡。
298
+ */
299
+ function ipv6Interfaces(port, interfaces = os.networkInterfaces(), opts = {}) {
295
300
  // ipv4-only:整条 IPv6 直连通道不产出,手机也就不会拿到会超时的 v6 候选。
296
301
  if (!allowsIpv6Candidates(ipVersionPolicy)) return []
297
- const all = toCandidates(collectEndpoints(interfaces, isGlobalUnicastV6, 'IPv6'), port, 'IPv6')
302
+ // 退休地址(PPPoE 重拨换前缀后的旧地址)先踢掉:它还挂在网卡上、长得也像全球单播,
303
+ // 但已经收不到外面的连接。读不到系统详情时名单为空,退回老行为,不让候选生成断链。
304
+ const retired = typeof opts.retired === 'function' ? opts.retired() : (opts.retired || ipv6Lifetime.retiredAddresses())
305
+ const retiredNumbers = new Set((Array.isArray(retired) ? retired : []).map(ipv6Number).filter((v) => v !== null))
306
+ const accept = (address) => isGlobalUnicastV6(address) && !retiredNumbers.has(ipv6Number(address))
307
+ const all = toCandidates(collectEndpoints(interfaces, accept, 'IPv6'), port, 'IPv6')
298
308
  .slice(0, IPV6_CANDIDATE_MAX)
299
309
  // 本机活性预筛:已知连不上的(临时地址轮换/前缀撤销后的死地址)先从候选里过滤掉,别再发给手机。
300
310
  // 首轮没有结论时原样返回,探测在后台补齐(旁路,失败不影响候选生成)。
301
311
  const alive = new Set(ipv6Liveness.defaultCache.filter(all.map((candidate) => candidate.url)))
302
312
  return all.filter((candidate) => alive.has(candidate.url))
303
313
  }
304
- function ipv6Urls(port, interfaces = os.networkInterfaces()) {
305
- return ipv6Interfaces(port, interfaces).map((candidate) => candidate.url)
314
+ function ipv6Urls(port, interfaces = os.networkInterfaces(), opts = {}) {
315
+ return ipv6Interfaces(port, interfaces, opts).map((candidate) => candidate.url)
306
316
  }
307
- function ipv6Candidates(port, interfaces = os.networkInterfaces()) {
317
+ function ipv6Candidates(port, interfaces = os.networkInterfaces(), opts = {}) {
308
318
  // 与 `advertisedCandidates` 同一条口径:取不到网卡(异常)时回空清单、绝不抛 —— 它喂的
309
319
  // 也是二维码与 `/connection-info`,把它整条控制面拖下水不值得。
310
320
  try {
311
- return ipv6Interfaces(port, interfaces)
321
+ return ipv6Interfaces(port, interfaces, opts)
312
322
  } catch {
313
323
  return []
314
324
  }
@@ -1,18 +1,10 @@
1
+ // 2026-11-29:只有显式固定端口才锁原端口;端口被占即换号,不再看发现能力或穿透/手填地址。
1
2
  'use strict';
2
- // 固定入口禁止漂移;新端口仅在监听和发现发布成功后保存。
3
- // 没有活凭据就没有手机会拿旧端口找回来,此时占用可换号;有活设备仍按发现能力保护。
3
+ // 只有用户自己勾了「固定端口」才锁原入口;端口被占就换一个可用的,谁也不拦。
4
+ // 换号后由自带隧道各自跟随落点(见装配层 syncNetwork)。
4
5
 
5
- function lanPortLockReason(state, forwarding = false) {
6
- if (state.lanPortFixed === true) return 'fixed';
7
- if (forwarding || state.manualLanUrl || state.manualIpv6Url || state.manualTcpUrl) return 'forwarding';
8
- return '';
9
- }
10
-
11
- function canChangeLanPort(store, instanceId) {
12
- store.refresh?.();
13
- const rows = store.listActive().filter(row => row.instanceId === instanceId && row.kind !== 'computer');
14
- // 没有活设备就没有手机会拿旧端口找回来;有活设备仍要求全部支持发现。
15
- return rows.length === 0 || rows.every(row => row.lanDiscovery === 1);
6
+ function lanPortLockReason(state) {
7
+ return state.lanPortFixed === true ? 'fixed' : '';
16
8
  }
17
9
 
18
10
  function createLanPortPolicy({ state, saveState }) {
@@ -42,4 +34,4 @@ function createLanPortPolicy({ state, saveState }) {
42
34
  };
43
35
  }
44
36
 
45
- module.exports = { lanPortLockReason, canChangeLanPort, createLanPortPolicy };
37
+ module.exports = { lanPortLockReason, createLanPortPolicy };
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:需求变为不接老配对——/__lan_pair 的六位码入口直接拒掉,带票据的二维码照常配。
1
2
  // 2026-11-29:配对口不再按来源拒公网 IPv6,与公网 IPv4 同走全局令牌桶。
2
3
  // 2026-11-28:回环来源的通道标注从 lan 改记 tunnel,第三方穿透不再显示成「局域网」。
3
4
  // 2026-11-25:多开一条只听 127.0.0.1 的专属入口,与主入口共用 handleRequest;被占则内核另分一次并报上去。
@@ -27,7 +28,6 @@ const http = require('node:http');
27
28
  const { WebSocketServer, WebSocket } = require('ws');
28
29
  const core = require('./core.js');
29
30
  const { advertisedCandidates, ipv6Candidates, isGlobalUnicastV6 } = require('./lan-network.cjs');
30
- const { safeEqual } = require('../shared/dshtoken');
31
31
  const { isFreshRequest } = require('../shared/fresh-request');
32
32
  const { encodeJsonBody } = require('../shared/http-util');
33
33
  const { withViaHeader } = require('../shared/via-header');
@@ -866,7 +866,8 @@ function createLanProxy(opts) {
866
866
  const input = JSON.parse(b || '{}')
867
867
  // 校验用的码 / 票据 / 实例号以主进程为准(旁车缓存那份可能和二维码错开)。
868
868
  const pairing = await resolvePairing();
869
- // 两种形状(§8.3(2)):带 `sealed` 是协议 v2,带 `code` 是旧 App。
869
+ // 协议 v2 的形状:带 `sealed`。没有 sealed 的六位码入口不再受理
870
+ //(需求变为不接老配对),带 `proto` 的过期旧图在上面按重扫当前二维码收口。
870
871
  const sealed = typeof input?.sealed === 'string' ? input.sealed.trim() : '';
871
872
  // 与 `/pair` 同一条收口(§10.4(d)):认得协议(请求里带 `proto`)却还带
872
873
  // 六位码,只可能是过期的旧二维码 —— 那条形状逐位可试,不值得继续开门。
@@ -903,34 +904,19 @@ function createLanProxy(opts) {
903
904
  issuedExtra = { deviceKey: opened.deviceKey, keyId: opened.keyId };
904
905
  pairKey = opened.pairKey;
905
906
  } else {
906
- const code = typeof input?.code === 'string' ? input.code.trim() : '';
907
- // 长度不符直接判错(timingSafeEqual 长度不同会抛异常,曾导致整个 dsh web 崩溃)
908
- if (!/^\d{6}$/.test(code)) {
909
- res.writeHead(400, { 'content-type': 'application/json' });
910
- res.end(JSON.stringify({ ok: false, error: '配对码需为 6 位数字' }));
911
- return;
912
- }
913
- if (!safeEqual(code, String(pairing.code || ''))) {
914
- log('lan pair: pairing code mismatch')
915
- pairThrottle.noteFail();
916
- pairDenied(res);
917
- return;
918
- }
919
- suppliedDevice = input && typeof input.device === 'object' && input.device !== null
920
- ? input.device
921
- : {
922
- name: input?.name,
923
- platform: input?.platform,
924
- osVersion: input?.osVersion,
925
- version: input?.version,
926
- appVersion: input?.appVersion,
927
- id: input?.id,
928
- deviceId: input?.deviceId,
929
- }
907
+ // 需求变为不接老配对:无 proto 的六位码入口会新产生明文会话,官方二维码
908
+ // 都带票据,这个入口直接拒掉,提示用当前二维码重新扫。码的真假不再校验。
909
+ res.writeHead(400, { 'content-type': 'application/json' });
910
+ res.end(JSON.stringify({
911
+ ok: false,
912
+ code: 'pairing-code-retired',
913
+ error: '六位配对码已停用,请用电脑面板上当前的二维码重新扫',
914
+ }));
915
+ return;
930
916
  }
931
- // 配对码正确 / 票据解得开 → 桌面端授权(TeamViewer 模型)。透传手机端完整设备元数据。
917
+ // 票据解得开 → 桌面端授权(TeamViewer 模型)。透传手机端完整设备元数据。
932
918
  // 注意:这里**不**清限流计数——被拒绝的尝试同样要计数,否则
933
- // 猜对配对码但被拒的一方可以无限次重试。
919
+ // 拿得到票据但被拒的一方可以无限次重试。
934
920
  const device = {
935
921
  ...Object.fromEntries(Object.entries(suppliedDevice || {}).filter(([, value]) => value !== undefined)),
936
922
  ip: (suppliedDevice && suppliedDevice.ip) || ip,
@@ -939,8 +925,8 @@ function createLanProxy(opts) {
939
925
  .then(({ approved, token, platform }) => {
940
926
  if (!approved) {
941
927
  // 走到这里才是「电脑真的放行策略拒绝了它」;内部没答上那条已在
942
- // onApprove 里抛成 5xx,不会冒充这句。与「配对码错误」返回同一响应,
943
- // 配对码不再可通过状态码探测。
928
+ // onApprove 里抛成 5xx,不会冒充这句。与「解不开票据」返回同一响应,
929
+ // 授权结果不再可通过状态码探测。
944
930
  log('lan pair: approval denied by host policy')
945
931
  pairDenied(res);
946
932
  return;
@@ -1,3 +1,5 @@
1
+ // 2026-11-30:放大弹窗的勾选预览走 `pairingPayload.filterInclude`——按 query 只换码内容,不落盘、不动票据。
2
+ // 2026-11-29:公网 IPv6 也能单独撑起一张配对码——宿主侧拒 IPv6 的限制已删,出码判据跟上。
1
3
  // 2026-11-27:进二维码的服务商线路名字截到 40 字——名字只是显示用,长名字能把码撑到扫不出来。
2
4
  // 2026-11-24:服务商的 http(s) 地址同时进 lanUrls,让不认 routes 的老包也能扫码走服务商直连;
3
5
  // 二维码只带电脑自己配的线路,新机没自己的线路时蜂窝首次配对失败属于预期。
@@ -26,6 +28,7 @@ const {
26
28
  advertisedCandidates,
27
29
  phoneCandidates,
28
30
  manualCandidate,
31
+ manualIpv4Candidate,
29
32
  ipv6Candidates,
30
33
  withManualIpv4Candidate,
31
34
  withManualIpv6Candidate,
@@ -182,6 +185,72 @@ function pairingPayload(state, lanPort) {
182
185
  return { payload, text: pairingText(payload) };
183
186
  }
184
187
 
188
+ /**
189
+ * 放大弹窗里那五类勾选的预览过滤(`/api/relay/pairing?include=`)。
190
+ *
191
+ * 只在调用方明确带了 `?include=` 时才起作用;参数缺失,或者五类全在集合里,都原样返回——
192
+ * 默认那张码必须与没有这个功能时逐字一致。过滤是**就地把这次生成的 payload 削一削**,
193
+ * 不碰 state、不换票据、不写配置;调用方随后还会照常做 pairingHasAddress 判定,空集合自然出不了码。
194
+ *
195
+ * `lanUrls` 里混着三类地址:网卡扫出来的、用户手填的(含手填 IPv4),以及 TCP 桥那条
196
+ * `http://host:port`。这里按来源把它们分开:手填的认设置项,TCP 认 `tcpDirectTarget`,
197
+ * 剩下的才算「局域网自动发现」。服务商线路与 Cloudflare 是独立那一栏,不在这五类里,
198
+ * 仍按原样留在 `routes` 与 `lanUrls`。
199
+ *
200
+ * 挂在 `pairingPayload` 上而不是在控制面顶部加一条 import:出码那两行取样代码是票据复核的
201
+ * 基准(见 test/control-plane-routes.test.cjs 的变异用例),保持它原样最省事。
202
+ */
203
+ const PAIRING_INCLUDE_KEYS = ['relay', 'lan', 'direct', 'ipv6', 'tcp'];
204
+
205
+ /** query 值 → 勾选集合;参数缺失(`null`)表示全选。未知 token 忽略,全选等价于不过滤。 */
206
+ function parsePairingInclude(raw) {
207
+ if (raw === null || raw === undefined) return null;
208
+ const set = new Set(String(raw).split(',').map((part) => part.trim().toLowerCase())
209
+ .filter((part) => PAIRING_INCLUDE_KEYS.includes(part)));
210
+ if (PAIRING_INCLUDE_KEYS.every((key) => set.has(key))) return null;
211
+ return set;
212
+ }
213
+
214
+ function filterPairingInclude(payload, raw, state) {
215
+ const include = parsePairingInclude(raw);
216
+ if (!include || !payload || typeof payload !== 'object') return payload;
217
+ const keep = (key) => include.has(key);
218
+
219
+ if (!keep('relay')) {
220
+ delete payload.relayUrl;
221
+ delete payload.relayUrls;
222
+ }
223
+ if (!keep('ipv6')) delete payload.ipv6Candidates;
224
+ if (!keep('tcp')) delete payload.tcpUrl;
225
+ if (!keep('direct')) delete payload.directUrl;
226
+
227
+ const manual = new Set();
228
+ if (state && state.lanEnabled) {
229
+ const direct = manualCandidate(state.manualLanUrl);
230
+ if (direct) manual.add(direct.url);
231
+ const ipv4 = manualIpv4Candidate(state.manualIpv4Url);
232
+ if (ipv4) manual.add(ipv4.url);
233
+ }
234
+ const tcpTarget = tcpDirectTarget(state && state.manualTcpUrl);
235
+ const tcpLanUrl = tcpTarget ? `http://${tcpTarget}` : '';
236
+ // 服务商线路不在这五类里:routes 整栏照旧,写进 lanUrls 的那份兼容副本也照旧。
237
+ const routeUrls = new Set((Array.isArray(payload.routes) ? payload.routes : [])
238
+ .filter((row) => row && row.transport === 'http' && typeof row.url === 'string')
239
+ .map((row) => row.url));
240
+ if (Array.isArray(payload.lanUrls)) {
241
+ payload.lanUrls = payload.lanUrls.filter((url) => {
242
+ if (routeUrls.has(url)) return true;
243
+ if (manual.has(url)) return keep('direct');
244
+ if (tcpLanUrl && url === tcpLanUrl) return keep('tcp');
245
+ return keep('lan');
246
+ });
247
+ }
248
+ return payload;
249
+ }
250
+
251
+ pairingPayload.parseInclude = parsePairingInclude;
252
+ pairingPayload.filterInclude = filterPairingInclude;
253
+
185
254
  /**
186
255
  * 载荷 → 二维码里那一串 `dshpair://`。
187
256
  *
@@ -197,7 +266,11 @@ function pairingText(payload) {
197
266
  * 这张二维码里有没有一条手机能拿去配对的路。
198
267
  *
199
268
  * 配对这一刻能拨的:中转、局域网 / 直连 / TCP 桥(都在 `lanUrls`)、服务商线路(`routes`)、
200
- * 隧道与点对点。IPv6 候选只做配对后的数据通道(宿主拒公网 IPv6 来源的配对),不算。
269
+ * 隧道与点对点、以及公网 IPv6 候选。
270
+ *
271
+ * IPv6 从「不算」改成「算」:原判据说「宿主拒公网 IPv6 来源的配对」,那条限制 2026-11-29
272
+ * 已删(限流换成不看来源的全局令牌桶,旧理由不成立);二维码与心跳一直把 IPv6 当可用线路
273
+ * 报给手机、App 也把它当合法配对入口,唯独出码判据还拦着,一台只有公网 IPv6 的电脑就出不了码。
201
274
  *
202
275
  * 面板与命令行两个出码入口都调这一个判据。以前各写一遍、都把 `routes` 漏了,结果一台
203
276
  * 「只接了一家服务商」的机器(比如只挂 ZeroNews / 节点小宝 / FRP 自建 TCP)二维码出不来,
@@ -209,9 +282,10 @@ function pairingHasAddress(payload) {
209
282
  (typeof p.relayUrl === 'string' && p.relayUrl)
210
283
  || (Array.isArray(p.lanUrls) && p.lanUrls.length > 0)
211
284
  || (Array.isArray(p.routes) && p.routes.length > 0)
285
+ || (Array.isArray(p.ipv6Candidates) && p.ipv6Candidates.length > 0)
212
286
  || p.tailcat
213
287
  || p.p2p,
214
288
  );
215
289
  }
216
290
 
217
- module.exports = { pairingPayload, pairingText, pairingHasAddress };
291
+ module.exports = { pairingPayload, pairingText, pairingHasAddress, parsePairingInclude, filterPairingInclude, PAIRING_INCLUDE_KEYS };
@@ -1,9 +1,11 @@
1
1
  // IPv6 候选按真实监听端口生成,独立于 IPv4 局域网候选开关。
2
2
  // 2026-11-22:远程桌面候选也带上插件上报的第三方线路(含 ZeroNews),与手机共用同一批。
3
+ // 2026-11-29:补齐 Cloudflare / 节点小宝 / FRP —— 统一走 providerLinesOf,与手机同源不再分叉。
3
4
  'use strict';
4
5
  // 电脑间已认证控制信令只提供隧道会合,目标固定为本机插件入口。
5
6
  const { relayAddressesOf } = require('../relay/core.js');
6
7
  const { advertisedCandidates, phoneCandidates, ipv6Candidates, withManualIpv6Candidate, tcpDirectTarget } = require('../relay/lan-network.cjs');
8
+ const { providerLinesOf } = require('../relay/provider-lines.cjs');
7
9
 
8
10
  function routesOf({ state, lanPortInUse, lanAvailable = () => state.lanEnabled, interfaces }) {
9
11
  const routes = [];
@@ -28,14 +30,18 @@ function routesOf({ state, lanPortInUse, lanAvailable = () => state.lanEnabled,
28
30
  // 所以这里必须把它也当候选,否则远程电脑反而少一条可用的公网线路。
29
31
  const tcp = tcpDirectTarget(state.manualTcpUrl);
30
32
  if (tcp) push(`http://${tcp}`, 'tcp');
31
- // 通用线路:手机与远程桌面共用同一批。ZeroNews 由插件自己读本机 API 写进独立字段;
32
- // 其余线路由接入方运行时写入。远程侧按 URL + 通道名记账,custom 作为表外通道排最后。
33
- const zeroNews = typeof state.zeroNewsUrl === 'string' ? state.zeroNewsUrl.trim().replace(/\/+$/, '') : '';
34
- if (zeroNews) push(zeroNews, 'custom');
35
- for (const route of (Array.isArray(state.customRoutes) ? state.customRoutes : [])) {
36
- if (!route || typeof route !== 'object') continue;
37
- push(customRouteUrl(route.url, route.transport), 'custom');
38
- }
33
+ // 通用线路:手机与远程桌面共用同一份 providerLinesOf —— ZeroNews / 节点小宝 / FRP /
34
+ // 用户自定义都从这一处出,避免远程侧再各拼一遍、像以前那样漏掉后三家。tcp 的 host:port 补
35
+ // http 前缀(远程侧要的是可解析 URL),custom 作为表外通道排最后。
36
+ for (const line of providerLinesOf(state)) push(customRouteUrl(line.url, line.transport), 'custom');
37
+ // Cloudflare 兜底隧道:providerLinesOf 刻意不收它(免得手机把它当第三方线路重复画),
38
+ // 但远程桌面通道表里它是独立的一档、面板也显示,所以这里单独补一条。命名隧道优先于快速隧道,
39
+ // 与二维码 / 总控同一口径。
40
+ const cfRaw = typeof state.cloudflareNamedUrl === 'string' && state.cloudflareNamedUrl.trim()
41
+ ? state.cloudflareNamedUrl
42
+ : state.cloudflareUrl;
43
+ const cf = typeof cfRaw === 'string' ? cfRaw.trim().replace(/\/+$/, '') : '';
44
+ if (cf) push(cf, 'cloudflare');
39
45
  return routes;
40
46
  }
41
47
  /** 通用线路地址:http(s) 原样,tcp 的 host:port 补 http 前缀(远程侧要的是可解析 URL)。 */
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:出码路由支持 ?include= 勾选预览:只换二维码内容,不落盘、不作废票据。
1
2
  // 2026-11-28:新增语音面板配置口(/api/relay/voice/config),纳入网页访问窗口。
2
3
  // 2026-11-27:面板中转检测与 APP 同判据——不跟跳、回包必须 ok 且服务名正确,别再给假绿灯。
3
4
  // 2026-11-27:二维码回归一次性门票——隧道段只在唯一通路时进码,点对点只带身份不带候选清单。
@@ -1213,7 +1214,14 @@ function registerControlPlaneRoutes(deps) {
1213
1214
  * 配置」,等于拿一条还没验过的地址覆盖正在用的设置;现在预览走这里,真写入只在用户
1214
1215
  * 明确按下「连接中转」时发生。
1215
1216
  */
1216
- const preview = typeof req.url === 'string' ? new URL(req.url, 'http://local').searchParams.get('relayUrl') : null
1217
+ const query = typeof req.url === 'string' ? new URL(req.url, 'http://local').searchParams : null
1218
+ const preview = query ? query.get('relayUrl') : null
1219
+ /**
1220
+ * `?include=` 是放大弹窗那五类勾选的**预览参数**:relay / lan / direct / ipv6 / tcp 的逗号集合。
1221
+ * 与上面的 `?relayUrl=` 同一条规矩——只换这一张码的内容,不写配置、不作废票据;参数缺失
1222
+ * (以及五类全选)由 `filterInclude` 原样放过,生成的码与没有这个功能时逐字一致。
1223
+ */
1224
+ const include = query ? query.get('include') : null
1217
1225
  // 预览那一份要**两格一起换**:只改 `relayUrl` 的话,state 上原来那组 `relayUrls` 会
1218
1226
  // 按「列表优先」把预览地址盖回去,面板上填了新域名却还是旧的那张码。
1219
1227
  const previewUrl = preview && /^https?:\/\/[^\s]+$/i.test(preview.trim())
@@ -1233,6 +1241,8 @@ function registerControlPlaneRoutes(deps) {
1233
1241
  }
1234
1242
  const source = previewUrl ? { ...state, relayUrl: previewUrl, relayUrls: [previewUrl] } : state
1235
1243
  const { payload } = pairingPayload(source, lanPortInUse())
1244
+ // 勾选预览:就在这一份 payload 上剔字段,下面验票 / 地址判定 / SVG 全用剔过的那份。
1245
+ if (include !== null) pairingPayload.filterInclude(payload, include, source)
1236
1246
  // 隧道这一整段又长又敏感(地址、钥匙、证明),而它是**配好之后**才需要的数据通道:
1237
1247
  // 手机配完凭已经通着的那条连接报名就能换到入口地址。所以只有它本身就是唯一通路
1238
1248
  // (没中转、没局域网/服务商线路)时才写进码里;有别的路可走就不重复投递。
@@ -1,3 +1,4 @@
1
+ // 2026-11-30:五类真实动作的成功回包记账,按设备时间经 activity 的状态出口带出去。
1
2
  // 2026-11-29:挂语音自动学习词库接口 /voice/lexicon/learn。
2
3
  // 2026-11-28:语音流升级路由改由装配层显式交 ctx(取值器),不再只靠运行时记下的那一个。
3
4
  // 2026-11-28:挂语音网关三条移动路由(能力表 / 整段 / 流式升级),实现在 mobile/voice/。
@@ -115,6 +116,8 @@ const sync = require('../mobile/sync.js');
115
116
  const { createTransferTickets } = require('../mobile/transfer-tickets.js');
116
117
  const { createSyncInboxStore } = require('../mobile/sync-inbox-store.js');
117
118
  const { credentialsEntry } = require('../shared/credentials-entry.js');
119
+ // 五类真实操作的记账:包装层只看这五条路径的成功回包,其它一律不碰。
120
+ const activity = require('../mobile/activity.cjs');
118
121
  const { handleCredentialUpgrade } = require('../mobile/credential-upgrade.js');
119
122
  const { handleSyncIdentity } = require('../mobile/claim-identity.js');
120
123
  const extensions = require('../mobile/extensions.js');
@@ -295,7 +298,7 @@ function registerMobileRoutes(deps) {
295
298
  const tunnel = getSidecarSnapshot?.()?.tunnel
296
299
  return state.enabled && tunnel?.state === 'connected' ? tunnel.relayUrl || tunnel.route?.url || null : null
297
300
  }
298
- const route = (path, handler) => registerRoute({ kind: 'exact', path, handler: guarded(handler) })
301
+ const route = (path, handler) => registerRoute({ kind: 'exact', path, handler: guarded(activity.withInteractionNote(path, handler)) })
299
302
  // 只能 POST 的写路由:路由注册器不分方法,若不挡,GET 带查询串也能进写 handler
300
303
  // (Forge 的读体会回落到查询串),等于给了个可被链接/预取误触的写入口。
301
304
  const postOnly = (handler) => (ctx, req, res) => (req.method === 'POST'
@@ -1,6 +1,6 @@
1
+ // 2026-11-29:不再上报/保存局域网发现能力位。
1
2
  'use strict';
2
3
  // 包名 / 构建号 / 渠道也随身份头上报:AI 反馈提交要按真实安装包报身份(2026-11-18)。
3
- // 本地发现能力只在鉴权成功后随设备元信息保存。
4
4
 
5
5
  /**
6
6
  * 手机每次请求顺带上来的身份:设备名、机型、平台、系统版本、App 版本。
@@ -78,8 +78,6 @@ function deviceMetaFromHeaders(req) {
78
78
  if (buildNumber) meta.buildNumber = buildNumber;
79
79
  const channel = headerText(headers, CHANNEL_HEADER);
80
80
  if (channel) meta.channel = channel;
81
- const discovery = headerText(headers, 'x-dsh-lan-discovery');
82
- if (discovery === '1' || discovery === '0') meta.lanDiscovery = Number(discovery);
83
81
  return meta;
84
82
  }
85
83