ssh-net 26.9.8 → 26.9.9
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/CHANGELOG.md +25 -0
- package/libexec/cli.mjs +2 -1
- package/libexec/commands/checkin.mjs +24 -18
- package/libexec/commands/doctor.mjs +2 -2
- package/libexec/commands/install.mjs +12 -14
- package/libexec/commands/start.mjs +8 -17
- package/libexec/commands/status.mjs +29 -22
- package/libexec/commands/stop.mjs +7 -3
- package/libexec/lib/exec.mjs +25 -4
- package/libexec/lib/ipv6.mjs +0 -10
- package/libexec/lib/paths.mjs +0 -1
- package/libexec/lib/probe.mjs +5 -4
- package/libexec/lib/runtime.mjs +9 -27
- package/libexec/lib/state.mjs +0 -10
- package/libexec/ssh-net-link-core +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,31 @@
|
|
|
6
6
|
首发即 26.10.8(2026-09-29 定,取代此前「序号每月重置」的约定);更早的
|
|
7
7
|
0.x 为过渡期编号。
|
|
8
8
|
|
|
9
|
+
## [26.9.9] - 2026-09-30
|
|
10
|
+
|
|
11
|
+
### 变更(清理与体验:死代码删除、status 提速、命令面收敛)
|
|
12
|
+
|
|
13
|
+
- **死代码删除**:`isGlobalUnicastV6`(生产无人调用,可拨判定由
|
|
14
|
+
`isDialableV6` 覆盖);install 的旧 `ON` 总开关迁移(26.9.5 历史,五台
|
|
15
|
+
已迁完);runtime 对 0.1.x 软链的检测/替换分支(实体拷贝方案的迁移期
|
|
16
|
+
兼容,已全员落地);start 对旧 plist(盯 ON 模板)的拒绝防线。审计矩阵
|
|
17
|
+
回到三态:missing/ok/stale
|
|
18
|
+
- **checkin 拆分**:core 侧的内部 RPC 改名 `_register`(下划线前缀不进
|
|
19
|
+
help),`checkin` 只剩 edge 手动报名一个语义,link-core 的报名命令同步
|
|
20
|
+
改。注意 bash 脚本是进程内一次性解析:edge 升级后**必须
|
|
21
|
+
`ssh-net restart`**(隧道开着的话)让循环加载新命令——不 restart 的话
|
|
22
|
+
relay 态最长等 600s 寿命到点重载,peer 态健康连接无定时器、不会自然
|
|
23
|
+
重载。升级动作:`npm i -g` + `ssh-net install` + `ssh-net restart`
|
|
24
|
+
- **status 探测并发**:relay 实测 ssh(8s 超时)与 peer probe(5s)此前
|
|
25
|
+
串行,relay 不通时一条 status 卡 13s+;现在与转发口/LAN 的 TCP 探测
|
|
26
|
+
一起并发,耗时取决于最慢一条
|
|
27
|
+
- **install 预检修正**:10022 在听但 `bin/peer-probe` 还没拷上(首装)
|
|
28
|
+
时不再误判「僵尸监听」——探针缺失不判 banner,install 随后就拷
|
|
29
|
+
- **细粒度 start/stop 诚实措辞**:start link / stop link 的 kickstart
|
|
30
|
+
失败不再无条件报「已触发重估/已断开」,按结果分双文案
|
|
31
|
+
- 测试同步(150 个);`SSH_NET_FAKE_CHECKIN_RC` 测试注入改名
|
|
32
|
+
`SSH_NET_FAKE_REGISTER_RC`
|
|
33
|
+
|
|
9
34
|
## [26.9.8] - 2026-09-29
|
|
10
35
|
|
|
11
36
|
### 变更(版本号规则:序号永不重置)
|
package/libexec/cli.mjs
CHANGED
|
@@ -16,7 +16,7 @@ import { run as startRun } from './commands/start.mjs';
|
|
|
16
16
|
import { run as stopRun } from './commands/stop.mjs';
|
|
17
17
|
import { run as restartRun } from './commands/restart.mjs';
|
|
18
18
|
import { run as statusRun } from './commands/status.mjs';
|
|
19
|
-
import { run as checkinRun } from './commands/checkin.mjs';
|
|
19
|
+
import { run as checkinRun, runRegister as registerRun } from './commands/checkin.mjs';
|
|
20
20
|
import { run as doctorRun } from './commands/doctor.mjs';
|
|
21
21
|
|
|
22
22
|
const COMMANDS = {
|
|
@@ -28,6 +28,7 @@ const COMMANDS = {
|
|
|
28
28
|
status: { run: statusRun, desc: '本机角色状态(开关与线路分开实测)' },
|
|
29
29
|
doctor: { run: doctorRun, desc: '立即重估线路(edge):peer 不通时重新报名+选路,不等定时器' },
|
|
30
30
|
checkin: { run: checkinRun, desc: '手动报名(edge):把本机 v6 告诉 core,几秒内回拨建立直连' },
|
|
31
|
+
_register: { run: registerRun, internal: true, desc: '内部 RPC(core):接收 edge 报名,建/唤回拨 job' },
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
function help() {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
// checkin
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
1
|
+
// checkin:edge 手动报名(无参)。取本机 v6 走 m4-via-relay 发给 core 的
|
|
2
|
+
// `_register` 并转述结果。不受开关控制(显式动作);一次性——v6 变化后
|
|
3
|
+
// 失联需重跑,常驻维护用 start peer。
|
|
4
|
+
//
|
|
5
|
+
// core 侧的报名接收端是内部命令 `_register`(下划线前缀不进 help,由
|
|
6
|
+
// link-core 循环与 start peer 经 ssh 调起)。四态显式处理(design §6.3,
|
|
7
|
+
// 实测矩阵见 notes);四态之前先对账运行时脚本与 plist——install 不预建
|
|
8
|
+
// uplink-edge,其脚本与 job 参数(user 等)变更只有这条更新通道,缺了会
|
|
9
|
+
// 永远用旧参数/旧目标拨号、六连败休眠循环。launchctl 真返回成功才退出 0;
|
|
10
|
+
// 失败非零,edge 下一轮自然重试。
|
|
10
11
|
import fs from 'node:fs';
|
|
11
12
|
import path from 'node:path';
|
|
12
13
|
import { explainV6Error } from '../lib/ipv6.mjs';
|
|
@@ -35,7 +36,7 @@ export function runEdgeAnnounce(ctx) {
|
|
|
35
36
|
'-o', 'ServerAliveInterval=10', '-o', 'ServerAliveCountMax=2',
|
|
36
37
|
'-o', 'ControlMaster=no', '-o', 'ControlPath=none',
|
|
37
38
|
`${ctx.topo.core.alias}-via-relay`,
|
|
38
|
-
`ssh-net
|
|
39
|
+
`ssh-net _register ${ctx.self.alias} ${v6}`,
|
|
39
40
|
], { timeout: 60_000 });
|
|
40
41
|
if (r.code !== 0)
|
|
41
42
|
throw new Error(`报名失败(${r.stderr.trim() || `exit ${r.code}`}):检查 s100 与 core 侧 relay 是否可用,稍后重试`);
|
|
@@ -51,20 +52,25 @@ function rollbackEdgeV6(ctx, alias, prevV6) {
|
|
|
51
52
|
else ctx.state.writeEdgeV6(alias, prevV6);
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
/** edge 手动报名:`ssh-net checkin`(无参)。 */
|
|
56
|
+
export function run(ctx, args = []) {
|
|
57
|
+
if (ctx.role !== 'edge')
|
|
58
|
+
throw new Error(`checkin 是 edge 的手动报名命令,本机角色是 ${ctx.role}(core 侧的报名接收端是内部命令 _register)`);
|
|
59
|
+
if (args.length) throw new Error('edge 上 checkin 不带参数:直接 ssh-net checkin 报名本机 v6');
|
|
60
|
+
return runEdgeAnnounce(ctx);
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
/**
|
|
64
|
+
* 内部 RPC(core):`ssh-net _register <别名> <v6>`,由 edge 的报名 ssh 触发。
|
|
55
65
|
* @param {object} ctx
|
|
56
|
-
* @param {string[]} args
|
|
66
|
+
* @param {string[]} args [别名, v6]
|
|
57
67
|
* @returns {string} 给 edge 的简短结果
|
|
58
68
|
*/
|
|
59
|
-
export function
|
|
60
|
-
if (ctx.role === 'edge') {
|
|
61
|
-
if (args.length) throw new Error('edge 上 checkin 不带参数:直接 ssh-net checkin 报名本机 v6');
|
|
62
|
-
return runEdgeAnnounce(ctx);
|
|
63
|
-
}
|
|
69
|
+
export function runRegister(ctx, args = []) {
|
|
64
70
|
if (ctx.role !== 'core')
|
|
65
|
-
throw new Error(`
|
|
71
|
+
throw new Error(`_register 只在 core 接受(edge 的手动报名是 ssh-net checkin),本机角色是 ${ctx.role}`);
|
|
66
72
|
const [alias, v6] = args;
|
|
67
|
-
if (!alias || !v6) throw new Error('用法:
|
|
73
|
+
if (!alias || !v6) throw new Error('用法:_register <edge 别名> <v6>');
|
|
68
74
|
|
|
69
75
|
const edge = ctx.topo.edges.find((e) => e.alias === alias);
|
|
70
76
|
if (!edge) throw new Error(`未知 edge 别名:${alias}`);
|
|
@@ -11,7 +11,7 @@ import * as launchd from '../lib/launchd.mjs';
|
|
|
11
11
|
import { peerProbeOk } from '../lib/probe.mjs';
|
|
12
12
|
import { linkLabel } from '../lib/render.mjs';
|
|
13
13
|
|
|
14
|
-
export function run(ctx) {
|
|
14
|
+
export async function run(ctx) {
|
|
15
15
|
if (ctx.role !== 'edge')
|
|
16
16
|
return '本机不是 edge,无需处理:core 等对应笔记本报名自动恢复,node 由 systemd 自动重启';
|
|
17
17
|
|
|
@@ -26,7 +26,7 @@ export function run(ctx) {
|
|
|
26
26
|
if (!st.registered)
|
|
27
27
|
throw new Error(`link job 未注册(先 ssh-net install):launchctl print gui/${ctx.uid}/${label}`);
|
|
28
28
|
|
|
29
|
-
const peer = peerProbeOk(ctx.runner, ctx.paths.binDir);
|
|
29
|
+
const peer = await peerProbeOk(ctx.runner, ctx.paths.binDir);
|
|
30
30
|
if (peer && st.running)
|
|
31
31
|
return `线路正常(peer 直达 ${ctx.topo.core.alias}),无需处理`;
|
|
32
32
|
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from '../lib/render.mjs';
|
|
22
22
|
|
|
23
23
|
/** edge 端口预检(纯读 + banner 判定),冲突抛错并报持有者。 */
|
|
24
|
-
function precheckEdgePorts(ctx) {
|
|
24
|
+
async function precheckEdgePorts(ctx) {
|
|
25
25
|
const { runner, paths, uid, topo } = ctx;
|
|
26
26
|
const jobPid = launchd.inspect(runner, uid, linkLabel(topo.core.alias)).pid;
|
|
27
27
|
|
|
@@ -33,9 +33,14 @@ function precheckEdgePorts(ctx) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// 10022 持口者永远是本机 sshd,无法按 pid 溯源:读到 SSH banner
|
|
36
|
+
// 10022 持口者永远是本机 sshd,无法按 pid 溯源:读到 SSH banner 才认。
|
|
37
|
+
// 首装时 bin/peer-probe 还没拷上,探针缺失不判僵尸(install 随后就拷)
|
|
37
38
|
const holders = listListeners(runner, CALLBACK_PORT);
|
|
38
|
-
if (
|
|
39
|
+
if (
|
|
40
|
+
holders.length > 0
|
|
41
|
+
&& fs.existsSync(path.join(paths.binDir, 'peer-probe'))
|
|
42
|
+
&& !(await peerProbeOk(runner, paths.binDir))
|
|
43
|
+
) {
|
|
39
44
|
const who = runner.run('lsof', ['-nP', `-iTCP:${CALLBACK_PORT}`, '-sTCP:LISTEN']).stdout.trim();
|
|
40
45
|
throw new Error(
|
|
41
46
|
`端口 ${CALLBACK_PORT} 在听但读不到 SSH banner(僵尸监听或他进程占用):\n${who}`,
|
|
@@ -43,12 +48,10 @@ function precheckEdgePorts(ctx) {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
function installEdge(ctx) {
|
|
51
|
+
async function installEdge(ctx) {
|
|
47
52
|
const { topo, paths } = ctx;
|
|
48
|
-
// 预检纯读且在落任何产物之前:被拒时 bin/
|
|
49
|
-
precheckEdgePorts(ctx);
|
|
50
|
-
// 26.9.5 前的总开关:见到即按「全开」迁移(迁移失败不阻断安装)
|
|
51
|
-
const migrated = ctx.state.migrateLegacyOn();
|
|
53
|
+
// 预检纯读且在落任何产物之前:被拒时 bin/ 一个都不建
|
|
54
|
+
await precheckEdgePorts(ctx);
|
|
52
55
|
ensureRuntime(ctx, [
|
|
53
56
|
[linkLinkName(topo.core.alias), 'ssh-net-link-core'],
|
|
54
57
|
['peer-probe', 'peer-probe'],
|
|
@@ -68,11 +71,6 @@ function installEdge(ctx) {
|
|
|
68
71
|
plistPath: path.join(paths.launchAgentsDir, plistFileName(linkLabel(topo.core.alias))),
|
|
69
72
|
content,
|
|
70
73
|
});
|
|
71
|
-
// 迁移发生时别说「默认关闭」——开关是从旧 ON 原样迁移的(全开)
|
|
72
|
-
if (migrated)
|
|
73
|
-
return r.unchanged
|
|
74
|
-
? '已安装,无需改动(旧开关 ON 已迁移为 relay/peer/link,全部保持开启)'
|
|
75
|
-
: '安装完成,开关保持迁移前状态(旧 ON → relay/peer/link 全开)';
|
|
76
74
|
return r.unchanged
|
|
77
75
|
? '已安装,无需改动'
|
|
78
76
|
: '安装完成。隧道默认关闭——at home(或 ssh-net start)开启';
|
|
@@ -131,7 +129,7 @@ function installNode(ctx) {
|
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
/** @param {object} ctx */
|
|
134
|
-
export function run(ctx) {
|
|
132
|
+
export async function run(ctx) {
|
|
135
133
|
switch (ctx.role) {
|
|
136
134
|
case 'edge': return installEdge(ctx);
|
|
137
135
|
case 'core': return installCore(ctx);
|
|
@@ -18,10 +18,9 @@ function parseTargets(args) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/** 细粒度开关立即生效:kickstart 让循环重来(自检新开关)。失败不阻断——
|
|
21
|
-
*
|
|
21
|
+
* 开关已置,下轮循环兜底;结果交调用方诚实措辞。 */
|
|
22
22
|
function kickLinkJob(ctx) {
|
|
23
|
-
|
|
24
|
-
launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
23
|
+
return launchd.kickstartEnabled(ctx.runner, ctx.uid, linkLabel(ctx.topo.core.alias));
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
function startCore(ctx) {
|
|
@@ -52,18 +51,8 @@ export function run(ctx, args = []) {
|
|
|
52
51
|
const st = launchd.inspect(ctx.runner, ctx.uid, label);
|
|
53
52
|
if (!st.registered)
|
|
54
53
|
throw new Error(`link job 未注册(先 ssh-net install):launchctl print gui/${ctx.uid}/${label}`);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let plist = '';
|
|
58
|
-
try {
|
|
59
|
-
plist = fs.readFileSync(
|
|
60
|
-
path.join(ctx.paths.launchAgentsDir, plistFileName(label)), 'utf8',
|
|
61
|
-
);
|
|
62
|
-
} catch {
|
|
63
|
-
throw new Error(`job 配置文件缺失(注册态仍在)——先跑一次 ssh-net install`);
|
|
64
|
-
}
|
|
65
|
-
if (!plist.includes('RELAY_ON'))
|
|
66
|
-
throw new Error('job 配置还是旧版(盯 ON 标记)——先跑一次 ssh-net install 再 start');
|
|
54
|
+
if (!fs.existsSync(path.join(ctx.paths.launchAgentsDir, plistFileName(label))))
|
|
55
|
+
throw new Error('job 配置文件缺失(注册态仍在)——先跑一次 ssh-net install');
|
|
67
56
|
|
|
68
57
|
const targets = new Set(parseTargets(args));
|
|
69
58
|
if (targets.has('peer') || targets.has('link')) targets.add('relay'); // 依赖级联
|
|
@@ -93,8 +82,10 @@ export function run(ctx, args = []) {
|
|
|
93
82
|
return `peer 已开启(relay 一并开启;${note})`;
|
|
94
83
|
}
|
|
95
84
|
if (targets.has('link')) {
|
|
96
|
-
kickLinkJob(ctx);
|
|
97
|
-
return
|
|
85
|
+
const r = kickLinkJob(ctx);
|
|
86
|
+
return r.code === 0
|
|
87
|
+
? 'link 已开启(relay 一并开启;已触发重估,本地转发口几秒内建立)'
|
|
88
|
+
: 'link 已开启(relay 一并开启;重估没触发成功,转发口随下轮循环自动建立)';
|
|
98
89
|
}
|
|
99
90
|
return 'relay 已开启(隧道基础。peer/link 未开时不报名、无本地转发——要被 core 连到再 start peer,要本机代理再 start link)';
|
|
100
91
|
}
|
|
@@ -37,10 +37,10 @@ function forwardLabel(f) {
|
|
|
37
37
|
return `端口转发 127.0.0.1:${f.listenPort} → ${target}`;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function relayPortListening(ctx, port) {
|
|
40
|
+
async function relayPortListening(ctx, port) {
|
|
41
41
|
// relay 别名的 User/HostName 由 ssh config Host 块提供;
|
|
42
42
|
// BatchMode 防换机器/换钥匙时在终端闪密码提示(与运行时五个 ssh 同约定)
|
|
43
|
-
const r = ctx.runner.
|
|
43
|
+
const r = await ctx.runner.runAsync('ssh', [
|
|
44
44
|
'-o', 'BatchMode=yes', '-o', 'ConnectTimeout=5',
|
|
45
45
|
ctx.topo.relay.alias, 'ss', '-tlnH',
|
|
46
46
|
], { timeout: 8000 });
|
|
@@ -49,8 +49,8 @@ function relayPortListening(ctx, port) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** edge 的 relay 线路实测:经 m4-via-relay 跑一条真 ssh(报名/中继同信道)。 */
|
|
52
|
-
function relayPathOk(ctx) {
|
|
53
|
-
const r = ctx.runner.
|
|
52
|
+
async function relayPathOk(ctx) {
|
|
53
|
+
const r = await ctx.runner.runAsync('ssh', [
|
|
54
54
|
'-o', 'BatchMode=yes', '-o', 'ConnectTimeout=5',
|
|
55
55
|
`${ctx.topo.core.alias}-via-relay`, 'true',
|
|
56
56
|
], { timeout: 8000 });
|
|
@@ -80,25 +80,30 @@ async function collectEdge(ctx) {
|
|
|
80
80
|
const job = launchd.inspect(ctx.runner, ctx.uid, label);
|
|
81
81
|
const switches = state.readSwitches();
|
|
82
82
|
|
|
83
|
-
//
|
|
83
|
+
// 就绪实测全部并发(On 是意图、ready 是事实;开关关的线路不探测=null):
|
|
84
|
+
// relay 实测 ssh(8s 超时)与 peer probe(5s)串行要 13s+,转发口/LAN 的
|
|
85
|
+
// TCP 探测随其一起发起,最坏耗时取决于最慢一条
|
|
84
86
|
const relayOk = ctx.relayOk ?? relayPathOk; // 测试可注入
|
|
85
87
|
const openTcp = ctx.openTcp ?? tcpOpen;
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
? peerProbeOk(ctx.runner, paths.binDir)
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
const probes = [
|
|
89
|
+
switches.relay ? relayOk(ctx) : null,
|
|
90
|
+
switches.relay && switches.peer ? peerProbeOk(ctx.runner, paths.binDir) : null,
|
|
91
|
+
// link 关也探:软生效窗口里旧转发连接的口还在听(「关」不等于口已消失),
|
|
92
|
+
// status 要能区分「现有连接保持中」与「彻底没了」
|
|
93
|
+
...topo.forwards.map((f) => openTcp('127.0.0.1', f.listenPort)),
|
|
94
|
+
];
|
|
95
|
+
// relay 开但 core 的 LAN 22 可达 = 人在办公室忘了关(只提示不纠偏)
|
|
96
|
+
const lanIdx = switches.relay && topo.core.lanIp ? probes.length : -1;
|
|
97
|
+
if (lanIdx >= 0) probes.push(openTcp(topo.core.lanIp, 22, 1200));
|
|
98
|
+
const got = await Promise.all(probes);
|
|
99
|
+
const relayReady = got[0];
|
|
100
|
+
const peerReady = got[1];
|
|
91
101
|
const ports = {};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
for (const f of topo.forwards) ports[f.listenPort] = await openTcp('127.0.0.1', f.listenPort);
|
|
102
|
+
topo.forwards.forEach((f, i) => { ports[f.listenPort] = got[2 + i]; });
|
|
103
|
+
const lanReachable = lanIdx >= 0 ? got[lanIdx] : false;
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const lanReachable = await openTcp(topo.core.lanIp, 22, 1200);
|
|
99
|
-
if (lanReachable)
|
|
100
|
-
issues.push(`检测到 ${topo.core.alias}(${topo.core.lanIp})局域网直连可达——隧道可能在空转绕中继;人在办公室可 ssh-net stop`);
|
|
101
|
-
}
|
|
105
|
+
if (lanReachable)
|
|
106
|
+
issues.push(`检测到 ${topo.core.alias}(${topo.core.lanIp})局域网直连可达——隧道可能在空转绕中继;人在办公室可 ssh-net stop`);
|
|
102
107
|
|
|
103
108
|
// relay 关(全关/级联)但转发口仍在听 = 孤儿进程;link 软关的口在听不报
|
|
104
109
|
if (!switches.relay)
|
|
@@ -140,7 +145,8 @@ async function collectCore(ctx) {
|
|
|
140
145
|
|
|
141
146
|
const relayLabelName = relayLabel(topo.relay.alias);
|
|
142
147
|
const relayJob = launchd.inspect(ctx.runner, ctx.uid, relayLabelName);
|
|
143
|
-
|
|
148
|
+
// s100 口实测是 8s 超时的真 ssh:先发起来,边等边做下面的注册态体检
|
|
149
|
+
const relayPortP = relayPortListening(ctx, topo.core.relayPort);
|
|
144
150
|
|
|
145
151
|
const edges = [];
|
|
146
152
|
for (const e of topo.edges) {
|
|
@@ -171,6 +177,7 @@ async function collectCore(ctx) {
|
|
|
171
177
|
});
|
|
172
178
|
}
|
|
173
179
|
|
|
180
|
+
const relayPort = await relayPortP;
|
|
174
181
|
if (!relayJob.running) issues.push('relay 未在运行——ssh-net start 可拉起');
|
|
175
182
|
if (!relayPort.listening)
|
|
176
183
|
issues.push(`s100 入口 ${topo.core.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 s100 或本机网络)`);
|
|
@@ -181,7 +188,7 @@ async function collectCore(ctx) {
|
|
|
181
188
|
};
|
|
182
189
|
}
|
|
183
190
|
|
|
184
|
-
function collectNode(ctx) {
|
|
191
|
+
async function collectNode(ctx) {
|
|
185
192
|
const { topo } = ctx;
|
|
186
193
|
const issues = [];
|
|
187
194
|
const { issue: vIssue, runtimeVersion } = versionInfo(ctx);
|
|
@@ -196,7 +203,7 @@ function collectNode(ctx) {
|
|
|
196
203
|
|
|
197
204
|
const unit = relayUnitName(topo.relay.alias);
|
|
198
205
|
const active = systemd.isActive(ctx.runner, unit);
|
|
199
|
-
const relayPort = relayPortListening(ctx, ctx.self.relayPort);
|
|
206
|
+
const relayPort = await relayPortListening(ctx, ctx.self.relayPort);
|
|
200
207
|
if (active !== 'active')
|
|
201
208
|
issues.push(`系统服务 ${unit} 状态 ${active}——systemctl status ${unit} 查看`);
|
|
202
209
|
if (!relayPort.listening)
|
|
@@ -39,9 +39,13 @@ export function run(ctx, args = []) {
|
|
|
39
39
|
// 立即生效:kickstart 断当前转发 ssh(承载的正是用户要关的东西,不算
|
|
40
40
|
// 闪断),循环重来后不再起。job 没跑就不用动(本来也没转发口)
|
|
41
41
|
const label = linkLabel(ctx.topo.core.alias);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
let off = '本地转发口已断开';
|
|
43
|
+
if (launchd.inspect(ctx.runner, ctx.uid, label).registered) {
|
|
44
|
+
const r = launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
45
|
+
if (r.code !== 0)
|
|
46
|
+
off = '断开请求未生效(现有连接会随其自然断开而消失;要立即断开跑 ssh-net restart)';
|
|
47
|
+
}
|
|
48
|
+
return `link 已关闭(${off};被连接方向不受影响——core 仍可经回拨进入本机)`;
|
|
45
49
|
}
|
|
46
50
|
// 全关 / 只关 relay:级联删三个(peer、link 都依赖 relay),硬停 job
|
|
47
51
|
const { gone, label } = stopEdgeLink(ctx);
|
package/libexec/lib/exec.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// 唯一 import child_process 的模块:外部命令绝对路径 +
|
|
2
|
-
// launchd/systemd/probe 只构造 argv 与解释输出,经注入的 Runner
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// 唯一 import child_process 的模块:外部命令绝对路径 + 执行封装(同步/异步
|
|
2
|
+
// 同构造)。launchd/systemd/probe 只构造 argv 与解释输出,经注入的 Runner
|
|
3
|
+
// 执行,测试用环境变量 SSH_NET_<KEY> 把命令换成 fake(与 shell 脚本同一
|
|
4
|
+
// 接缝风格)。status 把多条慢探测并发跑,用异步封装。
|
|
5
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
5
6
|
|
|
6
7
|
/** 命令默认绝对路径(launchd 最小环境没有交互 PATH)。 */
|
|
7
8
|
const DEFAULTS = {
|
|
@@ -38,6 +39,8 @@ export function commandPath(key, env = process.env) {
|
|
|
38
39
|
* @property {(key: string) => string} path
|
|
39
40
|
* @property {(key: string, args?: string[], opts?: object) => RunResult} run
|
|
40
41
|
* @property {(file: string, args?: string[], opts?: object) => RunResult} runRaw
|
|
42
|
+
* @property {(key: string, args?: string[], opts?: object) => Promise<RunResult>} runAsync
|
|
43
|
+
* @property {(file: string, args?: string[], opts?: object) => Promise<RunResult>} runRawAsync
|
|
41
44
|
*/
|
|
42
45
|
|
|
43
46
|
/**
|
|
@@ -59,9 +62,27 @@ export function createRunner(env = process.env) {
|
|
|
59
62
|
error: r.error ?? null,
|
|
60
63
|
};
|
|
61
64
|
};
|
|
65
|
+
const doSpawnAsync = (file, args = [], opts = {}) =>
|
|
66
|
+
new Promise((resolve) => {
|
|
67
|
+
const child = spawn(file, args, {
|
|
68
|
+
encoding: 'utf8',
|
|
69
|
+
...opts,
|
|
70
|
+
env: { ...env, ...(opts.env ?? {}) },
|
|
71
|
+
});
|
|
72
|
+
let stdout = '';
|
|
73
|
+
let stderr = '';
|
|
74
|
+
child.stdout?.on('data', (d) => { stdout += d; });
|
|
75
|
+
child.stderr?.on('data', (d) => { stderr += d; });
|
|
76
|
+
child.on('error', (error) =>
|
|
77
|
+
resolve({ code: null, signal: null, stdout, stderr, error }));
|
|
78
|
+
child.on('close', (code, signal) =>
|
|
79
|
+
resolve({ code, signal, stdout, stderr, error: null }));
|
|
80
|
+
});
|
|
62
81
|
return {
|
|
63
82
|
path: (key) => commandPath(key, env),
|
|
64
83
|
run: (key, args, opts) => doSpawn(commandPath(key, env), args, opts),
|
|
65
84
|
runRaw: (file, args, opts) => doSpawn(file, args, opts),
|
|
85
|
+
runAsync: (key, args, opts) => doSpawnAsync(commandPath(key, env), args, opts),
|
|
86
|
+
runRawAsync: (file, args, opts) => doSpawnAsync(file, args, opts),
|
|
66
87
|
};
|
|
67
88
|
}
|
package/libexec/lib/ipv6.mjs
CHANGED
|
@@ -23,16 +23,6 @@ function firstHextetOf(value) {
|
|
|
23
23
|
return Number.isInteger(g0) ? g0 : null;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* 2000::/3 全局单播(首组 0x2000–0x3fff)。
|
|
28
|
-
* @param {unknown} value
|
|
29
|
-
* @returns {boolean}
|
|
30
|
-
*/
|
|
31
|
-
export function isGlobalUnicastV6(value) {
|
|
32
|
-
const g0 = firstHextetOf(value);
|
|
33
|
-
return g0 !== null && g0 >= 0x2000 && g0 <= 0x3fff;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
/**
|
|
37
27
|
* 可拨号段:2000::/3 公网单播或 fc00::/7 ULA(首组 0xfc00–0xfdff)。
|
|
38
28
|
* @param {unknown} value
|
package/libexec/lib/paths.mjs
CHANGED
|
@@ -45,7 +45,6 @@ export function machinePaths(env = process.env) {
|
|
|
45
45
|
peer: path.join(stateDir, 'PEER_ON'),
|
|
46
46
|
link: path.join(stateDir, 'LINK_ON'),
|
|
47
47
|
}),
|
|
48
|
-
legacyOnFile: path.join(stateDir, 'ON'),
|
|
49
48
|
edgesDir: path.join(stateDir, 'edges'),
|
|
50
49
|
launchAgentsDir: path.join(home, 'Library', 'LaunchAgents'),
|
|
51
50
|
logsDir: path.join(home, 'Library', 'Logs'),
|
package/libexec/lib/probe.mjs
CHANGED
|
@@ -104,13 +104,14 @@ export function classifyLocalPort(runner, port, jobPid) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* 跑 bin/peer-probe(install 预检与 status
|
|
107
|
+
* 跑 bin/peer-probe(install 预检与 status 共用同一实现)。异步:status 把
|
|
108
|
+
* 它与 relay 实测、端口探测并发,避免串行累加超时。
|
|
108
109
|
* @param {import('./exec.mjs').Runner} runner
|
|
109
110
|
* @param {string} binDir
|
|
110
111
|
* @param {number} [timeoutMs]
|
|
111
|
-
* @returns {boolean}
|
|
112
|
+
* @returns {Promise<boolean>}
|
|
112
113
|
*/
|
|
113
|
-
export function peerProbeOk(runner, binDir, timeoutMs = 5000) {
|
|
114
|
-
const r = runner.
|
|
114
|
+
export async function peerProbeOk(runner, binDir, timeoutMs = 5000) {
|
|
115
|
+
const r = await runner.runRawAsync(path.join(binDir, 'peer-probe'), [], { timeout: timeoutMs });
|
|
115
116
|
return r.code === 0;
|
|
116
117
|
}
|
package/libexec/lib/runtime.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// 运行时脚本的拷贝对账(install/checkin/status 三方共享,design §2.3)。
|
|
2
|
-
// 2026-09-29 定:bin/ 放包脚本的**实体拷贝**(0755
|
|
2
|
+
// 2026-09-29 定:bin/ 放包脚本的**实体拷贝**(0755),不软链 fnm alias——
|
|
3
3
|
// 运行时零 npm/fnm 依赖,npm 误卸载/切版本不影响常驻服务;代价是包升级后
|
|
4
4
|
// 要重跑 install 刷新(core 侧 checkin 每次报名自动对账刷新 uplink-edge),
|
|
5
5
|
// runtime-version 戳记录安装时的包版本,status 见版本差不一致即报。
|
|
6
|
-
//
|
|
6
|
+
// 幂等:内容相同不重写(只补可执行位)。
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { packageScriptPath } from './paths.mjs';
|
|
@@ -19,19 +19,11 @@ export const RUNTIME_VERSION = pkg.version;
|
|
|
19
19
|
*/
|
|
20
20
|
export function ensureScript(dstPath, srcPath) {
|
|
21
21
|
const src = fs.readFileSync(srcPath);
|
|
22
|
-
// 先判软链(lstat 不跟随):0.1.x 遗留软链即使内容巧合相同也必须替换成
|
|
23
|
-
// 实体——readFileSync 会跟随目标骗过内容比对
|
|
24
|
-
let isLink = false;
|
|
25
|
-
try {
|
|
26
|
-
isLink = fs.lstatSync(dstPath).isSymbolicLink();
|
|
27
|
-
} catch { /* 不存在 */ }
|
|
28
22
|
let cur = null;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!err || err.code !== 'ENOENT') throw err;
|
|
34
|
-
}
|
|
23
|
+
try {
|
|
24
|
+
cur = fs.readFileSync(dstPath);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
if (!err || err.code !== 'ENOENT') throw err;
|
|
35
27
|
}
|
|
36
28
|
if (cur !== null && cur.equals(src)) {
|
|
37
29
|
// 内容对但可执行位丢了(cp/同步工具吃掉 mode):补上
|
|
@@ -39,17 +31,12 @@ export function ensureScript(dstPath, srcPath) {
|
|
|
39
31
|
fs.chmodSync(dstPath, 0o755);
|
|
40
32
|
return 'repaired';
|
|
41
33
|
}
|
|
42
|
-
//
|
|
43
|
-
try {
|
|
44
|
-
fs.unlinkSync(dstPath);
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if (!err || err.code !== 'ENOENT') throw err;
|
|
47
|
-
}
|
|
34
|
+
// 缺失或旧内容:tmp+rename 原子换(rename 直接替换目录项)
|
|
48
35
|
const tmp = `${dstPath}.tmp-${process.pid}`;
|
|
49
36
|
fs.writeFileSync(tmp, src, { mode: 0o755 });
|
|
50
37
|
fs.renameSync(tmp, dstPath);
|
|
51
38
|
fs.chmodSync(dstPath, 0o755);
|
|
52
|
-
return
|
|
39
|
+
return cur !== null ? 'updated' : 'created';
|
|
53
40
|
}
|
|
54
41
|
|
|
55
42
|
/**
|
|
@@ -77,10 +64,7 @@ export function ensureRuntime(ctx, entries) {
|
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
/**
|
|
80
|
-
* 运行时脚本体检(status
|
|
81
|
-
* 也判 stale:运行时必须是实体文件(readFileSync 跟随软链会骗过内容比对,
|
|
82
|
-
* 与 ensureScript 写路径的 lstat 判定对齐——实测 2026-09-29 m4 上
|
|
83
|
-
* uplink-edge-mb5 软链存活一天、status 全绿,靠的就是这个盲区)。
|
|
67
|
+
* 运行时脚本体检(status 用):与包内实体逐字节比对。
|
|
84
68
|
* @param {string} dstPath
|
|
85
69
|
* @param {string} srcPath
|
|
86
70
|
* @returns {'ok'|'missing'|'stale'}
|
|
@@ -88,8 +72,6 @@ export function ensureRuntime(ctx, entries) {
|
|
|
88
72
|
export function auditScript(dstPath, srcPath) {
|
|
89
73
|
let cur;
|
|
90
74
|
try {
|
|
91
|
-
// 先判软链(lstat 不跟随)
|
|
92
|
-
if (fs.lstatSync(dstPath).isSymbolicLink()) return 'stale';
|
|
93
75
|
cur = fs.readFileSync(dstPath);
|
|
94
76
|
} catch (err) {
|
|
95
77
|
if (!err || err.code !== 'ENOENT') throw err;
|
package/libexec/lib/state.mjs
CHANGED
|
@@ -13,7 +13,6 @@ const SWITCH_NAMES = ['relay', 'peer', 'link'];
|
|
|
13
13
|
* @property {(names: Array<'relay'|'peer'|'link'>) => void} setOn 幂等 touch
|
|
14
14
|
* @property {(names: Array<'relay'|'peer'|'link'>) => void} removeOn 幂等删除
|
|
15
15
|
* @property {() => {relay: boolean, peer: boolean, link: boolean}} readSwitches
|
|
16
|
-
* @property {() => boolean} migrateLegacyOn 旧 ON 在 → 迁移为三开关(全开)并删
|
|
17
16
|
* @property {(alias: string) => string | null} readEdgeV6
|
|
18
17
|
* @property {(alias: string, v6: string) => void} writeEdgeV6
|
|
19
18
|
* @property {(alias: string) => void} removeEdgeV6 不存在时静默
|
|
@@ -31,7 +30,6 @@ export function createStateStore(stateDir) {
|
|
|
31
30
|
peer: path.join(stateDir, 'PEER_ON'),
|
|
32
31
|
link: path.join(stateDir, 'LINK_ON'),
|
|
33
32
|
};
|
|
34
|
-
const legacyOnFile = path.join(stateDir, 'ON');
|
|
35
33
|
|
|
36
34
|
const ensureState = () => {
|
|
37
35
|
fs.mkdirSync(stateDir, { recursive: true, mode: 0o700 });
|
|
@@ -79,14 +77,6 @@ export function createStateStore(stateDir) {
|
|
|
79
77
|
};
|
|
80
78
|
},
|
|
81
79
|
|
|
82
|
-
// 26.9.5 前的总开关:见到即按「全开」迁移(install 时调,输出提示由调用方给)
|
|
83
|
-
migrateLegacyOn() {
|
|
84
|
-
if (!fs.existsSync(legacyOnFile)) return false;
|
|
85
|
-
this.setOn(SWITCH_NAMES);
|
|
86
|
-
fs.unlinkSync(legacyOnFile);
|
|
87
|
-
return true;
|
|
88
|
-
},
|
|
89
|
-
|
|
90
80
|
readEdgeV6(alias) {
|
|
91
81
|
try {
|
|
92
82
|
const v6 = fs.readFileSync(path.join(edgesDir, alias), 'utf8').trim();
|
|
@@ -90,7 +90,7 @@ while :; do
|
|
|
90
90
|
if ! "$SSH" -o BatchMode=yes -o ConnectTimeout=15 \
|
|
91
91
|
-o ServerAliveInterval=10 -o ServerAliveCountMax=2 \
|
|
92
92
|
-o ControlMaster=no -o ControlPath=none \
|
|
93
|
-
"$peer-via-relay" "ssh-net
|
|
93
|
+
"$peer-via-relay" "ssh-net _register $self $v6" >/dev/null 2>&1; then
|
|
94
94
|
echo "$(/bin/date '+%F %T') 报名失败($self $v6):中继不受影响,下轮自动重试" >&2
|
|
95
95
|
fi
|
|
96
96
|
fi
|