ssh-net 26.10.32 → 26.10.34
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 +28 -0
- package/libexec/cli.mjs +0 -1
- package/libexec/commands/install.mjs +13 -19
- package/libexec/commands/register.mjs +30 -57
- package/libexec/commands/status.mjs +26 -38
- package/libexec/commands/uninstall.mjs +4 -13
- package/libexec/lib/launchd.mjs +23 -0
- package/libexec/lib/paths.mjs +4 -6
- package/libexec/lib/render.mjs +2 -2
- package/libexec/lib/sshconfig.mjs +6 -9
- package/libexec/lib/state.mjs +0 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,34 @@
|
|
|
7
7
|
GitHub Release(Actions 自动跑测试后 npm publish;跳号与 0.x 的完整
|
|
8
8
|
考据见 git 史)。
|
|
9
9
|
|
|
10
|
+
## [26.10.34] - 2026-10-03
|
|
11
|
+
|
|
12
|
+
### 精简:冗余清理(代码/测试/文档三面,对外行为仅删 update 别名)
|
|
13
|
+
|
|
14
|
+
- **`update` 别名删除**:与 `upgrade` 两名一实(同 26.10.31 删 checkin
|
|
15
|
+
的先例),help 与文档只推 `upgrade`——习惯敲 update 的改敲 upgrade
|
|
16
|
+
- **死代码删除**:state 的 `removeAllEdges`、sshconfig 的 User 解析
|
|
17
|
+
(hostTable 只喂 HostName,user 一律来自 topology)、paths 的 `home`
|
|
18
|
+
导出、status 三个无消费的返回字段(runtimeVersion/links/run 的
|
|
19
|
+
status)、fake ssh 的 release 放行通路(link 循环时代遗留、零调用)
|
|
20
|
+
- **重复收敛**:uplink-edge plist 的 glob 三份拷贝 →
|
|
21
|
+
`launchd.edgeAliasesOnDisk`;`_register` 四分支合并为「部署/唤醒」两
|
|
22
|
+
条路径(行为不变,返回文案原样);core·node 的 relay 口 issue 文案、
|
|
23
|
+
测试的 sleep/waitForLog 与 edge 正常形态 fake 组合各收敛为一份
|
|
24
|
+
- **文档修正**:design §2.1「LAN IP 在 topology」为去 IP 改造前残留、
|
|
25
|
+
§5 预检段补 26.10.33 的默认形态限定并删一处逐字重复句;
|
|
26
|
+
vscode-mark/putFirst 注释漂移与 ci.yml 过期用例数清理
|
|
27
|
+
|
|
28
|
+
## [26.10.33] - 2026-10-03
|
|
29
|
+
|
|
30
|
+
### 修复:edge 端口预检按 link 形态收窄
|
|
31
|
+
|
|
32
|
+
- **默认零常驻形态不再预检转发口**:install 只有装 link 附加件时才绑
|
|
33
|
+
topology forwards 的端口;默认形态下他进程占用这些口(mb5 实案:
|
|
34
|
+
VS Code Remote 的自动端口转发在本机占着 1090/1080/5900)与本服务无关,
|
|
35
|
+
旧版预检却拒绝 install、挡住升级。`--with-link` 或 marker 在时预检照旧;
|
|
36
|
+
`[::1]:10022` 的 banner 检查不受影响(peer 按需路径仍由它保护)
|
|
37
|
+
|
|
10
38
|
## [26.10.32] - 2026-10-03
|
|
11
39
|
|
|
12
40
|
### 精简:VS Code 打标并入 routes,文档去演进考古层
|
package/libexec/cli.mjs
CHANGED
|
@@ -24,7 +24,6 @@ import { run as upgradeRun } from './commands/upgrade.mjs';
|
|
|
24
24
|
const COMMANDS = {
|
|
25
25
|
install: { run: installRun, desc: '按本机角色安装;edge 可带 --with-link/--without-link 管理转发附加件' },
|
|
26
26
|
upgrade: { run: upgradeRun, desc: '一键升级(npm i -g @latest + install 按 marker 刷新运行时)' },
|
|
27
|
-
update: { run: upgradeRun, desc: 'upgrade 的别名' },
|
|
28
27
|
uninstall: { run: uninstallRun, desc: '停用并删除全部作业、运行时与状态(再 npm uninstall -g)' },
|
|
29
28
|
start: { run: startRun, desc: 'edge 开隧道(relay|peer,缺省或 -a=relay+peer)/ core·node 启动' },
|
|
30
29
|
stop: { run: stopRun, desc: 'edge 关隧道(relay|peer,缺省或 -a 全关)/ core·node 停服' },
|
|
@@ -42,13 +42,15 @@ function compNote(results) {
|
|
|
42
42
|
return `(组件对账:${parts.join('、')})`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** edge 端口预检(纯读 + banner
|
|
46
|
-
|
|
45
|
+
/** edge 端口预检(纯读 + banner 判定),冲突抛错并报持有者。转发口只在
|
|
46
|
+
* link 附加件本次会装时才查:默认零常驻不绑这些口,他进程(如 VS Code
|
|
47
|
+
* 自动转发到本机的端口)占用与本服务无关。 */
|
|
48
|
+
async function precheckEdgePorts(ctx, linkOn) {
|
|
47
49
|
|
|
48
50
|
const { runner, paths, uid, topo } = ctx;
|
|
49
51
|
const jobPid = launchd.inspect(runner, uid, linkLabel(topo.core.alias)).pid;
|
|
50
52
|
|
|
51
|
-
for (const port of topo.forwards.map((f) => f.listenPort)) {
|
|
53
|
+
if (linkOn) for (const port of topo.forwards.map((f) => f.listenPort)) {
|
|
52
54
|
const c = classifyLocalPort(runner, port, jobPid);
|
|
53
55
|
if (c.kind === 'foreign') {
|
|
54
56
|
const who = runner.run('lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN']).stdout.trim();
|
|
@@ -92,10 +94,13 @@ function parseLinkFlag(args) {
|
|
|
92
94
|
|
|
93
95
|
async function installEdge(ctx, args) {
|
|
94
96
|
const { topo, paths } = ctx;
|
|
97
|
+
const flag = parseLinkFlag(args);
|
|
98
|
+
// 本次 install 后 link 在不在:显式 flag 说了算,无 flag 按 marker
|
|
99
|
+
const linkOn = flag === true
|
|
100
|
+
|| (flag !== false && fs.existsSync(paths.linkEnabledFile));
|
|
95
101
|
// 预检纯读且在落任何产物之前:被拒时 bin/ 一个都不建
|
|
96
|
-
await precheckEdgePorts(ctx);
|
|
102
|
+
await precheckEdgePorts(ctx, linkOn);
|
|
97
103
|
|
|
98
|
-
const flag = parseLinkFlag(args);
|
|
99
104
|
const label = linkLabel(topo.core.alias);
|
|
100
105
|
const plistPath = path.join(paths.launchAgentsDir, plistFileName(label));
|
|
101
106
|
|
|
@@ -105,7 +110,6 @@ async function installEdge(ctx, args) {
|
|
|
105
110
|
writeFileAtomic(paths.linkEnabledFile, '1\n', 0o600);
|
|
106
111
|
}
|
|
107
112
|
if (flag === false) fs.rmSync(paths.linkEnabledFile, { force: true });
|
|
108
|
-
const linkOn = fs.existsSync(paths.linkEnabledFile);
|
|
109
113
|
|
|
110
114
|
// 基础 3 实体(sn-probe/route/ipv6);linkOn 才加第 4 实体与带机器名
|
|
111
115
|
// 软链。回拨通知与 link 秒切已内联在 sn-route 成功点(本地进程调用),
|
|
@@ -141,7 +145,7 @@ async function installEdge(ctx, args) {
|
|
|
141
145
|
removeJob(ctx, label, plistPath);
|
|
142
146
|
fs.rmSync(path.join(paths.binDir, 'ssh-net-link-core'), { force: true });
|
|
143
147
|
fs.rmSync(path.join(paths.binDir, linkLinkName(topo.core.alias)), { force: true });
|
|
144
|
-
// 退役状态残留(
|
|
148
|
+
// 退役状态残留(26.10.31 退役;按约定一个月后删本两行)
|
|
145
149
|
fs.rmSync(path.join(paths.stateDir, 'ROUTE_PEER'), { force: true });
|
|
146
150
|
fs.rmSync(path.join(paths.stateDir, 'LINK_ON'), { force: true });
|
|
147
151
|
}
|
|
@@ -149,7 +153,7 @@ async function installEdge(ctx, args) {
|
|
|
149
153
|
// conf.d 片段(design §4.2):edge 是 routes 的唯一安装角色——routes 含
|
|
150
154
|
// 选路 Match 与尾部 VS Code 打标块;新签名带本机别名
|
|
151
155
|
const routesChanged = syncConfFile(paths.routesFile, renderRoutes(topo, ctx.self.alias));
|
|
152
|
-
// 打标块并入 routes 后的旧文件清理(26.
|
|
156
|
+
// 打标块并入 routes 后的旧文件清理(26.10.32 退役;按约定一个月后删本行)
|
|
153
157
|
fs.rmSync(path.join(paths.confDir, 'vscode-mark'), { force: true });
|
|
154
158
|
const fragMsg = routesChanged ? '(选路片段已更新)' : '';
|
|
155
159
|
if (!comp && !routesChanged && flag === undefined) {
|
|
@@ -161,16 +165,6 @@ async function installEdge(ctx, args) {
|
|
|
161
165
|
return `${head}${comp}${fragMsg}`;
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
/** 磁盘上已注册的 uplink-edge 别名(plist glob;topology 已删的机器靠它兜底)。 */
|
|
165
|
-
function registeredEdgeAliases(ctx) {
|
|
166
|
-
let files = [];
|
|
167
|
-
try {
|
|
168
|
-
files = fs.readdirSync(ctx.paths.launchAgentsDir)
|
|
169
|
-
.filter((f) => f.startsWith('local.ssh-net-uplink-edge-') && f.endsWith('.plist'));
|
|
170
|
-
} catch { /* 目录不存在 */ }
|
|
171
|
-
return files.map((f) => f.slice('local.ssh-net-uplink-edge-'.length, -'.plist'.length));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
168
|
function installCore(ctx) {
|
|
175
169
|
const { topo, paths } = ctx;
|
|
176
170
|
reconcileEdgeFragments(ctx);
|
|
@@ -178,7 +172,7 @@ function installCore(ctx) {
|
|
|
178
172
|
// 已注册的回拨组件在 install 时一并迁移/对账(旧版带机器名实体拷贝 →
|
|
179
173
|
// 软链):否则 upgrade 后 core status 要对每台未联系的 edge 报组件异常,
|
|
180
174
|
// 直到它下次报名才自愈(2026-09-30 补)
|
|
181
|
-
const edges =
|
|
175
|
+
const edges = launchd.edgeAliasesOnDisk(paths.launchAgentsDir);
|
|
182
176
|
const entities = [
|
|
183
177
|
['ssh-net-uplink-relay', 'ssh-net-uplink-relay'],
|
|
184
178
|
];
|
|
@@ -103,6 +103,16 @@ function rollbackEdgeRegistration(ctx, edge, prevV6) {
|
|
|
103
103
|
else writeEdgeRegistration(ctx, edge, prevV6);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/** 未注册/重部署分支的部署失败回滚:state 恢复旧 v6(无旧值则删)、
|
|
107
|
+
* 片段删除——没有 job 兜底的片段就是假入口。回滚失败不遮蔽原始错误。 */
|
|
108
|
+
function rollbackRegistration(ctx, edge, prevV6) {
|
|
109
|
+
try {
|
|
110
|
+
if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
|
|
111
|
+
else ctx.state.writeEdgeV6(edge.alias, prevV6);
|
|
112
|
+
removeConfFile(ctx.paths.edgeHostFile(edge.alias));
|
|
113
|
+
} catch { /* 回滚失败不遮蔽原始错误 */ }
|
|
114
|
+
}
|
|
115
|
+
|
|
106
116
|
/** start peer 的实现:控制面立即报名 + 置 relay+peer 开关。返回给人看的
|
|
107
117
|
* 文案(带上报名详情:v6 与 core 的响应)。先报名、成功后才落开关——
|
|
108
118
|
* 未安装(fatal)零副作用;可重试的报名失败(relay 不通、当场无 v6)
|
|
@@ -162,71 +172,34 @@ export function runRegister(ctx, args = []) {
|
|
|
162
172
|
[['ssh-net-uplink-edge', 'ssh-net-uplink-edge']],
|
|
163
173
|
[[edgeLinkName(alias), 'ssh-net-uplink-edge']]);
|
|
164
174
|
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const r = syncPlist(ctx, { label, plistPath, content });
|
|
175
|
-
if (r.lintError) throw new Error(`uplink-edge plist 校验失败:${r.lintError}`);
|
|
176
|
-
} catch (err) {
|
|
177
|
-
try {
|
|
178
|
-
if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
|
|
179
|
-
else ctx.state.writeEdgeV6(edge.alias, prevV6);
|
|
180
|
-
removeConfFile(ctx.paths.edgeHostFile(edge.alias));
|
|
181
|
-
} catch { /* 回滚失败不遮蔽原始错误 */ }
|
|
182
|
-
throw err;
|
|
183
|
-
}
|
|
184
|
-
return `registered ${alias}`;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 已注册但渲染结果与磁盘不符(topology 的 user 等变了):重新部署。
|
|
188
|
-
// syncPlist 走 bootout→落盘→enable→bootstrap,bootstrap 即首发,无需 kickstart。
|
|
189
|
-
// 失败回滚与首注册同款(state 恢复 + **片段删除**):syncPlist 内容变化路径
|
|
190
|
-
// 先 bootout,失败时 job 已不在册——没有 job 兜底的片段就是假入口;且
|
|
191
|
-
// 重写会用改过的新 user 拼旧 v6,既不准确也不诚实。下轮报名自愈
|
|
192
|
-
if (existing !== content) {
|
|
175
|
+
// 未注册(首次报名)或已注册但渲染结果与磁盘不符(topology 的 user 等变了):
|
|
176
|
+
// 重新部署。syncPlist 走 bootout→落盘→enable→bootstrap,bootstrap 即首发,
|
|
177
|
+
// 无需 kickstart。部署失败回滚登记:不回滚的话 conf.d/edge-<别名> 是没有
|
|
178
|
+
// job 兜底的假入口(install 的 reconcileEdgeFragments 自己定义的不变式),
|
|
179
|
+
// 只能等下轮报名或人工 install 修。回滚形态:state 恢复旧 v6、**片段删除**
|
|
180
|
+
// (而非重写)——未注册态的片段按 reconcile 不变式本就不该在(休眠/会话
|
|
181
|
+
// 重建时已被 retire 清掉),内容变化路径 syncPlist 先 bootout、失败时 job
|
|
182
|
+
// 已不在册,重写同样造出假入口。下轮报名自愈;回滚失败不遮蔽原始错误
|
|
183
|
+
if (!st.registered || existing !== content) {
|
|
193
184
|
writeEdgeRegistration(ctx, edge, v6);
|
|
194
185
|
try {
|
|
195
186
|
const r = syncPlist(ctx, { label, plistPath, content });
|
|
196
187
|
if (r.lintError) throw new Error(`uplink-edge plist 校验失败:${r.lintError}`);
|
|
197
188
|
} catch (err) {
|
|
198
|
-
|
|
199
|
-
if (prevV6 === null) ctx.state.removeEdgeV6(edge.alias);
|
|
200
|
-
else ctx.state.writeEdgeV6(edge.alias, prevV6);
|
|
201
|
-
removeConfFile(ctx.paths.edgeHostFile(edge.alias));
|
|
202
|
-
} catch { /* 回滚失败不遮蔽原始错误 */ }
|
|
189
|
+
rollbackRegistration(ctx, edge, prevV6);
|
|
203
190
|
throw err;
|
|
204
191
|
}
|
|
205
|
-
return `redeployed ${alias}`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// 休眠中:写 v6 → enable 清 override → kickstart 唤醒(enable 本身不首发)。
|
|
209
|
-
// enable 失败不用回滚:disabled 分支排在前面,下轮照走本分支
|
|
210
|
-
if (st.disabled) {
|
|
211
|
-
writeEdgeRegistration(ctx, edge, v6);
|
|
212
|
-
let r = launchd.enable(ctx.runner, ctx.uid, label);
|
|
213
|
-
if (r.code !== 0) throw new Error(`enable 失败:${r.stderr.trim()}`);
|
|
214
|
-
r = launchd.kickstart(ctx.runner, ctx.uid, label);
|
|
215
|
-
if (r.code !== 0) {
|
|
216
|
-
try {
|
|
217
|
-
rollbackEdgeRegistration(ctx, edge, prevV6);
|
|
218
|
-
} catch { /* 回滚失败不遮蔽原始错误 */ }
|
|
219
|
-
throw new Error(`kickstart 失败:${r.stderr.trim()}`);
|
|
220
|
-
}
|
|
221
|
-
return `woken ${alias}`;
|
|
192
|
+
return st.registered ? `redeployed ${alias}` : `registered ${alias}`;
|
|
222
193
|
}
|
|
223
194
|
|
|
224
|
-
// enabled(running 且 v6 相同 / v6 变了 /
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
195
|
+
// 休眠中(disable 睡着)或 enabled(running 且 v6 相同 / v6 变了 /
|
|
196
|
+
// not-running 三种形态合并):写 v6 → enable(休眠唤醒要清 override;
|
|
197
|
+
// enabled 幂等无害)→ kickstart。报名只会由活 edge 上的真实 ssh 触发,
|
|
198
|
+
// 无条件重拨正是人等连接时要的语义,进程重启即六连败计数清零。enable
|
|
199
|
+
// 失败不用回滚(disabled 态没变,下轮报名照走本分支)。两处同写先于
|
|
200
|
+
// kickstart:顺带 reconcile conf.d 片段(uplink-edge 六连败休眠删片段与
|
|
201
|
+
// 报名存在删/写竞态,缺则补)。kickstart 失败回滚 state 到 job 实际在用
|
|
202
|
+
// 的 v6:不回滚则磁盘已是新值,job 仍拿旧 v6 拨到六连败休眠
|
|
230
203
|
writeEdgeRegistration(ctx, edge, v6);
|
|
231
204
|
const en = launchd.enable(ctx.runner, ctx.uid, label);
|
|
232
205
|
if (en.code !== 0) throw new Error(`enable 失败:${en.stderr.trim()}`);
|
|
@@ -237,5 +210,5 @@ export function runRegister(ctx, args = []) {
|
|
|
237
210
|
} catch { /* 回滚失败不遮蔽原始错误 */ }
|
|
238
211
|
throw new Error(`kickstart 失败:${r.stderr.trim()}`);
|
|
239
212
|
}
|
|
240
|
-
return `kickstarted ${alias}`;
|
|
213
|
+
return st.disabled ? `woken ${alias}` : `kickstarted ${alias}`;
|
|
241
214
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import {
|
|
12
|
-
auditScript, auditLink,
|
|
12
|
+
auditScript, auditLink, runtimeVersionIssue,
|
|
13
13
|
} from '../lib/runtime.mjs';
|
|
14
14
|
import { packageScriptPath } from '../lib/paths.mjs';
|
|
15
15
|
import * as launchd from '../lib/launchd.mjs';
|
|
@@ -59,12 +59,6 @@ function runtimeIssues(ctx, { entities, serviceLinks }) {
|
|
|
59
59
|
return { issues, links };
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** 版本对账问题(各角色共用);版本值不单列展示,不一致才说话。 */
|
|
63
|
-
function versionInfo(ctx) {
|
|
64
|
-
const issue = runtimeVersionIssue(ctx.paths);
|
|
65
|
-
return { issue, runtimeVersion: readRuntimeVersion(ctx.paths) };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
62
|
/** forward 的人话标签:写出目标(loopback 是落地机环回)。 */
|
|
69
63
|
function forwardLabel(f) {
|
|
70
64
|
const target = f.targetAlias === 'loopback'
|
|
@@ -73,6 +67,15 @@ function forwardLabel(f) {
|
|
|
73
67
|
return `端口转发 127.0.0.1:${f.listenPort} → ${target}`;
|
|
74
68
|
}
|
|
75
69
|
|
|
70
|
+
/** relay 口没在监听时的 issue(core/node 同款文案):不可达与没监听分开报——
|
|
71
|
+
* 把 relay 不可达断言成「没在监听」会把故障点错指向本机转发,排障方向
|
|
72
|
+
* 完全不同。 */
|
|
73
|
+
function relayPortIssue(relayAlias, port, r) {
|
|
74
|
+
return r.reachable === false
|
|
75
|
+
? `连不上 ${relayAlias}(${r.detail || 'ssh 探测失败'}),入口 ${port} 状态未知——查 ${relayAlias} 可达性或本机网络`
|
|
76
|
+
: `${relayAlias} 入口 ${port} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${relayAlias} 或本机网络)`;
|
|
77
|
+
}
|
|
78
|
+
|
|
76
79
|
async function relayPortListening(ctx, port) {
|
|
77
80
|
// relay 别名的 User/HostName 由 ssh config Host 块提供;
|
|
78
81
|
// BatchMode 防换机器/换钥匙时在终端闪密码提示;IdentitiesOnly 防 agent
|
|
@@ -106,7 +109,7 @@ async function relayPathOk(ctx) {
|
|
|
106
109
|
async function collectEdge(ctx) {
|
|
107
110
|
const { topo, paths, state } = ctx;
|
|
108
111
|
const issues = [];
|
|
109
|
-
const
|
|
112
|
+
const vIssue = runtimeVersionIssue(ctx.paths);
|
|
110
113
|
if (vIssue) issues.push(vIssue);
|
|
111
114
|
// link 附加件以 marker 为准:默认只有 5 实体、无服务软链;装了才加
|
|
112
115
|
// link-core(转发口只取决于装没装,不是运行时开关)
|
|
@@ -203,16 +206,16 @@ async function collectEdge(ctx) {
|
|
|
203
206
|
: [];
|
|
204
207
|
return {
|
|
205
208
|
role: 'edge', alias: ctx.self.alias, switches, relayReady, peerReady,
|
|
206
|
-
linkInstalled, job,
|
|
209
|
+
linkInstalled, job, ports, forwardViews,
|
|
207
210
|
coreAlias: topo.core.alias, relayAlias: topo.relay.alias,
|
|
208
|
-
v6, v6ProbeOk,
|
|
211
|
+
v6, v6ProbeOk, issues,
|
|
209
212
|
};
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
async function collectCore(ctx) {
|
|
213
216
|
const { topo, paths } = ctx;
|
|
214
217
|
const issues = [];
|
|
215
|
-
const
|
|
218
|
+
const vIssue = runtimeVersionIssue(ctx.paths);
|
|
216
219
|
if (vIssue) issues.push(vIssue);
|
|
217
220
|
const { issues: rtIssues } = runtimeIssues(ctx, {
|
|
218
221
|
entities: [['ssh-net-uplink-relay', 'ssh-net-uplink-relay']],
|
|
@@ -275,30 +278,20 @@ async function collectCore(ctx) {
|
|
|
275
278
|
|
|
276
279
|
const relayPort = await relayPortP;
|
|
277
280
|
if (!relayJob.running) issues.push('relay 未在运行——ssh-net start 可拉起');
|
|
278
|
-
if (!relayPort.listening)
|
|
279
|
-
|
|
280
|
-
// 指向本机转发,实际更可能是 relay 不可达(排障方向完全不同)
|
|
281
|
-
if (relayPort.reachable === false)
|
|
282
|
-
issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${topo.core.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
|
|
283
|
-
else
|
|
284
|
-
issues.push(`${topo.relay.alias} 入口 ${topo.core.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${topo.relay.alias} 或本机网络)`);
|
|
285
|
-
}
|
|
281
|
+
if (!relayPort.listening)
|
|
282
|
+
issues.push(relayPortIssue(topo.relay.alias, topo.core.relayPort, relayPort));
|
|
286
283
|
|
|
287
284
|
// topology 已删(edge 改名/退役)但磁盘上还有回拨 job:不渲染成 edges 行
|
|
288
285
|
//(state/conf.d 都按新别名走),单独点破。残留无害——六连败后自休眠、
|
|
289
286
|
// 端口争抢由胜者持有且监听功能等价——但不可见会让改名现场少一条线索
|
|
290
287
|
const knownAliases = new Set(topo.edges.map((e) => e.alias));
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (!knownAliases.has(alias))
|
|
296
|
-
issues.push(`${alias} 的回拨 job 还在但 topology 已没有这个 edge(改名/退役残留,无害)——清理:launchctl bootout gui/${ctx.uid}/${f.replace(/\.plist$/, '')} 后删该 plist;或无视(它六连败后会自休眠)`);
|
|
297
|
-
}
|
|
298
|
-
} catch { /* LaunchAgents 目录不存在(未装) */ }
|
|
288
|
+
for (const alias of launchd.edgeAliasesOnDisk(paths.launchAgentsDir)) {
|
|
289
|
+
if (!knownAliases.has(alias))
|
|
290
|
+
issues.push(`${alias} 的回拨 job 还在但 topology 已没有这个 edge(改名/退役残留,无害)——清理:launchctl bootout gui/${ctx.uid}/${edgeLabel(alias)} 后删该 plist;或无视(它六连败后会自休眠)`);
|
|
291
|
+
}
|
|
299
292
|
|
|
300
293
|
return {
|
|
301
|
-
role: 'core', alias: ctx.self.alias,
|
|
294
|
+
role: 'core', alias: ctx.self.alias,
|
|
302
295
|
relayAlias: topo.relay.alias, relayJob, relayPort, edges, issues,
|
|
303
296
|
};
|
|
304
297
|
}
|
|
@@ -306,7 +299,7 @@ async function collectCore(ctx) {
|
|
|
306
299
|
async function collectNode(ctx) {
|
|
307
300
|
const { topo } = ctx;
|
|
308
301
|
const issues = [];
|
|
309
|
-
const
|
|
302
|
+
const vIssue = runtimeVersionIssue(ctx.paths);
|
|
310
303
|
if (vIssue) issues.push(vIssue);
|
|
311
304
|
const { issues: rtIssues } = runtimeIssues(ctx, {
|
|
312
305
|
entities: [['ssh-net-uplink-relay', 'ssh-net-uplink-relay']],
|
|
@@ -319,16 +312,11 @@ async function collectNode(ctx) {
|
|
|
319
312
|
const relayPort = await relayPortListening(ctx, ctx.self.relayPort);
|
|
320
313
|
if (active !== 'active')
|
|
321
314
|
issues.push(`系统服务 ${unit} 状态 ${active}——systemctl status ${unit} 查看`);
|
|
322
|
-
if (!relayPort.listening)
|
|
323
|
-
|
|
324
|
-
if (relayPort.reachable === false)
|
|
325
|
-
issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${ctx.self.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
|
|
326
|
-
else
|
|
327
|
-
issues.push(`${ctx.topo.relay.alias} 入口 ${ctx.self.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${ctx.topo.relay.alias} 或本机网络)`);
|
|
328
|
-
}
|
|
315
|
+
if (!relayPort.listening)
|
|
316
|
+
issues.push(relayPortIssue(topo.relay.alias, ctx.self.relayPort, relayPort));
|
|
329
317
|
|
|
330
318
|
return {
|
|
331
|
-
role: 'node', alias: ctx.self.alias,
|
|
319
|
+
role: 'node', alias: ctx.self.alias,
|
|
332
320
|
relayAlias: topo.relay.alias, unit, active, relayPort, issues,
|
|
333
321
|
};
|
|
334
322
|
}
|
|
@@ -439,5 +427,5 @@ export function renderText(s) {
|
|
|
439
427
|
|
|
440
428
|
export async function run(ctx) {
|
|
441
429
|
const s = await collect(ctx);
|
|
442
|
-
return { text: renderText(s), issues: s.issues
|
|
430
|
+
return { text: renderText(s), issues: s.issues };
|
|
443
431
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { removeJob } from '../lib/manage.mjs';
|
|
7
|
+
import * as launchd from '../lib/launchd.mjs';
|
|
7
8
|
import * as systemd from '../lib/systemd.mjs';
|
|
8
9
|
import {
|
|
9
10
|
linkLabel, plistFileName,
|
|
@@ -12,17 +13,6 @@ import {
|
|
|
12
13
|
|
|
13
14
|
const rm = (p) => fs.rmSync(p, { recursive: true, force: true });
|
|
14
15
|
|
|
15
|
-
/** 列出磁盘上全部 uplink-edge plist(topology 已删的机器只能靠 glob 发现)。 */
|
|
16
|
-
function edgePlistFiles(ctx) {
|
|
17
|
-
let files = [];
|
|
18
|
-
try {
|
|
19
|
-
files = fs
|
|
20
|
-
.readdirSync(ctx.paths.launchAgentsDir)
|
|
21
|
-
.filter((f) => f.startsWith('local.ssh-net-uplink-edge-') && f.endsWith('.plist'));
|
|
22
|
-
} catch { /* 目录不存在 */ }
|
|
23
|
-
return files;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
function uninstallEdge(ctx) {
|
|
27
17
|
const label = linkLabel(ctx.topo.core.alias);
|
|
28
18
|
removeJob(ctx, label, path.join(
|
|
@@ -41,8 +31,9 @@ function uninstallCore(ctx) {
|
|
|
41
31
|
const dir = ctx.paths.launchAgentsDir;
|
|
42
32
|
// label → plist 路径:磁盘 glob(topology 已删的残留)∪ topology 在册 edge
|
|
43
33
|
const edgeJobs = new Map();
|
|
44
|
-
for (const
|
|
45
|
-
|
|
34
|
+
for (const alias of launchd.edgeAliasesOnDisk(dir)) {
|
|
35
|
+
const label = edgeLabel(alias);
|
|
36
|
+
edgeJobs.set(label, path.join(dir, plistFileName(label)));
|
|
46
37
|
}
|
|
47
38
|
for (const e of ctx.topo.edges) {
|
|
48
39
|
const label = edgeLabel(e.alias);
|
package/libexec/lib/launchd.mjs
CHANGED
|
@@ -4,9 +4,32 @@
|
|
|
4
4
|
// - 休眠判据只用 print-disabled 字典(print 正文无稳定字段)
|
|
5
5
|
// - 任何 bootstrap 前无条件先 enable(override 残留时 bootstrap error 5)
|
|
6
6
|
// - enable 本身不触发首发,唤醒必须 kickstart -k
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import { edgeLabel } from './render.mjs';
|
|
9
|
+
|
|
7
10
|
/** @param {number} uid */
|
|
8
11
|
export const guiDomain = (uid) => `gui/${uid}`;
|
|
9
12
|
|
|
13
|
+
const EDGE_PLIST_PREFIX = edgeLabel(''); // 'local.ssh-net-uplink-edge-'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 磁盘 LaunchAgents 里 uplink-edge job plist 的别名清单(install/status/
|
|
17
|
+
* uninstall 共用;topology 已删的机器只能靠这个 glob 兜底发现,目录不存在
|
|
18
|
+
* 时空)。
|
|
19
|
+
* @param {string} launchAgentsDir
|
|
20
|
+
* @returns {string[]}
|
|
21
|
+
*/
|
|
22
|
+
export function edgeAliasesOnDisk(launchAgentsDir) {
|
|
23
|
+
try {
|
|
24
|
+
return fs
|
|
25
|
+
.readdirSync(launchAgentsDir)
|
|
26
|
+
.filter((f) => f.startsWith(EDGE_PLIST_PREFIX) && f.endsWith('.plist'))
|
|
27
|
+
.map((f) => f.slice(EDGE_PLIST_PREFIX.length, -'.plist'.length));
|
|
28
|
+
} catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
10
33
|
/**
|
|
11
34
|
* print 正文解析。
|
|
12
35
|
* @param {{code:number|null, stderr:string, stdout:string}} result
|
package/libexec/lib/paths.mjs
CHANGED
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
// state/ 易变状态(两开关、edges v6、PROBE_FAIL、ENSURE)
|
|
12
12
|
// link.enabled link 附加件的持久安装意图(树根,不放 state/)
|
|
13
13
|
// conf.d/ 渲染给 ssh Include 的配置片段(生成物,不进 dotfiles):
|
|
14
|
-
// routes edge:Match
|
|
15
|
-
// vscode-mark edge:VS Code 连接打标块(install 渲染常量)
|
|
14
|
+
// routes edge:Match 选路块 + 尾部 VS Code 打标块(install 渲染)
|
|
16
15
|
// edge-<别名> core:edge 在线入口(_register 写/休眠删)
|
|
17
16
|
// ~/.ssh/config dotfiles 托管,顶部 Include conf.d/* + 静态主机块(IP 唯一来源)
|
|
18
17
|
import path from 'node:path';
|
|
@@ -45,7 +44,6 @@ export function machinePaths(env = process.env) {
|
|
|
45
44
|
const sshNetDir = path.join(home, '.ssh', 'ssh-net');
|
|
46
45
|
const stateDir = path.join(sshNetDir, 'state');
|
|
47
46
|
return Object.freeze({
|
|
48
|
-
home,
|
|
49
47
|
sshDir: path.join(home, '.ssh'),
|
|
50
48
|
sshConfigFile: path.join(home, '.ssh', 'config'),
|
|
51
49
|
sshNetDir,
|
|
@@ -53,9 +51,9 @@ export function machinePaths(env = process.env) {
|
|
|
53
51
|
binDir: path.join(sshNetDir, 'bin'),
|
|
54
52
|
runtimeVersionFile: path.join(sshNetDir, 'runtime-version'),
|
|
55
53
|
stateDir,
|
|
56
|
-
// ssh Include 片段目录(design §4.2,2026-10-01):routes
|
|
57
|
-
//
|
|
58
|
-
// Include glob 零匹配静默,主 config 五台可同份
|
|
54
|
+
// ssh Include 片段目录(design §4.2,2026-10-01):routes 仅 edge install
|
|
55
|
+
// 写(含尾部 VS Code 打标块);edge-<别名> 仅 core _register/休眠写删;
|
|
56
|
+
// node 不建。Include glob 零匹配静默,主 config 五台可同份
|
|
59
57
|
confDir: path.join(sshNetDir, 'conf.d'),
|
|
60
58
|
routesFile: path.join(sshNetDir, 'conf.d', 'routes'),
|
|
61
59
|
/** @param {string} alias edge 别名 */
|
package/libexec/lib/render.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 渲染唯一来源(design §2.3、§4.2、§6.1、§6.2):
|
|
2
2
|
// - plist/systemd unit:每机差异只以位置参数出现(端口、别名、user、转发列表)
|
|
3
|
-
// - conf.d 片段:routes(edge 选路 Match
|
|
4
|
-
//
|
|
3
|
+
// - conf.d 片段:routes(edge 选路 Match + 尾部 VS Code 打标块)与
|
|
4
|
+
// edge-<别名>(core 上的 edge 入口)
|
|
5
5
|
// 纯字符串函数;渲染快照测试钉死输出;结构性断言(XML 闭合、只绑环回)在测试侧另查。
|
|
6
6
|
import { CALLBACK_PORT } from './constants.mjs';
|
|
7
7
|
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
/**
|
|
14
14
|
* @typedef {Object} StaticHost
|
|
15
15
|
* @property {string} [hostname] HostName;缺省时 ssh 以别名为地址
|
|
16
|
-
* @property {string} [user] User
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
18
|
const GLOB_CHARS = new Set(['*', '?', '!']);
|
|
@@ -35,10 +34,6 @@ export function parseStaticHosts(text) {
|
|
|
35
34
|
let currentPatterns = [];
|
|
36
35
|
let inMatch = false;
|
|
37
36
|
|
|
38
|
-
const putFirst = (host, key, value) => {
|
|
39
|
-
if (host[key] === undefined) host[key] = value;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
37
|
for (const raw of text.split('\n')) {
|
|
43
38
|
const line = raw.trim();
|
|
44
39
|
if (line.length === 0 || line.startsWith('#')) continue;
|
|
@@ -53,7 +48,7 @@ export function parseStaticHosts(text) {
|
|
|
53
48
|
if (keyword === 'host') {
|
|
54
49
|
inMatch = false;
|
|
55
50
|
// 精确模式入表(多模式逐个);同一别名多个 Host 块时 ssh 取首次值——
|
|
56
|
-
//
|
|
51
|
+
// 已存在的记录对象继续沿用,首次值写入不被后块覆盖
|
|
57
52
|
currentPatterns = cols.slice(1).filter(isExactPattern);
|
|
58
53
|
for (const p of currentPatterns) {
|
|
59
54
|
if (!table.has(p)) table.set(p, {});
|
|
@@ -61,11 +56,13 @@ export function parseStaticHosts(text) {
|
|
|
61
56
|
continue;
|
|
62
57
|
}
|
|
63
58
|
if (inMatch || currentPatterns.length === 0) continue;
|
|
64
|
-
if (keyword === 'hostname'
|
|
59
|
+
if (keyword === 'hostname') {
|
|
65
60
|
const value = cols.slice(1).join(' ');
|
|
66
61
|
if (value) {
|
|
67
|
-
for (const p of currentPatterns)
|
|
68
|
-
|
|
62
|
+
for (const p of currentPatterns) {
|
|
63
|
+
const host = table.get(p);
|
|
64
|
+
if (host.hostname === undefined) host.hostname = value;
|
|
65
|
+
}
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
}
|
package/libexec/lib/state.mjs
CHANGED
|
@@ -18,7 +18,6 @@ const SWITCH_NAMES = ['relay', 'peer'];
|
|
|
18
18
|
* @property {(alias: string) => string | null} readEdgeV6
|
|
19
19
|
* @property {(alias: string, v6: string) => void} writeEdgeV6
|
|
20
20
|
* @property {(alias: string) => void} removeEdgeV6 不存在时静默
|
|
21
|
-
* @property {() => void} removeAllEdges
|
|
22
21
|
*/
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -104,9 +103,5 @@ export function createStateStore({ stateDir, switchFiles, edgesDir }) {
|
|
|
104
103
|
throw err;
|
|
105
104
|
}
|
|
106
105
|
},
|
|
107
|
-
|
|
108
|
-
removeAllEdges() {
|
|
109
|
-
fs.rmSync(edgesDir, { recursive: true, force: true });
|
|
110
|
-
},
|
|
111
106
|
};
|
|
112
107
|
}
|