dsh-plugin-mesh 0.5.1 → 0.5.2

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.
package/AGENTS.md CHANGED
@@ -146,7 +146,7 @@ If you must release from this machine (offline, or the pipeline is broken):
146
146
 
147
147
  ```bash
148
148
  npm run check && npm test
149
- npm run release-plugin -- --publish # tarball -> GitHub release -> LAN mirror
149
+ ./scripts/release-plugin.sh --publish # tarball -> GitHub release -> LAN mirror
150
150
  npm publish # npm; publishConfig pins the public registry
151
151
  ```
152
152
 
package/README.md CHANGED
@@ -37,7 +37,6 @@ DSH 的 Mesh 插件:**启动后自动发现同一网段的其他 DSH 实例**
37
37
 
38
38
 
39
39
  # 进程版本 ≠ 磁盘版本 → [WARN] 新代码**没**被加载,检查 plugins 挂载
40
- ```
41
40
 
42
41
  (不依赖 `node`:优先 `python3` 解 JSON,退回到正则抠 `version` 字段。)
43
42
 
@@ -402,7 +401,7 @@ VPN,换网 MAC 就变;iOS / Android / macOS 现在默认按 SSID 使用随
402
401
 
403
402
  名字是人手填的,可能撞。页面会检测并告警,派发时也不会随便挑一台:
404
403
 
405
- - **从 A 看**:`--peer winbox` 只要在 A 的上游对端里唯一就能用(自己不算)
404
+ - **从 A 看**:`mesh_run` 的 `peer` 填 `winbox`,只要在 A 的上游对端里唯一就能用(自己不算)
406
405
  - **从第三台机器看**:如果它发现有两台都叫 winbox,`mesh_run` 会**拒绝**并列出候选,
407
406
  让你改用 `<ip>:<port>` 精确定位
408
407
 
@@ -496,7 +495,7 @@ dsh plugin add /path/to/dsh-plugin-mesh
496
495
 
497
496
  ### 升级已安装的插件
498
497
 
499
- `release-plugin.sh --publish` 发完版会**自动同步到局域网镜像**并打印一段可直接
498
+ `scripts/release-plugin.sh --publish` 发完版会**自动同步到局域网镜像**并打印一段可直接
500
499
  粘贴到对端的命令。对端(尤其是 Android,见下面的 `/tmp` 坑)执行后**必须重启 DSH**
501
500
  才会加载新版本。
502
501
 
@@ -666,7 +665,7 @@ agent 多出四个工具:
666
665
  # ── 循环限速 ──
667
666
  maxWakesPerThread: 30 # 每窗口内最多自动唤醒几次;0 = 不限制
668
667
  threadWindowMs: 3600000 # 窗口长度(毫秒),默认 1 小时
669
- threadCooldownMs: 20000 # 两次自动唤醒的最小间隔;0 = 不限制
668
+ threadCooldownMs: 5000 # 两次自动唤醒的最小间隔;0 = 不限制
670
669
  minTaskChars: 24 # 正文短于此长度只入箱不唤醒(挡 ping/ack)
671
670
  ```
672
671
 
@@ -683,7 +682,7 @@ Mesh 页面看到,不会被丢弃):
683
682
  |---|---|---|
684
683
  | `minTaskChars` | 24 | 太短的内容不开会话 |
685
684
  | 寒暄识别 | 内置 | `ping` / `ack` / `收到` / `好的` 等整条即寒暄的,不开会话 |
686
- | `threadCooldownMs` | 20s | 同一 thread 不会连续秒回,管**突发** |
685
+ | `threadCooldownMs` | 5s | 同一 thread 不会连续秒回,管**突发** |
687
686
  | `maxWakesPerThread` | 30 | 同一 thread 在 `threadWindowMs` 内的唤醒上限,管**持续速率** |
688
687
 
689
688
  `maxWakesPerThread` 是**滑动窗口限速,不是终身配额**:只统计最近
@@ -7,7 +7,8 @@
7
7
  * node lib/_selftest-capabilities.mjs
8
8
  */
9
9
  import { strict as assert } from "node:assert";
