ssh-net 26.10.54 → 26.10.56
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 +57 -1
- package/README.md +166 -104
- package/libexec/cli.mjs +53 -16
- package/libexec/commands/doctor.mjs +19 -16
- package/libexec/commands/install.mjs +68 -40
- package/libexec/commands/register.mjs +28 -20
- package/libexec/commands/restart.mjs +5 -5
- package/libexec/commands/start.mjs +8 -5
- package/libexec/commands/status.mjs +126 -95
- package/libexec/commands/stop.mjs +56 -20
- package/libexec/commands/uninstall.mjs +62 -22
- package/libexec/commands/update.mjs +26 -27
- package/libexec/lib/cliargs.mjs +10 -4
- package/libexec/lib/jobctl.mjs +5 -4
- package/libexec/lib/launchd.mjs +4 -2
- package/libexec/lib/manage.mjs +5 -2
- package/libexec/lib/manifest.mjs +3 -0
- package/libexec/lib/paths.mjs +2 -1
- package/libexec/lib/render.mjs +1 -1
- package/libexec/lib/systemd.mjs +7 -5
- package/libexec/sn-register-lan +3 -3
- package/libexec/sn-route +71 -41
- package/libexec/ssh-net-uplink-edge +3 -3
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// install:对账到 topology
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// install:对账到 topology 描述的稳态。幂等:运行时脚本内容相同不重写、
|
|
2
|
+
// plist/unit 字节相同不 bootout(不断连)。edge 只注册 PathState job(RELAY_ON
|
|
3
|
+
// 不在不启动);core/node 会恢复 stop 的中继服务;core 不预建 uplink-edge
|
|
4
|
+
//(首次报名才生成),node 写 unit 并 enable --now。
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
@@ -18,8 +18,9 @@ import {
|
|
|
18
18
|
classifyLocalPort, lsofListen, v6LoopbackPids, peerProbeOk,
|
|
19
19
|
} from '../lib/probe.mjs';
|
|
20
20
|
import { writeFileAtomic } from '../lib/fsutil.mjs';
|
|
21
|
+
import { packageScriptPath } from '../lib/paths.mjs';
|
|
21
22
|
import {
|
|
22
|
-
SN_PROBE, edgeRuntimePlan, coreNodeRuntimePlan,
|
|
23
|
+
SN_PROBE, RESIDENT_SCRIPTS, edgeRuntimePlan, coreNodeRuntimePlan,
|
|
23
24
|
edgeCallbacksPlan, linkAddonPlan, mergePlans,
|
|
24
25
|
} from '../lib/manifest.mjs';
|
|
25
26
|
import {
|
|
@@ -27,9 +28,8 @@ import {
|
|
|
27
28
|
renderEdgeHost, renderEdgeLinkPlist, renderRelayPlist, renderRelayUnit, renderRoutes,
|
|
28
29
|
} from '../lib/render.mjs';
|
|
29
30
|
|
|
30
|
-
/** ensureRuntime
|
|
31
|
-
|
|
32
|
-
function compNote(results) {
|
|
31
|
+
/** ensureRuntime 结果的人话摘要;常驻实体换新时顺便说明运行中进程的生效时机。 */
|
|
32
|
+
function compNote(results, entities) {
|
|
33
33
|
const LABELS = {
|
|
34
34
|
created: '新拷脚本', updated: '更新脚本', repaired: '补执行权限',
|
|
35
35
|
linked: '新软链', relinked: '修正软链', replaced: '换为软链',
|
|
@@ -40,7 +40,12 @@ function compNote(results) {
|
|
|
40
40
|
counts.set(s, (counts.get(s) ?? 0) + 1);
|
|
41
41
|
}
|
|
42
42
|
if (counts.size === 0) return '';
|
|
43
|
-
|
|
43
|
+
const summary = `本次更新:${[...counts].map(([k, n]) => `${LABELS[k] ?? k} ${n} 个`).join('、')}`;
|
|
44
|
+
const residentUpdated = entities.some(([name], i) =>
|
|
45
|
+
results[i] === 'updated' && RESIDENT_SCRIPTS.includes(name));
|
|
46
|
+
return residentUpdated
|
|
47
|
+
? `${summary};常驻脚本已更新,运行中的进程将在下次重连后使用新版`
|
|
48
|
+
: summary;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/** 安装结果文案:组件刷新/配置更新若干条 note 合并进一对括号(''=零附加信息)。 */
|
|
@@ -49,12 +54,25 @@ function notesPart(...notes) {
|
|
|
49
54
|
return parts.length ? `(${parts.join(';')})` : '';
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
/**
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
/** plist/unit 的同构部署结果统一变成用户可读的任务变化。 */
|
|
58
|
+
function deploymentNote(r, task, config) {
|
|
59
|
+
if (r.deployed)
|
|
60
|
+
return r.restarted ? `${config}已更新,可能断开当前连接` : `${task}已部署`;
|
|
61
|
+
if (r.revived) return `${task}已恢复`;
|
|
62
|
+
if (r.registered) return `${task}已注册`;
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** core/node 安装结果同构:服务配置未变只报刷新项,变了报中继通道已开启。 */
|
|
67
|
+
function coreNodeInstallMsg(comp, entryChanged, result, relayLine) {
|
|
68
|
+
const note = notesPart(
|
|
69
|
+
comp,
|
|
70
|
+
entryChanged ? 'edge 入口已更新' : '',
|
|
71
|
+
deploymentNote(result, '中继任务', '中继服务配置'),
|
|
72
|
+
);
|
|
73
|
+
if (result.unchanged)
|
|
56
74
|
return note ? `已刷新${note};服务配置无需改动` : '已安装,无需改动';
|
|
57
|
-
return `安装完成${note}
|
|
75
|
+
return `安装完成${note},中继通道已开启(${relayLine})`;
|
|
58
76
|
}
|
|
59
77
|
|
|
60
78
|
/** edge 端口预检(纯读 + banner 判定),冲突抛错并报持有者。转发口只在
|
|
@@ -62,7 +80,7 @@ function coreNodeInstallMsg(comp, entryChanged, unchanged, relayLine) {
|
|
|
62
80
|
* 自动转发到本机的端口)占用与本服务无关。 */
|
|
63
81
|
async function precheckEdgePorts(ctx, linkOn) {
|
|
64
82
|
|
|
65
|
-
const { runner,
|
|
83
|
+
const { runner, uid, topo } = ctx;
|
|
66
84
|
const forwardPorts = topo.forwards.map((f) => f.listenPort);
|
|
67
85
|
if (linkOn && forwardPorts.length > 0) {
|
|
68
86
|
// 只要 pid 判持口者归属(link-core 是 exec ssh,job pid 即持口者)
|
|
@@ -78,13 +96,12 @@ async function precheckEdgePorts(ctx, linkOn) {
|
|
|
78
96
|
// 10022 持口者永远是本机 sshd,无法按 pid 溯源:读到 SSH banner 才认。
|
|
79
97
|
// 只盯 [::1](本服务的监听面);127.0.0.1:10022 的持有者如 VS Code 本地
|
|
80
98
|
// 转发与本服务不同地址族、可共存,不判冲突。
|
|
81
|
-
// 一次 lsof 同时拿持有者 pid
|
|
82
|
-
//
|
|
99
|
+
// 一次 lsof 同时拿持有者 pid 与报错展示文本。预检执行包内探针:
|
|
100
|
+
// 不能用待修复的 bin/sn-probe,否则探针损坏会把 install 自己的修复入口堵住
|
|
83
101
|
const listeners = lsofListen(runner, CALLBACK_PORT);
|
|
84
102
|
if (
|
|
85
103
|
v6LoopbackPids(listeners, CALLBACK_PORT).length > 0
|
|
86
|
-
&&
|
|
87
|
-
&& !(await peerProbeOk(runner, paths.binDir))
|
|
104
|
+
&& !(await peerProbeOk(runner, path.dirname(packageScriptPath(SN_PROBE))))
|
|
88
105
|
) {
|
|
89
106
|
throw new Error(
|
|
90
107
|
`端口 ${CALLBACK_PORT} 有程序在监听但没有响应(多半是断线残留,或被别的程序占用):\n${listeners}`,
|
|
@@ -118,8 +135,8 @@ function parseLinkFlag(args) {
|
|
|
118
135
|
export function notifyDepNote({ hasTerminalNotifier, hasOsascript }) {
|
|
119
136
|
if (hasTerminalNotifier) return '';
|
|
120
137
|
if (hasOsascript)
|
|
121
|
-
return '\n
|
|
122
|
-
return '\n
|
|
138
|
+
return '\n提示:桌面通知走系统通知发送;想要更丰富的通知样式可 brew install terminal-notifier(可选)';
|
|
139
|
+
return '\n提示:此机没有桌面通知工具,直连恢复时不会弹通知(不影响连接功能)';
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
/** 本机真实检测(分档文案由 notifyDepNote 纯函数测试锚定)。 */
|
|
@@ -153,14 +170,15 @@ async function installEdge(ctx, args) {
|
|
|
153
170
|
if (flag === false) fs.rmSync(paths.linkEnabledFile, { force: true });
|
|
154
171
|
|
|
155
172
|
// 实体/软链清单唯一来源在 manifest:基础 3 实体,linkOn 才加第 4 实体与
|
|
156
|
-
// 带机器名软链。回拨通知与 link
|
|
157
|
-
// 调用),不再有独立信令脚本与跨机反拨
|
|
173
|
+
// 带机器名软链。回拨通知与 link 秒切由 sn-route 成功点在本地执行
|
|
158
174
|
const plan = edgeRuntimePlan(topo, linkOn);
|
|
159
|
-
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links));
|
|
175
|
+
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
|
|
176
|
+
let linkChanged = false;
|
|
177
|
+
let linkNote = '';
|
|
160
178
|
|
|
161
179
|
if (linkOn) {
|
|
162
180
|
// 附加件:渲染纯 ssh plist 并对账(RELAY_ON 在 syncPlist 按 stopped 语义
|
|
163
|
-
// 首发,不在注册待命);转发参数是最终 -
|
|
181
|
+
// 首发,不在注册待命);转发参数是最终 -L argv
|
|
164
182
|
const content = renderEdgeLinkPlist({
|
|
165
183
|
binDir: paths.binDir,
|
|
166
184
|
coreAlias: topo.core.alias,
|
|
@@ -170,13 +188,19 @@ async function installEdge(ctx, args) {
|
|
|
170
188
|
});
|
|
171
189
|
const r = syncPlist(ctx, { label, plistPath, content });
|
|
172
190
|
if (r.lintError) throw new Error(`link plist 校验失败:${r.lintError}`);
|
|
191
|
+
linkChanged = !r.unchanged;
|
|
192
|
+
linkNote = deploymentNote(r, '本地转发任务', '本地转发配置');
|
|
173
193
|
} else {
|
|
174
194
|
// 默认零常驻:清掉加装过的 link 全部产物。plist 必须先 bootout,否则
|
|
175
195
|
// 删了实体后 launchd 每 ThrottleInterval 刷 ENOENT
|
|
176
|
-
removeJob(ctx, label, plistPath);
|
|
196
|
+
const jobRemoved = removeJob(ctx, label, plistPath);
|
|
177
197
|
const addon = linkAddonPlan(topo);
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
const addonPaths = [...addon.entities, ...addon.links].map(([name]) => paths.binScript(name));
|
|
199
|
+
const addonRemoved = addonPaths.some((p) =>
|
|
200
|
+
fs.lstatSync(p, { throwIfNoEntry: false }) !== undefined);
|
|
201
|
+
for (const p of addonPaths) fs.rmSync(p, { force: true });
|
|
202
|
+
linkChanged = jobRemoved || addonRemoved;
|
|
203
|
+
if (linkChanged) linkNote = '本地转发任务与组件已移除';
|
|
180
204
|
}
|
|
181
205
|
|
|
182
206
|
// conf.d 片段(design §4.2):edge 是 routes 的唯一安装角色——routes 含
|
|
@@ -184,14 +208,17 @@ async function installEdge(ctx, args) {
|
|
|
184
208
|
const routesChanged = syncConfFile(paths.routesFile, renderRoutes(topo, ctx.self.alias));
|
|
185
209
|
const depNote = localNotifyDepNote();
|
|
186
210
|
const head = linkOn
|
|
187
|
-
? '
|
|
188
|
-
: '
|
|
189
|
-
const base = (!comp && !routesChanged && flag === undefined)
|
|
211
|
+
? '安装完成(含本地端口转发)'
|
|
212
|
+
: '安装完成(默认不安装本地端口转发;需要时运行 ssh-net install --with-link)';
|
|
213
|
+
const base = (!comp && !linkChanged && !routesChanged && flag === undefined)
|
|
190
214
|
? (linkOn
|
|
191
|
-
? '
|
|
192
|
-
: '
|
|
193
|
-
: `${head}${notesPart(comp, routesChanged ? 'ssh 配置片段已更新' : '')}`;
|
|
194
|
-
|
|
215
|
+
? '已安装(本地端口转发已启用),无需改动'
|
|
216
|
+
: '已安装,无需改动(未安装本地端口转发)')
|
|
217
|
+
: `${head}${notesPart(comp, linkNote, routesChanged ? 'ssh 配置片段已更新' : '')}`;
|
|
218
|
+
const startNote = ctx.state.isOn('relay')
|
|
219
|
+
? ''
|
|
220
|
+
: '\n当前为关闭状态;开启自动选路和 IPv6 直连:ssh-net start';
|
|
221
|
+
return `${base}${startNote}${depNote}`;
|
|
195
222
|
}
|
|
196
223
|
|
|
197
224
|
/**
|
|
@@ -230,7 +257,7 @@ function installCore(ctx) {
|
|
|
230
257
|
const edges = launchd.edgeAliasesOnDisk(paths.launchAgentsDir);
|
|
231
258
|
// relay 基础形态 + 磁盘在册 edge 的回拨组件(清单与报名/status 体检同源)
|
|
232
259
|
const plan = mergePlans(coreNodeRuntimePlan(topo), edgeCallbacksPlan(edges));
|
|
233
|
-
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links));
|
|
260
|
+
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
|
|
234
261
|
const label = relayLabel(topo.relay.alias);
|
|
235
262
|
const content = renderRelayPlist({
|
|
236
263
|
binDir: paths.binDir,
|
|
@@ -241,7 +268,7 @@ function installCore(ctx) {
|
|
|
241
268
|
const r = syncPlist(ctx, { label, plistPath: paths.plistFile(label), content });
|
|
242
269
|
// lint 失败不能静默报「安装完成」:syncPlist 以返回值交错误(register 同判)
|
|
243
270
|
if (r.lintError) throw new Error(`relay plist 校验失败:${r.lintError}`);
|
|
244
|
-
return coreNodeInstallMsg(comp, entryChanged, r
|
|
271
|
+
return coreNodeInstallMsg(comp, entryChanged, r,
|
|
245
272
|
`${topo.relay.alias} 入口 ${topo.core.relayPort}`);
|
|
246
273
|
}
|
|
247
274
|
|
|
@@ -251,7 +278,7 @@ function installNode(ctx) {
|
|
|
251
278
|
throw new Error('node 安装写 /etc/systemd/system 需要 root,请以 root 运行');
|
|
252
279
|
const entryChanged = syncEdgeEntries(ctx);
|
|
253
280
|
const plan = coreNodeRuntimePlan(topo);
|
|
254
|
-
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links));
|
|
281
|
+
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
|
|
255
282
|
const unitName = relayUnitName(topo.relay.alias);
|
|
256
283
|
// HOME 用 root 的真实家目录(getpwuid),不取 $HOME:sudo 保留 HOME 的环境
|
|
257
284
|
// (sudo -E,或部分发行版的默认值)会把调用者的家目录写进 unit——root
|
|
@@ -261,8 +288,9 @@ function installNode(ctx) {
|
|
|
261
288
|
// (plist 侧是 XML 数组无此问题)——当场拒绝比装出一个起不来的 unit 诚实
|
|
262
289
|
if (/\s/.test(home))
|
|
263
290
|
throw new Error(`node 的 HOME(${home})含空白字符:systemd ExecStart 无法转义,拒绝安装`);
|
|
291
|
+
const unitPath = path.join(paths.systemdUnitDir, unitName);
|
|
264
292
|
const r = systemd.syncUnit(runner, {
|
|
265
|
-
unitPath
|
|
293
|
+
unitPath,
|
|
266
294
|
unitName,
|
|
267
295
|
content: renderRelayUnit({
|
|
268
296
|
binDir: paths.binDir,
|
|
@@ -271,7 +299,7 @@ function installNode(ctx) {
|
|
|
271
299
|
home,
|
|
272
300
|
}),
|
|
273
301
|
});
|
|
274
|
-
return coreNodeInstallMsg(comp, entryChanged, r
|
|
302
|
+
return coreNodeInstallMsg(comp, entryChanged, r,
|
|
275
303
|
`${ctx.topo.relay.alias} 入口 ${ctx.self.relayPort}`);
|
|
276
304
|
}
|
|
277
305
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
//
|
|
7
7
|
// core 侧:报名只会由活 edge 上的真实连接触发(sn-route 现场、start peer),
|
|
8
8
|
// 所以任何报名都带「人正在等连接」语义——同 v6 也无条件 enable+kickstart,
|
|
9
|
-
//
|
|
10
|
-
//
|
|
9
|
+
// 回拨立即重拨、重试额度随进程重启重置。install 与报名都会刷新运行时脚本;
|
|
10
|
+
// uplink-edge 的 job 参数(user 等)由报名重新渲染。
|
|
11
11
|
import { explainV6Error } from '../lib/ipv6.mjs';
|
|
12
12
|
import * as launchd from '../lib/launchd.mjs';
|
|
13
13
|
import { syncPlist } from '../lib/manage.mjs';
|
|
@@ -19,59 +19,67 @@ import {
|
|
|
19
19
|
edgeLabel, renderUplinkEdgePlist, coreViaRelayArgs,
|
|
20
20
|
} from '../lib/render.mjs';
|
|
21
21
|
|
|
22
|
+
/** 可重试的即时通知失败:开关仍可保存,但必须把具体原因带给用户。 */
|
|
23
|
+
function retryableError(message) {
|
|
24
|
+
const err = new Error(message);
|
|
25
|
+
err.retryable = true;
|
|
26
|
+
return err;
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
/** edge 侧报名:取 v6 + 命令行 -J 经 relay 调 core 的 _register。 */
|
|
23
30
|
function runEdgeAnnounce(ctx) {
|
|
31
|
+
const { progress } = ctx;
|
|
32
|
+
progress('正在探测本机可用 IPv6…');
|
|
24
33
|
const probe = ctx.runner.runRaw(
|
|
25
34
|
ctx.paths.binScript(SN_IPV6), [], { timeout: 5000 },
|
|
26
35
|
);
|
|
27
|
-
// bin/sn-ipv6 缺失(未 install)别误报成「无 IPv6
|
|
28
|
-
// enablePeer
|
|
29
|
-
if (probe.error && probe.error.code === 'ENOENT')
|
|
30
|
-
|
|
31
|
-
e.fatal = true;
|
|
32
|
-
throw e;
|
|
33
|
-
}
|
|
36
|
+
// bin/sn-ipv6 缺失(未 install)别误报成「无 IPv6」;未标记 retryable,
|
|
37
|
+
// enablePeer 会原样抛出且不保存开关
|
|
38
|
+
if (probe.error && probe.error.code === 'ENOENT')
|
|
39
|
+
throw new Error('未安装(缺运行时脚本)——先跑 ssh-net install');
|
|
34
40
|
// 「探测没跑成」与「网络没有 IPv6」是两回事,failed 绝不能谎称没有 v6
|
|
35
41
|
const { state, v6 } = classifyV6Probe(probe);
|
|
36
42
|
if (state === 'failed') {
|
|
37
43
|
const why = probe.error?.message
|
|
38
44
|
?? (probe.signal !== null && probe.signal !== undefined
|
|
39
45
|
? `signal ${probe.signal}` : `exit ${probe.code}`);
|
|
40
|
-
throw
|
|
46
|
+
throw retryableError(`本机 IPv6 探测失败(${why});这不代表网络没有 IPv6`);
|
|
41
47
|
}
|
|
42
48
|
if (state === 'none')
|
|
43
|
-
throw
|
|
49
|
+
throw retryableError('当前网络没有可用 IPv6');
|
|
44
50
|
// 拼进远端命令串前本地校验:输出被污染(多行/元字符)时报清晰错误,
|
|
45
51
|
// 而不是拼出一条让 core 侧 shell 莫名解析失败的命令
|
|
46
52
|
const v6Err = explainV6Error(v6);
|
|
47
|
-
if (v6Err) throw
|
|
53
|
+
if (v6Err) throw retryableError(`本机 IPv6 选取异常(sn-ipv6 输出不是可用地址:${v6Err})`);
|
|
48
54
|
// 报名固定走 relay:peer 僵尸时自动选路会把报名一起挂死。无人值守首连
|
|
49
55
|
// 信任 accept-new(status 探测不带,见 design §4.3)。挂死由 60s timeout 兜底
|
|
56
|
+
progress(`正在经 ${ctx.topo.relay.alias} 通知 ${ctx.topo.core.alias}…`);
|
|
50
57
|
const r = ctx.runner.run('ssh', coreViaRelayArgs(ctx.topo, {
|
|
51
58
|
acceptHost: true,
|
|
52
59
|
remoteCommand: `ssh-net _register ${ctx.self.alias} ${v6}`,
|
|
53
60
|
}), { timeout: 60_000 });
|
|
54
61
|
if (r.code !== 0)
|
|
55
|
-
throw
|
|
62
|
+
throw retryableError(`经 ${ctx.topo.relay.alias} 通知失败(${r.stderr.trim() || `exit ${r.code}`})`);
|
|
56
63
|
const core = r.stdout.trim();
|
|
57
|
-
return `已通知 core(本机地址 ${v6};core 回应:${core}
|
|
64
|
+
return `已通知 core(本机地址 ${v6};core 回应:${core});core 已受理,接下来会尝试回连,直连是否就绪用 ssh-net status --probe 查看`;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
/** start peer 的实现:立即报名 + 置 relay+peer
|
|
61
|
-
*
|
|
67
|
+
/** start peer 的实现:立即报名 + 置 relay+peer 开关。未安装等非预期错误零副作用;
|
|
68
|
+
* 标记为 retryable 的报名失败不阻断用户意图,开关照置并展示具体原因——下次
|
|
62
69
|
* 发起连接时 sn-route 会再报。
|
|
63
70
|
* @param {object} ctx
|
|
64
71
|
* @param {boolean} [alreadyOn] 开关此前已全开:措辞用「已是开启状态」 */
|
|
65
72
|
export function enablePeer(ctx, alreadyOn = false) {
|
|
66
|
-
const prefix = alreadyOn ? '隧道已是开启状态' : 'peer
|
|
73
|
+
const prefix = alreadyOn ? '隧道已是开启状态' : 'peer 和 relay 开关已开启';
|
|
67
74
|
try {
|
|
68
75
|
const detail = runEdgeAnnounce(ctx);
|
|
69
76
|
ctx.state.setOn(['relay', 'peer']); // relay 是根:peer 依赖它
|
|
70
|
-
return `${prefix}
|
|
77
|
+
return `${prefix};${detail}`;
|
|
71
78
|
} catch (err) {
|
|
72
|
-
|
|
79
|
+
// 只有明确的网络/探测失败才降级为「开关已开、稍后再试」;程序错误照抛
|
|
80
|
+
if (!err?.retryable) throw err;
|
|
73
81
|
ctx.state.setOn(['relay', 'peer']);
|
|
74
|
-
return `${prefix}
|
|
82
|
+
return `${prefix};本次未能通知 core:${err.message}。开关已保存,下次 ssh 会自动重试,也可再跑 ssh-net start peer`;
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
85
|
|
|
@@ -13,25 +13,25 @@ export function run(ctx, args = []) {
|
|
|
13
13
|
const label = linkLabel(ctx.topo.core.alias);
|
|
14
14
|
// 只要 registered(printState),不跑全域 print-disabled
|
|
15
15
|
if (!launchd.printState(ctx.runner, ctx.uid, label).registered) {
|
|
16
|
-
return '
|
|
16
|
+
return '默认未安装本地端口转发,没有可重启的对象;立即尝试 IPv6 直连用 ssh-net doctor,需要 SOCKS/VNC 端口用 ssh-net install --with-link';
|
|
17
17
|
}
|
|
18
18
|
// kickstartEnabled:与 core 同规则,残留 disabled override 时不被拒
|
|
19
19
|
const r = launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
20
20
|
if (r.code !== 0) throw new Error(`重启失败:${r.stderr.trim()}`);
|
|
21
|
-
return '
|
|
21
|
+
return '本地端口转发已重启(正在重新连接)';
|
|
22
22
|
}
|
|
23
23
|
if (ctx.role === 'core') {
|
|
24
24
|
const label = relayLabel(ctx.topo.relay.alias);
|
|
25
25
|
// 只要 registered(printState),不跑全域 print-disabled
|
|
26
26
|
if (!launchd.printState(ctx.runner, ctx.uid, label).registered)
|
|
27
|
-
throw new Error('
|
|
27
|
+
throw new Error('中继任务尚未加载(已 stop?先 ssh-net start)');
|
|
28
28
|
const r = launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
29
29
|
if (r.code !== 0) throw new Error(`重启失败:${r.stderr.trim()}`);
|
|
30
|
-
return '
|
|
30
|
+
return '中继通道已重启';
|
|
31
31
|
}
|
|
32
32
|
if (ctx.role === 'node') {
|
|
33
33
|
systemd.enableRestart(ctx.runner, relayUnitName(ctx.topo.relay.alias));
|
|
34
|
-
return '
|
|
34
|
+
return '中继通道已重启';
|
|
35
35
|
}
|
|
36
36
|
throw new Error(`未知角色:${ctx.role}`);
|
|
37
37
|
}
|
|
@@ -28,9 +28,9 @@ function startCore(ctx) {
|
|
|
28
28
|
const action = ensureLoaded(ctx, { label, plistPath: plist }, {
|
|
29
29
|
kickWhenStopped: true,
|
|
30
30
|
});
|
|
31
|
-
if (action === 'bootstrapped') return '
|
|
32
|
-
if (action === 'kickstarted') return '
|
|
33
|
-
return '
|
|
31
|
+
if (action === 'bootstrapped') return '中继通道已开启';
|
|
32
|
+
if (action === 'kickstarted') return '中继通道已重新拉起';
|
|
33
|
+
return '中继通道已在运行';
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function run(ctx, args = []) {
|
|
@@ -43,14 +43,17 @@ export function run(ctx, args = []) {
|
|
|
43
43
|
return enablePeer(ctx, before.relay && before.peer);
|
|
44
44
|
}
|
|
45
45
|
ctx.state.setOn(['relay']);
|
|
46
|
-
|
|
46
|
+
const peerNote = before.peer
|
|
47
|
+
? 'peer 保持开启,仍会主动恢复 IPv6 直连'
|
|
48
|
+
: 'peer 仍关闭;需要自动恢复时运行 ssh-net start peer';
|
|
49
|
+
return `relay ${before.relay ? '已是开启状态' : '已开启'}(${peerNote})`;
|
|
47
50
|
}
|
|
48
51
|
// core/node 是单总开关(等同 --all):显式 -a/--all 收下,其余参数拒绝
|
|
49
52
|
assertUnitSwitchArgs(args, 'start');
|
|
50
53
|
if (ctx.role === 'core') return startCore(ctx);
|
|
51
54
|
if (ctx.role === 'node') {
|
|
52
55
|
systemd.enableStart(ctx.runner, relayUnitName(ctx.topo.relay.alias));
|
|
53
|
-
return '
|
|
56
|
+
return '中继通道已开启';
|
|
54
57
|
}
|
|
55
58
|
throw new Error(`未知角色:${ctx.role}`);
|
|
56
59
|
}
|