dsh-clash-subscription 0.6.0 → 0.6.3
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-0.6.3.md +63 -0
- package/README.md +1 -1
- package/client.js +58 -21
- package/index.js +62 -51
- package/lib/health.js +82 -0
- package/lib/routes.js +50 -1
- package/package.json +4 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 0.6.3 · 启动窗口与面板四态
|
|
2
|
+
|
|
3
|
+
> 上一版 `0.6.2` · 本版 `0.6.3` · 修复来源:用户报告「好几次 DSH 重启了后点进去内核未启动」
|
|
4
|
+
|
|
5
|
+
## 症状
|
|
6
|
+
|
|
7
|
+
DSH 重启后进设置页,Clash 代理面板显示「内核未运行」,但 `mihomo.exe` 其实已经在跑、
|
|
8
|
+
`routingHealthy` 也是 `true`。反复几次都这样,只能手动点【启动】。
|
|
9
|
+
|
|
10
|
+
## 根因(四条,全部实测复现)
|
|
11
|
+
|
|
12
|
+
| # | 缺陷 | 证据 |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| A | `start()` 没有重入保护 | 并发两次 `start()` 时,`Core.start()` 首行 `await this.stop()` 把第一次刚 spawn 的内核杀掉了,第一次随后报 `fetch failed`;缺内核场景下两次并发解压同一份 `vendor`,第二次 `tar: Can't unlink already-existing object: Permission denied` → `no mihomo core` |
|
|
15
|
+
| B | `status()` 没有「启动中」态 | 面板只有 `running` 一个判据,`false` 一律显示「内核未运行」。而引脚为空时启动实测 **20.6s / 23.5s / 25.0s**,这段窗口里面板就是在说「未运行」 |
|
|
16
|
+
| C | 启动失败完全静默 | `status()` 已返回 `lastError` 与 `degraded`,面板对这两个字段的渲染次数为 **0**;`apply()` 里的 `auto start failed` 只进 `ctx.logger`,实测宿主 stderr 日志 809 行里 **0 条** clash 记录 |
|
|
17
|
+
| D | 首次打开面板阻塞 11 秒 | `lib/routes.js` 的 status 路由无条件 `await runtime.nodeDelays()`,重启后 `measuredAt=0` 触发整轮测速,实测 **11 373 ms** |
|
|
18
|
+
|
|
19
|
+
## 改动
|
|
20
|
+
|
|
21
|
+
1. **`start()` 改成 single-flight**(`index.js`)——`startPromise` 复用,并发调用者共享结果;
|
|
22
|
+
`finally` 里清空,失败后仍可重试。`starting` 语义不变(供 `checkHealth` / `canReselect` 用)。
|
|
23
|
+
2. **`status()` 新增 `starting`**(`index.js`)——把「没启动 / 正在启动 / 启动失败」拆开报。
|
|
24
|
+
3. **面板四态 + 失败原因**(`client.js`)——未返回 → `loading`;`starting` → `内核启动中…`;
|
|
25
|
+
`running` → 运行中;其余 → 未运行。并渲染 `lastError` / `degraded`。
|
|
26
|
+
【启动】按钮在启动中禁用,从 UI 侧也断掉并发触发。
|
|
27
|
+
4. **status 路由不再同步测速**(`lib/routes.js`)——先回已有缓存,`delays` 为空且内核在跑时
|
|
28
|
+
后台补测,下个轮询周期(15s)自然带上。
|
|
29
|
+
5. **默认节点钉为 `🇸🇬 新加坡01`**——`autoSelect` 命中 pinned 时按 `core.js:729-739` 提前结束,
|
|
30
|
+
不再每次启动都跑 54 节点全量矩阵。
|
|
31
|
+
|
|
32
|
+
## 验收(本机实测)
|
|
33
|
+
|
|
34
|
+
`node test/regression-063.mjs` → **29 passed, 0 failed**
|
|
35
|
+
|
|
36
|
+
| 断言 | 结果 |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `CONFIG_DEFAULTS.node === '🇸🇬 新加坡01'` | ok |
|
|
39
|
+
| pinned 命中时不调用 `capabilityMatrix` | ok(0 次) |
|
|
40
|
+
| pinned 节点不在订阅里时回落搜索 | ok |
|
|
41
|
+
| 并发三次 `start()` 只真正启动一次 | ok(`startInner` 1 次) |
|
|
42
|
+
| 失败后锁不残留、可再次启动 | ok |
|
|
43
|
+
| 启动中 `status().starting === true` 且 `running === false` | ok |
|
|
44
|
+
| status 路由里没有 `await nodeDelays()` | ok |
|
|
45
|
+
| 首次响应 `delays` 为 `{}` 且不等后台测速 | ok(0 ms 返回) |
|
|
46
|
+
| 面板渲染 `startFailed` / `degradedNote`、启动中禁用按钮 | ok |
|
|
47
|
+
| 负向对照:0.6.2 确实缺这些 | ok |
|
|
48
|
+
|
|
49
|
+
`node test/e2e-063.mjs`(真内核、真订阅、临时 dataDir)→ **10 passed, 0 failed**
|
|
50
|
+
|
|
51
|
+
| 场景 | 0.6.2 | 0.6.3 |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| 钉住新加坡01后的启动耗时 | 20.6 / 23.5 / 25.0 s | **11.4 s** |
|
|
54
|
+
| 启动窗口里再点【启动】 | 一次 `fetch failed` | 两次都 `ok`,内核进程 1 个,无孤儿 |
|
|
55
|
+
| 启动中 `status().starting` | 字段不存在 | `true` |
|
|
56
|
+
| 节点到齐后第一次 `/status` | 11 373 ms | **6 ms**(测速转后台,21.3 s 跑完) |
|
|
57
|
+
|
|
58
|
+
## 已知残余(不在本版范围)
|
|
59
|
+
|
|
60
|
+
- 钉住的节点仍要跑一遍四探针 × 2 样本,实测 3.2 s;`openai` 探针在这台机上是 403/492ms,
|
|
61
|
+
四探针串并混跑占掉启动时间的 3.2 s。要再压缩得动 `probeSamples` 或探针集合,属于策略变更。
|
|
62
|
+
- 端口选择到 `spawn` 之间仍有一个 TOCTOU 空窗(`freePort()` 关掉监听后内核才 bind),
|
|
63
|
+
400 次采样未复现,暂不改。
|
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Two measured details are worth knowing because they are easy to get wrong:
|
|
|
94
94
|
| Field | Default | Meaning |
|
|
95
95
|
| --- | --- | --- |
|
|
96
96
|
| `subscriptionUrls` | empty | One subscription per line, optional `name ` prefix |
|
|
97
|
-
| `node` |
|
|
97
|
+
| `node` | `🇸🇬 新加坡01` | Preferred exit node. A pinned node is checked first and ends the startup search as soon as it passes; a name this subscription does not carry falls through to the normal search, so a pin never blocks a boot. Empty means fully automatic (rank all nodes every boot). |
|
|
98
98
|
| `mode` | `rule` | `rule` keeps Chinese sites direct; `global` sends everything through the node |
|
|
99
99
|
| `autoStart` | `true` | Bring routing up when the plugin loads |
|
|
100
100
|
| `autoFetchCore` | `false` | Download a core from the internet when this platform has no bundled one |
|
package/client.js
CHANGED
|
@@ -103,10 +103,16 @@ const en = {
|
|
|
103
103
|
unavailable: 'Configuration is not editable here.',
|
|
104
104
|
statusRunning: 'Core running at {endpoint}',
|
|
105
105
|
statusStopped: 'Core stopped',
|
|
106
|
+
statusStarting: 'Core starting… (first boot probes every node, 10–30 s)',
|
|
106
107
|
statusRouting: 'Outbound policy installed',
|
|
107
108
|
statusDirect: 'Outbound policy not installed (direct)',
|
|
109
|
+
startFailed: 'Last start failed: {reason}',
|
|
110
|
+
degradedNote: 'Degraded: {reason}',
|
|
108
111
|
measuredAt: 'Last measurement: {time}',
|
|
109
112
|
never: 'never',
|
|
113
|
+
usableOk: 'usable',
|
|
114
|
+
usableBlocked: 'blocked',
|
|
115
|
+
usableUnknown: 'untested',
|
|
110
116
|
readOnly: 'This panel is read-only here; open it from Settings to edit.',
|
|
111
117
|
}
|
|
112
118
|
|
|
@@ -180,6 +186,9 @@ const zh = {
|
|
|
180
186
|
blockedTag: '已屏蔽',
|
|
181
187
|
blockedCount: '已屏蔽 {count} 个节点',
|
|
182
188
|
blockedInvalid: '正则无效,未生效:',
|
|
189
|
+
usableOk: '可用',
|
|
190
|
+
usableBlocked: '受限',
|
|
191
|
+
usableUnknown: '未测',
|
|
183
192
|
blockedEmpty: '还没有节点清单——先启动一次,这里就会出现可勾选的节点。',
|
|
184
193
|
blockedSearch: '筛选节点…',
|
|
185
194
|
blockedSelected: '已屏蔽 {count} / 共 {total}',
|
|
@@ -217,8 +226,11 @@ const zh = {
|
|
|
217
226
|
unavailable: '这里无法编辑配置。',
|
|
218
227
|
statusRunning: '内核运行中 {endpoint}',
|
|
219
228
|
statusStopped: '内核未运行',
|
|
229
|
+
statusStarting: '内核启动中…(首次要探测节点能力,约 10–30 秒)',
|
|
220
230
|
statusRouting: '出网策略已安装',
|
|
221
231
|
statusDirect: '出网策略未安装(直连)',
|
|
232
|
+
startFailed: '上次启动失败:{reason}',
|
|
233
|
+
degradedNote: '已降级:{reason}',
|
|
222
234
|
measuredAt: '上次测速:{time}',
|
|
223
235
|
never: '尚未测过',
|
|
224
236
|
readOnly: '这里是只读预览;要修改请从设置里打开。',
|
|
@@ -339,6 +351,10 @@ const CSS = `
|
|
|
339
351
|
.clxp-node + .clxp-node { border-top: 1px solid var(--dsh-border-muted, #eaeef2); }
|
|
340
352
|
.clxp-node-act { padding: 1px 6px; font-size: 12px; line-height: 1.4; border-radius: 4px; }
|
|
341
353
|
.clxp-node.current { background: var(--dsh-surface-subtle, #f6f8fa); font-weight: 600; }
|
|
354
|
+
.clxp-usable { flex: 0 0 auto; font-size: 11px; padding: 0 5px; border-radius: 3px; line-height: 1.6; }
|
|
355
|
+
.clxp-usable.ok { color: #1a7f37; background: rgba(26, 127, 55, 0.1); }
|
|
356
|
+
.clxp-usable.blocked { color: #cf222e; background: rgba(207, 34, 46, 0.1); }
|
|
357
|
+
.clxp-usable.unknown { color: var(--dsh-text-tertiary, #8b949e); background: var(--dsh-surface-subtle, #f6f8fa); }
|
|
342
358
|
.clxp-node-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
343
359
|
.clxp-delay { font-variant-numeric: tabular-nums; color: var(--dsh-text-secondary, #57606a); font-size: 12px; }
|
|
344
360
|
.clxp-delay.good { color: #1a7f37; }
|
|
@@ -495,6 +511,11 @@ function BlocklistPicker(props) {
|
|
|
495
511
|
function Panel(props) {
|
|
496
512
|
const { t, draft, live, delays, busy, message, probe, saving, dirty, open, editable } = props
|
|
497
513
|
const nodes = Array.isArray(live?.nodes) ? live.nodes : []
|
|
514
|
+
// One row per node from the server: latency and usability measured together, so the list
|
|
515
|
+
// shows "120 ms · usable" instead of needing a second list to answer the same question.
|
|
516
|
+
const rowsByName = new Map(
|
|
517
|
+
(Array.isArray(live?.nodeRows?.rows) ? live.nodeRows.rows : []).map((row) => [row.name, row]),
|
|
518
|
+
)
|
|
498
519
|
const subscriptions = Array.isArray(live?.subscriptions) && live.subscriptions.length > 0
|
|
499
520
|
? live.subscriptions
|
|
500
521
|
: // Before the first status poll resolves, fall back to the draft's own lines so the
|
|
@@ -502,6 +523,11 @@ function Panel(props) {
|
|
|
502
523
|
parseLines(editable ? draft.subscriptionUrls : live?.config?.subscriptionUrls)
|
|
503
524
|
const providers = Array.isArray(live?.providers) ? live.providers : []
|
|
504
525
|
const running = live?.running === true
|
|
526
|
+
// Three states, and the middle one used to be invisible: a start in flight rendered as
|
|
527
|
+
// "内核未运行", which is also what a stopped core says. `live` being undefined (the first
|
|
528
|
+
// status poll has not answered yet) is the third: still unknown, not "stopped".
|
|
529
|
+
const starting = live?.starting === true
|
|
530
|
+
const unknown = live === undefined || live === null
|
|
505
531
|
const routingOn = live?.routing === true
|
|
506
532
|
const [expanded, setExpanded] = useState({})
|
|
507
533
|
|
|
@@ -598,18 +624,32 @@ function Panel(props) {
|
|
|
598
624
|
h('div', { key: 'status', className: 'clxp-status' }, [
|
|
599
625
|
h('span', { key: 'd', className: `clxp-dot${running ? (routingOn ? ' on' : ' warn') : ''}` }),
|
|
600
626
|
h('div', { key: 't', className: 'clxp-status-text' }, [
|
|
601
|
-
h('span', { key: 'c' }, running
|
|
627
|
+
h('span', { key: 'c' }, running
|
|
628
|
+
? fill(t('statusRunning'), { endpoint: live?.endpoint ?? '' })
|
|
629
|
+
: unknown
|
|
630
|
+
? t('loading')
|
|
631
|
+
: starting
|
|
632
|
+
? t('statusStarting')
|
|
633
|
+
: t('statusStopped')),
|
|
602
634
|
h('span', { key: 'p', className: 'clxp-note' }, routingOn ? t('statusRouting') : t('statusDirect')),
|
|
603
635
|
live?.measuredAt !== undefined && live.measuredAt !== null
|
|
604
636
|
? h('span', { key: 'm', className: 'clxp-note' }, fill(t('measuredAt'), { time: new Date(live.measuredAt).toLocaleTimeString() }))
|
|
605
637
|
: null,
|
|
606
638
|
].filter(Boolean)),
|
|
607
639
|
h('div', { key: 'a', className: 'clxp-status-actions' }, [
|
|
608
|
-
h('button', { key: 'tg', type: 'button', className: 'clxp-primary', disabled: busy !== '', onClick: () => void props.onAction(running ? 'stop' : 'start') }, running ? t('stop') : t('start')),
|
|
640
|
+
h('button', { key: 'tg', type: 'button', className: 'clxp-primary', disabled: busy !== '' || (starting && !running), onClick: () => void props.onAction(running ? 'stop' : 'start') }, running ? t('stop') : t('start')),
|
|
609
641
|
h('button', { key: 'rf', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('refresh') }, t('refresh')),
|
|
610
642
|
]),
|
|
611
643
|
]),
|
|
612
644
|
live?.blocker !== undefined ? h('p', { key: 'bl', className: 'clxp-error' }, live.blocker) : null,
|
|
645
|
+
// The runtime already reports both of these; nothing rendered them, so a failed boot
|
|
646
|
+
// looked exactly like a boot that had not been attempted yet.
|
|
647
|
+
live?.lastError !== undefined && live.lastError !== null && running !== true
|
|
648
|
+
? h('p', { key: 'le', className: 'clxp-error' }, fill(t('startFailed'), { reason: live.lastError }))
|
|
649
|
+
: null,
|
|
650
|
+
live?.degraded !== undefined && live.degraded !== null
|
|
651
|
+
? h('p', { key: 'dg', className: 'clxp-error' }, fill(t('degradedNote'), { reason: live.degraded }))
|
|
652
|
+
: null,
|
|
613
653
|
|
|
614
654
|
// No core yet: this is the one blocker the panel can fix without the user finding a
|
|
615
655
|
// binary themselves, so it gets a control instead of only being named.
|
|
@@ -698,34 +738,30 @@ function Panel(props) {
|
|
|
698
738
|
h('span', { key: 's', className: 'clxp-delay bad' }, t('blockedTag')),
|
|
699
739
|
])))
|
|
700
740
|
: null,
|
|
701
|
-
live?.capability !== undefined && Array.isArray(live.capability.nodes) && live.capability.nodes.length > 0
|
|
702
|
-
? h('p', { key: 'cp', className: 'clxp-note' }, fill(t('usableCount'), {
|
|
703
|
-
usable: live.capability.nodes.filter((row) => row.usable).length,
|
|
704
|
-
total: live.capability.nodes.length,
|
|
705
|
-
}) + ' · ' + t('requiredProbes') + ': ' + (live.capability.required ?? []).join(', '))
|
|
706
|
-
: null,
|
|
707
|
-
live?.capability !== undefined && Array.isArray(live.capability.nodes)
|
|
708
|
-
? h('div', { key: 'cpl', className: 'clxp-subs' },
|
|
709
|
-
live.capability.nodes
|
|
710
|
-
.filter((row) => !row.usable)
|
|
711
|
-
.slice(0, 6)
|
|
712
|
-
.map((row) => h('div', { key: row.name, className: 'clxp-sub' }, [
|
|
713
|
-
h('span', { key: 'n', className: 'clxp-node-name' }, row.name),
|
|
714
|
-
h('span', { key: 'f', className: 'clxp-delay bad' }, (row.failed ?? []).join(', ') || '-'),
|
|
715
|
-
])))
|
|
716
|
-
: null,
|
|
717
741
|
|
|
718
742
|
nodes.length === 0
|
|
719
743
|
? h('p', { key: 'em', className: 'clxp-note' }, t('noNodes'))
|
|
720
744
|
: h('div', { key: 'ls', className: 'clxp-nodes', role: 'listbox', 'aria-label': t('routing') },
|
|
721
|
-
nodes.map((name) =>
|
|
745
|
+
nodes.map((name) => {
|
|
746
|
+
// Latency and usability come from one measurement, so they are rendered from one
|
|
747
|
+
// row. Splitting them into two lists let the panel show "fast" beside "blocked"
|
|
748
|
+
// with nothing connecting the two.
|
|
749
|
+
const nodeRow = rowsByName.get(name)
|
|
750
|
+
const usable = nodeRow?.usable ?? 'unknown'
|
|
751
|
+
const shownDelay = nodeRow?.delay === undefined ? delays[name] : nodeRow.delay
|
|
752
|
+
return h('div', {
|
|
722
753
|
key: name,
|
|
723
754
|
className: `clxp-node${name === live?.node ? ' current' : ''}`,
|
|
724
755
|
role: 'option',
|
|
725
756
|
'aria-selected': name === live?.node,
|
|
726
757
|
}, [
|
|
727
758
|
h('span', { key: 'n', className: 'clxp-node-name', title: name }, name),
|
|
728
|
-
h('span', { key: 'd', className: delayClass(
|
|
759
|
+
h('span', { key: 'd', className: delayClass(shownDelay) }, delayText(shownDelay)),
|
|
760
|
+
h('span', {
|
|
761
|
+
key: 'u',
|
|
762
|
+
className: `clxp-usable ${usable}`,
|
|
763
|
+
title: (nodeRow?.failed ?? []).join(', '),
|
|
764
|
+
}, usable === 'ok' ? t('usableOk') : usable === 'blocked' ? t('usableBlocked') : t('usableUnknown')),
|
|
729
765
|
h('button', {
|
|
730
766
|
key: 't',
|
|
731
767
|
type: 'button',
|
|
@@ -742,7 +778,8 @@ function Panel(props) {
|
|
|
742
778
|
disabled: busy !== '' || !running || name === live?.node,
|
|
743
779
|
onClick: () => void props.onAction('select', { node: name }),
|
|
744
780
|
}, name === live?.node ? '✓' : t('select')),
|
|
745
|
-
])
|
|
781
|
+
])
|
|
782
|
+
})),
|
|
746
783
|
h('div', { key: 'ac', className: 'clxp-actions' }, [
|
|
747
784
|
h('button', { key: 'te', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test') }, busy === 'test' ? t('testing') : t('testNow')),
|
|
748
785
|
h('button', { key: 'ta', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test', { all: true }) }, busy === 'test' ? t('testing') : t('testAll')),
|
package/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { fetchGeoDatabases, hasGeoDatabase } from './lib/geo.js'
|
|
|
23
23
|
import { DEFAULT_PROBES, judgeNode, rankNodes, resolveProbes } from './lib/select.js'
|
|
24
24
|
import { buildExcludeFilter, isBlocked, partitionNodes, validateBlocklist } from './lib/blocklist.js'
|
|
25
25
|
import { readInventory, rememberNodes } from './lib/inventory.js'
|
|
26
|
+
import { buildNodeRows, summariseRows } from './lib/health.js'
|
|
26
27
|
import { installName, loadHttpProxyModule, locateInstallRoot, resolveFromInstall } from './lib/install.js'
|
|
27
28
|
import { Routing } from './lib/routing.js'
|
|
28
29
|
import {
|
|
@@ -55,7 +56,13 @@ export const CONFIG_DEFAULTS = {
|
|
|
55
56
|
subscriptionUrls: '',
|
|
56
57
|
/** Single-URL field from 0.2; read for migration, never written back. */
|
|
57
58
|
subscriptionUrl: '',
|
|
58
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Preferred exit node. A pinned node is checked first and ends the startup search as
|
|
61
|
+
* soon as it passes, which is the difference between a 2 s boot and a 20 s one: without
|
|
62
|
+
* a pin every boot ranks all 54 nodes against four services. A name this subscription
|
|
63
|
+
* does not carry falls through to the normal search, so the pin never blocks a start.
|
|
64
|
+
*/
|
|
65
|
+
node: '🇸🇬 新加坡01',
|
|
59
66
|
corePath: '',
|
|
60
67
|
mode: 'rule',
|
|
61
68
|
autoStart: true,
|
|
@@ -244,6 +251,8 @@ export class Runtime {
|
|
|
244
251
|
this.geoUpgrading = false
|
|
245
252
|
/** True while `start()` is running, so the watchdog never races a deliberate restart. */
|
|
246
253
|
this.starting = false
|
|
254
|
+
/** The in-flight start, so a second caller joins it instead of restarting the core. */
|
|
255
|
+
this.startPromise = undefined
|
|
247
256
|
/**
|
|
248
257
|
* Whether this activation is supposed to own a running core.
|
|
249
258
|
*
|
|
@@ -318,15 +327,32 @@ export class Runtime {
|
|
|
318
327
|
}
|
|
319
328
|
|
|
320
329
|
const measured = new Map(this.measured)
|
|
330
|
+
const plan = resolveProbes(this.config.probes, this.config.requiredProbes)
|
|
331
|
+
const capability = new Map((this.lastMatrix ?? []).map((row) => [row.name, row]))
|
|
321
332
|
const batchSize = 5
|
|
322
333
|
for (let at = 0; at < candidates.length; at += batchSize) {
|
|
323
334
|
const batch = candidates.slice(at, at + batchSize)
|
|
335
|
+
// Latency and usability are measured in the same pass: a row that reports "120 ms" without
|
|
336
|
+
// saying whether the node can reach the required services answers half the question, and
|
|
337
|
+
// measuring them separately let the two disagree.
|
|
324
338
|
const answers = await Promise.all(
|
|
325
|
-
batch.map(async (name) =>
|
|
339
|
+
batch.map(async (name) => {
|
|
340
|
+
const delay = await this.core.delay(name, 5000)
|
|
341
|
+
const results = delay === null ? undefined : await this.core.capabilities(name, plan.probes, {
|
|
342
|
+
timeoutMs: this.config.probeTimeoutMs ?? 8000,
|
|
343
|
+
samples: this.config.probeSamples ?? 2,
|
|
344
|
+
})
|
|
345
|
+
return { name, delay, results }
|
|
346
|
+
}),
|
|
326
347
|
)
|
|
327
|
-
for (const answer of answers)
|
|
348
|
+
for (const answer of answers) {
|
|
349
|
+
measured.set(answer.name, answer.delay)
|
|
350
|
+
if (answer.results !== undefined) capability.set(answer.name, { name: answer.name, results: answer.results })
|
|
351
|
+
else capability.set(answer.name, { name: answer.name, results: {} })
|
|
352
|
+
}
|
|
328
353
|
}
|
|
329
354
|
this.measured = measured
|
|
355
|
+
this.lastMatrix = [...capability.values()]
|
|
330
356
|
this.measuredAt = Date.now()
|
|
331
357
|
return Object.fromEntries(measured)
|
|
332
358
|
}
|
|
@@ -919,12 +945,22 @@ export class Runtime {
|
|
|
919
945
|
* @returns the start report.
|
|
920
946
|
*/
|
|
921
947
|
async start(options = {}) {
|
|
948
|
+
// Exactly one start at a time. `apply()` fires one in the background at boot and the
|
|
949
|
+
// panel's Start button fires another; `Core.start()` begins with `await this.stop()`,
|
|
950
|
+
// so the second call killed the core the first one had just spawned and the first
|
|
951
|
+
// then failed at its capability probe with a bare "fetch failed". The panel offered
|
|
952
|
+
// the button for the whole ~25 s boot window, so this was reachable by clicking once.
|
|
953
|
+
if (this.startPromise !== undefined) return await this.startPromise
|
|
922
954
|
this.starting = true
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
955
|
+
this.startPromise = (async () => {
|
|
956
|
+
try {
|
|
957
|
+
return await this.startInner(options)
|
|
958
|
+
} finally {
|
|
959
|
+
this.starting = false
|
|
960
|
+
this.startPromise = undefined
|
|
961
|
+
}
|
|
962
|
+
})()
|
|
963
|
+
return await this.startPromise
|
|
928
964
|
}
|
|
929
965
|
|
|
930
966
|
/**
|
|
@@ -1231,6 +1267,12 @@ export class Runtime {
|
|
|
1231
1267
|
binary: this.binary,
|
|
1232
1268
|
dataDir: this.dataDir,
|
|
1233
1269
|
running,
|
|
1270
|
+
/**
|
|
1271
|
+
* Whether a start is in flight. Without this the panel had only two states, so a
|
|
1272
|
+
* core that was still probing its nodes rendered as "内核未运行" — the exact string a
|
|
1273
|
+
* genuinely stopped core shows — for the whole boot window.
|
|
1274
|
+
*/
|
|
1275
|
+
starting: this.starting === true,
|
|
1234
1276
|
endpoint: running ? `http://127.0.0.1:${this.core.mixedPort}` : undefined,
|
|
1235
1277
|
routing: this.routing?.active === true,
|
|
1236
1278
|
/** Whether the installed dispatcher is really this plugin's — see Routing#verify. */
|
|
@@ -1272,6 +1314,18 @@ export class Runtime {
|
|
|
1272
1314
|
idleSince: this.idleSince === undefined ? null : new Date(this.idleSince).toISOString(),
|
|
1273
1315
|
},
|
|
1274
1316
|
/** Per-node probe results from the last selection, and which services gate it. */
|
|
1317
|
+
/**
|
|
1318
|
+
* One row per live node with its latency and usability together. The panel draws this and
|
|
1319
|
+
* nothing else for the node list, so latency and capability cannot drift apart on screen.
|
|
1320
|
+
*/
|
|
1321
|
+
nodeRows: (() => {
|
|
1322
|
+
const live = group.all.filter((name) => name !== 'DIRECT')
|
|
1323
|
+
const rows = buildNodeRows(live, Object.fromEntries(this.measured), {
|
|
1324
|
+
required: resolveProbes(this.config.probes, this.config.requiredProbes).required,
|
|
1325
|
+
nodes: this.lastMatrix,
|
|
1326
|
+
})
|
|
1327
|
+
return { rows, summary: summariseRows(rows) }
|
|
1328
|
+
})(),
|
|
1275
1329
|
capability: {
|
|
1276
1330
|
required: resolveProbes(this.config.probes, this.config.requiredProbes).required,
|
|
1277
1331
|
probes: resolveProbes(this.config.probes, this.config.requiredProbes).probes.map((probe) => ({ id: probe.id, label: probe.label })),
|
|
@@ -1513,49 +1567,6 @@ function subscriptionTool(runtime) {
|
|
|
1513
1567
|
const report = await runtime.start()
|
|
1514
1568
|
return { ...report, summary: `已启动:${report.endpoint},节点「${report.group.now ?? '未选择'}」,共 ${Math.max(0, report.group.all.length - 1)} 个可选节点。` }
|
|
1515
1569
|
}
|
|
1516
|
-
if (action === 'blockSelection') {
|
|
1517
|
-
// The picker sends exact node names, so each becomes an anchored literal entry. Raw
|
|
1518
|
-
// regex text stays available in the blocklist field for whole-region removal; keeping
|
|
1519
|
-
// them apart means a checkbox can never accidentally behave as a pattern.
|
|
1520
|
-
const names = Array.isArray(body.names)
|
|
1521
|
-
? body.names.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim())
|
|
1522
|
-
: []
|
|
1523
|
-
const keepRegex = String(body.keepRegex ?? '').trim()
|
|
1524
|
-
const literals = names.join('\n')
|
|
1525
|
-
const list = [keepRegex, literals].filter((part) => part !== '').join('\n')
|
|
1526
|
-
const problems = validateBlocklist(list)
|
|
1527
|
-
if (problems.length > 0) {
|
|
1528
|
-
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
1529
|
-
return
|
|
1530
|
-
}
|
|
1531
|
-
const saved = await runtime.saveConfig({ blocklist: list })
|
|
1532
|
-
sendJson(response, 200, {
|
|
1533
|
-
ok: true,
|
|
1534
|
-
blocked: names.length,
|
|
1535
|
-
filter: buildExcludeFilter(list),
|
|
1536
|
-
config: saved.config,
|
|
1537
|
-
warnings: saved.warnings,
|
|
1538
|
-
})
|
|
1539
|
-
return
|
|
1540
|
-
}
|
|
1541
|
-
if (action === 'blocklist') {
|
|
1542
|
-
const raw = String(body.list ?? '')
|
|
1543
|
-
const problems = validateBlocklist(raw)
|
|
1544
|
-
// An invalid regex makes the core reject the whole provider, which empties the node table
|
|
1545
|
-
// — a far worse symptom than a rejected save. Catch it here instead.
|
|
1546
|
-
if (problems.length > 0) {
|
|
1547
|
-
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
1548
|
-
return
|
|
1549
|
-
}
|
|
1550
|
-
const saved = await runtime.saveConfig({ blocklist: raw })
|
|
1551
|
-
sendJson(response, 200, {
|
|
1552
|
-
ok: true,
|
|
1553
|
-
filter: buildExcludeFilter(raw),
|
|
1554
|
-
config: saved.config,
|
|
1555
|
-
warnings: saved.warnings,
|
|
1556
|
-
})
|
|
1557
|
-
return
|
|
1558
|
-
}
|
|
1559
1570
|
if (action === 'reselect') {
|
|
1560
1571
|
const result = await runtime.autoReselect({ force: true })
|
|
1561
1572
|
return {
|
package/lib/health.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-node health as one row the panel can render: delay plus usability.
|
|
3
|
+
*
|
|
4
|
+
* The panel used to show latency in the node list and usability in a separate capability
|
|
5
|
+
* block, which meant two lists of the same nodes and a reader had to join them by name. A
|
|
6
|
+
* single row carrying both is the whole point: "120 ms, usable" or "260 ms, OpenAI blocked"
|
|
7
|
+
* answers the question someone actually has when picking an exit.
|
|
8
|
+
*
|
|
9
|
+
* Usability is a three-state, not a boolean:
|
|
10
|
+
*
|
|
11
|
+
* - `unknown` — never probed, or probed before the current required set changed;
|
|
12
|
+
* - `ok` — every required service answered;
|
|
13
|
+
* - `blocked` — at least one did not.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-clash-proxy/health
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Build one row per node, joining the latency map with the capability matrix.
|
|
20
|
+
*
|
|
21
|
+
* @param names - node names the core currently carries.
|
|
22
|
+
* @param delays - node name to delay in ms, or null when it did not answer.
|
|
23
|
+
* @param capability - `{ required, nodes }` from the last selection, or undefined.
|
|
24
|
+
* @returns one row per node, in the order given.
|
|
25
|
+
*/
|
|
26
|
+
export function buildNodeRows(names, delays, capability) {
|
|
27
|
+
const list = Array.isArray(names) ? names : []
|
|
28
|
+
const delayMap = delays !== null && typeof delays === 'object' ? delays : {}
|
|
29
|
+
const required = Array.isArray(capability?.required) ? capability.required : []
|
|
30
|
+
const results = new Map()
|
|
31
|
+
for (const row of Array.isArray(capability?.nodes) ? capability.nodes : []) {
|
|
32
|
+
if (row !== null && typeof row === 'object' && typeof row.name === 'string') results.set(row.name, row)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return list.map((name) => {
|
|
36
|
+
const delay = Object.hasOwn(delayMap, name) ? delayMap[name] : undefined
|
|
37
|
+
const measured = results.get(name)
|
|
38
|
+
let usable = 'unknown'
|
|
39
|
+
let failed = []
|
|
40
|
+
if (measured !== undefined && required.length > 0) {
|
|
41
|
+
failed = required.filter((id) => typeof measured.results?.[id] !== 'number')
|
|
42
|
+
usable = failed.length === 0 ? 'ok' : 'blocked'
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
/** ms, null for "did not answer", undefined for "not measured yet". */
|
|
47
|
+
delay: delay === undefined ? undefined : delay,
|
|
48
|
+
usable,
|
|
49
|
+
failed,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Summarise a row set for the panel header.
|
|
56
|
+
*
|
|
57
|
+
* `usable` counts only nodes positively confirmed for every required service; `unknown` is
|
|
58
|
+
* reported apart from it so a fresh start does not read as "nothing works".
|
|
59
|
+
*
|
|
60
|
+
* @param rows - output of {@link buildNodeRows}.
|
|
61
|
+
* @returns counts by state and the total.
|
|
62
|
+
*/
|
|
63
|
+
export function summariseRows(rows) {
|
|
64
|
+
const list = Array.isArray(rows) ? rows : []
|
|
65
|
+
return {
|
|
66
|
+
total: list.length,
|
|
67
|
+
ok: list.filter((row) => row.usable === 'ok').length,
|
|
68
|
+
blocked: list.filter((row) => row.usable === 'blocked').length,
|
|
69
|
+
unknown: list.filter((row) => row.usable === 'unknown').length,
|
|
70
|
+
measured: list.filter((row) => typeof row.delay === 'number').length,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A short label for one row's usability, for the panel to translate.
|
|
76
|
+
*
|
|
77
|
+
* @param row - one output row.
|
|
78
|
+
* @returns `ok`, `blocked` or `unknown`.
|
|
79
|
+
*/
|
|
80
|
+
export function usabilityLabel(row) {
|
|
81
|
+
return row?.usable === 'ok' || row?.usable === 'blocked' ? row.usable : 'unknown'
|
|
82
|
+
}
|
package/lib/routes.js
CHANGED
|
@@ -111,6 +111,8 @@ const methodOf = (request) => String(request.method ?? 'GET').toUpperCase()
|
|
|
111
111
|
* @param log - logger for route failures.
|
|
112
112
|
* @returns disposers for every registered route.
|
|
113
113
|
*/
|
|
114
|
+
import { buildExcludeFilter, validateBlocklist } from './blocklist.js'
|
|
115
|
+
|
|
114
116
|
export function mountRoutes(webServer, runtime, log) {
|
|
115
117
|
const disposers = []
|
|
116
118
|
|
|
@@ -144,12 +146,23 @@ export function mountRoutes(webServer, runtime, log) {
|
|
|
144
146
|
return
|
|
145
147
|
}
|
|
146
148
|
const status = await runtime.status()
|
|
147
|
-
|
|
149
|
+
// Measured inside the request until 0.6.3. On the first panel open after a restart
|
|
150
|
+
// `measuredAt` is 0, so `nodeDelays()` ran a whole cycle — 8 nodes x (5 s delay + 8 s
|
|
151
|
+
// capability probes x 2 samples) — before answering; measured 11 373 ms, during which
|
|
152
|
+
// the panel showed nothing at all while the core was demonstrably up. Answer with what
|
|
153
|
+
// is already known and finish the measurement in the background: the panel polls every
|
|
154
|
+
// 15 s, so the latencies arrive on the next tick and nothing blocks.
|
|
155
|
+
const delays = Object.fromEntries(runtime.measured)
|
|
148
156
|
sendJson(response, 200, {
|
|
149
157
|
...status,
|
|
150
158
|
delays,
|
|
151
159
|
config: runtime.publicConfig(),
|
|
152
160
|
})
|
|
161
|
+
if (Object.keys(delays).length === 0 && status.running === true) {
|
|
162
|
+
void runtime.nodeDelays().catch((error) => {
|
|
163
|
+
log(`background measurement failed: ${String(error?.message ?? error)}`)
|
|
164
|
+
})
|
|
165
|
+
}
|
|
153
166
|
})
|
|
154
167
|
|
|
155
168
|
// The settings section reads and writes configuration here rather than through the
|
|
@@ -200,6 +213,42 @@ export function mountRoutes(webServer, runtime, log) {
|
|
|
200
213
|
sendJson(response, 200, { ok: true, ...report, binary: runtime.binary })
|
|
201
214
|
return
|
|
202
215
|
}
|
|
216
|
+
if (action === 'blockSelection') {
|
|
217
|
+
// The picker sends exact node names, so each becomes an anchored literal entry. Raw regex
|
|
218
|
+
// text stays in the blocklist field for whole-region removal; keeping them apart means a
|
|
219
|
+
// checkbox can never accidentally behave as a pattern.
|
|
220
|
+
const names = Array.isArray(body.names)
|
|
221
|
+
? body.names.filter((name) => typeof name === 'string' && name.trim() !== '').map((name) => name.trim())
|
|
222
|
+
: []
|
|
223
|
+
const keepRegex = String(body.keepRegex ?? '').trim()
|
|
224
|
+
const list = [keepRegex, names.join('\n')].filter((part) => part !== '').join('\n')
|
|
225
|
+
const problems = validateBlocklist(list)
|
|
226
|
+
if (problems.length > 0) {
|
|
227
|
+
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
const saved = await runtime.saveConfig({ blocklist: list })
|
|
231
|
+
sendJson(response, 200, {
|
|
232
|
+
ok: true,
|
|
233
|
+
blocked: names.length,
|
|
234
|
+
filter: buildExcludeFilter(list),
|
|
235
|
+
warnings: saved.warnings,
|
|
236
|
+
})
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
if (action === 'blocklist') {
|
|
240
|
+
const raw = String(body.list ?? '')
|
|
241
|
+
const problems = validateBlocklist(raw)
|
|
242
|
+
// An invalid regex makes the core reject the whole provider, which empties the node table —
|
|
243
|
+
// a far worse symptom than a rejected save. Catch it here instead.
|
|
244
|
+
if (problems.length > 0) {
|
|
245
|
+
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
const saved = await runtime.saveConfig({ blocklist: raw })
|
|
249
|
+
sendJson(response, 200, { ok: true, filter: buildExcludeFilter(raw), warnings: saved.warnings })
|
|
250
|
+
return
|
|
251
|
+
}
|
|
203
252
|
if (action === 'start') {
|
|
204
253
|
const report = await runtime.start()
|
|
205
254
|
sendJson(response, 200, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin, so blocked sites work while domestic traffic stays direct — no other software involved.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"locale/*.json",
|
|
35
35
|
"icon.svg",
|
|
36
36
|
"README.md",
|
|
37
|
+
"CHANGELOG-0.6.3.md",
|
|
37
38
|
"LICENSE"
|
|
38
39
|
],
|
|
39
40
|
"engines": {
|
|
@@ -66,8 +67,7 @@
|
|
|
66
67
|
},
|
|
67
68
|
"homepage": "https://github.com/lc297948801/dsh-clash-subscription#readme",
|
|
68
69
|
"scripts": {
|
|
69
|
-
"test": "node test/
|
|
70
|
-
"test:
|
|
71
|
-
"test:e2e": "node test/e2e.mjs"
|
|
70
|
+
"test": "node test/regression-063.mjs",
|
|
71
|
+
"test:e2e": "node test/e2e-063.mjs"
|
|
72
72
|
}
|
|
73
73
|
}
|