ssh-net 26.10.27 → 26.10.30
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 +201 -9
- package/README.md +50 -34
- package/libexec/cli.mjs +10 -21
- package/libexec/commands/checkin.mjs +101 -39
- package/libexec/commands/doctor.mjs +19 -34
- package/libexec/commands/install.mjs +105 -53
- package/libexec/commands/restart.mjs +7 -3
- package/libexec/commands/start.mjs +23 -53
- package/libexec/commands/status.mjs +85 -65
- package/libexec/commands/stop.mjs +19 -33
- package/libexec/commands/uninstall.mjs +1 -0
- package/libexec/commands/upgrade.mjs +13 -7
- package/libexec/lib/config.mjs +28 -48
- package/libexec/lib/ipv6.mjs +1 -1
- package/libexec/lib/jobctl.mjs +7 -6
- package/libexec/lib/launchd.mjs +5 -2
- package/libexec/lib/manage.mjs +11 -3
- package/libexec/lib/paths.mjs +22 -15
- package/libexec/lib/render.mjs +59 -24
- package/libexec/lib/runtime.mjs +3 -11
- package/libexec/lib/state.mjs +10 -12
- package/libexec/sn-route +187 -65
- package/libexec/sn-signal +35 -28
- package/libexec/ssh-net-link-core +13 -474
- package/libexec/ssh-net-uplink-edge +16 -9
- package/package.json +1 -1
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
// start(design §5):edge
|
|
2
|
-
// relay
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// start(design §5):edge 两开关(缺省或 -a/--all=relay+peer,peer 自动补
|
|
2
|
+
// relay + 立即报名);core 重新 enable+bootstrap uplink-relay;node systemctl。
|
|
3
|
+
// link 不再是运行时开关(转发口只取决于装没装附加件)。重复 start 是幂等
|
|
4
|
+
// 确认:动作照做(重新报名让恢复立即发生),措辞区分「已开启」与「已是开启
|
|
5
|
+
// 状态」。
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import * as launchd from '../lib/launchd.mjs';
|
|
9
9
|
import * as systemd from '../lib/systemd.mjs';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { relayLabel, relayUnitName, plistFileName } from '../lib/render.mjs';
|
|
11
|
+
import { enablePeer } from './checkin.mjs';
|
|
12
12
|
|
|
13
|
-
const TARGETS = ['relay', 'peer'
|
|
13
|
+
const TARGETS = ['relay', 'peer'];
|
|
14
14
|
|
|
15
15
|
function parseTargets(args) {
|
|
16
|
-
if (args.length === 0 || args.length === 1 && (args[0] === '-a' || args[0] === '--all'))
|
|
17
|
-
return ['relay', 'peer'
|
|
18
|
-
if (args.length
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/** 细粒度开关立即生效:kickstart 让循环重来(自检新开关)。失败不阻断——
|
|
24
|
-
* 开关已置,下轮循环兜底;结果交调用方诚实措辞。 */
|
|
25
|
-
function kickLinkJob(ctx) {
|
|
26
|
-
return launchd.kickstartEnabled(ctx.runner, ctx.uid, linkLabel(ctx.topo.core.alias));
|
|
16
|
+
if (args.length === 0 || (args.length === 1 && (args[0] === '-a' || args[0] === '--all')))
|
|
17
|
+
return ['relay', 'peer'];
|
|
18
|
+
if (args.length === 1 && TARGETS.includes(args[0]))
|
|
19
|
+
return [args[0]];
|
|
20
|
+
if (args.length === 1 && args[0] === 'link')
|
|
21
|
+
throw new Error('link 不再是运行时开关:转发口只取决于装没装附加件——加装 ssh-net install --with-link,移除 ssh-net install --without-link');
|
|
22
|
+
throw new Error('用法:start [-a|--all|relay|peer](不带参数或 -a=relay+peer)');
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
function startCore(ctx) {
|
|
@@ -32,7 +28,8 @@ function startCore(ctx) {
|
|
|
32
28
|
if (!fs.existsSync(plist)) throw new Error(`尚未安装(缺 ${plist}),先跑 ssh-net install`);
|
|
33
29
|
const st = launchd.inspect(ctx.runner, ctx.uid, label);
|
|
34
30
|
if (!st.registered) {
|
|
35
|
-
launchd.enable(ctx.runner, ctx.uid, label);
|
|
31
|
+
const en = launchd.enable(ctx.runner, ctx.uid, label);
|
|
32
|
+
if (en.code !== 0) throw new Error(`enable 失败:${en.stderr.trim()}`);
|
|
36
33
|
const r = launchd.bootstrap(ctx.runner, ctx.uid, plist);
|
|
37
34
|
if (r.code !== 0) throw new Error(`启动失败:${r.stderr.trim()}`);
|
|
38
35
|
return 'relay 已开启';
|
|
@@ -50,45 +47,18 @@ function startCore(ctx) {
|
|
|
50
47
|
|
|
51
48
|
export function run(ctx, args = []) {
|
|
52
49
|
if (ctx.role === 'edge') {
|
|
53
|
-
const label = linkLabel(ctx.topo.core.alias);
|
|
54
|
-
const st = launchd.inspect(ctx.runner, ctx.uid, label);
|
|
55
|
-
if (!st.registered)
|
|
56
|
-
throw new Error(`link job 未注册(先 ssh-net install):launchctl print gui/${ctx.uid}/${label}`);
|
|
57
|
-
if (!fs.existsSync(path.join(ctx.paths.launchAgentsDir, plistFileName(label))))
|
|
58
|
-
throw new Error('job 配置文件缺失(注册态仍在)——先跑一次 ssh-net install');
|
|
59
|
-
|
|
60
50
|
const before = ctx.state.readSwitches();
|
|
61
|
-
const targets =
|
|
62
|
-
if (targets.has('peer') || targets.has('link')) targets.add('relay'); // 依赖级联
|
|
63
|
-
ctx.state.setOn([...targets]);
|
|
51
|
+
const targets = parseTargets(args); // ['relay','peer'] 或 ['relay'];link 抛错
|
|
64
52
|
|
|
65
|
-
if (targets.
|
|
66
|
-
//
|
|
67
|
-
// 顺手报一次名让 peer 立即跟上;全关态 PathState 拉起循环本来就会报,
|
|
68
|
-
// 多报一次对 core 是 no-op,失败静默(循环自己会报)
|
|
69
|
-
let announced = false;
|
|
70
|
-
try { runEdgeAnnounce(ctx); announced = true; } catch { /* 循环兜底 */ }
|
|
71
|
-
// 幂等确认:开关本来全开——动作照做(让恢复立即发生),措辞说清
|
|
72
|
-
const prefix = before.relay && before.peer && before.link ? '已是开启状态' : '已开启';
|
|
73
|
-
return announced
|
|
74
|
-
? `隧道${prefix}(relay · peer · link;已报名,core 几秒内回拨,ssh-net status 查看线路)`
|
|
75
|
-
: `隧道${prefix}(relay · peer · link;数秒内建立,ssh-net status 查看线路)`;
|
|
76
|
-
}
|
|
77
|
-
if (targets.has('peer')) {
|
|
78
|
-
// 与 checkin 同一条实现;幂等(relay+peer 本就在)时换措辞
|
|
53
|
+
if (targets.includes('peer')) {
|
|
54
|
+
// 默认/-a/peer:enablePeer 置两开关(幂等)+ 立即报名带 now
|
|
79
55
|
const msg = enablePeer(ctx);
|
|
80
56
|
return before.relay && before.peer
|
|
81
|
-
? msg.replace('peer 已开启', '
|
|
57
|
+
? msg.replace('peer 已开启', '隧道已是开启状态')
|
|
82
58
|
: msg;
|
|
83
59
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const prefix = before.relay && before.link ? '已是开启状态' : '已开启';
|
|
87
|
-
return r.code === 0
|
|
88
|
-
? `link ${prefix}(relay 一并开启;已触发重估,本地转发口几秒内建立)`
|
|
89
|
-
: `link ${prefix}(relay 一并开启;重估没触发成功,转发口随下轮循环自动建立)`;
|
|
90
|
-
}
|
|
91
|
-
return `relay ${before.relay ? '已是开启状态' : '已开启'}(隧道基础。peer/link 未开时不报名、无本地转发——要被 core 连到再 start peer,要本机代理再 start link)`;
|
|
60
|
+
ctx.state.setOn(['relay']);
|
|
61
|
+
return `relay ${before.relay ? '已是开启状态' : '已开启'}(隧道基础,不报名——要被 core 连到再 ssh-net start peer)`;
|
|
92
62
|
}
|
|
93
63
|
// core/node 是单总开关(等同 --all):显式 -a/--all 收下,其余参数拒绝
|
|
94
64
|
if (args.length && !(args.length === 1 && (args[0] === '-a' || args[0] === '--all')))
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// status(design §6.7):只报本机角色,判据是 banner/端口/注册态真实探测。
|
|
2
2
|
// collect 返回结构化对象(测试断言对象,不锁文本);renderText 给人看——
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// 真跑一条 ssh
|
|
3
|
+
// 按「开关(意图)与就绪(实测)分开」组织:开关行报 RELAY_ON/PEER_ON
|
|
4
|
+
// 两开关 + link 附加件(装没装,不是运行时开关),线路行逐条实测
|
|
5
|
+
// (relay 就绪=命令行 -J 经 relay 真跑一条 ssh,不从「probe 不通」推断),
|
|
6
|
+
// 开关关的线路报「关」不探测。
|
|
6
7
|
// bin/ 体检(2026-09-30 软链方案):实体逐字节比对 + 服务软链指向/悬空检查。
|
|
7
8
|
// 退出码:健康(含 edge 关闭态)0;有可行动问题 1。
|
|
8
9
|
import fs from 'node:fs';
|
|
@@ -16,7 +17,7 @@ import * as systemd from '../lib/systemd.mjs';
|
|
|
16
17
|
import { peerProbeOk, tcpOpen, detectTerminalNotifier } from '../lib/probe.mjs';
|
|
17
18
|
import {
|
|
18
19
|
linkLabel, linkLinkName, relayLabel, relayLinkName, relayUnitName,
|
|
19
|
-
edgeLabel, edgeLinkName, renderRoutes, renderEdgeHost,
|
|
20
|
+
edgeLabel, edgeLinkName, renderRoutes, renderVscodeMark, renderEdgeHost,
|
|
20
21
|
} from '../lib/render.mjs';
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -81,6 +82,7 @@ async function relayPortListening(ctx, port) {
|
|
|
81
82
|
const r = await ctx.runner.runAsync('ssh', [
|
|
82
83
|
'-o', 'BatchMode=yes', '-o', 'ConnectTimeout=5',
|
|
83
84
|
'-o', 'IdentitiesOnly=yes',
|
|
85
|
+
'-o', 'ControlMaster=no', '-o', 'ControlPath=none',
|
|
84
86
|
ctx.topo.relay.alias, 'ss', '-tlnH',
|
|
85
87
|
], { timeout: 8000 });
|
|
86
88
|
if (r.code !== 0) return { port, reachable: false, listening: false, detail: r.stderr.trim() };
|
|
@@ -96,6 +98,7 @@ async function relayPathOk(ctx) {
|
|
|
96
98
|
'-o', `HostKeyAlias=${ctx.topo.core.alias}`,
|
|
97
99
|
'-o', 'BatchMode=yes', '-o', 'ConnectTimeout=5',
|
|
98
100
|
'-o', 'IdentitiesOnly=yes',
|
|
101
|
+
'-o', 'ControlMaster=no', '-o', 'ControlPath=none',
|
|
99
102
|
`${ctx.topo.core.user}@127.0.0.1`, 'true',
|
|
100
103
|
], { timeout: 8000 });
|
|
101
104
|
return r.code === 0;
|
|
@@ -106,51 +109,58 @@ async function collectEdge(ctx) {
|
|
|
106
109
|
const issues = [];
|
|
107
110
|
const { issue: vIssue, runtimeVersion } = versionInfo(ctx);
|
|
108
111
|
if (vIssue) issues.push(vIssue);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
],
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
// link 附加件以 marker 为准:默认只有 5 实体、无服务软链;装了才加
|
|
113
|
+
// link-core(转发口只取决于装没装,不是运行时开关)
|
|
114
|
+
const linkInstalled = fs.existsSync(paths.linkEnabledFile);
|
|
115
|
+
/** @type {[string,string][]} */
|
|
116
|
+
const entities = [
|
|
117
|
+
['sn-probe', 'sn-probe'],
|
|
118
|
+
['sn-route', 'sn-route'],
|
|
119
|
+
['sn-ipv6', 'sn-ipv6'],
|
|
120
|
+
['sn-signal', 'sn-signal'],
|
|
121
|
+
['sn-notify', 'sn-notify'],
|
|
122
|
+
];
|
|
123
|
+
/** @type {[string,string][]} */
|
|
124
|
+
const serviceLinks = [];
|
|
125
|
+
if (linkInstalled) {
|
|
126
|
+
entities.push(['ssh-net-link-core', 'ssh-net-link-core']);
|
|
127
|
+
serviceLinks.push([linkLinkName(topo.core.alias), 'ssh-net-link-core']);
|
|
128
|
+
}
|
|
129
|
+
const { issues: rtIssues, links } = runtimeIssues(ctx, { entities, serviceLinks });
|
|
120
130
|
issues.push(...rtIssues);
|
|
121
131
|
|
|
122
|
-
//
|
|
123
|
-
// routes 被手删/过期会让 ssh 静默退回 lan
|
|
124
|
-
|
|
125
|
-
|
|
132
|
+
// 片段体检(sn-route 实体在才查:没装时 rtIssues 已报「尚未安装」):
|
|
133
|
+
// routes 被手删/过期会让 ssh 静默退回 lan 直连;vscode-mark 缺失则 VS Code
|
|
134
|
+
// 连接不打标、dot.via 不刷新——都必须显眼
|
|
135
|
+
if (links.find((l) => l.link === 'sn-route')?.audit === 'ok') {
|
|
136
|
+
const routeAudit = auditConfFragment(paths.routesFile, renderRoutes(topo, ctx.self.alias));
|
|
126
137
|
if (routeAudit !== 'ok')
|
|
127
138
|
issues.push(`选路片段 conf.d/routes ${routeAudit === 'missing' ? '缺失' : '与 topology 不一致'}——跑一次 ssh-net install 刷新`);
|
|
139
|
+
const markAudit = auditConfFragment(paths.vscodeMarkFile, renderVscodeMark());
|
|
140
|
+
if (markAudit !== 'ok')
|
|
141
|
+
issues.push(`打标片段 conf.d/vscode-mark ${markAudit === 'missing' ? '缺失' : '内容异常'}——跑一次 ssh-net install 刷新`);
|
|
128
142
|
}
|
|
129
143
|
|
|
130
144
|
const label = linkLabel(topo.core.alias);
|
|
131
145
|
const job = launchd.inspect(ctx.runner, ctx.uid, label);
|
|
132
146
|
const switches = state.readSwitches();
|
|
133
147
|
|
|
134
|
-
// 非法组合:peer
|
|
135
|
-
//
|
|
136
|
-
//
|
|
148
|
+
// 非法组合:peer 依赖 relay。开关是「文件即接口」——手 touch/rm state 里
|
|
149
|
+
// 的标记可造出组合(设计接受手改,这里负责显眼指出,而不是让线路行各说
|
|
150
|
+
// 各话)
|
|
137
151
|
if (switches.peer && !switches.relay)
|
|
138
|
-
issues.push('开关组合异常:peer 开但 relay 关(peer 依赖 relay,多半是 state
|
|
139
|
-
if (switches.link && !switches.relay)
|
|
140
|
-
issues.push('开关组合异常:link 开但 relay 关(link 依赖 relay,多半是 state 里的开关文件被手动改动)——跑一次 ssh-net stop 清零后再按需要的 start');
|
|
152
|
+
issues.push('开关组合异常:peer 开但 relay 关(peer 依赖 relay,多半是 state 里的开关被手动改动)——跑一次 ssh-net stop 后再按需要 start');
|
|
141
153
|
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
// TCP 探测随其一起发起,最坏耗时取决于最慢一条
|
|
154
|
+
// 就绪实测并发(On 是意图、ready 是事实;开关关的线路不探测=null)。
|
|
155
|
+
// 转发口只有装了 link 才可能存在——默认形态不探
|
|
145
156
|
const relayOk = ctx.relayOk ?? relayPathOk; // 测试可注入
|
|
146
157
|
const openTcp = ctx.openTcp ?? tcpOpen;
|
|
147
158
|
const probes = [
|
|
148
159
|
switches.relay ? relayOk(ctx) : null,
|
|
149
160
|
switches.relay && switches.peer ? peerProbeOk(ctx.runner, paths.binDir) : null,
|
|
150
|
-
// link 关也探:软生效窗口里旧转发连接的口还在听(「关」不等于口已消失),
|
|
151
|
-
// status 要能区分「现有连接保持中」与「彻底没了」
|
|
152
|
-
...topo.forwards.map((f) => openTcp('127.0.0.1', f.listenPort)),
|
|
153
161
|
];
|
|
162
|
+
if (linkInstalled)
|
|
163
|
+
for (const f of topo.forwards) probes.push(openTcp('127.0.0.1', f.listenPort));
|
|
154
164
|
// relay 开但 core 的 LAN 22 可达 = 人在办公室忘了关(只提示不纠偏)。
|
|
155
165
|
// core 的 LAN IP 不进 topology,从 ~/.ssh/config 的静态 Host 块取(契约校验
|
|
156
166
|
// 已保证存在),不读 routes——Match 会把地址改写成环回口
|
|
@@ -161,21 +171,22 @@ async function collectEdge(ctx) {
|
|
|
161
171
|
const relayReady = got[0];
|
|
162
172
|
const peerReady = got[1];
|
|
163
173
|
const ports = {};
|
|
164
|
-
|
|
174
|
+
if (linkInstalled)
|
|
175
|
+
topo.forwards.forEach((f, i) => { ports[f.listenPort] = got[2 + i]; });
|
|
165
176
|
const lanReachable = lanIdx >= 0 ? got[lanIdx] : false;
|
|
166
177
|
|
|
167
178
|
if (lanReachable)
|
|
168
179
|
issues.push(`检测到 ${topo.core.alias}(${coreLanIp})局域网直连可达——隧道可能在空转绕中继;人在办公室可 ssh-net stop`);
|
|
169
180
|
|
|
170
|
-
// relay
|
|
171
|
-
if (!switches.relay)
|
|
181
|
+
// relay 关但转发口仍在听 = 孤儿进程(仅装了 link 才可能)
|
|
182
|
+
if (!switches.relay && linkInstalled)
|
|
172
183
|
for (const f of topo.forwards)
|
|
173
184
|
if (ports[f.listenPort])
|
|
174
185
|
issues.push(`隧道已关但 ${forwardLabel(f)} 仍被占用——疑似残留进程:lsof -nP -iTCP:${f.listenPort} -sTCP:LISTEN 查占用者`);
|
|
175
186
|
|
|
176
187
|
// loopback 转发的出口在 core 本机环回(microsocks),ssh-net 管辖外:
|
|
177
|
-
//
|
|
178
|
-
if (
|
|
188
|
+
// 未就绪给根因提示,别让排障只在 edge 侧打转
|
|
189
|
+
if (linkInstalled)
|
|
179
190
|
for (const f of topo.forwards)
|
|
180
191
|
if (f.kind === 'local' && f.targetAlias === 'loopback' && !ports[f.listenPort])
|
|
181
192
|
issues.push(`${forwardLabel(f)} 未就绪:edge 侧正常时多半是 core 上的出口代理(microsocks)没跑——到 core 上查 local.microsocks`);
|
|
@@ -192,13 +203,15 @@ async function collectEdge(ctx) {
|
|
|
192
203
|
v6ProbeOk = !probe.error && probe.code === 0;
|
|
193
204
|
}
|
|
194
205
|
|
|
195
|
-
const forwardViews =
|
|
196
|
-
|
|
197
|
-
|
|
206
|
+
const forwardViews = linkInstalled
|
|
207
|
+
? topo.forwards.map((f) => [forwardLabel(f), ports[f.listenPort]])
|
|
208
|
+
: [];
|
|
209
|
+
// 线路通知组件:未装不算故障(sn-notify 静默回退 osascript/notify-send)
|
|
198
210
|
const notify = ctx.tnPath === undefined ? detectTerminalNotifier() : ctx.tnPath;
|
|
199
211
|
return {
|
|
200
212
|
role: 'edge', alias: ctx.self.alias, switches, relayReady, peerReady,
|
|
201
|
-
job, links, ports, forwardViews,
|
|
213
|
+
linkInstalled, job, links, ports, forwardViews,
|
|
214
|
+
coreAlias: topo.core.alias, relayAlias: topo.relay.alias,
|
|
202
215
|
v6, v6ProbeOk, runtimeVersion, issues, notify,
|
|
203
216
|
};
|
|
204
217
|
}
|
|
@@ -244,9 +257,10 @@ async function collectCore(ctx) {
|
|
|
244
257
|
);
|
|
245
258
|
if (linkState !== 'ok') bad.push(`软链(${linkState})`);
|
|
246
259
|
if (bad.length)
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
|
|
260
|
+
// 已注册 edge 的实体/软链其实会被 install 刷新(26.9.19 起),但
|
|
261
|
+
// 报名是自愈通道且不用人手动跑——按「等下次报名」引导,想立即修
|
|
262
|
+
// 也可跑 ssh-net install
|
|
263
|
+
issues.push(`${e.alias} 的回拨组件异常(${bad.join('、')})——它下次报名时会自动刷新(或跑一次 ssh-net install 手动修复)`);
|
|
250
264
|
}
|
|
251
265
|
const v6 = ctx.state.readEdgeV6(e.alias);
|
|
252
266
|
// edge 入口片段体检:job 在册且未休眠(enabled)+ 有 v6 时,片段必须
|
|
@@ -275,8 +289,14 @@ async function collectCore(ctx) {
|
|
|
275
289
|
|
|
276
290
|
const relayPort = await relayPortP;
|
|
277
291
|
if (!relayJob.running) issues.push('relay 未在运行——ssh-net start 可拉起');
|
|
278
|
-
if (!relayPort.listening)
|
|
279
|
-
|
|
292
|
+
if (!relayPort.listening) {
|
|
293
|
+
// 连不上 relay 时入口状态未知,别断言成「没在监听」——那是把故障点
|
|
294
|
+
// 指向本机转发,实际更可能是 relay 不可达(排障方向完全不同)
|
|
295
|
+
if (relayPort.reachable === false)
|
|
296
|
+
issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${topo.core.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
|
|
297
|
+
else
|
|
298
|
+
issues.push(`${topo.relay.alias} 入口 ${topo.core.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${topo.relay.alias} 或本机网络)`);
|
|
299
|
+
}
|
|
280
300
|
|
|
281
301
|
// topology 已删(edge 改名/退役)但磁盘上还有回拨 job:不渲染成 edges 行
|
|
282
302
|
//(state/conf.d 都按新别名走),单独点破。残留无害——六连败后自休眠、
|
|
@@ -313,8 +333,13 @@ async function collectNode(ctx) {
|
|
|
313
333
|
const relayPort = await relayPortListening(ctx, ctx.self.relayPort);
|
|
314
334
|
if (active !== 'active')
|
|
315
335
|
issues.push(`系统服务 ${unit} 状态 ${active}——systemctl status ${unit} 查看`);
|
|
316
|
-
if (!relayPort.listening)
|
|
317
|
-
|
|
336
|
+
if (!relayPort.listening) {
|
|
337
|
+
// 与 core 侧同款区分:relay 不可达 ≠ 入口没在监听,排障方向不同
|
|
338
|
+
if (relayPort.reachable === false)
|
|
339
|
+
issues.push(`连不上 ${topo.relay.alias}(${relayPort.detail || 'ssh 探测失败'}),入口 ${ctx.self.relayPort} 状态未知——查 ${topo.relay.alias} 可达性或本机网络`);
|
|
340
|
+
else
|
|
341
|
+
issues.push(`${ctx.topo.relay.alias} 入口 ${ctx.self.relayPort} 没在监听:在外面暂时进不来(断线会自动重连;持续出现请查 ${ctx.topo.relay.alias} 或本机网络)`);
|
|
342
|
+
}
|
|
318
343
|
|
|
319
344
|
return {
|
|
320
345
|
role: 'node', alias: ctx.self.alias, runtimeVersion,
|
|
@@ -340,12 +365,12 @@ function lineOf(name, on, ready, okText, failText, offText) {
|
|
|
340
365
|
: ` ${name}: ✗ ${failText}`;
|
|
341
366
|
}
|
|
342
367
|
|
|
343
|
-
/**
|
|
344
|
-
function profileOf(sw) {
|
|
368
|
+
/** 开关+附加件 → 一行人话总结(回答「我现在是什么形态」)。 */
|
|
369
|
+
function profileOf(sw, linkInstalled) {
|
|
345
370
|
if (!sw.relay) return null; // 全关有独立文案,不加形态行
|
|
346
|
-
if (sw.relay && sw.peer &&
|
|
371
|
+
if (sw.relay && sw.peer && linkInstalled) return '全功能:core 直连优先,回拨与本地转发口都开';
|
|
347
372
|
if (sw.relay && sw.peer) return '被连接形态:core 可回拨进来,无本地转发口';
|
|
348
|
-
if (sw.relay &&
|
|
373
|
+
if (sw.relay && linkInstalled) return '仅本地转发:经中继出去,core 不回拨';
|
|
349
374
|
return '仅中继信道(待命:不报名、无本地转发口)';
|
|
350
375
|
}
|
|
351
376
|
|
|
@@ -355,11 +380,11 @@ export function renderText(s) {
|
|
|
355
380
|
|
|
356
381
|
if (s.role === 'edge') {
|
|
357
382
|
const sw = s.switches;
|
|
358
|
-
if (!sw.relay && !sw.peer
|
|
383
|
+
if (!sw.relay && !sw.peer) {
|
|
359
384
|
lines.push(' 开关: 全关(在办公室,局域网直连即可;需要时 ssh-net start)');
|
|
360
385
|
} else {
|
|
361
|
-
lines.push(` 开关: relay ${sw.relay ? '开' : '关'} · peer ${sw.peer ? '开' : '关'}
|
|
362
|
-
lines.push(` 形态: ${profileOf(sw)}`);
|
|
386
|
+
lines.push(` 开关: relay ${sw.relay ? '开' : '关'} · peer ${sw.peer ? '开' : '关'}`);
|
|
387
|
+
lines.push(` 形态: ${profileOf(sw, s.linkInstalled)}`);
|
|
363
388
|
lines.push(lineOf('relay', sw.relay, s.relayReady,
|
|
364
389
|
`可用(经 ${s.coreAlias} 的中继信道)`,
|
|
365
390
|
`不可用(经 ${s.relayAlias} 连不上 core;刚开启请等几秒再看,持续出现查 ${s.relayAlias} 或 core 侧 ssh-net status)`,
|
|
@@ -374,20 +399,15 @@ export function renderText(s) {
|
|
|
374
399
|
`已就绪(v6 直达 ${s.coreAlias},一条 ssh)`,
|
|
375
400
|
peerUnready,
|
|
376
401
|
'按开关:不报名,core 不会回拨'));
|
|
377
|
-
if (!
|
|
378
|
-
//
|
|
379
|
-
|
|
380
|
-
// 都属非预期,文案直接说破而不是按软关常态描述
|
|
381
|
-
const lingering = s.forwardViews.some(([, ok]) => ok);
|
|
382
|
-
lines.push(lingering
|
|
383
|
-
? ' link: 关(按开关;转发口仍在听属非预期——stop link 本应立即使其断开:开关文件被手改过,或当时断开请求失败。要立即断开跑 ssh-net restart)'
|
|
384
|
-
: ' link: 关(按开关,本地无转发口;core 仍可经回拨进入本机)');
|
|
402
|
+
if (!s.linkInstalled) {
|
|
403
|
+
// 默认形态不探转发口(没有生产者会去占它们)
|
|
404
|
+
lines.push(' link: 未安装(默认零常驻;要 SOCKS/VNC 转发口:ssh-net install --with-link)');
|
|
385
405
|
} else {
|
|
386
406
|
const views = s.forwardViews;
|
|
387
407
|
const allOk = views.length > 0 && views.every(([, ok]) => ok);
|
|
388
408
|
lines.push(allOk
|
|
389
409
|
? ` link: ✓ 就绪(${views.map(([l]) => l).join(' · ')})`
|
|
390
|
-
: ` link: ✗ 未就绪(${views.filter(([, ok]) => !ok).map(([l]) => l).join('、')}
|
|
410
|
+
: ` link: ✗ 未就绪(${views.filter(([, ok]) => !ok).map(([l]) => l).join('、')} 没在听;隧道建立中)`);
|
|
391
411
|
}
|
|
392
412
|
lines.push(s.v6 !== ''
|
|
393
413
|
? ` 对外地址: ${s.v6}`
|
|
@@ -395,7 +415,7 @@ export function renderText(s) {
|
|
|
395
415
|
? ' 对外地址: 未知(v6 探测没跑成:sn-ipv6 超时或异常——vpn 重环境下 route 查询可能拖过探测时限,稍后再试)'
|
|
396
416
|
: ` 对外地址: 无 v6${sw.peer ? '(peer 建不起来,只能走 relay)' : ''}`);
|
|
397
417
|
}
|
|
398
|
-
lines.push(` 后台任务: ${!s.job.registered ?
|
|
418
|
+
lines.push(` 后台任务: ${!s.job.registered ? `未装 link(默认零常驻)` : s.job.running ? 'link 运行中' : 'link 已停止'}`);
|
|
399
419
|
// 通知行按平台分文案:terminal-notifier/osascript/brew 是 mac 世界的
|
|
400
420
|
// 东西;Linux(node 角色)的兜底是 notify-send,照实说,别引导 brew
|
|
401
421
|
if (s.notify)
|
|
@@ -428,7 +448,7 @@ export function renderText(s) {
|
|
|
428
448
|
} else {
|
|
429
449
|
lines.push(s.relayPort.listening
|
|
430
450
|
? ` relay: ✓ 开着(在外面经 ${s.relayAlias} 进入 ${s.alias} · 入口 ${s.relayPort.port})`
|
|
431
|
-
: ` relay: ✗
|
|
451
|
+
: ` relay: ✗ ${s.relayPort.reachable === false ? `连不上 ${s.relayAlias},入口状态未知` : `入口 ${s.relayPort.port} 没在监听`}`);
|
|
432
452
|
lines.push(` relay 进程: ${s.active === 'active' ? '运行中(systemd)' : `${s.active}(systemd)`}`);
|
|
433
453
|
}
|
|
434
454
|
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
// stop(design §5):edge
|
|
2
|
-
//
|
|
3
|
-
// design §5
|
|
1
|
+
// stop(design §5):edge 关两开关——缺省或 -a/--all(或带 relay)=级联全关
|
|
2
|
+
// (删两开关 + TERM 纯 ssh job 并校验真退出);只关 peer 是软关(只删标记,
|
|
3
|
+
// 零闪断,design §5「软生效」)。link 不是运行时目标(移除附加件用
|
|
4
|
+
// install --without-link)。重复 stop 是幂等确认,措辞区分「已关闭」与「已是
|
|
4
5
|
// 关闭状态」。core disable+bootout uplink-relay(不动 uplink-edge);
|
|
5
6
|
// node stop+disable。
|
|
6
7
|
import * as launchd from '../lib/launchd.mjs';
|
|
7
8
|
import * as systemd from '../lib/systemd.mjs';
|
|
8
9
|
import { stopEdgeLink } from '../lib/jobctl.mjs';
|
|
9
|
-
import {
|
|
10
|
+
import { relayLabel, relayUnitName } from '../lib/render.mjs';
|
|
10
11
|
|
|
11
|
-
const TARGETS = ['relay', 'peer'
|
|
12
|
+
const TARGETS = ['relay', 'peer'];
|
|
12
13
|
|
|
13
14
|
function parseTarget(args) {
|
|
14
15
|
if (args.length === 0 || args.length === 1 && (args[0] === '-a' || args[0] === '--all'))
|
|
15
16
|
return null; // 全关
|
|
16
|
-
if (args.length
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (args.length === 1 && TARGETS.includes(args[0]))
|
|
18
|
+
return args[0];
|
|
19
|
+
if (args.length === 1 && args[0] === 'link')
|
|
20
|
+
throw new Error('link 不是运行时目标:移除附加件跑 ssh-net install --without-link(卸载会一并清掉)');
|
|
21
|
+
throw new Error('用法:stop [-a|--all|relay|peer](不带参数或 -a=全部关闭)');
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
function stopCore(ctx) {
|
|
@@ -37,29 +40,12 @@ export function run(ctx, args = []) {
|
|
|
37
40
|
if (target === 'peer') {
|
|
38
41
|
ctx.state.removeOn(['peer']);
|
|
39
42
|
if (!before.peer) return 'peer 已是关闭状态(无需改动)';
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
? 'peer 已关闭(软生效:停止报名,已建立的回拨随网络变化自然消亡;下一轮循环起不再报名)'
|
|
44
|
-
: 'peer 已关闭(软生效:停止报名;后台任务未在运行,开启时会读取本开关)';
|
|
43
|
+
// 软关:只停止报名。已建立的连接继续用;装了 link,其转发 ssh 重连
|
|
44
|
+
// 时 sn-route 不报名,自然只走中继
|
|
45
|
+
return 'peer 已关闭(软生效:停止报名。已建立的连接继续用,断了重连就只走中继)';
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!before.link) return 'link 已是关闭状态(无需改动)';
|
|
49
|
-
// 立即生效:kickstart 断当前转发 ssh(承载的正是用户要关的东西,不算
|
|
50
|
-
// 闪断),循环重来后不再起。job 没跑就不用动(本来也没转发口)
|
|
51
|
-
let off = '本地转发口已断开';
|
|
52
|
-
if (launchd.inspect(ctx.runner, ctx.uid, linkLabel(ctx.topo.core.alias)).registered) {
|
|
53
|
-
const r = launchd.kickstartEnabled(ctx.runner, ctx.uid, linkLabel(ctx.topo.core.alias));
|
|
54
|
-
if (r.code !== 0)
|
|
55
|
-
off = '断开请求未生效(现有连接会随其自然断开而消失;要立即断开跑 ssh-net restart)';
|
|
56
|
-
} else {
|
|
57
|
-
off = '后台任务未在运行,本就无转发口';
|
|
58
|
-
}
|
|
59
|
-
return `link 已关闭(${off};被连接方向不受影响——core 仍可经回拨进入本机)`;
|
|
60
|
-
}
|
|
61
|
-
// 全关 / 只关 relay:级联删三个(peer/link 依赖 relay),硬停 job
|
|
62
|
-
const alreadyAllOff = !before.relay && !before.peer && !before.link;
|
|
47
|
+
// 全关 / 只关 relay:级联删两开关,硬停 link job(未装附加件则直接 gone)
|
|
48
|
+
const alreadyAllOff = !before.relay && !before.peer;
|
|
63
49
|
const { gone, label } = stopEdgeLink(ctx);
|
|
64
50
|
if (!gone)
|
|
65
51
|
throw new Error(
|
|
@@ -68,11 +54,11 @@ export function run(ctx, args = []) {
|
|
|
68
54
|
if (target === null) {
|
|
69
55
|
return alreadyAllOff
|
|
70
56
|
? '隧道已是关闭状态(无需改动)'
|
|
71
|
-
: '
|
|
57
|
+
: '隧道已关闭。几分钟后 core 侧会停止回拨并静默(正常现象,下次开启自动恢复)';
|
|
72
58
|
}
|
|
73
59
|
return alreadyAllOff
|
|
74
|
-
? 'relay 已是关闭状态(peer
|
|
75
|
-
: 'relay 已关闭(peer
|
|
60
|
+
? 'relay 已是关闭状态(peer 本就没开)'
|
|
61
|
+
: 'relay 已关闭(peer 一并关闭——它依赖 relay)。几分钟后 core 侧会停止回拨并静默';
|
|
76
62
|
}
|
|
77
63
|
// core/node 是单总开关(等同 --all):显式 -a/--all 收下,其余参数拒绝
|
|
78
64
|
if (args.length && !(args.length === 1 && (args[0] === '-a' || args[0] === '--all')))
|
|
@@ -32,6 +32,7 @@ function uninstallEdge(ctx) {
|
|
|
32
32
|
rm(ctx.paths.stateDir);
|
|
33
33
|
rm(ctx.paths.confDir); // routes(edge 装的);node 上不存在无害
|
|
34
34
|
rm(ctx.paths.runtimeVersionFile);
|
|
35
|
+
rm(ctx.paths.linkEnabledFile); // link 附加件意图
|
|
35
36
|
rm(path.join(ctx.paths.logsDir, `${label}.log`));
|
|
36
37
|
return '已卸载。最后一步:npm uninstall -g ssh-net';
|
|
37
38
|
}
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
// 跑 install 会盖一个旧版本戳、越对账越乱。
|
|
11
11
|
//
|
|
12
12
|
// 边界:node 角色需要 root(install 写 /etc/systemd/system),先检查再动
|
|
13
|
-
// npm,避免「包装上了、install 被拒」的半截态;core
|
|
14
|
-
//
|
|
13
|
+
// npm,避免「包装上了、install 被拒」的半截态;core 侧**已注册** edge 的
|
|
14
|
+
// uplink-edge 实体随 install 刷新(26.9.19 起),job 参数仍等各 edge 下次
|
|
15
|
+
// 报名对账(design §5)。
|
|
15
16
|
import { readRuntimeVersion, RUNTIME_VERSION } from '../lib/runtime.mjs';
|
|
16
17
|
|
|
17
18
|
const NPM_TIMEOUT = 180_000; // 慢网络下全局装包的余量
|
|
@@ -21,14 +22,19 @@ export async function run(ctx) {
|
|
|
21
22
|
if (ctx.role === 'node' && ctx.uid !== 0)
|
|
22
23
|
throw new Error('node 上升级要写 /etc/systemd/system(install 步骤),请以 root 运行(sudo ssh-net upgrade)');
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
// 首跑就带 --prefer-online(notes #10,2026-10-02 落地):npm 默认读本地
|
|
26
|
+
// packument 缓存的 dist-tags,刚发布后 latest 仍旧值时不报 ETARGET 而是
|
|
27
|
+
// 「成功」装回旧版——ETARGET 分支只盖「显式版本比元数据新」,@latest 解析
|
|
28
|
+
// 完全绕过它。跳过缓存读 dist-tags 一劳永逸,慢个几秒可接受
|
|
29
|
+
const npmArgs = ['install', '-g', 'ssh-net@latest', '--prefer-online'];
|
|
25
30
|
let r = ctx.runner.run('npm', npmArgs, { timeout: NPM_TIMEOUT });
|
|
26
31
|
if (r.error && r.error.code === 'ENOENT')
|
|
27
32
|
throw new Error('PATH 上找不到 npm(非交互环境的 node/npm 由 dotfiles 保证,见 design §7.5)——检查 ~/.zshenv 或 .bashrc 登录链后重试');
|
|
28
33
|
if (r.code !== 0 && /ETARGET/.test(r.stderr)) {
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
34
|
+
// 剩余传播窗口:本机 --prefer-online 也绕不开 registry 各边缘节点间的
|
|
35
|
+
// 元数据不一致(m5 实踩:另一台已能 view 到新版、这台仍报无此版本)。
|
|
36
|
+
// 再试一次(覆盖另一台边缘节点/瞬时网络),仍失败才让人等
|
|
37
|
+
r = ctx.runner.run('npm', npmArgs, { timeout: NPM_TIMEOUT });
|
|
32
38
|
if (r.code !== 0)
|
|
33
39
|
throw new Error(
|
|
34
40
|
`安装最新版失败(ETARGET:registry 元数据还没传播过来,常见于刚发布几分钟内)——等几分钟再跑 ssh-net upgrade,或手动 npm i -g ssh-net@<版本> --prefer-online。npm 输出:${r.stderr.trim()}`,
|
|
@@ -58,6 +64,6 @@ export async function run(ctx) {
|
|
|
58
64
|
// 文件已全部对账,但**在跑的 job 进程仍是旧脚本**(install 幂等不断连,
|
|
59
65
|
// 不重启健康服务)——新行为要等进程自然重建(断线/重启)后生效;多数
|
|
60
66
|
// 运行时改动不影响已建立的隧道,不主动 restart(那会把连接断掉)
|
|
61
|
-
const rollover = '(在跑的隧道进程继续用旧脚本直到下次重建;如需立刻加载新行为,ssh-net restart 会断当前连接。core
|
|
67
|
+
const rollover = '(在跑的隧道进程继续用旧脚本直到下次重建;如需立刻加载新行为,ssh-net restart 会断当前连接。core 侧的回拨组件:已注册的随本次 install 刷新、job 参数随各 edge 下次报名对账)';
|
|
62
68
|
return `${upToDate ? '已是最新版本' : '升级完成'}。${inst.stdout.trim()}${rollover}`;
|
|
63
69
|
}
|