dsh-mobile-plugin 0.5.77 → 0.5.79
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/lib/frpc/runner.cjs +30 -2
- package/lib/impl.js +9 -4
- package/lib/mobile/relay-control.js +7 -0
- package/lib/mobile/stream.js +20 -1
- package/lib/mobile/workflow-live.js +32 -1
- package/lib/p2p/session.cjs +15 -0
- package/lib/p2p/wiring.cjs +5 -2
- package/lib/panel/index.html +15 -15
- package/lib/relay/control.js +15 -3
- package/lib/relay/core.js +3 -0
- package/lib/relay/lan-proxy.js +3 -3
- package/lib/relay/status.js +3 -0
- package/lib/relay/tunnel-forwarder.cjs +15 -5
- package/lib/relay/tunnel.js +5 -2
- package/lib/remote/runtime.cjs +2 -1
- package/lib/routes/control-plane.js +17 -4
- package/lib/sidecar-facade-worker.cjs +11 -4
- package/lib/tailcat/wiring.cjs +4 -2
- package/package.json +1 -1
package/lib/relay/control.js
CHANGED
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
phoneCandidates,
|
|
22
22
|
ipv6Candidates,
|
|
23
23
|
withManualIpv6Candidate,
|
|
24
|
+
tcpDirectTarget,
|
|
24
25
|
} = require('./lan-network.cjs');
|
|
25
26
|
const { relayAddressesOf } = require('./core.js');
|
|
26
27
|
const { sealHistoryBlob } = require('../mirror/history-blob.cjs');
|
|
@@ -37,6 +38,10 @@ function controlWsUrl(base = CONTROL_BASE_URL) {
|
|
|
37
38
|
* 折出本机要上报的全部连接地址(明文,上送前再加密)。
|
|
38
39
|
* 与配对二维码同源:中转取 `relayUrls`;局域网走 `phoneCandidates(advertisedCandidates)`;
|
|
39
40
|
* IPv6 走 `ipv6Candidates` 并缀上手填那条。`lanEnabled` 关掉或端口拿不到时不含局域网/IPv6。
|
|
41
|
+
* 「TCP 直连」目标(`manualTcpUrl`)单独一条,**不受 `lanEnabled` 影响**:它不挂在局域网监听上,
|
|
42
|
+
* 是一条独立的裸 TCP 出站通道。这一格必须报上来——配了 TCP(或手填直连)时公用中转会被规则关掉,
|
|
43
|
+
* 而 TCP 又替换不了「宿主地址」在手机上的同步:手机离开局域网后连不上宿主,只能靠总控把 TCP
|
|
44
|
+
* 目标补给它。漏了这一格,总控这条兜底就等于空转。
|
|
40
45
|
*/
|
|
41
46
|
function controlAddresses(state, port) {
|
|
42
47
|
const out = [];
|
|
@@ -67,6 +72,11 @@ function controlAddresses(state, port) {
|
|
|
67
72
|
/* 同上 */
|
|
68
73
|
}
|
|
69
74
|
}
|
|
75
|
+
// TCP 直连:用户填的 `host:port`(可能带方括号 IPv6)。不受 `lanEnabled` 管——它是一条独立的
|
|
76
|
+
// 裸 TCP 出站通道,关掉局域网直连时它照样能用;而它恰恰是「公用中转被关掉」那种配置下手机
|
|
77
|
+
// 唯一还能连上的地址,必须进总控这份兜底清单。
|
|
78
|
+
const tcp = tcpDirectTarget(state.manualTcpUrl);
|
|
79
|
+
if (tcp) out.push({ kind: 'tcp', url: tcp });
|
|
70
80
|
const seen = new Set();
|
|
71
81
|
const dedup = [];
|
|
72
82
|
for (const a of out) {
|
|
@@ -163,6 +173,8 @@ function createControlClient({ state, persist, getPort, getHistoryKey, getAddres
|
|
|
163
173
|
function connect() {
|
|
164
174
|
if (!running || sock) return;
|
|
165
175
|
if (!state.enabled) return;
|
|
176
|
+
// 用户在面板关掉了「自动上报网络地址」:立刻不连(sync/stop 会把已在连的这条也收掉)。
|
|
177
|
+
if (state.controlReportEnabled === false) return;
|
|
166
178
|
const addresses = build(state);
|
|
167
179
|
if (!Array.isArray(addresses) || addresses.length === 0) {
|
|
168
180
|
connected = false;
|
|
@@ -249,7 +261,7 @@ function createControlClient({ state, persist, getPort, getHistoryKey, getAddres
|
|
|
249
261
|
tickTimer = setInterval(tick, 60_000);
|
|
250
262
|
if (tickTimer.unref) tickTimer.unref();
|
|
251
263
|
}
|
|
252
|
-
if (state.enabled && !sock) connect();
|
|
264
|
+
if (state.enabled && state.controlReportEnabled !== false && !sock) connect();
|
|
253
265
|
return snapshot();
|
|
254
266
|
}
|
|
255
267
|
|
|
@@ -267,9 +279,9 @@ function createControlClient({ state, persist, getPort, getHistoryKey, getAddres
|
|
|
267
279
|
attempt = 0;
|
|
268
280
|
}
|
|
269
281
|
|
|
270
|
-
/** 配置变更后调用:没开 / 没地址 / 没 HK 就停;否则起连或复核。 */
|
|
282
|
+
/** 配置变更后调用:没开 / 用户关了上报 / 没地址 / 没 HK 就停;否则起连或复核。 */
|
|
271
283
|
function sync() {
|
|
272
|
-
if (!state.enabled || build(state).length === 0 || !hk()) {
|
|
284
|
+
if (!state.enabled || state.controlReportEnabled === false || build(state).length === 0 || !hk()) {
|
|
273
285
|
stop();
|
|
274
286
|
return;
|
|
275
287
|
}
|
package/lib/relay/core.js
CHANGED
|
@@ -56,6 +56,9 @@ function defaultState() {
|
|
|
56
56
|
// 老状态文件没这一格时靠这里兜底,别在别处再判一次「没有就拒绝」。
|
|
57
57
|
pairingTier: 'full',
|
|
58
58
|
lanEnabled: true, lanPort: 18787, lanSecret: crypto.randomBytes(32).toString('hex'), enabled: false,
|
|
59
|
+
// 是否把本机的网络地址加密上报给「总控」(地址目录)。默认开:这正是本功能一直以来的
|
|
60
|
+
// 行为,做成开关只为了让不想要的人能关掉(关掉后手机换网、手里没新地址就找不回这台电脑)。
|
|
61
|
+
controlReportEnabled: true,
|
|
59
62
|
// 中转侧 TUNNEL_REGISTER_SECRET 的对偶值。为空时隧道注册会被中转以
|
|
60
63
|
// close(1008, 'bad registration secret') 拒掉(除非中转根本没开校验)。
|
|
61
64
|
registerSecret: '',
|
package/lib/relay/lan-proxy.js
CHANGED
|
@@ -377,7 +377,7 @@ function createLanProxy(opts) {
|
|
|
377
377
|
const headers = withViaHeader(
|
|
378
378
|
Object.fromEntries(Object.entries(req.headers).filter(([k]) => !HOP_BY_HOP.has(k))),
|
|
379
379
|
'lan',
|
|
380
|
-
`${upstreamHost}:${upstreamPort}`,
|
|
380
|
+
`${formatHost(upstreamHost)}:${upstreamPort}`,
|
|
381
381
|
);
|
|
382
382
|
const isSse = String(req.headers.accept || '').toLowerCase().includes('text/event-stream');
|
|
383
383
|
if (isSse && upstreamSseOpen >= maxUpstreamSse) {
|
|
@@ -487,7 +487,7 @@ function createLanProxy(opts) {
|
|
|
487
487
|
const headers = withViaHeader(
|
|
488
488
|
Object.fromEntries(Object.entries(req.headers).filter(([key, value]) => !HOP_BY_HOP.has(key) && value !== undefined)),
|
|
489
489
|
'lan',
|
|
490
|
-
`${upstreamHost}:${upstreamPort}`,
|
|
490
|
+
`${formatHost(upstreamHost)}:${upstreamPort}`,
|
|
491
491
|
);
|
|
492
492
|
// 上游要认得这条请求:新 T1 记录没有存下来的宿主令牌,就把请求里出示的那一枚
|
|
493
493
|
// 原样带上去;旧 HMAC 记录仍用它自己的 hostToken。
|
|
@@ -496,7 +496,7 @@ function createLanProxy(opts) {
|
|
|
496
496
|
|
|
497
497
|
let up;
|
|
498
498
|
try {
|
|
499
|
-
up = new WebSocket(`ws://${upstreamHost}:${upstreamPort}${req.url}`, {
|
|
499
|
+
up = new WebSocket(`ws://${formatHost(upstreamHost)}:${upstreamPort}${req.url}`, {
|
|
500
500
|
headers,
|
|
501
501
|
handshakeTimeout: WS_UPSTREAM_HANDSHAKE_MS,
|
|
502
502
|
});
|
package/lib/relay/status.js
CHANGED
|
@@ -123,6 +123,9 @@ function createStatusView(deps) {
|
|
|
123
123
|
// 审批自动审阅档(默认关,见 lib/mobile/auto-review.js)。面板与手机设置页都读这一格
|
|
124
124
|
// 显示开关状态;非 true 一律当关,与 `configOf(state)` 的读法同一口径。
|
|
125
125
|
approvalAutoReview: state.approvalAutoReview === true,
|
|
126
|
+
// 「自动上报网络地址」(总控上报)开关状态。面板据此显示开关;非 false 一律当开,
|
|
127
|
+
// 与 `configOf(state)` 的读法同一口径(老状态文件没这一格时默认开)。
|
|
128
|
+
controlReportEnabled: state.controlReportEnabled !== false,
|
|
126
129
|
// 桌面设置页那两颗侧边栏图标的显示开关。**只给桌面客户端读**,手机端不画它们;
|
|
127
130
|
// 老机器没落过这两格时按开处理,与 configOf 的默认值同一口径。
|
|
128
131
|
desktopPhoneIcon: state.desktopPhoneIcon !== false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
// 落点代理转给宿主 web 服务时跟随宿主实际绑定地址(不再写死回环),回环绑定行为不变。
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 隧道数据的落脚代理:隧道里进来的请求先到这里,打上转发标记,再转给宿主 web 端口。
|
|
@@ -25,7 +26,7 @@ const http = require('node:http');
|
|
|
25
26
|
const net = require('node:net');
|
|
26
27
|
const { VIA_HEADER, VIA_TUNNEL, withViaHeader } = require('../shared/via-header');
|
|
27
28
|
|
|
28
|
-
const
|
|
29
|
+
const DEFAULT_UPSTREAM_HOST = '127.0.0.1';
|
|
29
30
|
|
|
30
31
|
// 与局域网代理同一份逐跳头名单:两条路转给同一个上游,头的处理口径必须一致。
|
|
31
32
|
const HOP_BY_HOP = new Set([
|
|
@@ -36,17 +37,26 @@ const HOP_BY_HOP = new Set([
|
|
|
36
37
|
/**
|
|
37
38
|
* @param {object} options
|
|
38
39
|
* @param {() => number} options.upstreamPort 宿主 web 端口(每次请求现读,允许变化)
|
|
40
|
+
* @param {() => string} [options.upstreamHost] 宿主 web 绑定地址(取值器;缺省回环)
|
|
39
41
|
* @param {(message: string) => void} [options.log]
|
|
40
42
|
*/
|
|
41
43
|
function createTunnelForwarder(options) {
|
|
42
44
|
const upstreamPort = options.upstreamPort;
|
|
45
|
+
const upstreamHost = typeof options.upstreamHost === 'function'
|
|
46
|
+
? options.upstreamHost
|
|
47
|
+
: () => options.upstreamHost || DEFAULT_UPSTREAM_HOST;
|
|
43
48
|
const log = options.log || (() => {});
|
|
44
49
|
let server = null;
|
|
45
50
|
let port = 0;
|
|
46
51
|
let starting = null;
|
|
47
52
|
const live = new Set();
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
// 写 Host 头时 IPv6 字面量要带方括号;连接本身用裸地址。
|
|
55
|
+
const hostText = () => {
|
|
56
|
+
const host = upstreamHost();
|
|
57
|
+
return host.includes(':') ? `[${host}]` : host;
|
|
58
|
+
};
|
|
59
|
+
const upstreamOf = () => `${hostText()}:${Number(upstreamPort())}`;
|
|
50
60
|
|
|
51
61
|
/** 转发用的头:与局域网代理同源,客户端自带的同名标记会被覆盖掉。 */
|
|
52
62
|
function forwardedHeaders(incoming) {
|
|
@@ -59,7 +69,7 @@ function createTunnelForwarder(options) {
|
|
|
59
69
|
|
|
60
70
|
function forwardRequest(req, res) {
|
|
61
71
|
const up = http.request(
|
|
62
|
-
{ hostname:
|
|
72
|
+
{ hostname: upstreamHost(), port: Number(upstreamPort()), method: req.method, path: req.url, headers: forwardedHeaders(req.headers) },
|
|
63
73
|
(ures) => {
|
|
64
74
|
const out = {};
|
|
65
75
|
for (const [key, value] of Object.entries(ures.headers)) {
|
|
@@ -108,7 +118,7 @@ function createTunnelForwarder(options) {
|
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
function forwardUpgrade(req, socket, head) {
|
|
111
|
-
const upstream = net.connect({ host:
|
|
121
|
+
const upstream = net.connect({ host: upstreamHost(), port: Number(upstreamPort()) });
|
|
112
122
|
live.add(socket);
|
|
113
123
|
live.add(upstream);
|
|
114
124
|
const drop = () => {
|
|
@@ -145,7 +155,7 @@ function createTunnelForwarder(options) {
|
|
|
145
155
|
});
|
|
146
156
|
starting = new Promise((resolve) => {
|
|
147
157
|
try {
|
|
148
|
-
server.listen(0,
|
|
158
|
+
server.listen(0, '127.0.0.1', () => {
|
|
149
159
|
// 这条监听不该把进程钉住:它只是个转发口,真正撑住宿主的是别的东西。
|
|
150
160
|
server.unref?.();
|
|
151
161
|
const address = server.address();
|
package/lib/relay/tunnel.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
// 中转隧道把请求转给宿主 web 服务时,上游地址跟随宿主实际绑定地址(可能不是回环)。
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 出站隧道客户端 v2:连接 dsh-mobile-server 中转,把中转发来的 HTTP/WS 请求转发到
|
|
5
|
-
* 本机 dsh web
|
|
6
|
+
* 本机 dsh web(宿主实际绑定的地址:<port>,默认回环)。
|
|
6
7
|
*
|
|
7
8
|
* 协议 v2 相对 v1 的变更(协议定义见中转仓库 relay-core 的 `PROTOCOL.md`):
|
|
8
9
|
* - 二进制帧取代 JSON/base64 文本帧(数据通道不再 base64);
|
|
@@ -86,6 +87,8 @@ class RelayTunnel {
|
|
|
86
87
|
this.lanUrls = Array.isArray(opts.lanUrls) ? opts.lanUrls.slice() : [];
|
|
87
88
|
this.lanCandidates = Array.isArray(opts.lanCandidates) ? opts.lanCandidates.slice() : [];
|
|
88
89
|
this.upstream = new URL(opts.upstream);
|
|
90
|
+
// `URL.hostname` 对 IPv6 字面量保留方括号(如 `[::1]`),而 `http.request` 的 host 要裸地址。
|
|
91
|
+
this.upstreamHost = this.upstream.hostname.replace(/^\[|\]$/g, '');
|
|
89
92
|
// 注册密钥:relay.json 里的显式值优先,环境变量作为无头/命令行场景的兜底。
|
|
90
93
|
this.registerSecret = typeof opts.registerSecret === 'string' && opts.registerSecret
|
|
91
94
|
? opts.registerSecret
|
|
@@ -668,7 +671,7 @@ class RelayTunnel {
|
|
|
668
671
|
}
|
|
669
672
|
const req = http.request(
|
|
670
673
|
{
|
|
671
|
-
host: this.
|
|
674
|
+
host: this.upstreamHost,
|
|
672
675
|
port: this.upstream.port,
|
|
673
676
|
method: msg.method,
|
|
674
677
|
path: msg.path,
|
package/lib/remote/runtime.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// 电脑间远程网页的装配与生命周期;入口只在可信本机界面签发。
|
|
3
|
+
// 落点代理转给宿主 web 服务时跟随宿主实际绑定地址(见 relay/tunnel-forwarder.cjs)。
|
|
3
4
|
const os = require('node:os');
|
|
4
5
|
const { createRemoteStore } = require('./store.cjs');
|
|
5
6
|
const { createRemoteHost } = require('./host.cjs');
|
|
@@ -11,7 +12,7 @@ const { createTunnelForwarder } = require('../relay/tunnel-forwarder.cjs');
|
|
|
11
12
|
|
|
12
13
|
function mountRemoteComputers({ ctx, state, credentials, registerRoute, lanPortInUse, tailcat, p2p, lanAvailable, onBindingsChanged, onInvite, log = () => {} }) {
|
|
13
14
|
const store = createRemoteStore({ credentials: () => ctx.get('credentials') });
|
|
14
|
-
const forwarder = createTunnelForwarder({ upstreamPort: () => ctx.webServer.port, log });
|
|
15
|
+
const forwarder = createTunnelForwarder({ upstreamPort: () => ctx.webServer.port, upstreamHost: () => ctx.webServer.host, log });
|
|
15
16
|
const control = createHostControl({ state, tailcat, p2p, lanPortInUse, lanAvailable });
|
|
16
17
|
const host = createRemoteHost({
|
|
17
18
|
state, credentials, routesOf: control.routesOf,
|
|
@@ -577,13 +577,21 @@ function registerControlPlaneRoutes(deps) {
|
|
|
577
577
|
// 为什么白名单是「节点公钥」而不是设备 id:隧道那一层只认 WireGuard 公钥,和移动端
|
|
578
578
|
// 凭据是两套东西 —— 吊销设备凭据并不会把它从隧道白名单里摘掉(见 A3-86)。所以这里
|
|
579
579
|
// 单独给一个出口,否则「踢一台手机」在隧道这一层无法完成。
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
//
|
|
580
|
+
// 点对点隧道只有格里要说的事:这条通道起没起、打通了没有、走的是谁。
|
|
581
|
+
// 助手默认关、用户显式开启才启动(与直连隧道同一口径);走不走这条通道仍由手机侧档位
|
|
582
|
+
// (`channelMode`)决定 —— 这里只管本机这半边准不准它起来。
|
|
583
583
|
registerRoute({ kind: 'exact', path: '/api/relay/p2p', handler: localOnly('GET', async (_req, res) => {
|
|
584
584
|
const state = deps.p2p && typeof deps.p2p.status === 'function' ? deps.p2p.status() : null
|
|
585
585
|
sendJson(res, 200, { ok: true, status: state })
|
|
586
586
|
}) })
|
|
587
|
+
registerRoute({ kind: 'exact', path: '/api/relay/p2p/enabled', handler: localOnly('POST', async (req, res) => {
|
|
588
|
+
const body = await readJson(req)
|
|
589
|
+
if (deps.p2p && typeof deps.p2p.setEnabled === 'function') {
|
|
590
|
+
deps.p2p.setEnabled(Boolean(body && body.enabled))
|
|
591
|
+
}
|
|
592
|
+
const state = deps.p2p && typeof deps.p2p.status === 'function' ? deps.p2p.status() : null
|
|
593
|
+
sendJson(res, 200, { ok: true, status: state })
|
|
594
|
+
}) })
|
|
587
595
|
|
|
588
596
|
// ── FRP 直连:导入配置 → 落盘并拉起本地 frpc ───────────────────────────────
|
|
589
597
|
//
|
|
@@ -988,6 +996,9 @@ function registerControlPlaneRoutes(deps) {
|
|
|
988
996
|
// 审批自动审阅档(默认关)。只认布尔值,别的形状一律当没带 —— 这一个是安全开关,
|
|
989
997
|
// 把 'false' / 0 静默解释成 false 会让「我明明关掉了」变成一句不可查的话。
|
|
990
998
|
if (typeof body?.approvalAutoReview === 'boolean') patch.approvalAutoReview = body.approvalAutoReview
|
|
999
|
+
// 「自动上报网络地址」(总控上报)开关。只认布尔值,别的形状当没带 —— 'false' / 0 静默
|
|
1000
|
+
// 解释成关会让用户以为是自己关的,而界面上再也没处改回来。
|
|
1001
|
+
if (typeof body?.controlReportEnabled === 'boolean') patch.controlReportEnabled = body.controlReportEnabled
|
|
991
1002
|
// 桌面侧边栏那两颗图标的显示开关。非布尔值当没带:'false' / 0 静默解释成隐藏,
|
|
992
1003
|
// 用户会以为是自己关的,而界面上再也找不到那颗图标去改回来。
|
|
993
1004
|
if (typeof body?.desktopPhoneIcon === 'boolean') patch.desktopPhoneIcon = body.desktopPhoneIcon
|
|
@@ -1340,8 +1351,9 @@ const WEB_ACCESS_ROUTES = new Set([
|
|
|
1340
1351
|
// 但仍留在窗口白名单里保持「路由都在白名单」这条语义统一。
|
|
1341
1352
|
'/api/relay/frp/import',
|
|
1342
1353
|
'/api/relay/frp/stop',
|
|
1343
|
-
//
|
|
1354
|
+
// 点对点隧道的现状与启停(没有白名单:能连上的前提就是密钥对得上)。
|
|
1344
1355
|
'/api/relay/p2p',
|
|
1356
|
+
'/api/relay/p2p/enabled',
|
|
1345
1357
|
'/api/relay/revoke-all',
|
|
1346
1358
|
'/api/relay/config',
|
|
1347
1359
|
'/api/relay/check-port',
|
|
@@ -1382,6 +1394,7 @@ const LOCAL_OPERATOR_ROUTES = new Set([
|
|
|
1382
1394
|
'/api/relay/devices/permissions',
|
|
1383
1395
|
'/api/relay/tailcat/enabled',
|
|
1384
1396
|
'/api/relay/tailcat/revoke',
|
|
1397
|
+
'/api/relay/p2p/enabled',
|
|
1385
1398
|
// FRP 直连的启停:会拉起/杀掉本机进程,属于只允许本机或局域网直连的动作。
|
|
1386
1399
|
'/api/relay/frp/import',
|
|
1387
1400
|
'/api/relay/frp/stop',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
// LAN 生命周期等待旧监听释放,并由同一处绑定与发布入口。
|
|
3
|
+
// 转发给宿主 web 服务的上游地址跟随宿主实际绑定地址(不再写死回环)。
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* sidecar worker:真正持有「中转隧道 + 局域网代理」的那个子进程。
|
|
@@ -280,7 +281,11 @@ async function parentJson(path, body, signal) {
|
|
|
280
281
|
if (res.statusCode !== 200) throw new Error(value.error?.message || value.error || `parent RPC failed: ${res.statusCode}`)
|
|
281
282
|
return value.data ?? value
|
|
282
283
|
}
|
|
283
|
-
function upstream() {
|
|
284
|
+
function upstream() {
|
|
285
|
+
const host = config.upstreamHost || '127.0.0.1'
|
|
286
|
+
// URL 里的 IPv6 字面量要方括号,否则 `new URL` 解析不出来。
|
|
287
|
+
return `http://${host.includes(':') ? `[${host}]` : host}:${config.upstreamPort}`
|
|
288
|
+
}
|
|
284
289
|
// 读取隔离:把移动端高频读请求(sessions/workspaces/messages/stats)从本地快照直接回,
|
|
285
290
|
// 不再打扰主进程。快照缺失或路径不在清单内时返回 null → 调用方回源主进程。
|
|
286
291
|
function snapshotRead(info) {
|
|
@@ -358,13 +363,13 @@ function snapshotRead(info) {
|
|
|
358
363
|
* 的信号。这也意味着写回队首之后**不能**再触发一次配置下发 —— 见 adoptRoute 那一段。
|
|
359
364
|
*/
|
|
360
365
|
function tunnelSignature(c) {
|
|
361
|
-
return JSON.stringify([Boolean(c.enabled), c.relayUrl || '', Array.isArray(c.relayUrls) ? c.relayUrls : [], c.instanceId || '', c.upstreamPort || 0, c.registerSecret || ''])
|
|
366
|
+
return JSON.stringify([Boolean(c.enabled), c.relayUrl || '', Array.isArray(c.relayUrls) ? c.relayUrls : [], c.instanceId || '', c.upstreamPort || 0, c.upstreamHost || '', c.registerSecret || ''])
|
|
362
367
|
}
|
|
363
368
|
/** 「这份配置里哪几项决定局域网代理要重建」。 */
|
|
364
369
|
function lanSignature(c) {
|
|
365
370
|
// **配对码与票据不在其中**:它们由 `currentPairing` 现读,改它们不该重建监听 ——
|
|
366
371
|
// 配对成功就要换一次(§5.1),跟着重建会把刚握上的连接掐掉。
|
|
367
|
-
return JSON.stringify([Boolean(c.enabled), Boolean(c.lanEnabled), c.lanPort || 0, c.upstreamPort || 0, c.instanceId || '', c.lanSecret || '', c.pairingTier || 'full'])
|
|
372
|
+
return JSON.stringify([Boolean(c.enabled), Boolean(c.lanEnabled), c.lanPort || 0, c.upstreamPort || 0, c.upstreamHost || '', c.instanceId || '', c.lanSecret || '', c.pairingTier || 'full'])
|
|
368
373
|
}
|
|
369
374
|
/** 「这份配置里哪几项决定网络监视器要不要重排」。 */
|
|
370
375
|
function monitorSignature(c) {
|
|
@@ -683,6 +688,7 @@ async function startLan() {
|
|
|
683
688
|
// 新配对权限档位(电脑侧选定):局域网这条配对入口按它展开权限位。
|
|
684
689
|
pairingTier: config.pairingTier || 'full',
|
|
685
690
|
upstreamPort: config.upstreamPort,
|
|
691
|
+
upstreamHost: config.upstreamHost || '127.0.0.1',
|
|
686
692
|
readSnapshot: snapshotRead,
|
|
687
693
|
onLog: (...args) => process.stderr.write(`[dsh-ai-hub sidecar] ${args.join(' ')}\n`),
|
|
688
694
|
// 配对成功之后换码 + 换票据:走宿主的控制面(那是唯一能写状态文件的地方)。
|
|
@@ -726,13 +732,14 @@ async function configure(next) {
|
|
|
726
732
|
// `relayUrls` 在白名单里,而且从这一轮起**进签名**(见 tunnelSignature):地址组或它的
|
|
727
733
|
// 顺序变了就要重新择路。白名单缺了它,宿主下发这一格会直接抛 unknown configuration
|
|
728
734
|
// field,整次配置下发失败。
|
|
729
|
-
const allowed = ['enabled', 'relayUrl', 'relayUrls', 'instanceId', 'pairingCode', 'pairingTicket', 'pairingTier', 'name', 'upstreamPort', 'lanPort', 'lanEnabled', 'lanSecret', 'registerSecret']
|
|
735
|
+
const allowed = ['enabled', 'relayUrl', 'relayUrls', 'instanceId', 'pairingCode', 'pairingTicket', 'pairingTier', 'name', 'upstreamPort', 'upstreamHost', 'lanPort', 'lanEnabled', 'lanSecret', 'registerSecret']
|
|
730
736
|
if (Object.keys(next).some(key => !allowed.includes(key))) throw new Error('unknown configuration field')
|
|
731
737
|
if (typeof next.instanceId !== 'string' || next.instanceId.length > 128) throw new Error('invalid instanceId')
|
|
732
738
|
if (typeof next.pairingCode !== 'string' || !/^\d{6}$/.test(next.pairingCode)) throw new Error('invalid pairingCode')
|
|
733
739
|
if (next.pairingTicket !== undefined && (typeof next.pairingTicket !== 'string' || !/^[A-Za-z0-9_-]{0,64}$/.test(next.pairingTicket))) throw new Error('invalid pairingTicket')
|
|
734
740
|
if (next.pairingTier !== undefined && !['readonly', 'approve', 'full'].includes(next.pairingTier)) throw new Error('invalid pairingTier')
|
|
735
741
|
if (typeof next.upstreamPort !== 'number' || !Number.isInteger(next.upstreamPort) || next.upstreamPort < 1 || next.upstreamPort > 65535) throw new Error('invalid upstreamPort')
|
|
742
|
+
if (next.upstreamHost !== undefined && (typeof next.upstreamHost !== 'string' || !next.upstreamHost || next.upstreamHost.length > 64)) throw new Error('invalid upstreamHost')
|
|
736
743
|
if (next.lanPort !== undefined && (!Number.isInteger(next.lanPort) || next.lanPort < 1024 || next.lanPort > 65535)) throw new Error('invalid lanPort')
|
|
737
744
|
if (next.registerSecret !== undefined && (typeof next.registerSecret !== 'string' || next.registerSecret.length > 512)) throw new Error('invalid registerSecret')
|
|
738
745
|
// 只重建真正变了的那一半:
|
package/lib/tailcat/wiring.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// 隧道始终走独立的带来源标记入口,不依赖局域网监听。
|
|
3
|
+
// 落点代理转给宿主时跟随宿主实际绑定地址(见 relay/tunnel-forwarder.cjs)。
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 把直连隧道挂进装配层:回环入口 + 落点代理 + 助手会话 + 一条自己的启停 effect。
|
|
@@ -27,6 +28,7 @@ const { createTunnelForwarder } = require('../relay/tunnel-forwarder.cjs');
|
|
|
27
28
|
* @param {() => boolean} options.lanEnabled 局域网直连开着没有
|
|
28
29
|
* @param {() => number} options.lanPort 当前局域网端口(会漂)
|
|
29
30
|
* @param {() => number} options.webPort 宿主 web 端口(落点代理最终转给它)
|
|
31
|
+
* @param {() => string} [options.webHost] 宿主 web 绑定地址(落点代理转给它;缺省回环)
|
|
30
32
|
* @param {() => string} options.hostName 电脑名
|
|
31
33
|
* @param {object} options.ctx 插件 ctx(只为 `ctx.effect`)
|
|
32
34
|
* @param {string} options.name 插件名,用于 effect 标签
|
|
@@ -38,10 +40,10 @@ function chooseTailcatTarget({ tunnelPort }) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function mountTailcat(options) {
|
|
41
|
-
const { mount, warn, state, saveState, lanEnabled, lanPort, webPort, hostName, ctx, name } = options;
|
|
43
|
+
const { mount, warn, state, saveState, lanEnabled, lanPort, webPort, webHost, hostName, ctx, name } = options;
|
|
42
44
|
// 落点代理与入口各是一条回环监听,都得活着;任何一个起不来就只是这块不可用(`mount` 兜住)。
|
|
43
45
|
const forwarder = mount('隧道落点代理', () =>
|
|
44
|
-
createTunnelForwarder({ upstreamPort: webPort, log: message => warn(message) }),
|
|
46
|
+
createTunnelForwarder({ upstreamPort: webPort, upstreamHost: webHost, log: message => warn(message) }),
|
|
45
47
|
);
|
|
46
48
|
// 与入口一起先把端口开出来:第一条连接进来时(可能比 effect 跑得还早)落点就得有值。
|
|
47
49
|
if (forwarder) void forwarder.start();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.79",
|
|
4
4
|
"description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "./icon.png",
|