ssh-net 26.9.5 → 26.9.6
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 +22 -0
- package/libexec/cli.mjs +1 -1
- package/libexec/commands/checkin.mjs +10 -4
- package/libexec/commands/install.mjs +7 -5
- package/libexec/commands/start.mjs +44 -10
- package/libexec/commands/status.mjs +22 -15
- package/libexec/commands/stop.mjs +7 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@
|
|
|
4
4
|
版本号格式为**年.月.序号**(如 26.9.1),序号每月重置——2026-09-29 起
|
|
5
5
|
启用;此前的 0.x 为过渡期编号。
|
|
6
6
|
|
|
7
|
+
## [26.9.6] - 2026-09-29
|
|
8
|
+
|
|
9
|
+
### 变更(细粒度开关一律立即生效;文案对齐用户视角)
|
|
10
|
+
|
|
11
|
+
- **start/stop link 立即生效**:kickstart 让循环重来——stop link 断当前
|
|
12
|
+
转发 ssh(承载的正是要关的东西,不算闪断),转发口即时消失;start
|
|
13
|
+
link 几秒内重建。此前是软生效,relay 长连接下 stop link 后 SOCKS 口
|
|
14
|
+
可能残留数小时,观感像「关不掉」
|
|
15
|
+
- **start peer / start(全开)顺手报名**:控制面直接发一次报名 ssh(零
|
|
16
|
+
断连)。此前文案说「几秒内报名」,实际循环可能卡在上一轮 wait、
|
|
17
|
+
最长 10 分钟才报——现在报名即时,core 回拨建立后信令让循环秒级跟上;
|
|
18
|
+
失败不阻断开关,下轮/手动 `ssh-net checkin` 兜底。stop peer 维持
|
|
19
|
+
软关(停止报名即时;core 侧既有回拨随网络变化自然消亡)
|
|
20
|
+
- **status 文案修正**:无 v6 时 peer 行说「本网络没有 IPv6,直连建不
|
|
21
|
+
起来」(此前是「等 core 回拨建立」——永远等不到,误导);link 软关
|
|
22
|
+
残留口区分「现有转发连接保持中」与「本地无转发口」(26.9.5 后续
|
|
23
|
+
修复,随本版上机);全关行附「需要时 ssh-net start」;loopback 转发
|
|
24
|
+
显示「落地机本机环回」
|
|
25
|
+
- **checkin 修正**:未安装时报「缺运行时脚本」不再误报「无 IPv6」;
|
|
26
|
+
help 描述补人话
|
|
27
|
+
- design §5「生效时机」二修;§6.1 timer 分支注释与实现对齐
|
|
28
|
+
|
|
7
29
|
## [26.9.5] - 2026-09-29
|
|
8
30
|
|
|
9
31
|
### 变更(edge 三开关:一个总开关拆成 relay/peer/link;开关与就绪分开报)
|
package/libexec/cli.mjs
CHANGED
|
@@ -27,7 +27,7 @@ const COMMANDS = {
|
|
|
27
27
|
restart: { run: restartRun, desc: 'kickstart/restart 让循环重来' },
|
|
28
28
|
status: { run: statusRun, desc: '本机角色状态(开关与线路分开实测)' },
|
|
29
29
|
doctor: { run: doctorRun, desc: '立即重估线路(edge):peer 不通时重新报名+选路,不等定时器' },
|
|
30
|
-
checkin: { run: checkinRun, desc: '
|
|
30
|
+
checkin: { run: checkinRun, desc: '手动报名(edge):把本机 v6 告诉 core,几秒内回拨建立直连' },
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
function help() {
|
|
@@ -17,11 +17,17 @@ import {
|
|
|
17
17
|
edgeLabel, edgeLinkName, plistFileName, renderUplinkEdgePlist,
|
|
18
18
|
} from '../lib/render.mjs';
|
|
19
19
|
|
|
20
|
-
/** 手动报名(edge):与 link-core 循环里的报名 ssh 同一命令形态与选项集。
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
/** 手动报名(edge):与 link-core 循环里的报名 ssh 同一命令形态与选项集。
|
|
21
|
+
* 也被 start peer 复用——循环可能卡在上一轮的 wait(最长 600s),控制面
|
|
22
|
+
* 直接报一次名让 core 马上回拨。 */
|
|
23
|
+
export function runEdgeAnnounce(ctx) {
|
|
24
|
+
const probe = ctx.runner.runRaw(
|
|
23
25
|
path.join(ctx.paths.binDir, 'v6-address'), [], { timeout: 5000 },
|
|
24
|
-
)
|
|
26
|
+
);
|
|
27
|
+
// bin/v6-address 缺失(未 install)别误报成「无 IPv6」
|
|
28
|
+
if (probe.error && probe.error.code === 'ENOENT')
|
|
29
|
+
throw new Error('未安装(缺运行时脚本)——先跑 ssh-net install');
|
|
30
|
+
const v6 = probe.stdout.trim();
|
|
25
31
|
if (!v6)
|
|
26
32
|
throw new Error('当前网络没有可用 IPv6,没有可报名的地址(中继不受影响)');
|
|
27
33
|
const r = ctx.runner.run('ssh', [
|
|
@@ -68,12 +68,14 @@ function installEdge(ctx) {
|
|
|
68
68
|
plistPath: path.join(paths.launchAgentsDir, plistFileName(linkLabel(topo.core.alias))),
|
|
69
69
|
content,
|
|
70
70
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
// 迁移发生时别说「默认关闭」——开关是从旧 ON 原样迁移的(全开)
|
|
72
|
+
if (migrated)
|
|
73
|
+
return r.unchanged
|
|
74
|
+
? '已安装,无需改动(旧开关 ON 已迁移为 relay/peer/link,全部保持开启)'
|
|
75
|
+
: '安装完成,开关保持迁移前状态(旧 ON → relay/peer/link 全开)';
|
|
74
76
|
return r.unchanged
|
|
75
|
-
?
|
|
76
|
-
:
|
|
77
|
+
? '已安装,无需改动'
|
|
78
|
+
: '安装完成。隧道默认关闭——at home(或 ssh-net start)开启';
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
function installCore(ctx) {
|
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import * as launchd from '../lib/launchd.mjs';
|
|
7
7
|
import * as systemd from '../lib/systemd.mjs';
|
|
8
8
|
import { linkLabel, relayLabel, relayUnitName, plistFileName } from '../lib/render.mjs';
|
|
9
|
+
import { runEdgeAnnounce } from './checkin.mjs';
|
|
9
10
|
|
|
10
11
|
const TARGETS = ['relay', 'peer', 'link'];
|
|
11
12
|
|
|
@@ -16,6 +17,13 @@ function parseTargets(args) {
|
|
|
16
17
|
return [args[0]];
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/** 细粒度开关立即生效:kickstart 让循环重来(自检新开关)。失败不阻断——
|
|
21
|
+
* 开关已置,软生效(下轮循环)兜底。 */
|
|
22
|
+
function kickLinkJob(ctx) {
|
|
23
|
+
const label = linkLabel(ctx.topo.core.alias);
|
|
24
|
+
launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
function startCore(ctx) {
|
|
20
28
|
const label = relayLabel(ctx.topo.relay.alias);
|
|
21
29
|
const plist = path.join(ctx.paths.launchAgentsDir, plistFileName(label));
|
|
@@ -46,9 +54,14 @@ export function run(ctx, args = []) {
|
|
|
46
54
|
throw new Error(`link job 未注册(先 ssh-net install):launchctl print gui/${ctx.uid}/${label}`);
|
|
47
55
|
// 防「新包 + 旧 plist」:plist 还是盯 ON 的旧模板时置 RELAY_ON 拉不起
|
|
48
56
|
// job,start 会谎报成功(npm 升级后没重跑 install 的典型姿势)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
52
65
|
if (!plist.includes('RELAY_ON'))
|
|
53
66
|
throw new Error('job 配置还是旧版(盯 ON 标记)——先跑一次 ssh-net install 再 start');
|
|
54
67
|
|
|
@@ -56,13 +69,34 @@ export function run(ctx, args = []) {
|
|
|
56
69
|
if (targets.has('peer') || targets.has('link')) targets.add('relay'); // 依赖级联
|
|
57
70
|
ctx.state.setOn([...targets]);
|
|
58
71
|
|
|
59
|
-
if (targets.size === 3)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
if (targets.size === 3) {
|
|
73
|
+
// 半开状态补全(如先 start link 再 start)时 job 可能卡在上一轮 wait,
|
|
74
|
+
// 顺手报一次名让 peer 立即跟上;全关态 PathState 拉起循环本来就会报,
|
|
75
|
+
// 多报一次对 core 是 no-op,失败静默(循环自己会报)
|
|
76
|
+
let announced = false;
|
|
77
|
+
try { runEdgeAnnounce(ctx); announced = true; } catch { /* 循环兜底 */ }
|
|
78
|
+
return announced
|
|
79
|
+
? '隧道已开启(relay · peer · link;已报名,core 几秒内回拨,ssh-net status 查看线路)'
|
|
80
|
+
: '隧道已开启(relay · peer · link;数秒内建立,ssh-net status 查看线路)';
|
|
81
|
+
}
|
|
82
|
+
if (targets.has('peer')) {
|
|
83
|
+
// 立即报名(零断连):循环可能还卡在上一轮的 wait(最长 600s),控制面
|
|
84
|
+
// 直接报一次名,core 回拨建立后信令(USR1)让循环秒级跟上;失败不阻断
|
|
85
|
+
// 开关本身——下轮循环/手动 checkin 兜底
|
|
86
|
+
let note = '';
|
|
87
|
+
try {
|
|
88
|
+
runEdgeAnnounce(ctx);
|
|
89
|
+
note = '已报名,core 几秒内回拨建立直连';
|
|
90
|
+
} catch {
|
|
91
|
+
note = '本次报名没成功(不影响开关;稍后会自动重试,也可手动 ssh-net checkin)';
|
|
92
|
+
}
|
|
93
|
+
return `peer 已开启(relay 一并开启;${note})`;
|
|
94
|
+
}
|
|
95
|
+
if (targets.has('link')) {
|
|
96
|
+
kickLinkJob(ctx);
|
|
97
|
+
return 'link 已开启(relay 一并开启;已触发重估,本地转发口几秒内建立)';
|
|
98
|
+
}
|
|
99
|
+
return 'relay 已开启(隧道基础。peer/link 未开时不报名、无本地转发——要被 core 连到再 start peer,要本机代理再 start link)';
|
|
66
100
|
}
|
|
67
101
|
if (args.length) throw new Error('本机是单总开关,start 不带参数');
|
|
68
102
|
if (ctx.role === 'core') return startCore(ctx);
|
|
@@ -28,11 +28,13 @@ function versionInfo(ctx) {
|
|
|
28
28
|
return { issue, runtimeVersion: readRuntimeVersion(ctx.paths) };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/** forward 的人话标签:dynamic 是 SOCKS,local
|
|
31
|
+
/** forward 的人话标签:dynamic 是 SOCKS,local 写出目标(loopback 是落地机环回)。 */
|
|
32
32
|
function forwardLabel(f) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (f.kind === 'dynamic') return `SOCKS 代理 127.0.0.1:${f.listenPort}`;
|
|
34
|
+
const target = f.targetAlias === 'loopback'
|
|
35
|
+
? `落地机本机环回:${f.targetPort}`
|
|
36
|
+
: `${f.targetAlias}:${f.targetPort}`;
|
|
37
|
+
return `端口转发 127.0.0.1:${f.listenPort} → ${target}`;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
function relayPortListening(ctx, port) {
|
|
@@ -86,9 +88,10 @@ async function collectEdge(ctx) {
|
|
|
86
88
|
? peerProbeOk(ctx.runner, paths.binDir)
|
|
87
89
|
: null;
|
|
88
90
|
|
|
89
|
-
const ports = {};
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const ports = {};
|
|
92
|
+
// link 关也探:软生效窗口里旧转发连接的口还在听(「关」不等于口已消失),
|
|
93
|
+
// status 要能区分「现有连接保持中」与「彻底没了」
|
|
94
|
+
for (const f of topo.forwards) ports[f.listenPort] = await openTcp('127.0.0.1', f.listenPort);
|
|
92
95
|
|
|
93
96
|
// relay 开但 core 的 LAN 22 可达 = 人在办公室忘了关(只提示不纠偏)
|
|
94
97
|
if (switches.relay && topo.core.lanIp) {
|
|
@@ -97,13 +100,11 @@ async function collectEdge(ctx) {
|
|
|
97
100
|
issues.push(`检测到 ${topo.core.alias}(${topo.core.lanIp})局域网直连可达——隧道可能在空转绕中继;人在办公室可 ssh-net stop`);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
//
|
|
103
|
+
// relay 关(全关/级联)但转发口仍在听 = 孤儿进程;link 软关的口在听不报
|
|
101
104
|
if (!switches.relay)
|
|
102
|
-
for (const f of topo.forwards)
|
|
103
|
-
|
|
104
|
-
if (listening)
|
|
105
|
+
for (const f of topo.forwards)
|
|
106
|
+
if (ports[f.listenPort])
|
|
105
107
|
issues.push(`隧道已关但 ${forwardLabel(f)} 仍被占用——疑似残留进程:lsof -nP -iTCP:${f.listenPort} -sTCP:LISTEN 查占用者`);
|
|
106
|
-
}
|
|
107
108
|
|
|
108
109
|
// loopback 转发的出口在 core 本机环回(microsocks),ssh-net 管辖外:
|
|
109
110
|
// 未就绪时给根因提示,别让排障只在 edge 侧打转
|
|
@@ -232,7 +233,7 @@ export function renderText(s) {
|
|
|
232
233
|
if (s.role === 'edge') {
|
|
233
234
|
const sw = s.switches;
|
|
234
235
|
if (!sw.relay && !sw.peer && !sw.link) {
|
|
235
|
-
lines.push(' 开关:
|
|
236
|
+
lines.push(' 开关: 全关(在办公室,局域网直连即可;需要时 ssh-net start)');
|
|
236
237
|
} else {
|
|
237
238
|
lines.push(` 开关: relay ${sw.relay ? '开' : '关'} · peer ${sw.peer ? '开' : '关'} · link ${sw.link ? '开' : '关'}`);
|
|
238
239
|
lines.push(lineOf('relay', sw.relay, s.relayReady,
|
|
@@ -242,10 +243,16 @@ export function renderText(s) {
|
|
|
242
243
|
// peer/link 依赖 relay:relay 关时一并显示关(手动 touch 出的非法定态)
|
|
243
244
|
lines.push(lineOf('peer', sw.relay && sw.peer, s.peerReady,
|
|
244
245
|
`已就绪(v6 直达 ${s.coreAlias},一条 ssh)`,
|
|
245
|
-
|
|
246
|
+
s.v6 === ''
|
|
247
|
+
? '未就绪(本网络没有 IPv6,直连建不起来;中继不受影响)'
|
|
248
|
+
: '未就绪(等 core 回拨建立;ssh-net doctor 立即重估,中继不受影响)',
|
|
246
249
|
'按开关:不报名,core 不会回拨'));
|
|
247
250
|
if (!(sw.relay && sw.link)) {
|
|
248
|
-
|
|
251
|
+
// 软生效:关开关不杀旧连接,口还在听=现有转发保持中
|
|
252
|
+
const lingering = s.forwardViews.some(([, ok]) => ok);
|
|
253
|
+
lines.push(lingering
|
|
254
|
+
? ' link: 关(按开关;现有转发连接保持中,断开后不再重建,要立即断开跑 ssh-net restart)'
|
|
255
|
+
: ' link: 关(按开关,本地无转发口;core 仍可经回拨进入本机)');
|
|
249
256
|
} else {
|
|
250
257
|
const views = s.forwardViews;
|
|
251
258
|
const allOk = views.length > 0 && views.every(([, ok]) => ok);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as launchd from '../lib/launchd.mjs';
|
|
6
6
|
import * as systemd from '../lib/systemd.mjs';
|
|
7
7
|
import { stopEdgeLink } from '../lib/jobctl.mjs';
|
|
8
|
-
import { relayLabel, relayUnitName } from '../lib/render.mjs';
|
|
8
|
+
import { linkLabel, relayLabel, relayUnitName } from '../lib/render.mjs';
|
|
9
9
|
|
|
10
10
|
const TARGETS = ['relay', 'peer', 'link'];
|
|
11
11
|
|
|
@@ -36,7 +36,12 @@ export function run(ctx, args = []) {
|
|
|
36
36
|
}
|
|
37
37
|
if (target === 'link') {
|
|
38
38
|
ctx.state.removeOn(['link']);
|
|
39
|
-
|
|
39
|
+
// 立即生效:kickstart 断当前转发 ssh(承载的正是用户要关的东西,不算
|
|
40
|
+
// 闪断),循环重来后不再起。job 没跑就不用动(本来也没转发口)
|
|
41
|
+
const label = linkLabel(ctx.topo.core.alias);
|
|
42
|
+
if (launchd.inspect(ctx.runner, ctx.uid, label).registered)
|
|
43
|
+
launchd.kickstartEnabled(ctx.runner, ctx.uid, label);
|
|
44
|
+
return 'link 已关闭(本地转发口已断开;被连接方向不受影响——core 仍可经回拨进入本机)';
|
|
40
45
|
}
|
|
41
46
|
// 全关 / 只关 relay:级联删三个(peer、link 都依赖 relay),硬停 job
|
|
42
47
|
const { gone, label } = stopEdgeLink(ctx);
|