10
- import { homedir } from "node:os";
10
+ import { homedir, tmpdir } from "node:os";
11
+ import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
11
12
  import { join } from "node:path";
12
13
  import {
13
14
  augmentedPath,
@@ -35,6 +36,7 @@ import {
35
36
  __storeAliasDir,
36
37
  __hasUncertainProbe,
37
38
  __probeFailCount,
39
+ __isUncertain,
38
40
  } from "./capabilities.js";
39
41
  import { MeshDiscovery, APP_TAG } from "./discovery.js";
40
42
 
@@ -413,6 +415,28 @@ test("Store 别名目录(WindowsApps)不算「补全真的生效」的证据
413
415
  assert.ok(!__storeAliasDir.test(String.raw`C:\tools\WindowsApps\extra`), "只排除该目录本身,不误伤子目录");
414
416
  });
415
417
 
418
+ test("探测 PATH 不再前置 WindowsApps(0 字节 Store 存根不能遮住真实运行时)", () => {
419
+ // 构造一个只存在 WindowsApps 的 LOCALAPPDATA。修复前 extraPathDirs() 会把它
420
+ // 加进候选;修复后必须为空 —— 否则它会排在真实 python/node 前面。
421
+ const tmp = mkdtempSync(join(tmpdir(), "mesh-path-"));
422
+ try {
423
+ mkdirSync(join(tmp, "Microsoft", "WindowsApps"), { recursive: true });
424
+ const dirs = __extraPathDirs("win32", { LOCALAPPDATA: tmp });
425
+ assert.ok(
426
+ !dirs.some((d) => __storeAliasDir.test(d)),
427
+ `不该把 WindowsApps 补进探测 PATH:${dirs.join(", ")}`,
428
+ );
429
+ } finally {
430
+ rmSync(tmp, { recursive: true, force: true });
431
+ }
432
+ });
433
+
434
+ test("exit-9009(Store 存根)算「不确定」,不能当「没装」", () => {
435
+ assert.equal(__isUncertain("exit-9009"), true);
436
+ assert.equal(__isUncertain("ENOENT"), false);
437
+ assert.equal(__isUncertain("timeout"), true);
438
+ });
439
+
416
440
  test("对端 Android:6 项 ENOENT 确实都没装(它自查 command -v 确认)", () => {
417
441
  // 对端跑过 command -v:go/docker/rustc/java/ffmpeg/adb **全部 absent**,
418
442
  // 所以它那台**没有缺陷**。这条用例记的是"它曾经被误判成活反例"这件事:
@@ -54,7 +54,7 @@ check("detectTarget 给出当前平台", () => {
54
54
 
55
55
  check("assetName 命名与 sidecar 构建脚本一致", () => {
56
56
  const name = assetName();
57
- assert.match(name, /^dsh-mesh-tsnet-(darwin|windows|linux|android)-(amd64|arm64)\.gz$/);
57
+ assert.match(name, /^dsh-mesh-tsnet-(darwin|windows|linux|android)-(amd64|arm64)(\.exe)?\.gz$/);
58
58
  });
59
59
 
60
60
  check("下载源:镜像在前、直连 GitHub 兜底", () => {
@@ -553,6 +553,17 @@ check("note() 显式传端口时以显式为准(tailnet / 扫描路径)", ()
553
553
  assert.equal(d.peers()[0].endpoints.find((e) => e.transport === "tsnet").port, 46150);
554
554
  });
555
555
 
556
+ check("note() 以观察到的地址为准,自述 host 不能改派发目标", () => {
557
+ const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
558
+ d.note(
559
+ { app: "dsh-mesh", id: "spoof", machine: "peer", host: "attacker.example.com", port: 8080 },
560
+ "10.1.2.3",
561
+ );
562
+ const p = d.peers()[0];
563
+ assert.equal(p.host, "10.1.2.3", "LAN 也必须用观察到的地址");
564
+ assert.equal(p.endpoints[0].host, "10.1.2.3");
565
+ });
566
+
556
567
  check("endpointAlive:存活窗口跟随探测间隔(慢节奏通道不被 TTL 判死)", () => {
557
568
  const now = 1_000_000;
558
569
  // tailnet 通道每 60s 才探一次,而默认 TTL 是 20s ——
@@ -565,6 +576,20 @@ check("endpointAlive:存活窗口跟随探测间隔(慢节奏通道不被 TT
565
576
  assert.equal(endpointAlive(fast, now, 20_000), false, "10s 节奏的通道 50s 没消息就该判死");
566
577
  });
567
578
 
579
+ check("心跳不清零出站失败冷却(单向可达时不再永远先打 LAN)", () => {
580
+ const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
581
+ const rec = { app: "dsh-mesh", id: "dev", machine: "hos", host: "10.0.0.9", port: 45917 };
582
+ d.note(rec, "10.0.0.9");
583
+ d.markEndpoint("dev", "lan", { ok: false });
584
+ d.markEndpoint("dev", "lan", { ok: false });
585
+ const before = d.peers()[0].endpoints.find((e) => e.transport === "lan");
586
+ assert.ok(before.downUntil > Date.now(), "连续失败后应进入冷却");
587
+ d.note(rec, "10.0.0.9");
588
+ const after = d.peers()[0].endpoints.find((e) => e.transport === "lan");
589
+ assert.equal(after.failCount, 2, "心跳不该清零 failCount");
590
+ assert.equal(after.downUntil, before.downUntil, "心跳不该清掉冷却截止时间");
591
+ });
592
+
568
593
  check("全部端点冷却时:投影为空,但 orderedEndpoints 仍要给出发送目标", () => {
569
594
  const d = new MeshDiscovery({ id: "self-1", port: 45917, meta: { machine: "me" } });
570
595
  d.note(
@@ -104,7 +104,8 @@ function extraPathDirs(p = platform(), env = process.env) {
104
104
  env["ProgramFiles(x86)"] && join(env["ProgramFiles(x86)"], "nodejs"),
105
105
  env.APPDATA && join(env.APPDATA, "npm"),
106
106
  env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Programs", "Python"),
107
- env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Microsoft", "WindowsApps"),
107
+ // 不要把 WindowsApps 补进探测 PATH:那里几乎全是 0 字节的 Store 别名存根,
108
+ // 前置后会遮住后面真正的 python.exe / node.exe(spawn 得 exit 9009)。
108
109
  env.ProgramFiles && join(env.ProgramFiles, "Git", "cmd"),
109
110
  env.ProgramFiles && join(env.ProgramFiles, "Docker", "Docker", "resources", "bin"),
110
111
  env.ProgramData && join(env.ProgramData, "chocolatey", "bin"),
@@ -263,7 +264,14 @@ async function probeRuntime(spec, timeoutMs = PROBE_TIMEOUT_MS) {
263
264
  * 是**不确定** —— 不能当作"没装"。
264
265
  */
265
266
  function isUncertain(error) {
266
- return error === "timeout" || error === "spawn-failed" || String(error).startsWith("throw:");
267
+ return (
268
+ error === "timeout" ||
269
+ error === "spawn-failed" ||
270
+ // Windows Store 别名存根:文件 0 字节,spawn 得到 exit 9009、无输出。
271
+ // 这是“没问出答案”,不是“确定没装”。
272
+ error === "exit-9009" ||
273
+ String(error).startsWith("throw:")
274
+ );
267
275
  }
268
276
 
269
277
  /**
@@ -391,8 +399,11 @@ function isEmptyButFailed({ runtimes, errors } = {}) {
391
399
  * WindowsApps 算进去,Windows 上会**恒判"可信"** → 假阴性原样复发 —— 实测
392
400
  * 文超-win 的候选表去掉 WindowsApps 后恰好为 0,带上它则为 1。
393
401
  *
394
- * 注意范围:只用于**健康判据**。探测用 PATH 里保留 WindowsApps 无害(它本来
395
- * 通常就在真实 PATH 里),且 store 存根输出为空不会被记成运行时(见 parseVersion)。
402
+ * 注意范围:这个正则本身只用于**健康判据**;探测用的 PATH 里也**不再**补
403
+ * WindowsApps(见 extraPathDirs)。原先这里写着"留着无害",是错的:把它前置到
404
+ * PATH 会挡住真正的 python.exe / node.exe,spawn 得到 exit=9009 + 空输出,
405
+ * 于是"装了"被当成"没装"。现在这种输出记为**不确定**(见 isUncertain),
406
+ * 而不是当作反向证据。
396
407
  */
397
408
  const STORE_ALIAS_DIR = /[\\/]Microsoft[\\/]WindowsApps$/i;
398
409
 
@@ -419,6 +430,7 @@ export const __pathLookupUnreliable = pathLookupUnreliable;
419
430
  export const __normPathForCompare = normPathForCompare;
420
431
  /** 只为自测导出:原始 GPU 探测输出 —— 用来区分"这台机器没有显卡"和"解析器坏了"。 */
421
432
  export const __probeGpu = probeGpu;
433
+ export const __isUncertain = isUncertain;
422
434
  /** 只为自测导出:Store 别名目录的排除规则(Mac 上没有该目录,无法端到端复现)。 */
423
435
  export const __storeAliasDir = STORE_ALIAS_DIR;
424
436
  /** 只为自测导出:让自测能按判据反推 runtimesIncomplete 的期望值,而不是写死。 */
package/lib/discovery.js CHANGED
@@ -708,7 +708,11 @@ export class MeshDiscovery extends EventEmitter {
708
708
  const address = String(rinfo.address ?? selfHost ?? "?").trim();
709
709
  // tailnet 通道**必须**用观察到的地址:对端自述的 host 是它的局域网 IP,
710
710
  // 跨互联网根本不可达。
711
- const host = transport === "tsnet" ? address : selfHost || address;
711
+ // Prefer the observed source address on every transport. The peer's
712
+ // self-reported host/port is unauthenticated; trusting it on the LAN lets a
713
+ // spoofed heartbeat redirect task dispatch (and X-Dsh-Mesh-Token) to an
714
+ // arbitrary host. note()'s contract has always said observed wins.
715
+ const host = address || selfHost;
712
716
  const port = Number(rinfo.port ?? msg.port) || 0;
713
717
  const verified = rinfo.probe === false ? false : true;
714
718
 
@@ -788,12 +792,15 @@ export class MeshDiscovery extends EventEmitter {
788
792
  lastOkAt: verified ? now : (prevEp?.lastOkAt ?? 0),
789
793
  lastFailAt: prevEp?.lastFailAt ?? 0,
790
794
  okCount: verified ? (prevEp?.okCount ?? 0) + 1 : (prevEp?.okCount ?? 0),
791
- failCount: 0,
795
+ // An inbound heartbeat proves the peer can reach us, not that we can
796
+ // reach it. Keep the outbound failure state; only a successful probe or
797
+ // send (markEndpoint ok) may clear it.
798
+ failCount: prevEp?.failCount ?? 0,
792
799
  // RTT 与探测间隔由调用方按实际结果带进来(成功路径走的是 note(),
793
800
  // 不是 markEndpoint,所以要在这里一并接住,否则 RTT 永远是 0)
794
801
  rttMs: Number(rinfo.rttMs) > 0 ? Number(rinfo.rttMs) : (prevEp?.rttMs ?? 0),
795
802
  probeIntervalMs: Number(rinfo.probeIntervalMs) > 0 ? Number(rinfo.probeIntervalMs) : (prevEp?.probeIntervalMs ?? 0),
796
- downUntil: 0,
803
+ downUntil: prevEp?.downUntil ?? 0,
797
804
  verified: prevEp?.verified === true || verified,
798
805
  };
799
806
 
package/lib/index.js CHANGED
@@ -59,7 +59,7 @@ import { tailnetFetch, tailnetOrigin } from "./tsnet/bridge.js";
59
59
  export const name = "dsh-plugin-mesh";
60
60
  export const inject = ["tools", "webServer"];
61
61
 
62
- const VERSION = "0.5.1";
62
+ const VERSION = "0.5.2";
63
63
  const RULE_ID = "mesh-inbound";
64
64
  const RULE_KIND = "mesh";
65
65
  const MAX_BODY = 256 * 1024;
@@ -1246,10 +1246,14 @@ function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadS
1246
1246
  // 只有"撞上限"值得提示用户去提高上限;寒暄/冷却/过短都是正常拦截
1247
1247
  if (verdict.kind === "cap") {
1248
1248
  const k = String(task.thread || "").trim();
1249
- const entry = throttled.get(k) ?? { taskIds: [], firstAt: now, lastAt: now, cap: capFor(k) };
1249
+ const entry = throttled.get(k) ?? { taskIds: [], firstAt: now, lastAt: now, cap: capFor(key), key };
1250
+ // The ledger and the cap override are keyed by conversationKey (machine +
1251
+ // thread), not by the bare thread label the UI displays. Remember it so
1252
+ // "/mesh/api/throttle/raise" can write the override under the right key.
1253
+ entry.key = key || entry.key || "";
1250
1254
  entry.taskIds.push(task.id);
1251
1255
  entry.lastAt = now;
1252
- entry.cap = capFor(k);
1256
+ entry.cap = capFor(entry.key || k);
1253
1257
  throttled.set(k, entry);
1254
1258
  warn(`任务 ${task.id} 因限速未唤醒(${verdict.reason});可在 Mesh 页面提高 ${k} 的上限`);
1255
1259
  } else {
@@ -1601,6 +1605,9 @@ async function runScan({ discovery, config, log, warn, signal, reason = "扫描"
1601
1605
  const ports = scanPortList(discovery, config);
1602
1606
  let lanFound = 0;
1603
1607
 
1608
+ if (addresses.length === 0) {
1609
+ warn(`${reason}: 没有可扫描的地址(检查 scanRanges 是否合法 / 网卡是否存在)`);
1610
+ }
1604
1611
  if (addresses.length > 0) {
1605
1612
  log(`${reason}: 探测 ${addresses.length} 个地址的 ${ports.join("/")} 端口…`);
1606
1613
  const started = Date.now();
@@ -1653,8 +1660,15 @@ async function pingKnownPeers({ discovery, config, warn }) {
1653
1660
  // 通道立刻探一次**,让它尽快有个真实状态而不是停在"未探测"。
1654
1661
  const tsnetInterval = Math.max(config.pingIntervalMs, config.tsnetProbeIntervalMs ?? 60000);
1655
1662
  const targets = endpoints.filter((ep) => {
1656
- if (ep.verified === false) return true; // 还没验证过,尽快探一次
1657
1663
  const interval = ep.transport === "tsnet" ? tsnetInterval : config.pingIntervalMs;
1664
+ if (ep.verified === false) {
1665
+ // 首次立刻探一次;失败后按通道节奏重试,并尊重 markEndpoint 记下
1666
+ // 的冷却时间。原来的 `return true` 让未验证端点每个 ping tick 都
1667
+ // 被探一次(默认 10s),完全绕过 tsnetProbeIntervalMs(60s)。
1668
+ if (!ep.lastFailAt) return true;
1669
+ if (Number(ep.downUntil ?? 0) > now) return false;
1670
+ return now - Number(ep.lastFailAt ?? 0) >= interval;
1671
+ }
1658
1672
  return now - Number(ep.lastSeen ?? 0) >= interval;
1659
1673
  });
1660
1674
  if (targets.length === 0) return;
@@ -2057,6 +2071,21 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2057
2071
  }),
2058
2072
  );
2059
2073
 
2074
+ /**
2075
+ * POST-only wrapper for state-changing routes.
2076
+ *
2077
+ * Without this a GET (an <img>, a link prefetch, or any local process) can
2078
+ * trigger mutations. "/mesh/api/pairing" was the worst: readJson() returns
2079
+ * null for a body-less GET, `body?.enabled === true` becomes false, and the
2080
+ * empty result was persisted as "pairing disabled" -- a fail-open.
2081
+ */
2082
+ const post = (path, handler) =>
2083
+ route(path, (req, res) =>
2084
+ req.method === "POST"
2085
+ ? handler(req, res)
2086
+ : send(res, 405, { ok: false, error: `method ${req.method} not allowed; use POST` }),
2087
+ );
2088
+
2060
2089
  /** 返回 { peer } 或 { error },避免撞名时静默挑错机器 */
2061
2090
  const findPeer = (name) => {
2062
2091
  const matches = findPeersByName(discovery, name);
@@ -2172,7 +2201,8 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2172
2201
  cap: v.cap,
2173
2202
  defaultCap: config.maxWakesPerThread ?? 0,
2174
2203
  windowMs: config.threadWindowMs ?? 3600000,
2175
- overridden: capOverrides.has(thread),
2204
+ key: v.key || thread,
2205
+ overridden: capOverrides.has(v.key || thread),
2176
2206
  firstAt: new Date(v.firstAt).toISOString(),
2177
2207
  lastAt: new Date(v.lastAt).toISOString(),
2178
2208
  })),
@@ -2187,20 +2217,21 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2187
2217
  * 提高后立刻放行**最近被挡的那一条**(对话的最新一环),其余仍留在收件箱 ——
2188
2218
  * 一次性全部重放会造成一个新的突发,反而失去限速的意义。
2189
2219
  */
2190
- route("/mesh/api/throttle/raise", async (req, res) => {
2220
+ post("/mesh/api/throttle/raise", async (req, res) => {
2191
2221
  const body = await readJson(req);
2192
2222
  const thread = String(body?.thread ?? "").trim();
2193
2223
  if (!thread) return send(res, 400, { ok: false, error: "thread 必填" });
2194
2224
  const entry = throttled.get(thread);
2195
2225
  if (!entry) return send(res, 404, { ok: false, error: `thread "${thread}" 当前没有被限速` });
2196
2226
 
2197
- const current = capFor(thread);
2227
+ const capKey = entry.key || thread;
2228
+ const current = capFor(capKey);
2198
2229
  const requested = Number(body?.cap);
2199
2230
  // 默认在当前基础上翻倍(至少 +10),也可由调用方指定
2200
2231
  const next = Number.isFinite(requested) && requested > current
2201
2232
  ? Math.floor(requested)
2202
2233
  : Math.max(current + 10, current * 2);
2203
- capOverrides.set(thread, next);
2234
+ capOverrides.set(capKey, next);
2204
2235
  // 必须显式传入,否则 saveThreads 会从磁盘读回旧值、把手动提高冲掉
2205
2236
  saveThreads(threadState, capOverrides);
2206
2237
 
@@ -2224,7 +2255,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2224
2255
  });
2225
2256
 
2226
2257
  /** 用户选择"忽略":清掉提示,不改上限。任务仍留在收件箱。 */
2227
- route("/mesh/api/throttle/dismiss", async (req, res) => {
2258
+ post("/mesh/api/throttle/dismiss", async (req, res) => {
2228
2259
  const body = await readJson(req);
2229
2260
  const thread = String(body?.thread ?? "").trim();
2230
2261
  if (!thread) return send(res, 400, { ok: false, error: "thread 必填" });
@@ -2235,7 +2266,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2235
2266
  });
2236
2267
 
2237
2268
  // 首次启动的"起名"接口:存进 state.json,并立刻重新广播
2238
- route("/mesh/api/name", async (req, res) => {
2269
+ post("/mesh/api/name", async (req, res) => {
2239
2270
  const body = await readJson(req);
2240
2271
  let name;
2241
2272
  try {
@@ -2258,12 +2289,12 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2258
2289
  send(res, 200, { ok: true, name, previous });
2259
2290
  });
2260
2291
 
2261
- route("/mesh/api/refresh", (_req, res) => {
2292
+ post("/mesh/api/refresh", (_req, res) => {
2262
2293
  discovery.announceNow();
2263
2294
  send(res, 200, { ok: true });
2264
2295
  });
2265
2296
 
2266
- route("/mesh/api/scan", async (_req, res) => {
2297
+ post("/mesh/api/scan", async (_req, res) => {
2267
2298
  try {
2268
2299
  const result = await runScan({ discovery, config, log, warn, reason: "手动扫描" });
2269
2300
  send(res, 200, { ok: true, ...result, peers: discovery.peers() });
@@ -2283,9 +2314,12 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2283
2314
  * 程序去改它风险太大(YAML 注释会被吃掉)。这也是 tsnet 开关一直在用的做法。
2284
2315
  * 配置里写死 requirePairing: true 的情况仍然优先(部署方能强制)。
2285
2316
  */
2286
- route("/mesh/api/pairing", async (req, res) => {
2317
+ post("/mesh/api/pairing", async (req, res) => {
2287
2318
  const body = await readJson(req);
2288
- const want = body?.enabled === true;
2319
+ if (typeof body?.enabled !== "boolean") {
2320
+ return send(res, 400, { ok: false, error: "enabled 必须是布尔值" });
2321
+ }
2322
+ const want = body.enabled;
2289
2323
  if (pairingPinned(config)) {
2290
2324
  return send(res, 409, {
2291
2325
  ok: false,
@@ -2297,7 +2331,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2297
2331
  return send(res, 200, { ok: true, requirePairing: want });
2298
2332
  });
2299
2333
 
2300
- route("/mesh/api/secret", async (req, res) => {
2334
+ post("/mesh/api/secret", async (req, res) => {
2301
2335
  const body = await readJson(req);
2302
2336
  const secret = String(body?.secret ?? "").trim();
2303
2337
  if (secret.length < 16) return send(res, 400, { ok: false, error: "配对码至少 16 个字符" });
@@ -2321,7 +2355,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2321
2355
  * 授权码存进 state.json(0600),所以**只需要输入一次**,重启不用再填。
2322
2356
  * 授权码传空串表示"不改动已保存的值",避免界面回显后又被空值覆盖。
2323
2357
  */
2324
- route("/mesh/api/tsnet/config", async (req, res) => {
2358
+ post("/mesh/api/tsnet/config", async (req, res) => {
2325
2359
  const body = await readJson(req);
2326
2360
  const patch = {};
2327
2361
  if (typeof body?.authKey === "string" && body.authKey.trim()) patch.tsnetAuthKey = body.authKey.trim();
@@ -2346,7 +2380,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2346
2380
  });
2347
2381
 
2348
2382
  /** 启动(或按最新配置重启)tailnet 节点。 */
2349
- route("/mesh/api/tsnet/start", async (_req, res) => {
2383
+ post("/mesh/api/tsnet/start", async (_req, res) => {
2350
2384
  if (tailnetNode) {
2351
2385
  const old = tailnetNode;
2352
2386
  tailnetNode = null;
@@ -2372,7 +2406,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2372
2406
  * 进程仍在跑、rendezvous 也没清)。不传参数即按归属判断:自己拉起的关掉,
2373
2407
  * 复用别人的只注销自己的 forward。
2374
2408
  */
2375
- route("/mesh/api/tsnet/stop", async (_req, res) => {
2409
+ post("/mesh/api/tsnet/stop", async (_req, res) => {
2376
2410
  const node = tailnetNode;
2377
2411
  tailnetNode = null;
2378
2412
  if (node) await node.stop().catch(() => {});
@@ -2380,7 +2414,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2380
2414
  });
2381
2415
 
2382
2416
  /** 清掉节点身份重新登录(授权码失效 / 换账号时用)。 */
2383
- route("/mesh/api/tsnet/relogin", async (_req, res) => {
2417
+ post("/mesh/api/tsnet/relogin", async (_req, res) => {
2384
2418
  if (!tailnetNode) return send(res, 409, { ok: false, error: "互联网组网未启动" });
2385
2419
  try {
2386
2420
  await tailnetNode.relogin();
@@ -2392,7 +2426,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2392
2426
  });
2393
2427
 
2394
2428
  /** 重新下载 sidecar 二进制(下载损坏或换平台时用)。 */
2395
- route("/mesh/api/tsnet/reinstall", async (_req, res) => {
2429
+ post("/mesh/api/tsnet/reinstall", async (_req, res) => {
2396
2430
  if (!tailnetNode) return send(res, 409, { ok: false, error: "互联网组网未启动" });
2397
2431
  try {
2398
2432
  const r = await tailnetNode.reinstallBinary();
@@ -2403,7 +2437,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2403
2437
  });
2404
2438
 
2405
2439
  /** 只扫 tailnet,不扫局域网。 */
2406
- route("/mesh/api/tsnet/scan", async (_req, res) => {
2440
+ post("/mesh/api/tsnet/scan", async (_req, res) => {
2407
2441
  const before = new Set(discovery.peers().map((p) => p.id));
2408
2442
  const result = await scanTailnet({
2409
2443
  discovery,
@@ -2420,7 +2454,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2420
2454
  });
2421
2455
  });
2422
2456
 
2423
- route("/mesh/api/send", async (req, res) => {
2457
+ post("/mesh/api/send", async (req, res) => {
2424
2458
  const body = await readJson(req);
2425
2459
  const peerName = String(body?.peer ?? "").trim();
2426
2460
  const task = String(body?.task ?? "").trim();
@@ -2514,7 +2548,7 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2514
2548
  }
2515
2549
  });
2516
2550
 
2517
- route("/mesh/api/probe", async (req, res) => {
2551
+ post("/mesh/api/probe", async (req, res) => {
2518
2552
  const body = await readJson(req);
2519
2553
  const found = findPeer(String(body?.peer ?? "").trim());
2520
2554
  if (found.error) return send(res, 404, { ok: false, error: found.error });
package/lib/scan.js CHANGED
@@ -25,20 +25,21 @@ export function candidateAddresses(extraRanges = [], limit = 1024) {
25
25
  out.push(ip);
26
26
  };
27
27
 
28
- for (const range of extraRanges) {
29
- for (const ip of expandCidr(range)) push(ip);
30
- }
31
-
32
- // 没给额外网段就扫本机所在 /24
28
+ // 本机所在 /24 **始终**要扫:scanRanges 是"额外"网段,不是替代品。
29
+ //
30
+ // 原来的实现一旦配了 scanRanges 就丢掉本机 /24;更糟的是 CIDR 写错时
31
+ // expandCidr 返回空数组,于是"扫描"变成 0 个地址且没有任何报错 ——
32
+ // 主动发现完全失效,界面却只显示"命中 0 台"。
33
33
  //
34
34
  // 注意:这里**不排除本机 IP**。因为同机跑多个实例时它们共用一个 IP,
35
35
  // 排掉就永远发现不了彼此;而扫到自己也无害 —— discovery.note() 会按
36
36
  // 实例 id 把自身拒掉。
37
- if (extraRanges.length === 0) {
38
- for (const { address } of lanIPv4Addresses()) {
39
- const prefix = address.slice(0, address.lastIndexOf("."));
40
- for (let host = 1; host <= 254; host += 1) push(`${prefix}.${host}`);
41
- }
37
+ for (const { address } of lanIPv4Addresses()) {
38
+ const prefix = address.slice(0, address.lastIndexOf("."));
39
+ for (let host = 1; host <= 254; host += 1) push(`${prefix}.${host}`);
40
+ }
41
+ for (const range of extraRanges) {
42
+ for (const ip of expandCidr(range)) push(ip);
42
43
  }
43
44
  return out;
44
45
  }
@@ -66,7 +66,11 @@ export function detectTarget() {
66
66
  /** 本平台对应的资产名,例如 dsh-mesh-tsnet-darwin-amd64.gz */
67
67
  export function assetName() {
68
68
  const { os, arch } = detectTarget();
69
- return `dsh-mesh-tsnet-${os}-${arch}.gz`;
69
+ // Windows release assets carry .exe before .gz (see build-sidecar.sh and
70
+ // PINNED_CHECKSUMS). Without it every mirror 404s and the checksum lookup
71
+ // silently misses, so the binary is never verified and never refreshed.
72
+ const exe = os === "windows" ? ".exe" : "";
73
+ return `dsh-mesh-tsnet-${os}-${arch}${exe}.gz`;
70
74
  }
71
75
 
72
76
  /** 缓存目录:~/.dsh/mesh/bin/sidecar-v1/ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-mesh",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "DSH Mesh:局域网自动发现同网段的 DSH 实例、显示每台机器上报的能力,并双向派发任务;可用内置的用户态 Tailscale 节点跨互联网组网。Discovers other DSH instances on the LAN, shows the capabilities each one reports, and dispatches tasks between machines in both directions, with an optional userspace Tailscale node for links across networks.",
6
6
  "license": "MIT",