dsh-mobile-plugin 0.5.94 → 0.5.95
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/README.md +1 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +10 -3
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/cloudflare.md +58 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/frp.md +50 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv4.md +2 -2
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/load-error-after-action.md +27 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network-guide.md +55 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +5 -1
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/plugin-not-loaded.md +22 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay-server.md +48 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +9 -0
- package/config/agent-presets/standard/skills/dsh-mobile-kb/references/selfhost-common.md +1 -1
- package/lib/cloudflared/provision.cjs +392 -0
- package/lib/cloudflared/runner.cjs +305 -0
- package/lib/cloudflared/wiring.cjs +82 -0
- package/lib/frpc/runner.cjs +1 -1
- package/lib/impl.js +11 -1
- package/lib/mobile/history-derive.js +16 -0
- package/lib/mobile/pairing.js +4 -0
- package/lib/panel/index.html +47 -27
- package/lib/relay/config-store.js +9 -0
- package/lib/relay/control.js +8 -0
- package/lib/relay/core.js +6 -0
- package/lib/relay/lan-network.cjs +23 -0
- package/lib/relay/pairing-payload.cjs +2 -1
- package/lib/remote/tunnel-helper.cjs +3 -3
- package/lib/routes/control-plane.js +100 -6
- package/lib/routes/mobile-api.js +10 -2
- package/lib/shared/route-channels.cjs +1 -0
- package/lib/shared/route-order.cjs +8 -1
- package/lib/tailcat/host-process.cjs +9 -3
- package/package.json +14 -13
|
@@ -42,9 +42,15 @@ const RemoteControlSettingsSchema = z.object({
|
|
|
42
42
|
// 用户手填的 IPv6 直连地址(`manualIpv6Url`,形如 `http://[240e::1]:18787`):与上一条并列,
|
|
43
43
|
// 只是拨的是 IPv6;网卡扫不到的那条固定地址靠它兜底,候选口径见 lan-network.cjs。
|
|
44
44
|
manualIpv6Url: z.string().max(200).default(''),
|
|
45
|
+
// 用户手填的公网 IPv4 地址(形如 `http://1.2.3.4:18787`):只认 IPv4 字面量,域名/其它交给直连地址。
|
|
46
|
+
manualIpv4Url: z.string().max(200).default(''),
|
|
45
47
|
// 用户手填的「TCP 直连」目标(`manualTcpUrl`,形如 `主机:端口` / `http://主机:端口`,IPv6 方括号)。
|
|
46
48
|
// 与上面两条并列、同样不进 sidecar;它只决定手机用裸 TCP 拨哪个目标(详见 lan-network.cjs)。
|
|
47
49
|
manualTcpUrl: z.string().max(200).default(''),
|
|
50
|
+
// Cloudflare 兜底隧道拿到的快速隧道地址(空 = 没起 / 没拿到)。**纯运行时写入**:由
|
|
51
|
+
// `cloudflared/wiring.cjs` 在 runner 报地址时 `settings.update` 落进来,手机端配置口
|
|
52
|
+
// (`relay-control.js` 的 configView / configPatch)**不开放**这一格,只能由运行时写。
|
|
53
|
+
cloudflareUrl: z.string().max(200).default(''),
|
|
48
54
|
})
|
|
49
55
|
|
|
50
56
|
|
|
@@ -76,7 +82,10 @@ function configOf(state) {
|
|
|
76
82
|
preferredLanAddress: typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : '',
|
|
77
83
|
manualLanUrl: typeof state.manualLanUrl === 'string' ? state.manualLanUrl : '',
|
|
78
84
|
manualIpv6Url: typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : '',
|
|
85
|
+
manualIpv4Url: typeof state.manualIpv4Url === 'string' ? state.manualIpv4Url : '',
|
|
79
86
|
manualTcpUrl: typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : '',
|
|
87
|
+
// 运行时写入的 Cloudflare 隧道地址;缺失时按空串(还没起 / 没拿到)。
|
|
88
|
+
cloudflareUrl: typeof state.cloudflareUrl === 'string' ? state.cloudflareUrl : '',
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
|
package/lib/relay/control.js
CHANGED
|
@@ -53,6 +53,8 @@ function controlWsUrl(base = CONTROL_BASE_URL) {
|
|
|
53
53
|
* 中转只取当前实际注册的线路;局域网只走 `advertisedCandidates`(网卡扫到的),手填直连地址
|
|
54
54
|
* 单独标成 `direct`,绝不并进 `lan`;IPv6 走 `ipv6Candidates` 并缀上手填那条,与局域网开关独立;
|
|
55
55
|
* 端口未监听时不发布。
|
|
56
|
+
* 「Cloudflare 兜底隧道」是**一条独立线路**:自己的地址类型 `kind:'cf'`,只取运行时写进
|
|
57
|
+
* `cloudflareUrl` 的那条地址(非空才报),**不受 `lanEnabled` 影响**,也不并进 `direct`。
|
|
56
58
|
* 「TCP 直连」目标(`manualTcpUrl`)单独一条,**不受 `lanEnabled` 影响**:它不挂在局域网监听上,
|
|
57
59
|
* 是一条独立的裸 TCP 出站通道。这一格必须报上来——配了 TCP(或手填直连)时公用中转会被规则关掉,
|
|
58
60
|
* 而 TCP 又替换不了「宿主地址」在手机上的同步:手机离开局域网后连不上宿主,只能靠总控把 TCP
|
|
@@ -83,6 +85,12 @@ function controlAddresses(state, port, connectedRelay = '') {
|
|
|
83
85
|
/* 同上 */
|
|
84
86
|
}
|
|
85
87
|
}
|
|
88
|
+
// 「Cloudflare 兜底隧道」:一条独立线路,自己的地址类型 `kind:'cf'`,**不受 `lanEnabled`
|
|
89
|
+
// 管**(和 tcp 一样,关掉局域网直连照样报)。只在运行时确实拿到了隧道地址
|
|
90
|
+
// (`state.cloudflareUrl` 非空)时才 push —— 空值没有可拨的地址,塞进来只会让总控白存一条。
|
|
91
|
+
// 它不并进 `direct` / `lan`:用户手填的直连地址原样保留,两条线路互不覆盖。
|
|
92
|
+
const cfUrl = typeof state.cloudflareUrl === 'string' ? state.cloudflareUrl.trim() : '';
|
|
93
|
+
if (cfUrl) out.push({ kind: 'cf', url: cfUrl });
|
|
86
94
|
// TCP 直连:用户填的 `host:port`(可能带方括号 IPv6)。不受 `lanEnabled` 管——它是一条独立的
|
|
87
95
|
// 裸 TCP 出站通道,关掉局域网直连时它照样能用;而它恰恰是「公用中转被关掉」那种配置下手机
|
|
88
96
|
// 唯一还能连上的地址,必须进总控这份兜底清单。
|
package/lib/relay/core.js
CHANGED
|
@@ -73,9 +73,15 @@ function defaultState() {
|
|
|
73
73
|
// 用户手填的直连地址(空 = 没填)。与上面那条同一条口径:也是 schema 里的一项、
|
|
74
74
|
// 也不进 sidecar 配置 —— 它只影响「报给手机的候选」与二维码,不影响隧道怎么连。
|
|
75
75
|
manualLanUrl: '',
|
|
76
|
+
// Cloudflare 兜底隧道此刻拿到的快速隧道地址(空 = 没起 / 没拿到)。**纯运行时字段**:
|
|
77
|
+
// 由 `cloudflared/wiring.cjs` 在 runner 报了新地址时写入,不开放给手机在配置口改
|
|
78
|
+
// (`relay-control.js` 的 configView / configPatch 都不带它)。它是独立线路,上报时
|
|
79
|
+
// 走自己的 `kind:'cf'`,**不并进** manualLanUrl(用户手填的直连原样保留)。
|
|
80
|
+
cloudflareUrl: '',
|
|
76
81
|
// 用户手填的 IPv6 直连地址(空 = 没填)。与上一条同一条口径:schema 里的一项、不进
|
|
77
82
|
// sidecar 配置,只影响「报给手机的 IPv6 候选」与二维码。
|
|
78
83
|
manualIpv6Url: '',
|
|
84
|
+
manualIpv4Url: '',
|
|
79
85
|
// 用户手填的「TCP 直连」目标(空 = 没填,形如 `主机:端口` 或 `http://主机:端口`,IPv6 用方括号)。
|
|
80
86
|
// 与上面两条并列、同样**不进 sidecar 配置**:它只决定手机经本机回环(安卓直接)用裸 TCP
|
|
81
87
|
// 拨哪个目标,不影响隧道怎么连。schema 里的一项,改它不该触发 sidecar 重配。
|
|
@@ -371,6 +371,27 @@ function withManualCandidate(list, value) {
|
|
|
371
371
|
return [...rest.filter(item => item && item.url !== manual.url), manual]
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
+
/**
|
|
375
|
+
* 用户手填的**公网 IPv4**(设置项 `manualIpv4Url`)→ 候选。
|
|
376
|
+
*
|
|
377
|
+
* 与「直连地址」(`manualLanUrl`,收域名/任意 http(s))区别开:这一格只认 IPv4 字面量,
|
|
378
|
+
* 对应「运营商分给我一个公网 IPv4、但网卡上挂着的是私网/没有这条」的情形。域名、IPv6 一律
|
|
379
|
+
* 返回 null,交给「直连地址」或「IPv6 直连地址」,避免两栏抢同一件事。
|
|
380
|
+
*/
|
|
381
|
+
function manualIpv4Candidate(value) {
|
|
382
|
+
const candidate = manualCandidate(value)
|
|
383
|
+
if (!candidate) return null
|
|
384
|
+
return /^\d{1,3}(?:\.\d{1,3}){3}$/.test(candidate.address) ? { ...candidate, family: 'IPv4' } : null
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** 网卡候选 + 手填公网 IPv4(排最后当兜底,口径同 `withManualCandidate`)。 */
|
|
388
|
+
function withManualIpv4Candidate(list, value) {
|
|
389
|
+
const manual = manualIpv4Candidate(value)
|
|
390
|
+
const rest = Array.isArray(list) ? list : []
|
|
391
|
+
if (!manual) return rest
|
|
392
|
+
return [...rest.filter(item => item && item.url !== manual.url), manual]
|
|
393
|
+
}
|
|
394
|
+
|
|
374
395
|
/**
|
|
375
396
|
* 用户**自己填的** IPv6 直连地址(设置项 `manualIpv6Url`)→ 候选。
|
|
376
397
|
*
|
|
@@ -501,6 +522,8 @@ module.exports = {
|
|
|
501
522
|
advertisedCandidates,
|
|
502
523
|
manualCandidate,
|
|
503
524
|
withManualCandidate,
|
|
525
|
+
manualIpv4Candidate,
|
|
526
|
+
withManualIpv4Candidate,
|
|
504
527
|
manualIpv6Candidate,
|
|
505
528
|
withManualIpv6Candidate,
|
|
506
529
|
orderCandidates,
|
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
phoneCandidates,
|
|
22
22
|
manualCandidate,
|
|
23
23
|
ipv6Candidates,
|
|
24
|
+
withManualIpv4Candidate,
|
|
24
25
|
withManualIpv6Candidate,
|
|
25
26
|
tcpDirectTarget,
|
|
26
27
|
} = require('./lan-network.cjs');
|
|
@@ -42,7 +43,7 @@ function pairingPayload(state, lanPort) {
|
|
|
42
43
|
const port = Number.isInteger(lanPort) ? lanPort : state.lanPort;
|
|
43
44
|
// 面板上选过的「手机优先用这条」在这里兑现:只挪到最前,其余继续当兜底(App 按顺序挨个试)。
|
|
44
45
|
const candidates = state.lanEnabled
|
|
45
|
-
? phoneCandidates(advertisedCandidates(port), { preferred: state.preferredLanAddress, manual: state.manualLanUrl })
|
|
46
|
+
? withManualIpv4Candidate(phoneCandidates(advertisedCandidates(port), { preferred: state.preferredLanAddress, manual: state.manualLanUrl }), state.manualIpv4Url)
|
|
46
47
|
: [];
|
|
47
48
|
const urls = candidates.map(candidate => candidate.url).filter(Boolean);
|
|
48
49
|
const tcpTarget = tcpDirectTarget(state.manualTcpUrl);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// 桌面助手 RPC
|
|
1
|
+
// 桌面助手 RPC 仅在明确不支持时停用,能力探测超时按现有退避恢复;助手文件名含 Windows ARM64。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const { spawn } = require('node:child_process');
|
|
5
5
|
const { randomUUID } = require('node:crypto');
|
|
6
6
|
const fs = require('node:fs');
|
|
7
7
|
const path = require('node:path');
|
|
8
|
-
const { resolveBinary, platformId, IPC_VERSION } = require('../tailcat/host-process.cjs');
|
|
8
|
+
const { resolveBinary, platformId, binaryName, IPC_VERSION } = require('../tailcat/host-process.cjs');
|
|
9
9
|
const MAX_LINE = 64 * 1024;
|
|
10
10
|
const BACKOFF_MS = [1000, 2000, 5000, 10000, 30000];
|
|
11
11
|
|
|
@@ -23,7 +23,7 @@ function resolveRemoteBinary(options = {}) {
|
|
|
23
23
|
const packageRoot = options.packageRoot || path.resolve(__dirname, '../..');
|
|
24
24
|
const platform = options.platformId || platformId();
|
|
25
25
|
if (platform) {
|
|
26
|
-
const name = platform
|
|
26
|
+
const name = binaryName(platform);
|
|
27
27
|
const bundled = path.join(packageRoot, 'native', platform, name);
|
|
28
28
|
if (exists(bundled)) return bundled;
|
|
29
29
|
if (exists(path.join(root, 'tailcat-host', 'runtime-version.json'))) {
|
|
@@ -35,7 +35,7 @@ const { canListen } = require('../relay/port-allocator.cjs');
|
|
|
35
35
|
// ⚠️ 面板里**能被选中的**那份仍然只能是 `lan`(没有私网时才退 `public`)——它与
|
|
36
36
|
// `advertisedCandidates` 同口径。IPv6 那份只**显示**、不进那个选择:它由手机侧实测择优
|
|
37
37
|
// (和公网中转比速度),做成可选中等于骗人(同 A3-40 的刻意设计)。
|
|
38
|
-
const { lanCandidates, publicCandidates, ipv6Candidates, withManualIpv6Candidate } = require('../relay/lan-network.cjs');
|
|
38
|
+
const { lanCandidates, publicCandidates, ipv6Candidates, withManualIpv4Candidate, withManualIpv6Candidate } = require('../relay/lan-network.cjs');
|
|
39
39
|
// 「手机连不上时哪一环断了」这份连接自检:本机只读、不改任何东西(口径见
|
|
40
40
|
// connection-check.js 与 firewall-probe.js 的文件头)。
|
|
41
41
|
const { createConnectionCheck } = require('../relay/connection-check.js');
|
|
@@ -402,15 +402,18 @@ function registerControlPlaneRoutes(deps) {
|
|
|
402
402
|
const manualIpv6 = typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : ''
|
|
403
403
|
// `manualTcp` 是「TCP 直连」目标(`主机:端口`):面板回显与修改它,手机拿它当裸 TCP 目标。
|
|
404
404
|
const manualTcp = typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : ''
|
|
405
|
+
// `manualIpv4` 是公网 IPv4(只认 IPv4 字面量):单列一格供面板回显,并缀进公网候选最后。
|
|
406
|
+
const manualIpv4 = typeof state.manualIpv4Url === 'string' ? state.manualIpv4Url : ''
|
|
405
407
|
sendJson(res, 200, {
|
|
406
408
|
ok: true,
|
|
407
409
|
port,
|
|
408
410
|
preferred: preferredLan,
|
|
409
411
|
manual,
|
|
410
412
|
manualIpv6,
|
|
413
|
+
manualIpv4,
|
|
411
414
|
manualTcp,
|
|
412
415
|
lan: lanCandidates(port),
|
|
413
|
-
public: publicCandidates(port),
|
|
416
|
+
public: withManualIpv4Candidate(publicCandidates(port), manualIpv4),
|
|
414
417
|
ipv6: withManualIpv6Candidate(ipv6Candidates(port), manualIpv6),
|
|
415
418
|
})
|
|
416
419
|
}) })
|
|
@@ -444,8 +447,13 @@ function registerControlPlaneRoutes(deps) {
|
|
|
444
447
|
const who = await fetch(`${url}/api/mobile/v1/health`, { signal: controller.signal, redirect: 'follow' })
|
|
445
448
|
.then((r) => (r.ok ? r.json() : null))
|
|
446
449
|
.catch(() => null)
|
|
447
|
-
|
|
448
|
-
|
|
450
|
+
const elapsed = Date.now() - started
|
|
451
|
+
// 中转自己那条地址体检 `/api/mobile/v1/health` 会带回 `service`。
|
|
452
|
+
if (who && who.service === 'dsh-mobile-relay') return { url, ms: elapsed, service: 'dsh-mobile-relay', version: who.version }
|
|
453
|
+
// 直连地址打回的是**宿主自己**:回 `service=dsh-mobile-plugin` + `instanceId`。带上实例号,
|
|
454
|
+
// 面板据此确认「这个地址绕回来就是本机」(回环检测),而不是别的机器或别的服务。
|
|
455
|
+
if (who && who.service === 'dsh-mobile-plugin') return { url, ms: elapsed, service: 'dsh-mobile-plugin', instanceId: who.instanceId || '', apiVersion: who.apiVersion }
|
|
456
|
+
return { url, ms: null }
|
|
449
457
|
} catch {
|
|
450
458
|
return { url, ms: null }
|
|
451
459
|
} finally {
|
|
@@ -454,6 +462,38 @@ function registerControlPlaneRoutes(deps) {
|
|
|
454
462
|
}))
|
|
455
463
|
sendJson(res, 200, { ok: true, results })
|
|
456
464
|
}) })
|
|
465
|
+
/**
|
|
466
|
+
* 直连地址的回环体检(`POST /api/relay/probe-direct`,body `{ url }`)。
|
|
467
|
+
*
|
|
468
|
+
* 直连地址打回的就是这台宿主自己,没有中转那套 `/healthz`;这里直接问它的
|
|
469
|
+
* `/api/mobile/v1/health`,把 `service` 与 `instanceId` 带回来,面板据此确认「绕回来
|
|
470
|
+
* 就是本机」。宿主代测是为了绕开浏览器 CORS,只认 http(s)、只发一次 GET。
|
|
471
|
+
*/
|
|
472
|
+
registerRoute({ kind: 'exact', path: '/api/relay/probe-direct', handler: localOnly('POST', async (req, res) => {
|
|
473
|
+
const body = await readJson(req)
|
|
474
|
+
const raw = typeof body?.url === 'string' ? body.url.trim().replace(/\/+$/, '') : ''
|
|
475
|
+
if (!/^https?:\/\//i.test(raw)) return sendJson(res, 200, { ok: true, ms: null })
|
|
476
|
+
const controller = new AbortController()
|
|
477
|
+
const timer = setTimeout(() => controller.abort(), RELAY_PROBE_TIMEOUT_MS)
|
|
478
|
+
const started = Date.now()
|
|
479
|
+
try {
|
|
480
|
+
const who = await fetch(`${raw}/api/mobile/v1/health`, { signal: controller.signal, redirect: 'follow' })
|
|
481
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
482
|
+
.catch(() => null)
|
|
483
|
+
if (!who || typeof who !== 'object') return sendJson(res, 200, { ok: true, ms: null })
|
|
484
|
+
sendJson(res, 200, {
|
|
485
|
+
ok: true,
|
|
486
|
+
ms: Date.now() - started,
|
|
487
|
+
service: typeof who.service === 'string' ? who.service : '',
|
|
488
|
+
instanceId: typeof who.instanceId === 'string' ? who.instanceId : '',
|
|
489
|
+
apiVersion: who.apiVersion,
|
|
490
|
+
})
|
|
491
|
+
} catch {
|
|
492
|
+
sendJson(res, 200, { ok: true, ms: null })
|
|
493
|
+
} finally {
|
|
494
|
+
clearTimeout(timer)
|
|
495
|
+
}
|
|
496
|
+
}) })
|
|
457
497
|
/**
|
|
458
498
|
* 配了几台手机、最近一次连线是什么时候。
|
|
459
499
|
*
|
|
@@ -492,7 +532,7 @@ function registerControlPlaneRoutes(deps) {
|
|
|
492
532
|
return false
|
|
493
533
|
}
|
|
494
534
|
}
|
|
495
|
-
registerRoute({ kind: 'exact', path: '/api/relay/status', handler: localOnly('GET', async (req, res) => sendJson(res, 200, { ...status(), shellChanged: shellChangedNow(), tailcat: deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null, frp: deps.frp && typeof deps.frp.status === 'function' ? deps.frp.status() : null, panelUrl: panelUrlOf(req), panelScope: panelScopeOf(req), devices: deviceSummary(), ...mobileActivity(), selfCheck: selfCheck.snapshot() })) })
|
|
535
|
+
registerRoute({ kind: 'exact', path: '/api/relay/status', handler: localOnly('GET', async (req, res) => sendJson(res, 200, { ...status(), shellChanged: shellChangedNow(), tailcat: deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null, frp: deps.frp && typeof deps.frp.status === 'function' ? deps.frp.status() : null, cloudflare: deps.cloudflare && typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null, panelUrl: panelUrlOf(req), panelScope: panelScopeOf(req), devices: deviceSummary(), ...mobileActivity(), selfCheck: selfCheck.snapshot() })) })
|
|
496
536
|
|
|
497
537
|
// ── 手机直连隧道(Tailcat):面板查看与管理 ────────────────────────────────
|
|
498
538
|
//
|
|
@@ -524,6 +564,22 @@ function registerControlPlaneRoutes(deps) {
|
|
|
524
564
|
// 面板把用户粘贴的 frpc 配置原样送上来,这里交给进程管理器:它会把 `localPort` 对齐到插件
|
|
525
565
|
// 此刻真实监听的端口,再起 `frpc -c 配置`。这样「TCP 直连地址」后面才真的有个隧道在转发,
|
|
526
566
|
// 而不是只填了个地址、什么都没跑。运行状态随 `/api/relay/status` 的 `frp` 一起回给面板。
|
|
567
|
+
registerRoute({ kind: 'exact', path: '/api/relay/frp/config', handler: localOnly('GET', async (_req, res) => {
|
|
568
|
+
if (!deps.frp) {
|
|
569
|
+
return sendJson(res, 503, { ok: false, error: { code: 'frp-unavailable', message: '这台宿主没有接入 frpc 运行能力' } })
|
|
570
|
+
}
|
|
571
|
+
let config = ''
|
|
572
|
+
if (typeof deps.frp.readConfig === 'function') {
|
|
573
|
+
config = deps.frp.readConfig() || ''
|
|
574
|
+
} else if (deps.frp._paths) {
|
|
575
|
+
// 运行中的实例可能是旧外壳(进程启动时缓存、换不掉):直接读它暴露的落盘路径,
|
|
576
|
+
// 免得「查看 FRP 配置」要等一次 DSH 重启才可用。
|
|
577
|
+
for (const file of [deps.frp._paths.jsonConfig, deps.frp._paths.config]) {
|
|
578
|
+
try { config = fs.readFileSync(file, 'utf8'); break } catch { /* 换下一个 */ }
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
sendJson(res, 200, { ok: true, config })
|
|
582
|
+
}) })
|
|
527
583
|
registerRoute({ kind: 'exact', path: '/api/relay/frp/import', handler: localOnly('POST', async (req, res) => {
|
|
528
584
|
const body = await readJson(req)
|
|
529
585
|
const config = body && typeof body.config === 'string' ? body.config : ''
|
|
@@ -555,6 +611,36 @@ function registerControlPlaneRoutes(deps) {
|
|
|
555
611
|
await settings.update({ manualTcpUrl: '' })
|
|
556
612
|
sendJson(res, 200, { ok: true, status: stopped })
|
|
557
613
|
}) })
|
|
614
|
+
|
|
615
|
+
// ── Cloudflare 兜底隧道:面板开关 → 启停本地 cloudflared 快速隧道 ─────────────
|
|
616
|
+
//
|
|
617
|
+
// 和 FRP 直连同一类「动作」:状态那一格随 `/api/relay/status` 的 `cloudflare` 一起回给
|
|
618
|
+
// 面板,这里只补启停两条。快速隧道进程的装配、地址写回与停用后恢复原地址都在
|
|
619
|
+
// `lib/cloudflared`(wiring / runner),面板不碰它们的细节。
|
|
620
|
+
registerRoute({ kind: 'exact', path: '/api/cloudflare/start', handler: localOnly('POST', async (_req, res) => {
|
|
621
|
+
if (!deps.cloudflare || typeof deps.cloudflare.start !== 'function') {
|
|
622
|
+
return sendJson(res, 503, { ok: false, error: { code: 'cloudflare-unavailable', message: '这台宿主没有接入 Cloudflare 隧道能力' } })
|
|
623
|
+
}
|
|
624
|
+
try {
|
|
625
|
+
await deps.cloudflare.start()
|
|
626
|
+
const current = typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null
|
|
627
|
+
sendJson(res, 200, { ok: true, ...(current || {}) })
|
|
628
|
+
} catch (err) {
|
|
629
|
+
sendJson(res, 500, { ok: false, error: { code: 'cloudflare-start-failed', message: err && err.message ? err.message : String(err) } })
|
|
630
|
+
}
|
|
631
|
+
}) })
|
|
632
|
+
registerRoute({ kind: 'exact', path: '/api/cloudflare/stop', handler: localOnly('POST', async (_req, res) => {
|
|
633
|
+
if (!deps.cloudflare || typeof deps.cloudflare.stop !== 'function') {
|
|
634
|
+
return sendJson(res, 503, { ok: false, error: { code: 'cloudflare-unavailable', message: '这台宿主没有接入 Cloudflare 隧道能力' } })
|
|
635
|
+
}
|
|
636
|
+
try {
|
|
637
|
+
await deps.cloudflare.stop()
|
|
638
|
+
const current = typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null
|
|
639
|
+
sendJson(res, 200, { ok: true, ...(current || {}) })
|
|
640
|
+
} catch (err) {
|
|
641
|
+
sendJson(res, 500, { ok: false, error: { code: 'cloudflare-stop-failed', message: err && err.message ? err.message : String(err) } })
|
|
642
|
+
}
|
|
643
|
+
}) })
|
|
558
644
|
const tailcatSnapshot = () => {
|
|
559
645
|
const state = deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null
|
|
560
646
|
const allowed = deps.tailcat && typeof deps.tailcat.allowedClients === 'function' ? deps.tailcat.allowedClients() : []
|
|
@@ -922,6 +1008,9 @@ function registerControlPlaneRoutes(deps) {
|
|
|
922
1008
|
patch.manualLanUrl = body.manualLanUrl.trim().replace(/\/+$/, '')
|
|
923
1009
|
}
|
|
924
1010
|
// 用户手填的 IPv6 直连地址(`http://[240e::1]:18787`)。空串合法 = 清掉,口径同上一条。
|
|
1011
|
+
if (typeof body?.manualIpv4Url === 'string' && body.manualIpv4Url.length <= 200) {
|
|
1012
|
+
patch.manualIpv4Url = body.manualIpv4Url.trim().replace(/\/+$/, '')
|
|
1013
|
+
}
|
|
925
1014
|
if (typeof body?.manualIpv6Url === 'string' && body.manualIpv6Url.length <= 200) {
|
|
926
1015
|
patch.manualIpv6Url = body.manualIpv6Url.trim().replace(/\/+$/, '')
|
|
927
1016
|
}
|
|
@@ -1235,6 +1324,7 @@ function registerControlPlaneRoutes(deps) {
|
|
|
1235
1324
|
const WEB_ACCESS_ROUTES = new Set([
|
|
1236
1325
|
'/api/relay/addresses',
|
|
1237
1326
|
'/api/relay/probe-relays',
|
|
1327
|
+
'/api/relay/probe-direct',
|
|
1238
1328
|
'/api/relay/status',
|
|
1239
1329
|
'/api/relay/panel',
|
|
1240
1330
|
'/api/relay/panel/setup',
|
|
@@ -1257,9 +1347,13 @@ const WEB_ACCESS_ROUTES = new Set([
|
|
|
1257
1347
|
'/api/relay/tailcat',
|
|
1258
1348
|
'/api/relay/tailcat/enabled',
|
|
1259
1349
|
'/api/relay/tailcat/revoke',
|
|
1260
|
-
// FRP
|
|
1350
|
+
// FRP 直连的配置读取与启停:与其它管理动作一样不按来源拦,仍留在清单里保持盘点完整。
|
|
1351
|
+
'/api/relay/frp/config',
|
|
1261
1352
|
'/api/relay/frp/import',
|
|
1262
1353
|
'/api/relay/frp/stop',
|
|
1354
|
+
// Cloudflare 兜底隧道的启停:与其它管理动作一样不按来源拦,仍留在清单里保持盘点完整。
|
|
1355
|
+
'/api/cloudflare/start',
|
|
1356
|
+
'/api/cloudflare/stop',
|
|
1263
1357
|
// 点对点隧道的现状与启停(没有白名单:能连上的前提就是密钥对得上)。
|
|
1264
1358
|
'/api/relay/p2p',
|
|
1265
1359
|
'/api/relay/p2p/enabled',
|
package/lib/routes/mobile-api.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const { sendJson } = require('../http/routing.js');
|
|
21
21
|
const { readJsonBody } = require('../shared/http-util.js');
|
|
22
22
|
const { createP2PRendezvousHandler } = require('../p2p/rendezvous.cjs');
|
|
23
|
-
const { orderCandidates, withManualCandidate, manualCandidate, withManualIpv6Candidate, tcpDirectTarget } = require('../relay/lan-network.cjs');
|
|
23
|
+
const { orderCandidates, withManualCandidate, manualCandidate, withManualIpv4Candidate, withManualIpv6Candidate, tcpDirectTarget } = require('../relay/lan-network.cjs');
|
|
24
24
|
// 中转地址两格的收敛(`relayUrls[0] === relayUrl`)。直接 require 而不是走注入:它是纯函数,
|
|
25
25
|
// 而这两条路由里少一格就是「手机看到两个矛盾的地址」,不该依赖装配层有没有把它递进来。
|
|
26
26
|
const { relayAddressesOf, publicRelayBlocked } = require('../relay/core.js');
|
|
@@ -235,6 +235,11 @@ function registerMobileRoutes(deps) {
|
|
|
235
235
|
// 形状与 `/api/relay/status` 的 `p2p` 完全一致(同一个 `getP2P()`),手机按该口的
|
|
236
236
|
// `available / enabled / ready / started / path` 说话,不自己猜。
|
|
237
237
|
p2p: p2p && typeof p2p.status === 'function' ? p2p.status() : null,
|
|
238
|
+
// 「Cloudflare 兜底隧道」这一格。形状照上面 p2p 那条先例:直接取 runner 的 `status()`
|
|
239
|
+
// (`{available,running,pid,url,error,startedAt,starting,retrying,waitingForPort,enabled}`),
|
|
240
|
+
// 手机按该口说话、不自己猜。它是独立线路自己的状态,和 p2p / 中转互不覆盖;宿主没接这一
|
|
241
|
+
// 块(老装配 / 运行时没起)时为 null,手机当「没有这条线路」处理。
|
|
242
|
+
cloudflare: deps.cloudflare && typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null,
|
|
238
243
|
// 公用中转被宿主强制停用了(用户配了公网可达的自建:自建中转 / 直连 / TCP 直连)。
|
|
239
244
|
// 面板那份 status(control-plane.js)早就带这一格,手机走的这条心跳原先没带 ——
|
|
240
245
|
// 于是手机永远按「公用中转还开着」画网络页:选择线路里仍摆「只走公用中转」、
|
|
@@ -408,7 +413,7 @@ function registerMobileRoutes(deps) {
|
|
|
408
413
|
// 手填的直连地址(穿透域名)缀在**最后**当兜底:它绕公网、比内网慢一个数量级,排在前面
|
|
409
414
|
// 就等于让手机永远选中它、家里那条内网地址一次都不试(见 `withManualCandidate` 的注释)。
|
|
410
415
|
const candidates = state.lanEnabled && port > 0
|
|
411
|
-
? withManualCandidate(orderCandidates(safeLanCandidates(port), state.preferredLanAddress), state.manualLanUrl)
|
|
416
|
+
? withManualIpv4Candidate(withManualCandidate(orderCandidates(safeLanCandidates(port), state.preferredLanAddress), state.manualLanUrl), state.manualIpv4Url)
|
|
412
417
|
: []
|
|
413
418
|
// IPv6 直连候选:单独一份、**不参与**上面的排序 —— 它和中转谁更快只有手机实测得出,
|
|
414
419
|
// 宿主无从判断对端走哪条路由。IPv6 监听独立于局域网开关,关闭 IPv4 不隐藏 IPv6。
|
|
@@ -436,6 +441,9 @@ function registerMobileRoutes(deps) {
|
|
|
436
441
|
lanCandidates: candidates,
|
|
437
442
|
// 手填的直连地址单独一格(空串 = 没填 / 局域网关掉):手机把它落到「直连」栏。
|
|
438
443
|
directUrl,
|
|
444
|
+
// 「Cloudflare 兜底隧道」地址:独立字段(不塞进 directUrl / lanUrls)。空串 = 没起 / 没拿到。
|
|
445
|
+
// 与二维码 / pairing 的 `cloudflareUrl` 同一口径,手机据此把它落到自己的 Cloudflare 槽。
|
|
446
|
+
cloudflareUrl: typeof state.cloudflareUrl === 'string' ? state.cloudflareUrl : '',
|
|
439
447
|
ipv6Candidates: ipv6,
|
|
440
448
|
// 「TCP 直连」目标:从设置项 `manualTcpUrl` 解出来,只此一条、不掺网卡候选(与二维码同一来源)。
|
|
441
449
|
// **始终带这一格**(没配时是空串):手机据此分清「老宿主不认识这格」(整格不出现,别动它手上
|
|
@@ -12,6 +12,7 @@ function createRouteChannels() {
|
|
|
12
12
|
{ channel: 'tunnel', backoffThreshold: 1, budget: 'tunnel' },
|
|
13
13
|
{ channel: 'p2p', backoffThreshold: 1, budget: 'tunnel' },
|
|
14
14
|
{ channel: 'tcp', backoffThreshold: 2, budget: 'tunnel' },
|
|
15
|
+
{ channel: 'cloudflare', backoffThreshold: 1, budget: 'tunnel' },
|
|
15
16
|
];
|
|
16
17
|
|
|
17
18
|
return exports;
|
|
@@ -161,7 +161,7 @@ function createRoutePolicy() {
|
|
|
161
161
|
const unknown = warm.filter((route) => !isFresh(facts, norm(route.url)));
|
|
162
162
|
const ordered = [...known, ...unknown, ...cold];
|
|
163
163
|
const at = ordered.findIndex((route) => norm(route.url) === current);
|
|
164
|
-
if (at <= 0 || cool.has(current)
|
|
164
|
+
if (at <= 0 || cool.has(current))
|
|
165
165
|
return ordered;
|
|
166
166
|
const currentCost = settledCostOf(facts, current);
|
|
167
167
|
if (currentCost === undefined)
|
|
@@ -174,6 +174,13 @@ function createRoutePolicy() {
|
|
|
174
174
|
const noise = noiseCostOf(facts, current) + noiseCostOf(facts, headUrl);
|
|
175
175
|
const clean = penaltyFor(facts, current) === 1 && penaltyFor(facts, headUrl) === 1;
|
|
176
176
|
const required = Math.max(noise, currentCost * ROUTE_SWITCH_SHARE, clean ? SWITCH_GAIN_FLOOR_MS : 0);
|
|
177
|
+
if (!isFresh(facts, current)) {
|
|
178
|
+
if (challenger && gain > 0 && gain <= required) {
|
|
179
|
+
const [item] = ordered.splice(at, 1);
|
|
180
|
+
ordered.unshift(item);
|
|
181
|
+
}
|
|
182
|
+
return ordered;
|
|
183
|
+
}
|
|
177
184
|
const bouncingBack = facts.lastSwitch?.to === current && facts.lastSwitch.from === headUrl;
|
|
178
185
|
const worthwhile = headCost !== undefined && gain > required;
|
|
179
186
|
const settled = !bouncingBack || gain > required * 2;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// 助手重启读取当前已持久身份与白名单,按 peer 保留 IPC
|
|
1
|
+
// 助手重启读取当前已持久身份与白名单,按 peer 保留 IPC 生命周期;平台表含 Windows ARM64。
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -74,7 +74,12 @@ function platformId(platform = process.platform, arch = process.arch) {
|
|
|
74
74
|
const os = platform === 'win32' ? 'win32' : platform;
|
|
75
75
|
const cpu = arch === 'x64' ? 'x64' : arch === 'arm64' ? 'arm64' : arch;
|
|
76
76
|
const id = `${os}-${cpu}`;
|
|
77
|
-
return ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64', 'win32-x64'].includes(id) ? id : undefined;
|
|
77
|
+
return ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64', 'win32-x64', 'win32-arm64'].includes(id) ? id : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 平台包里的助手文件名:Windows(x64 与 ARM64)都带 `.exe`。 */
|
|
81
|
+
function binaryName(platform) {
|
|
82
|
+
return String(platform).startsWith('win32-') ? 'dsh-tailcat-host.exe' : 'dsh-tailcat-host';
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/**
|
|
@@ -84,7 +89,7 @@ function platformId(platform = process.platform, arch = process.arch) {
|
|
|
84
89
|
function resolveBinary(options = {}) {
|
|
85
90
|
const platform = options.platformId || platformId(options.platform, options.arch);
|
|
86
91
|
if (!platform) return null;
|
|
87
|
-
const name = platform
|
|
92
|
+
const name = binaryName(platform);
|
|
88
93
|
const pkg = `dsh-mobile-tailcat-${platform}`;
|
|
89
94
|
|
|
90
95
|
// 1. 平台包(可选依赖装出来的那份)。npm / pnpm 把可选依赖装在「插件自己这份 node_modules」里,
|
|
@@ -342,6 +347,7 @@ module.exports = {
|
|
|
342
347
|
TUNNEL_PORT,
|
|
343
348
|
PAIRING_PORT,
|
|
344
349
|
platformId,
|
|
350
|
+
binaryName,
|
|
345
351
|
resolveBinary,
|
|
346
352
|
createTailcatHost,
|
|
347
353
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mobile-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.95",
|
|
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",
|
|
7
7
|
"engines": {
|
|
8
|
-
"dsh": ">=0.2.0"
|
|
8
|
+
"dsh": ">=0.2.0-0"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "lib/index.js",
|
|
@@ -83,17 +83,18 @@
|
|
|
83
83
|
"dsh-mobile-shell-linux-arm64": "0.1.2",
|
|
84
84
|
"dsh-mobile-shell-linux-x64": "0.1.2",
|
|
85
85
|
"dsh-mobile-shell-win32-x64": "0.1.2",
|
|
86
|
-
"dsh-mobile-tailcat-darwin-arm64": "1.1.
|
|
87
|
-
"dsh-mobile-tailcat-darwin-x64": "1.1.
|
|
88
|
-
"dsh-mobile-tailcat-linux-arm64": "1.1.
|
|
89
|
-
"dsh-mobile-tailcat-linux-x64": "1.1.
|
|
90
|
-
"dsh-mobile-tailcat-win32-x64": "1.1.
|
|
86
|
+
"dsh-mobile-tailcat-darwin-arm64": "1.1.7",
|
|
87
|
+
"dsh-mobile-tailcat-darwin-x64": "1.1.7",
|
|
88
|
+
"dsh-mobile-tailcat-linux-arm64": "1.1.7",
|
|
89
|
+
"dsh-mobile-tailcat-linux-x64": "1.1.7",
|
|
90
|
+
"dsh-mobile-tailcat-win32-x64": "1.1.7",
|
|
91
|
+
"dsh-mobile-tailcat-win32-arm64": "1.1.7"
|
|
91
92
|
},
|
|
92
93
|
"peerDependencies": {
|
|
93
94
|
"@deepseek-ai/cordis": ">=4.0.1",
|
|
94
|
-
"@deepseek-ai/dsh-client-locale": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
|
|
95
|
-
"@deepseek-ai/dsh-settings": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
|
|
96
|
-
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
|
|
95
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
96
|
+
"@deepseek-ai/dsh-settings": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
97
|
+
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
97
98
|
"@deepseek-ai/schemastery": "^3.18.1"
|
|
98
99
|
},
|
|
99
100
|
"dsh": {
|
|
@@ -110,9 +111,9 @@
|
|
|
110
111
|
}
|
|
111
112
|
},
|
|
112
113
|
"devDependencies": {
|
|
113
|
-
"@deepseek-ai/dsh-host-directory-picker-browse": "^0.2.1-rc.3 || ^0.2.2-rc.1",
|
|
114
|
-
"@deepseek-ai/dsh-tool-ask-user": "^0.2.1-rc.3 || ^0.2.2-rc.1",
|
|
115
|
-
"@deepseek-ai/dsh-tool-present": "^0.2.1-rc.3 || ^0.2.2-rc.1",
|
|
114
|
+
"@deepseek-ai/dsh-host-directory-picker-browse": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
115
|
+
"@deepseek-ai/dsh-tool-ask-user": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
116
|
+
"@deepseek-ai/dsh-tool-present": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
|
|
116
117
|
"yaml": "2.9.1"
|
|
117
118
|
}
|
|
118
119
|
}
|