dsh-clash-subscription 0.4.2 → 0.5.1
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/client.js +83 -0
- package/index.js +287 -10
- package/lib/blocklist.js +137 -0
- package/lib/core.js +178 -39
- package/lib/routes.js +4 -0
- package/lib/select.js +178 -0
- package/package.json +2 -2
package/client.js
CHANGED
|
@@ -62,6 +62,24 @@ const en = {
|
|
|
62
62
|
runtime: 'Runtime',
|
|
63
63
|
corePath: 'Core binary',
|
|
64
64
|
corePathHint: 'Path to a mihomo/mihomo-compatible executable. Leave empty to use the copy bundled with this plugin.',
|
|
65
|
+
capability: 'Node capability',
|
|
66
|
+
capabilityHint: 'A node is chosen only when it can reach every required service. Latency alone is not enough: a fast node that OpenAI blocks silently breaks one thing after another.',
|
|
67
|
+
requiredProbes: 'Required services',
|
|
68
|
+
requiredProbesHint: 'Comma-separated probe ids a node must reach, e.g. openai, google. Empty means every probe. Built-ins: gstatic, google, openai, anthropic.',
|
|
69
|
+
probes: 'Extra probes',
|
|
70
|
+
probesHint: 'One id=url per line, for services the built-in list does not cover. Example: hf=https://huggingface.co',
|
|
71
|
+
blocked: 'Blocked nodes',
|
|
72
|
+
blockedLabel: 'Hide these nodes',
|
|
73
|
+
blockedHint: 'One per line. A plain name is matched exactly; /regex/flags removes a whole group. Hidden nodes are removed by the core itself, so nothing can select or route to them.',
|
|
74
|
+
blockedPlaceholder: '香港高倍02 3x流量\n/^🇺🇸/',
|
|
75
|
+
blockedTag: 'blocked',
|
|
76
|
+
blockedCount: '{count} nodes hidden',
|
|
77
|
+
blockedInvalid: 'Invalid regex, not applied:',
|
|
78
|
+
reselect: 'Re-pick node by capability',
|
|
79
|
+
reselecting: 'Testing nodes…',
|
|
80
|
+
chosenNode: 'Chosen: {node}',
|
|
81
|
+
noUsableNode: 'No node reached every required service.',
|
|
82
|
+
usableCount: '{usable} / {total} nodes usable',
|
|
65
83
|
autoFetchCore: 'Fetch a core automatically',
|
|
66
84
|
autoFetchCoreHint: 'When no mihomo binary is present, download a verified private copy on startup instead of waiting for you to press Download.',
|
|
67
85
|
dns: 'DNS servers',
|
|
@@ -149,6 +167,24 @@ const zh = {
|
|
|
149
167
|
runtime: '运行时',
|
|
150
168
|
corePath: '内核程序',
|
|
151
169
|
corePathHint: 'mihomo 兼容内核的可执行文件路径。留空则使用插件自带的那个。',
|
|
170
|
+
capability: '节点能力',
|
|
171
|
+
capabilityHint: '只有能访问所有必需服务的节点才会被选中。只看延迟不够:延迟很低但被 OpenAI 屏蔽的节点,会让人以为是插件坏了。',
|
|
172
|
+
requiredProbes: '必需服务',
|
|
173
|
+
requiredProbesHint: '逗号分隔的探测项,节点必须全部可达,例如 openai, google。留空表示全部。内置:gstatic、google、openai、anthropic。',
|
|
174
|
+
probes: '额外探测',
|
|
175
|
+
probesHint: '一行一个 id=url,用于补充内置清单之外的服务。例:hf=https://huggingface.co',
|
|
176
|
+
blocked: '屏蔽节点',
|
|
177
|
+
blockedLabel: '屏蔽以下节点',
|
|
178
|
+
blockedHint: '一行一条。写普通名字则精确匹配;写 /正则/标志 可整组屏蔽。屏蔽由内核直接排除,选中、测速、自动挑选都不可能再用到它。',
|
|
179
|
+
blockedPlaceholder: '香港高倍02 3x流量\n/^🇺🇸/',
|
|
180
|
+
blockedTag: '已屏蔽',
|
|
181
|
+
blockedCount: '已屏蔽 {count} 个节点',
|
|
182
|
+
blockedInvalid: '正则无效,未生效:',
|
|
183
|
+
reselect: '按能力重挑节点',
|
|
184
|
+
reselecting: '正在测节点…',
|
|
185
|
+
chosenNode: '已选:{node}',
|
|
186
|
+
noUsableNode: '没有任何节点能访问全部必需服务。',
|
|
187
|
+
usableCount: '{usable} / {total} 个节点可用',
|
|
152
188
|
autoFetchCore: '自动获取内核',
|
|
153
189
|
autoFetchCoreHint: '机器上没有 mihomo 时,启动时自动下载一份经过校验的私有内核,不用手动点下载。',
|
|
154
190
|
dns: 'DNS 服务器',
|
|
@@ -295,6 +331,22 @@ function sections(t) {
|
|
|
295
331
|
{ key: 'speedTestCount', kind: 'number', label: t('count'), hint: t('countHint'), min: 1, max: 40, step: 1 },
|
|
296
332
|
],
|
|
297
333
|
},
|
|
334
|
+
{
|
|
335
|
+
id: 'capability',
|
|
336
|
+
title: t('capability'),
|
|
337
|
+
fields: [
|
|
338
|
+
{ key: 'requiredProbes', kind: 'text', label: t('requiredProbes'), hint: t('requiredProbesHint'), placeholder: 'openai, google' },
|
|
339
|
+
{ key: 'probes', kind: 'text', label: t('probes'), hint: t('probesHint'), placeholder: 'hf=https://huggingface.co' },
|
|
340
|
+
],
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: 'blocklist',
|
|
344
|
+
title: t('blocked'),
|
|
345
|
+
collapsed: true,
|
|
346
|
+
fields: [
|
|
347
|
+
{ key: 'blocklist', kind: 'textarea', label: t('blockedLabel'), hint: t('blockedHint'), placeholder: t('blockedPlaceholder') },
|
|
348
|
+
],
|
|
349
|
+
},
|
|
298
350
|
{
|
|
299
351
|
id: 'lists',
|
|
300
352
|
title: t('lists'),
|
|
@@ -513,6 +565,36 @@ function Panel(props) {
|
|
|
513
565
|
h('h4', { key: 'ti' }, t('routing')),
|
|
514
566
|
h('p', { key: 'hi', className: 'clxp-hint' }, t('routingHint')),
|
|
515
567
|
h('p', { key: 'cu', className: 'clxp-note' }, fill(t('currentNode'), { node: live?.node ?? t('autoSelect') })),
|
|
568
|
+
live?.blocklist !== undefined && live.blocklist.hidden !== undefined && live.blocklist.hidden.length > 0
|
|
569
|
+
? h('p', { key: 'bh', className: 'clxp-note' }, fill(t('blockedCount'), { count: live.blocklist.hidden.length }) + (live.blocklist.filter === '' ? '' : ' · ' + live.blocklist.filter))
|
|
570
|
+
: null,
|
|
571
|
+
live?.blocklist !== undefined && Array.isArray(live.blocklist.problems) && live.blocklist.problems.length > 0
|
|
572
|
+
? h('p', { key: 'bp', className: 'clxp-error', role: 'status' }, t('blockedInvalid') + ' ' + live.blocklist.problems.map((p) => p.source).join(', '))
|
|
573
|
+
: null,
|
|
574
|
+
live?.blocklist !== undefined && Array.isArray(live.blocklist.hidden)
|
|
575
|
+
? h('div', { key: 'bl', className: 'clxp-subs' },
|
|
576
|
+
live.blocklist.hidden.slice(0, 20).map((name) => h('div', { key: name, className: 'clxp-sub' }, [
|
|
577
|
+
h('span', { key: 'n', className: 'clxp-node-name' }, name),
|
|
578
|
+
h('span', { key: 's', className: 'clxp-delay bad' }, t('blockedTag')),
|
|
579
|
+
])))
|
|
580
|
+
: null,
|
|
581
|
+
live?.capability !== undefined && Array.isArray(live.capability.nodes) && live.capability.nodes.length > 0
|
|
582
|
+
? h('p', { key: 'cp', className: 'clxp-note' }, fill(t('usableCount'), {
|
|
583
|
+
usable: live.capability.nodes.filter((row) => row.usable).length,
|
|
584
|
+
total: live.capability.nodes.length,
|
|
585
|
+
}) + ' · ' + t('requiredProbes') + ': ' + (live.capability.required ?? []).join(', '))
|
|
586
|
+
: null,
|
|
587
|
+
live?.capability !== undefined && Array.isArray(live.capability.nodes)
|
|
588
|
+
? h('div', { key: 'cpl', className: 'clxp-subs' },
|
|
589
|
+
live.capability.nodes
|
|
590
|
+
.filter((row) => !row.usable)
|
|
591
|
+
.slice(0, 6)
|
|
592
|
+
.map((row) => h('div', { key: row.name, className: 'clxp-sub' }, [
|
|
593
|
+
h('span', { key: 'n', className: 'clxp-node-name' }, row.name),
|
|
594
|
+
h('span', { key: 'f', className: 'clxp-delay bad' }, (row.failed ?? []).join(', ') || '-'),
|
|
595
|
+
])))
|
|
596
|
+
: null,
|
|
597
|
+
|
|
516
598
|
nodes.length === 0
|
|
517
599
|
? h('p', { key: 'em', className: 'clxp-note' }, t('noNodes'))
|
|
518
600
|
: h('div', { key: 'ls', className: 'clxp-nodes', role: 'listbox', 'aria-label': t('routing') },
|
|
@@ -544,6 +626,7 @@ function Panel(props) {
|
|
|
544
626
|
h('div', { key: 'ac', className: 'clxp-actions' }, [
|
|
545
627
|
h('button', { key: 'te', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test') }, busy === 'test' ? t('testing') : t('testNow')),
|
|
546
628
|
h('button', { key: 'ta', type: 'button', disabled: busy !== '' || !running, onClick: () => void props.onAction('test', { all: true }) }, busy === 'test' ? t('testing') : t('testAll')),
|
|
629
|
+
h('button', { key: 'rs', type: 'button', className: 'clxp-primary', disabled: busy !== '' || !running, onClick: () => void props.onAction('reselect') }, busy === 'reselect' ? t('reselecting') : t('reselect')),
|
|
547
630
|
]),
|
|
548
631
|
]),
|
|
549
632
|
|
package/index.js
CHANGED
|
@@ -20,6 +20,8 @@ import { Core, findCoreBinary, splitList } from './lib/core.js'
|
|
|
20
20
|
import { installCore, installCoreFromFile, platformKey } from './lib/corefetch.js'
|
|
21
21
|
import { installVendoredCore, vendoredFor } from './lib/vendored.js'
|
|
22
22
|
import { fetchGeoDatabases, hasGeoDatabase } from './lib/geo.js'
|
|
23
|
+
import { DEFAULT_PROBES, judgeNode, rankNodes, resolveProbes } from './lib/select.js'
|
|
24
|
+
import { buildExcludeFilter, partitionNodes, validateBlocklist } from './lib/blocklist.js'
|
|
23
25
|
import { installName, loadHttpProxyModule, locateInstallRoot, resolveFromInstall } from './lib/install.js'
|
|
24
26
|
import { Routing } from './lib/routing.js'
|
|
25
27
|
import {
|
|
@@ -72,6 +74,32 @@ export const CONFIG_DEFAULTS = {
|
|
|
72
74
|
coreVersion: '',
|
|
73
75
|
/** Fetch GeoIP databases after routing works; they are an upgrade, not a requirement. */
|
|
74
76
|
autoFetchGeo: true,
|
|
77
|
+
/**
|
|
78
|
+
* Nodes to hide, one per line. A literal name matches exactly; /regex/flags removes a group.
|
|
79
|
+
* The core removes them from its proxy table entirely, so nothing can select or route to them.
|
|
80
|
+
*/
|
|
81
|
+
blocklist: '',
|
|
82
|
+
/** Extra capability probes as `id=url` lines; built-ins cover gstatic/google/openai/anthropic. */
|
|
83
|
+
probes: '',
|
|
84
|
+
/**
|
|
85
|
+
* Probe ids a node must pass to be chosen. Empty means every probe in the set.
|
|
86
|
+
* This is what turns "fastest node" into "node that actually works for my services".
|
|
87
|
+
*/
|
|
88
|
+
requiredProbes: '',
|
|
89
|
+
/** How long the startup node search may spend, in milliseconds. */
|
|
90
|
+
selectBudgetMs: 90000,
|
|
91
|
+
/** Re-check the live node on a schedule and switch only when it stops working. */
|
|
92
|
+
autoReselect: true,
|
|
93
|
+
/** How often that check runs, in minutes; 0 disables it. */
|
|
94
|
+
reselectMinutes: 15,
|
|
95
|
+
/** Active connections above which a re-selection waits, so nothing is interrupted. */
|
|
96
|
+
reselectIdleConnections: 2,
|
|
97
|
+
/** How long the line must stay quiet before switching, in milliseconds. */
|
|
98
|
+
reselectIdleGraceMs: 20000,
|
|
99
|
+
/** Attempts per probe when judging a node; every attempt must answer. */
|
|
100
|
+
probeSamples: 2,
|
|
101
|
+
/** Per-probe budget in milliseconds. */
|
|
102
|
+
probeTimeoutMs: 8000,
|
|
75
103
|
}
|
|
76
104
|
|
|
77
105
|
/**
|
|
@@ -104,6 +132,16 @@ async function buildConfigSchema() {
|
|
|
104
132
|
autoFetchCore: z.boolean().default(false),
|
|
105
133
|
coreVersion: z.string().default(''),
|
|
106
134
|
autoFetchGeo: z.boolean().default(true),
|
|
135
|
+
blocklist: z.string().default(''),
|
|
136
|
+
probes: z.string().default(''),
|
|
137
|
+
requiredProbes: z.string().default(''),
|
|
138
|
+
selectBudgetMs: z.number().default(90000),
|
|
139
|
+
autoReselect: z.boolean().default(true),
|
|
140
|
+
reselectMinutes: z.number().default(15),
|
|
141
|
+
reselectIdleConnections: z.number().default(2),
|
|
142
|
+
reselectIdleGraceMs: z.number().default(20000),
|
|
143
|
+
probeSamples: z.number().default(2),
|
|
144
|
+
probeTimeoutMs: z.number().default(8000),
|
|
107
145
|
})
|
|
108
146
|
} catch {
|
|
109
147
|
return undefined
|
|
@@ -127,9 +165,12 @@ export function resolveConfig(raw) {
|
|
|
127
165
|
config.autoStart = config.autoStart !== false && config.autoStart !== 'false'
|
|
128
166
|
config.autoFetchCore = config.autoFetchCore === true || config.autoFetchCore === 'true'
|
|
129
167
|
config.autoFetchGeo = config.autoFetchGeo !== false && config.autoFetchGeo !== 'false'
|
|
130
|
-
|
|
168
|
+
config.autoReselect = config.autoReselect !== false && config.autoReselect !== 'false'
|
|
169
|
+
for (const field of ['subscriptionUrls', 'subscriptionUrl', 'node', 'corePath', 'coreVersion', 'dnsServers', 'directDomains', 'proxyDomains', 'dataDir', 'probes', 'requiredProbes']) {
|
|
131
170
|
config[field] = String(config[field] ?? '').trim()
|
|
132
171
|
}
|
|
172
|
+
// A blocklist is multi-line by nature; only its outer whitespace is noise.
|
|
173
|
+
config.blocklist = String(config.blocklist ?? '').replace(/\r\n/g, '\n').trim()
|
|
133
174
|
// A profile written by 0.2 carries only `subscriptionUrl`. Normalizing it into the
|
|
134
175
|
// list here means every downstream reader sees one shape, and the panel shows the
|
|
135
176
|
// user's existing subscription in the list editor on first open.
|
|
@@ -142,6 +183,12 @@ export function resolveConfig(raw) {
|
|
|
142
183
|
config.speedTestMinutes = clamp(config.speedTestMinutes, 0, 1440, 30)
|
|
143
184
|
config.speedTestCount = clamp(config.speedTestCount, 1, 40, 8)
|
|
144
185
|
config.healthCheckMinutes = clamp(config.healthCheckMinutes, 0, 60, 1)
|
|
186
|
+
config.selectBudgetMs = clamp(config.selectBudgetMs, 5_000, 600_000, 90_000)
|
|
187
|
+
config.reselectMinutes = clamp(config.reselectMinutes, 0, 1440, 15)
|
|
188
|
+
config.reselectIdleConnections = clamp(config.reselectIdleConnections, 0, 100, 2)
|
|
189
|
+
config.reselectIdleGraceMs = clamp(config.reselectIdleGraceMs, 0, 600_000, 20_000)
|
|
190
|
+
config.probeSamples = clamp(config.probeSamples, 1, 5, 2)
|
|
191
|
+
config.probeTimeoutMs = clamp(config.probeTimeoutMs, 1_000, 60_000, 8_000)
|
|
145
192
|
return config
|
|
146
193
|
}
|
|
147
194
|
|
|
@@ -180,6 +227,16 @@ export class Runtime {
|
|
|
180
227
|
this.bootstrap = undefined
|
|
181
228
|
/** True while a download is in flight, so two clicks cannot race one archive. */
|
|
182
229
|
this.bootstrapping = false
|
|
230
|
+
/** Last capability matrix, so the panel can explain a selection. */
|
|
231
|
+
this.lastMatrix = []
|
|
232
|
+
/** Every node name seen so far, so blocked ones can still be listed. */
|
|
233
|
+
this.lastKnownNodes = []
|
|
234
|
+
/** When the line last became idle, so a switch waits for a quiet moment. */
|
|
235
|
+
this.idleSince = undefined
|
|
236
|
+
/** When the current node was last verified. */
|
|
237
|
+
this.lastCheckAt = undefined
|
|
238
|
+
/** Timer for the periodic re-check. */
|
|
239
|
+
this.reselectTimer = undefined
|
|
183
240
|
/** Progress/result of the optional GeoIP upgrade. */
|
|
184
241
|
this.geo = undefined
|
|
185
242
|
/** True while that upgrade is running. */
|
|
@@ -303,7 +360,10 @@ export class Runtime {
|
|
|
303
360
|
healthCheckMinutes: this.config.healthCheckMinutes,
|
|
304
361
|
directDomains: this.config.directDomains,
|
|
305
362
|
proxyDomains: this.config.proxyDomains,
|
|
363
|
+
blocklist: this.config.blocklist,
|
|
306
364
|
dnsServers: this.config.dnsServers,
|
|
365
|
+
blocklist: this.config.blocklist,
|
|
366
|
+
blocklistFilter: buildExcludeFilter(this.config.blocklist),
|
|
307
367
|
corePath: this.config.corePath,
|
|
308
368
|
coreVersion: this.config.coreVersion,
|
|
309
369
|
source: 'configured',
|
|
@@ -430,6 +490,142 @@ export class Runtime {
|
|
|
430
490
|
}, minutes * 60_000)
|
|
431
491
|
}
|
|
432
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Should the node be re-chosen right now?
|
|
495
|
+
*
|
|
496
|
+
* Changing the selected node tears down every connection that node is carrying. Doing that
|
|
497
|
+
* mid-session breaks whatever is in flight — a streaming response, a download, a tool call —
|
|
498
|
+
* and the user sees a stalled request with no obvious cause. So the re-check is periodic and
|
|
499
|
+
* only acts when the core reports no active connections.
|
|
500
|
+
*
|
|
501
|
+
* The idle requirement is deliberately strict: any live connection postpones the pass to the
|
|
502
|
+
* next tick, which costs nothing because the next tick is a minute away.
|
|
503
|
+
*
|
|
504
|
+
* @param options - `force` skips the idle gate (used by an explicit request), `graceMs`
|
|
505
|
+
* requires the idle state to have lasted this long.
|
|
506
|
+
* @returns whether a re-selection may run now, and why not when it may not.
|
|
507
|
+
*/
|
|
508
|
+
async canReselectNow(options = {}) {
|
|
509
|
+
if (this.core === undefined || this.core.running !== true) return { ok: false, reason: 'core-not-running' }
|
|
510
|
+
if (this.starting === true) return { ok: false, reason: 'starting' }
|
|
511
|
+
if (options.force === true) return { ok: true, reason: 'forced' }
|
|
512
|
+
if (this.config.autoReselect === false) return { ok: false, reason: 'disabled' }
|
|
513
|
+
|
|
514
|
+
let traffic
|
|
515
|
+
try {
|
|
516
|
+
traffic = await this.core.connections()
|
|
517
|
+
} catch {
|
|
518
|
+
return { ok: false, reason: 'traffic-unreadable' }
|
|
519
|
+
}
|
|
520
|
+
// A few connections are the plugin's own control calls and the core's health checks; the
|
|
521
|
+
// threshold keeps those from blocking forever while still catching real work.
|
|
522
|
+
const limit = Number(this.config.reselectIdleConnections ?? 2)
|
|
523
|
+
if (traffic.count > limit) {
|
|
524
|
+
this.idleSince = undefined
|
|
525
|
+
return { ok: false, reason: 'busy', connections: traffic.count }
|
|
526
|
+
}
|
|
527
|
+
const now = Date.now()
|
|
528
|
+
if (this.idleSince === undefined) this.idleSince = now
|
|
529
|
+
const grace = Number(this.config.reselectIdleGraceMs ?? 20_000)
|
|
530
|
+
if (now - this.idleSince < grace) {
|
|
531
|
+
return { ok: false, reason: 'warming', idleMs: now - this.idleSince, graceMs: grace }
|
|
532
|
+
}
|
|
533
|
+
return { ok: true, reason: 'idle', idleMs: now - this.idleSince }
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Re-check the current node's capabilities and switch only when it is no longer usable.
|
|
538
|
+
*
|
|
539
|
+
* This is the automatic half of selection. The startup choice already proves a node can
|
|
540
|
+
* reach every required service, but a node degrades: a service starts blocking the range, a
|
|
541
|
+
* provider rotates the server behind a name. Re-running the full matrix on every tick would
|
|
542
|
+
* be wasteful and would keep tearing down connections, so the current node is verified first
|
|
543
|
+
* and the expensive search only runs when that verification fails.
|
|
544
|
+
*
|
|
545
|
+
* @param options - `force` bypasses the idle gate.
|
|
546
|
+
* @returns what happened and why.
|
|
547
|
+
*/
|
|
548
|
+
async autoReselect(options = {}) {
|
|
549
|
+
const gate = await this.canReselectNow(options)
|
|
550
|
+
if (!gate.ok) return { state: 'skipped', ...gate }
|
|
551
|
+
|
|
552
|
+
const plan = resolveProbes(this.config.probes, this.config.requiredProbes)
|
|
553
|
+
const group = await this.core.group()
|
|
554
|
+
const current = group.now
|
|
555
|
+
if (current === undefined || current === 'DIRECT') {
|
|
556
|
+
// Nothing real is selected; a full search is the only way forward and it disturbs nobody.
|
|
557
|
+
const result = await this.core.autoSelect(this.preferredNode, {
|
|
558
|
+
probes: plan.probes,
|
|
559
|
+
required: plan.required,
|
|
560
|
+
budgetMs: this.config.selectBudgetMs,
|
|
561
|
+
})
|
|
562
|
+
this.lastMatrix = result.matrix
|
|
563
|
+
if (result.chosen !== undefined) this.rememberNode(result.chosen)
|
|
564
|
+
return { state: result.chosen === undefined ? 'no-node' : 'selected', chosen: result.chosen, required: plan.required }
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Cheap check first: is the node already selected still good for every required service?
|
|
568
|
+
const results = await this.core.capabilities(current, plan.probes, {
|
|
569
|
+
timeoutMs: this.config.probeTimeoutMs ?? 8000,
|
|
570
|
+
samples: this.config.probeSamples ?? 2,
|
|
571
|
+
})
|
|
572
|
+
const verdict = judgeNode(results, plan.required)
|
|
573
|
+
this.lastMatrix = [{ name: current, results }]
|
|
574
|
+
this.lastCheckAt = Date.now()
|
|
575
|
+
if (verdict.usable) {
|
|
576
|
+
this.log('node ' + current + ' still reaches ' + plan.required.join('/'))
|
|
577
|
+
return { state: 'kept', node: current, required: plan.required, results }
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
this.log('node ' + current + ' lost ' + (verdict.failed.join(',') || verdict.missing.join(',')) + '; searching again')
|
|
581
|
+
const result = await this.core.autoSelect('', {
|
|
582
|
+
probes: plan.probes,
|
|
583
|
+
required: plan.required,
|
|
584
|
+
budgetMs: this.config.selectBudgetMs,
|
|
585
|
+
samples: this.config.probeSamples ?? 2,
|
|
586
|
+
})
|
|
587
|
+
this.lastMatrix = result.matrix
|
|
588
|
+
if (result.chosen === undefined) {
|
|
589
|
+
return { state: 'no-alternative', lostNode: current, failed: verdict.failed, required: plan.required }
|
|
590
|
+
}
|
|
591
|
+
if (result.chosen === current) {
|
|
592
|
+
// The search re-picked the same node, which contradicts the probe; report rather than loop.
|
|
593
|
+
return { state: 'unchanged', node: current, failed: verdict.failed }
|
|
594
|
+
}
|
|
595
|
+
this.rememberNode(result.chosen)
|
|
596
|
+
this.log('switched ' + current + ' -> ' + result.chosen)
|
|
597
|
+
return { state: 'switched', from: current, to: result.chosen, failed: verdict.failed, required: plan.required }
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Arm the periodic capability re-check.
|
|
602
|
+
*
|
|
603
|
+
* Same rule as the other cycles: the interval must be created in the plugin context, so this
|
|
604
|
+
* is only ever called from a callback the plugin registered itself. A tick that finds the
|
|
605
|
+
* line busy returns immediately, which is why the period can be short without ever
|
|
606
|
+
* interrupting work.
|
|
607
|
+
*
|
|
608
|
+
* @param schedule - timer factory from the plugin context.
|
|
609
|
+
*/
|
|
610
|
+
scheduleReselect(schedule) {
|
|
611
|
+
if (this.reselectTimer !== undefined) this.reselectTimer()
|
|
612
|
+
this.reselectTimer = undefined
|
|
613
|
+
const minutes = this.config.reselectMinutes
|
|
614
|
+
if (this.config.autoReselect === false || minutes <= 0 || typeof schedule !== 'function') return
|
|
615
|
+
this.reselectTimer = schedule(() => {
|
|
616
|
+
void this.autoReselect().catch((error) => {
|
|
617
|
+
this.log('capability re-check failed: ' + String(error?.message ?? error))
|
|
618
|
+
})
|
|
619
|
+
}, minutes * 60_000)
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Stop the re-check. Safe to call when none is running. */
|
|
623
|
+
stopReselect() {
|
|
624
|
+
if (this.reselectTimer === undefined) return
|
|
625
|
+
this.reselectTimer()
|
|
626
|
+
this.reselectTimer = undefined
|
|
627
|
+
}
|
|
628
|
+
|
|
433
629
|
/**
|
|
434
630
|
* One liveness pass: is the core still listening, and does the policy still route?
|
|
435
631
|
*
|
|
@@ -857,6 +1053,8 @@ export class Runtime {
|
|
|
857
1053
|
dnsServers: splitList(this.config.dnsServers),
|
|
858
1054
|
directDomains: this.config.directDomains,
|
|
859
1055
|
proxyDomains: this.config.proxyDomains,
|
|
1056
|
+
// Blocked nodes are removed by the core, so they never enter the proxy table.
|
|
1057
|
+
blocklist: this.config.blocklist,
|
|
860
1058
|
// No geo directories are passed: the core's own data directory is authoritative,
|
|
861
1059
|
// and discovery supplies a machine-level fallback only when that copy is absent.
|
|
862
1060
|
})
|
|
@@ -873,9 +1071,30 @@ export class Runtime {
|
|
|
873
1071
|
const preferred = String(options.node ?? this.preferredNode ?? '').trim()
|
|
874
1072
|
// A fresh group starts on DIRECT, which would route foreign traffic straight out.
|
|
875
1073
|
// Selecting a real node is part of bringing routing up, not an optional extra.
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1074
|
+
// Selection is capability-based: a node must reach every required service, not merely
|
|
1075
|
+
// answer a latency check. The matrix is kept so the panel can show why a node lost.
|
|
1076
|
+
const plan = resolveProbes(this.config.probes, this.config.requiredProbes)
|
|
1077
|
+
const selection = group.all.some((entry) => entry !== 'DIRECT')
|
|
1078
|
+
? await this.core
|
|
1079
|
+
.autoSelect(preferred, {
|
|
1080
|
+
probes: plan.probes,
|
|
1081
|
+
required: plan.required,
|
|
1082
|
+
budgetMs: this.config.selectBudgetMs,
|
|
1083
|
+
})
|
|
1084
|
+
.catch((error) => {
|
|
1085
|
+
this.log('capability selection failed: ' + String(error?.message ?? error))
|
|
1086
|
+
return { chosen: undefined, matrix: [] }
|
|
1087
|
+
})
|
|
1088
|
+
: { chosen: undefined, matrix: [] }
|
|
1089
|
+
const selected = selection.chosen
|
|
1090
|
+
this.lastMatrix = selection.matrix
|
|
1091
|
+
const ranked = rankNodes(selection.matrix, plan.required)
|
|
1092
|
+
if (selected === undefined && selection.matrix.length > 0) {
|
|
1093
|
+
this.log('no node could reach every required probe: ' + plan.required.join(', '))
|
|
1094
|
+
} else if (selected !== undefined) {
|
|
1095
|
+
this.log('selected ' + selected + ' (' + plan.required.join('/') + ' all reachable)')
|
|
1096
|
+
}
|
|
1097
|
+
void ranked
|
|
879
1098
|
this.lastError = undefined
|
|
880
1099
|
this.degraded = undefined
|
|
881
1100
|
// Routing is now up under this activation's ownership, which is what arms the
|
|
@@ -983,6 +1202,12 @@ export class Runtime {
|
|
|
983
1202
|
async status() {
|
|
984
1203
|
const running = this.core?.running === true
|
|
985
1204
|
const group = running ? await this.core.group().catch(() => ({ all: [], now: undefined })) : { all: [], now: undefined }
|
|
1205
|
+
// The core hides blocked nodes, so it never reports them. Keep every name this runtime has
|
|
1206
|
+
// seen, otherwise the panel has no way to show what the blocklist is currently removing.
|
|
1207
|
+
if (running) {
|
|
1208
|
+
const visible = group.all.filter((name) => name !== 'DIRECT')
|
|
1209
|
+
if (visible.length > 0) this.lastKnownNodes = [...new Set([...(this.lastKnownNodes ?? []), ...visible])]
|
|
1210
|
+
}
|
|
986
1211
|
const provider = running
|
|
987
1212
|
? await this.core.providerStatus()
|
|
988
1213
|
: { updatedAt: null, vehicleType: null, providers: [], ok: false, healthy: 0, total: 0 }
|
|
@@ -1032,6 +1257,29 @@ export class Runtime {
|
|
|
1032
1257
|
bootstrap: this.bootstrap,
|
|
1033
1258
|
/** Optional GeoIP upgrade state; domestic routing works without it. */
|
|
1034
1259
|
geoUpgrade: this.geo,
|
|
1260
|
+
/** Automatic re-selection: whether it is armed, when it runs, and when it last acted. */
|
|
1261
|
+
reselect: {
|
|
1262
|
+
enabled: this.config.autoReselect !== false && this.config.reselectMinutes > 0,
|
|
1263
|
+
everyMinutes: this.config.reselectMinutes,
|
|
1264
|
+
idleConnections: this.config.reselectIdleConnections,
|
|
1265
|
+
idleGraceMs: this.config.reselectIdleGraceMs,
|
|
1266
|
+
lastCheckAt: this.lastCheckAt === undefined ? null : new Date(this.lastCheckAt).toISOString(),
|
|
1267
|
+
idleSince: this.idleSince === undefined ? null : new Date(this.idleSince).toISOString(),
|
|
1268
|
+
},
|
|
1269
|
+
/** Per-node probe results from the last selection, and which services gate it. */
|
|
1270
|
+
capability: {
|
|
1271
|
+
required: resolveProbes(this.config.probes, this.config.requiredProbes).required,
|
|
1272
|
+
probes: resolveProbes(this.config.probes, this.config.requiredProbes).probes.map((probe) => ({ id: probe.id, label: probe.label })),
|
|
1273
|
+
nodes: this.lastMatrix.map((row) => {
|
|
1274
|
+
const verdict = rankNodes([row], resolveProbes(this.config.probes, this.config.requiredProbes).required).usable[0]
|
|
1275
|
+
return {
|
|
1276
|
+
name: row.name,
|
|
1277
|
+
results: row.results,
|
|
1278
|
+
usable: verdict !== undefined,
|
|
1279
|
+
failed: Object.entries(row.results).filter(([, value]) => value === null).map(([id]) => id),
|
|
1280
|
+
}
|
|
1281
|
+
}),
|
|
1282
|
+
},
|
|
1035
1283
|
/** Whether the core uses an embedded CIDR rule set for the domestic bypass. */
|
|
1036
1284
|
cnRuleSet: this.core?.cnRuleSet === undefined
|
|
1037
1285
|
? undefined
|
|
@@ -1062,6 +1310,7 @@ export async function apply(ctx, rawConfig) {
|
|
|
1062
1310
|
ctx.effect(() => () => {
|
|
1063
1311
|
runtime.stopTimer()
|
|
1064
1312
|
runtime.stopWatchdog()
|
|
1313
|
+
runtime.stopReselect()
|
|
1065
1314
|
void runtime.stop()
|
|
1066
1315
|
})
|
|
1067
1316
|
|
|
@@ -1094,13 +1343,16 @@ export async function apply(ctx, rawConfig) {
|
|
|
1094
1343
|
runtime.rearm = () => {
|
|
1095
1344
|
runtime.scheduleSpeedTest(schedule)
|
|
1096
1345
|
runtime.scheduleWatchdog(schedule)
|
|
1346
|
+
runtime.scheduleReselect(schedule)
|
|
1097
1347
|
}
|
|
1098
1348
|
runtime.scheduleSpeedTest(schedule)
|
|
1099
1349
|
runtime.scheduleWatchdog(schedule)
|
|
1350
|
+
runtime.scheduleReselect(schedule)
|
|
1100
1351
|
return () => {
|
|
1101
1352
|
runtime.rearm = undefined
|
|
1102
1353
|
runtime.stopTimer()
|
|
1103
1354
|
runtime.stopWatchdog()
|
|
1355
|
+
runtime.stopReselect()
|
|
1104
1356
|
}
|
|
1105
1357
|
}, 'clash-proxy: speed test cycle and watchdog')
|
|
1106
1358
|
})
|
|
@@ -1171,7 +1423,7 @@ function subscriptionTool(runtime) {
|
|
|
1171
1423
|
properties: {
|
|
1172
1424
|
action: {
|
|
1173
1425
|
type: 'string',
|
|
1174
|
-
enum: ['status', 'import', 'start', 'stop', 'select', 'test', 'refresh', 'bootstrap'],
|
|
1426
|
+
enum: ['status', 'import', 'start', 'stop', 'select', 'test', 'refresh', 'bootstrap', 'reselect'],
|
|
1175
1427
|
description: 'status reports state; import sets or appends subscriptions; start/stop control routing; select switches the exit node; test measures latency; refresh re-downloads every subscription; bootstrap downloads and installs a private mihomo core when the machine has none.',
|
|
1176
1428
|
},
|
|
1177
1429
|
url: { type: 'string', description: 'One or more subscription URLs for action=import, one per line. A leading "name " is kept as the display name.' },
|
|
@@ -1240,11 +1492,36 @@ function subscriptionTool(runtime) {
|
|
|
1240
1492
|
const report = await runtime.start()
|
|
1241
1493
|
return { ...report, summary: `已启动:${report.endpoint},节点「${report.group.now ?? '未选择'}」,共 ${Math.max(0, report.group.all.length - 1)} 个可选节点。` }
|
|
1242
1494
|
}
|
|
1243
|
-
if (action === '
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1495
|
+
if (action === 'blocklist') {
|
|
1496
|
+
const raw = String(body.list ?? '')
|
|
1497
|
+
const problems = validateBlocklist(raw)
|
|
1498
|
+
// An invalid regex makes the core reject the whole provider, which empties the node table
|
|
1499
|
+
// — a far worse symptom than a rejected save. Catch it here instead.
|
|
1500
|
+
if (problems.length > 0) {
|
|
1501
|
+
sendJson(response, 400, { ok: false, error: 'invalid regex', problems })
|
|
1502
|
+
return
|
|
1503
|
+
}
|
|
1504
|
+
const saved = await runtime.saveConfig({ blocklist: raw })
|
|
1505
|
+
sendJson(response, 200, {
|
|
1506
|
+
ok: true,
|
|
1507
|
+
filter: buildExcludeFilter(raw),
|
|
1508
|
+
config: saved.config,
|
|
1509
|
+
warnings: saved.warnings,
|
|
1510
|
+
})
|
|
1511
|
+
return
|
|
1512
|
+
}
|
|
1513
|
+
if (action === 'reselect') {
|
|
1514
|
+
const result = await runtime.autoReselect({ force: true })
|
|
1515
|
+
return {
|
|
1516
|
+
...result,
|
|
1517
|
+
summary: result.state === 'kept'
|
|
1518
|
+
? '当前节点「' + result.node + '」仍能访问全部必需服务(' + (result.required ?? []).join('/') + '),未切换。'
|
|
1519
|
+
: result.state === 'switched'
|
|
1520
|
+
? '已从「' + result.from + '」切到「' + result.to + '」(原节点失去 ' + (result.failed ?? []).join(',') + ')。'
|
|
1521
|
+
: result.state === 'selected'
|
|
1522
|
+
? '已选「' + result.chosen + '」。'
|
|
1523
|
+
: '没有可用节点:' + (result.required ?? []).join(', ') + ' 无法全部访问。',
|
|
1524
|
+
}
|
|
1248
1525
|
}
|
|
1249
1526
|
if (action === 'test') {
|
|
1250
1527
|
const target = String(args?.node ?? '').trim()
|
package/lib/blocklist.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hiding nodes a person does not want to use.
|
|
3
|
+
*
|
|
4
|
+
* Exclusion happens in the core, not in the panel. mihomo's `proxy-provider` accepts an
|
|
5
|
+
* `exclude-filter` regex, so a hidden node never enters the proxy table at all — it cannot be
|
|
6
|
+
* auto-selected, cannot be picked by name, and cannot carry traffic even if something asks for
|
|
7
|
+
* it. Filtering only in the UI would leave a blocked node reachable through the tool, the
|
|
8
|
+
* startup search and the watchdog, which is three ways for a "hidden" node to still be used.
|
|
9
|
+
*
|
|
10
|
+
* Measured on the bundled core: `exclude-filter: '^block-.*$'` dropped both matching nodes from
|
|
11
|
+
* the group while leaving every other node, including Chinese-named ones, untouched.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-clash-proxy/blocklist
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Characters that must survive a trip through a regex unchanged. */
|
|
17
|
+
const REGEX_SPECIAL = /[.*+?^${}()|[\]\\]/g
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Escape one literal so it matches only itself.
|
|
21
|
+
*
|
|
22
|
+
* @param text - literal node name.
|
|
23
|
+
* @returns the escaped form.
|
|
24
|
+
*/
|
|
25
|
+
export function escapeLiteral(text) {
|
|
26
|
+
return String(text ?? '').replace(REGEX_SPECIAL, '\\$&')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parse the blocklist field into entries.
|
|
31
|
+
*
|
|
32
|
+
* One entry per line. A line that starts and ends with `/` is treated as a regular expression,
|
|
33
|
+
* which is what makes a whole region removable in one entry ("`/香港|HK/i`"); anything else is a
|
|
34
|
+
* literal node name. Blank lines and `#` comments are dropped.
|
|
35
|
+
*
|
|
36
|
+
* @param text - the configured field.
|
|
37
|
+
* @returns entries as `{ kind: 'literal'|'regex', value, source }`.
|
|
38
|
+
*/
|
|
39
|
+
export function parseBlocklist(text) {
|
|
40
|
+
const entries = []
|
|
41
|
+
for (const raw of String(text ?? '').split(/\r?\n/)) {
|
|
42
|
+
const line = raw.trim()
|
|
43
|
+
if (line === '' || line.startsWith('#')) continue
|
|
44
|
+
const asRegex = /^\/(.+)\/([a-z]*)$/.exec(line)
|
|
45
|
+
if (asRegex !== null) {
|
|
46
|
+
entries.push({ kind: 'regex', value: asRegex[1], flags: asRegex[2] ?? '', source: line })
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
entries.push({ kind: 'literal', value: line, source: line })
|
|
50
|
+
}
|
|
51
|
+
return entries
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Turn the blocklist into one `exclude-filter` pattern.
|
|
56
|
+
*
|
|
57
|
+
* The core takes a single regex, so literals and user regexes are combined with alternation.
|
|
58
|
+
* Every literal is escaped and anchored, which keeps `香港01` from also hiding `香港010` — a
|
|
59
|
+
* substring match would hide nodes the user did not name, and the mistake is invisible until a
|
|
60
|
+
* node goes missing.
|
|
61
|
+
*
|
|
62
|
+
* @param text - the configured blocklist field.
|
|
63
|
+
* @returns the pattern, or an empty string when nothing is blocked.
|
|
64
|
+
*/
|
|
65
|
+
export function buildExcludeFilter(text) {
|
|
66
|
+
const entries = parseBlocklist(text)
|
|
67
|
+
if (entries.length === 0) return ''
|
|
68
|
+
const parts = entries.map((entry) =>
|
|
69
|
+
entry.kind === 'literal' ? `^(?:${escapeLiteral(entry.value)})$` : `(?:${entry.value})`,
|
|
70
|
+
)
|
|
71
|
+
// `(?i)` is not portable across every regex flavour mihomo accepts on all platforms, so case
|
|
72
|
+
// insensitivity is left to the user's own flags on a regex entry.
|
|
73
|
+
return parts.join('|')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether a node name would be hidden by the pattern.
|
|
78
|
+
*
|
|
79
|
+
* Used to explain a selection ("this node is blocked") and to keep the panel honest, since the
|
|
80
|
+
* core no longer reports blocked nodes at all.
|
|
81
|
+
*
|
|
82
|
+
* @param name - node name.
|
|
83
|
+
* @param text - the configured blocklist field.
|
|
84
|
+
* @returns true when the name matches an entry.
|
|
85
|
+
*/
|
|
86
|
+
export function isBlocked(name, text) {
|
|
87
|
+
for (const entry of parseBlocklist(text)) {
|
|
88
|
+
try {
|
|
89
|
+
const pattern = entry.kind === 'literal' ? `^(?:${escapeLiteral(entry.value)})$` : entry.value
|
|
90
|
+
if (new RegExp(pattern, entry.kind === 'regex' ? entry.flags : '').test(String(name))) return true
|
|
91
|
+
} catch {
|
|
92
|
+
// An unusable user regex blocks nothing; the core would reject the whole provider rather
|
|
93
|
+
// than silently ignore it, so this path only protects the preview.
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Check that every regex entry compiles, so a typo is caught before it reaches the core.
|
|
101
|
+
*
|
|
102
|
+
* The core treats an invalid `exclude-filter` as a provider load failure, which would empty the
|
|
103
|
+
* node table — a much worse symptom than a rejected save.
|
|
104
|
+
*
|
|
105
|
+
* @param text - the configured blocklist field.
|
|
106
|
+
* @returns the invalid entries, with the reason.
|
|
107
|
+
*/
|
|
108
|
+
export function validateBlocklist(text) {
|
|
109
|
+
const problems = []
|
|
110
|
+
for (const entry of parseBlocklist(text)) {
|
|
111
|
+
if (entry.kind !== 'regex') continue
|
|
112
|
+
try {
|
|
113
|
+
new RegExp(entry.value, entry.flags)
|
|
114
|
+
} catch (error) {
|
|
115
|
+
problems.push({ source: entry.source, reason: String(error?.message ?? error) })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return problems
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Split a node list into visible and blocked names, for the panel and for diagnostics.
|
|
123
|
+
*
|
|
124
|
+
* @param names - every node name the subscription carries.
|
|
125
|
+
* @param text - the configured blocklist field.
|
|
126
|
+
* @returns the two lists and the pattern that produced them.
|
|
127
|
+
*/
|
|
128
|
+
export function partitionNodes(names, text) {
|
|
129
|
+
const list = Array.isArray(names) ? names : []
|
|
130
|
+
const visible = []
|
|
131
|
+
const blocked = []
|
|
132
|
+
for (const name of list) {
|
|
133
|
+
if (isBlocked(name, text)) blocked.push(name)
|
|
134
|
+
else visible.push(name)
|
|
135
|
+
}
|
|
136
|
+
return { visible, blocked, filter: buildExcludeFilter(text) }
|
|
137
|
+
}
|
package/lib/core.js
CHANGED
|
@@ -16,6 +16,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
|
16
16
|
import { createServer } from 'node:net'
|
|
17
17
|
import { join } from 'node:path'
|
|
18
18
|
import { CN_CIDR } from './cn-cidr.js'
|
|
19
|
+
import { buildExcludeFilter } from './blocklist.js'
|
|
19
20
|
import { findCoreBinary } from './discovery.js'
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -188,6 +189,7 @@ export function buildConfig(options) {
|
|
|
188
189
|
proxyDomains,
|
|
189
190
|
cnRuleSet,
|
|
190
191
|
cnRuleSetPath,
|
|
192
|
+
blocklist,
|
|
191
193
|
singleUrl,
|
|
192
194
|
subscriptionUrl,
|
|
193
195
|
providerPath,
|
|
@@ -227,11 +229,14 @@ export function buildConfig(options) {
|
|
|
227
229
|
const name = String(entry?.provider ?? `sub${at}`)
|
|
228
230
|
names.push(name)
|
|
229
231
|
const path = Array.isArray(providerPaths) ? providerPaths[at] : providerPath
|
|
232
|
+
// A blocked node is removed by the core itself, so it cannot be selected, tested or routed
|
|
233
|
+
// to by anything downstream. Filtering in the panel only would leave three ways to reach it.
|
|
230
234
|
providers[name] = {
|
|
231
235
|
type: 'http',
|
|
232
236
|
url: String(entry?.url ?? ''),
|
|
233
237
|
interval: 3600,
|
|
234
238
|
path: path ?? `providers/${name}.yaml`,
|
|
239
|
+
...(String(blocklist ?? '').trim() === '' ? {} : { 'exclude-filter': buildExcludeFilter(blocklist) }),
|
|
235
240
|
'health-check': {
|
|
236
241
|
enable: true,
|
|
237
242
|
url: 'http://www.gstatic.com/generate_204',
|
|
@@ -368,6 +373,7 @@ export class Core {
|
|
|
368
373
|
// bypass no longer depends on whether a GeoIP database happens to be present.
|
|
369
374
|
cnRuleSet: 'cn-cidr',
|
|
370
375
|
cnRuleSetPath: this.cnRuleSetPath,
|
|
376
|
+
blocklist: options.blocklist,
|
|
371
377
|
})
|
|
372
378
|
writeFileSync(this.configPath, `${JSON.stringify(config, null, 2)}\n`, 'utf8')
|
|
373
379
|
|
|
@@ -553,59 +559,192 @@ export class Core {
|
|
|
553
559
|
return null
|
|
554
560
|
}
|
|
555
561
|
|
|
562
|
+
/**
|
|
563
|
+
* Ask one node to reach one URL, using the core's own health-check.
|
|
564
|
+
*
|
|
565
|
+
* The core reports a delay when the target answers at all — measured, a 401 from
|
|
566
|
+
* api.openai.com counts as success while a blocked node returns 503. That is what makes
|
|
567
|
+
* this usable as a capability probe: it answers "can this node carry traffic to this
|
|
568
|
+
* service", which is the question latency alone cannot answer.
|
|
569
|
+
*
|
|
570
|
+
* @param name - node name.
|
|
571
|
+
* @param url - the URL to reach through that node.
|
|
572
|
+
* @param timeoutMs - per-probe budget.
|
|
573
|
+
* @returns the delay in ms, or null when the node could not reach it.
|
|
574
|
+
*/
|
|
575
|
+
async reach(name, url, timeoutMs = 8000) {
|
|
576
|
+
const query = new URLSearchParams({ timeout: String(timeoutMs), url })
|
|
577
|
+
const encoded = encodeURIComponent(name)
|
|
578
|
+
const owner = await this.providerOf(name)
|
|
579
|
+
const paths = [
|
|
580
|
+
...(owner === undefined ? [] : ['/providers/proxies/' + encodeURIComponent(owner) + '/' + encoded + '/healthcheck']),
|
|
581
|
+
...this.providerNames.map((provider) => '/providers/proxies/' + encodeURIComponent(provider) + '/' + encoded + '/healthcheck'),
|
|
582
|
+
'/proxies/' + encoded + '/delay',
|
|
583
|
+
]
|
|
584
|
+
for (const path of paths) {
|
|
585
|
+
try {
|
|
586
|
+
const data = await this.api(path + '?' + query)
|
|
587
|
+
if (typeof data?.delay === 'number' && data.delay >= 0) return data.delay
|
|
588
|
+
} catch {
|
|
589
|
+
// try the next namespace
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return null
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Measure how one node behaves against every probe.
|
|
597
|
+
*
|
|
598
|
+
* @param name - node name.
|
|
599
|
+
* @param probes - probe descriptors with id and url.
|
|
600
|
+
* @param options - timeoutMs per probe, concurrency across probes.
|
|
601
|
+
* @returns probe id to delay, or null where the node could not reach it.
|
|
602
|
+
*/
|
|
603
|
+
async capabilities(name, probes, options = {}) {
|
|
604
|
+
const timeoutMs = options.timeoutMs ?? 8000
|
|
605
|
+
const list = Array.isArray(probes) ? probes : []
|
|
606
|
+
const samples = Math.max(1, Number(options.samples ?? 2))
|
|
607
|
+
const limit = Math.max(1, Math.min(Number(options.concurrency ?? 3), list.length || 1))
|
|
608
|
+
// Repeat every probe: a single answer can come from a connection the previous node
|
|
609
|
+
// established, and measured, that reported a blocked node as working. Averaging only
|
|
610
|
+
// across attempts that all succeeded turns that into a reliable verdict.
|
|
611
|
+
const attempts = Array.from({ length: samples }, () => ({}))
|
|
612
|
+
for (let round = 0; round < samples; round += 1) {
|
|
613
|
+
let next = 0
|
|
614
|
+
const worker = async () => {
|
|
615
|
+
while (next < list.length) {
|
|
616
|
+
const probe = list[next]
|
|
617
|
+
next += 1
|
|
618
|
+
attempts[round][probe.id] = await this.reach(name, probe.url, timeoutMs)
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
await Promise.all(Array.from({ length: limit }, worker))
|
|
622
|
+
if (round + 1 < samples) await new Promise((resolve) => setTimeout(resolve, options.sampleGapMs ?? 400))
|
|
623
|
+
}
|
|
624
|
+
const results = {}
|
|
625
|
+
for (const probe of list) {
|
|
626
|
+
const values = attempts.map((attempt) => attempt[probe.id])
|
|
627
|
+
const allAnswered = values.every((value) => typeof value === 'number')
|
|
628
|
+
results[probe.id] = allAnswered ? Math.round(values.reduce((sum, value) => sum + value, 0) / values.length) : null
|
|
629
|
+
}
|
|
630
|
+
return results
|
|
631
|
+
}
|
|
632
|
+
|
|
556
633
|
/**
|
|
557
|
-
*
|
|
558
|
-
* lowest measured latency across a sample, then a single-node verification of the
|
|
559
|
-
* rest. Nodes whose latency cannot be measured are dead and are never chosen.
|
|
634
|
+
* Build the capability matrix for a set of nodes.
|
|
560
635
|
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
636
|
+
* Two phases, because a 54-node subscription times a probe set of four would cost
|
|
637
|
+
* minutes: a cheap baseline pass over every node drops the dead ones, then the full set
|
|
638
|
+
* runs over the survivors only, cheapest first, and stops as soon as a node passes
|
|
639
|
+
* everything — the search is for a node that works, not for the very best one.
|
|
563
640
|
*
|
|
564
|
-
* @param
|
|
565
|
-
* @returns the
|
|
641
|
+
* @param options - nodes to test, probes, budgets and a progress callback.
|
|
642
|
+
* @returns the matrix, the chosen node, how many were tested and which were skipped.
|
|
566
643
|
*/
|
|
567
|
-
async
|
|
644
|
+
async capabilityMatrix(options = {}) {
|
|
645
|
+
const probes = Array.isArray(options.probes) ? options.probes : []
|
|
646
|
+
const required = Array.isArray(options.required) ? options.required : probes.map((probe) => probe.id)
|
|
647
|
+
const baseline = options.baseline ?? probes[0]
|
|
648
|
+
const candidates = (Array.isArray(options.nodes) ? options.nodes : []).filter((name) => name !== 'DIRECT')
|
|
649
|
+
const report = options.onProgress ?? (() => {})
|
|
650
|
+
const deadline = Date.now() + (options.budgetMs ?? this.selectBudgetMs ?? 90_000)
|
|
651
|
+
const batchSize = Math.max(1, Math.min(Number(options.batchSize ?? 8), 16))
|
|
652
|
+
|
|
653
|
+
const matrix = []
|
|
654
|
+
let tested = 0
|
|
655
|
+
const skipped = []
|
|
656
|
+
|
|
657
|
+
// Phase 1 — baseline reachability, so dead nodes never reach the per-service probes.
|
|
658
|
+
const alive = []
|
|
659
|
+
for (let at = 0; at < candidates.length && Date.now() < deadline; at += batchSize) {
|
|
660
|
+
const batch = candidates.slice(at, at + batchSize)
|
|
661
|
+
const rows = await Promise.all(
|
|
662
|
+
batch.map(async (name) => ({
|
|
663
|
+
name,
|
|
664
|
+
delay: baseline === undefined ? 0 : await this.reach(name, baseline.url, options.baselineTimeoutMs ?? 5000),
|
|
665
|
+
})),
|
|
666
|
+
)
|
|
667
|
+
for (const row of rows) {
|
|
668
|
+
tested += 1
|
|
669
|
+
if (row.delay === null) {
|
|
670
|
+
matrix.push({ name: row.name, results: baseline === undefined ? {} : { [baseline.id]: null } })
|
|
671
|
+
continue
|
|
672
|
+
}
|
|
673
|
+
alive.push({ name: row.name, baselineDelay: row.delay })
|
|
674
|
+
}
|
|
675
|
+
report({ phase: 'baseline', tested, alive: alive.length, total: candidates.length })
|
|
676
|
+
}
|
|
677
|
+
for (const name of candidates) {
|
|
678
|
+
if (!alive.some((entry) => entry.name === name) && !matrix.some((entry) => entry.name === name)) skipped.push(name)
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Phase 2 — the full probe set, cheapest baseline first so a good node is found early.
|
|
682
|
+
alive.sort((a, b) => a.baselineDelay - b.baselineDelay)
|
|
683
|
+
let chosen
|
|
684
|
+
for (const entry of alive) {
|
|
685
|
+
if (Date.now() > deadline) {
|
|
686
|
+
skipped.push(entry.name)
|
|
687
|
+
continue
|
|
688
|
+
}
|
|
689
|
+
const results = await this.capabilities(entry.name, probes, {
|
|
690
|
+
timeoutMs: options.timeoutMs ?? 8000,
|
|
691
|
+
concurrency: options.concurrency ?? 3,
|
|
692
|
+
samples: options.samples ?? 2,
|
|
693
|
+
sampleGapMs: options.sampleGapMs ?? 400,
|
|
694
|
+
})
|
|
695
|
+
matrix.push({ name: entry.name, results })
|
|
696
|
+
report({ phase: 'probes', node: entry.name, results })
|
|
697
|
+
const passesAll = required.every((id) => typeof results[id] === 'number')
|
|
698
|
+
if (passesAll) {
|
|
699
|
+
chosen = entry.name
|
|
700
|
+
for (const rest of alive) if (rest.name !== entry.name && !matrix.some((row) => row.name === rest.name)) skipped.push(rest.name)
|
|
701
|
+
break
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return { matrix, chosen, tested, skipped }
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Choose a working exit node.
|
|
710
|
+
*
|
|
711
|
+
* The caller's explicit preference still wins when it exists and can actually reach every
|
|
712
|
+
* required service — honouring a pin is the point of a pin, but a pinned node that cannot
|
|
713
|
+
* reach OpenAI would otherwise reproduce the exact bug this method exists to prevent, so
|
|
714
|
+
* the preference is verified rather than trusted.
|
|
715
|
+
*
|
|
716
|
+
* @param preferred - a node name to honour when usable.
|
|
717
|
+
* @param options - probes, required ids, budgets.
|
|
718
|
+
* @returns the chosen node and the matrix it was chosen from.
|
|
719
|
+
*/
|
|
720
|
+
async autoSelect(preferred, options = {}) {
|
|
568
721
|
const group = await this.group()
|
|
569
722
|
const candidates = group.all.filter((entry) => entry !== 'DIRECT')
|
|
570
|
-
if (candidates.length === 0) return undefined
|
|
723
|
+
if (candidates.length === 0) return { chosen: undefined, matrix: [] }
|
|
571
724
|
|
|
572
725
|
const wanted = String(preferred ?? '').trim()
|
|
726
|
+
const probes = Array.isArray(options.probes) ? options.probes : []
|
|
727
|
+
const required = Array.isArray(options.required) ? options.required : probes.map((probe) => probe.id)
|
|
728
|
+
|
|
729
|
+
// A pinned node is checked first and, when it passes, ends the search immediately.
|
|
573
730
|
if (wanted !== '' && candidates.includes(wanted)) {
|
|
574
|
-
const
|
|
575
|
-
|
|
731
|
+
const results = await this.capabilities(wanted, probes, { timeoutMs: options.timeoutMs ?? 8000, samples: options.samples ?? 2 })
|
|
732
|
+
const passesAll = required.every((id) => typeof results[id] === 'number')
|
|
733
|
+
if (passesAll) {
|
|
576
734
|
await this.select(wanted)
|
|
577
|
-
return wanted
|
|
735
|
+
return { chosen: wanted, matrix: [{ name: wanted, results }] }
|
|
578
736
|
}
|
|
579
|
-
|
|
737
|
+
const unmet = required.filter((id) => typeof results[id] !== 'number')
|
|
738
|
+
this.log('preferred node "' + wanted + '" cannot reach ' + unmet.join(', ') + '; choosing another')
|
|
580
739
|
}
|
|
581
740
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// the choice.
|
|
587
|
-
const deadline = Date.now() + (this.selectBudgetMs ?? 45_000)
|
|
588
|
-
const batchSize = 10
|
|
589
|
-
let best
|
|
590
|
-
for (let at = 0; at < candidates.length && Date.now() < deadline; at += batchSize) {
|
|
591
|
-
const batch = candidates.slice(at, at + batchSize)
|
|
592
|
-
const results = await Promise.all(
|
|
593
|
-
batch.map(async (name) => ({ name, delay: await this.delay(name, 4000) })),
|
|
594
|
-
)
|
|
595
|
-
for (const result of results) {
|
|
596
|
-
if (result.delay === null) continue
|
|
597
|
-
if (best === undefined || result.delay < best.delay) best = result
|
|
598
|
-
}
|
|
599
|
-
// A clearly good node ends the search early: the first working exit is enough to
|
|
600
|
-
// bring routing up, and the panel can re-test later.
|
|
601
|
-
if (best !== undefined && best.delay <= 1200) break
|
|
602
|
-
}
|
|
603
|
-
if (best === undefined) {
|
|
604
|
-
this.log('no node answered a latency test; leaving the group on its current selection')
|
|
605
|
-
return undefined
|
|
741
|
+
const result = await this.capabilityMatrix({ nodes: candidates, probes, required, ...options })
|
|
742
|
+
if (result.chosen === undefined) {
|
|
743
|
+
this.log('no node passed every required probe; leaving the group on its current selection')
|
|
744
|
+
return { chosen: undefined, matrix: result.matrix }
|
|
606
745
|
}
|
|
607
|
-
await this.select(
|
|
608
|
-
return
|
|
746
|
+
await this.select(result.chosen)
|
|
747
|
+
return { chosen: result.chosen, matrix: result.matrix }
|
|
609
748
|
}
|
|
610
749
|
|
|
611
750
|
/**
|
package/lib/routes.js
CHANGED
package/lib/select.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability-aware node selection.
|
|
3
|
+
*
|
|
4
|
+
* Latency answers "is this node alive", not "does this node work for me". Measured on a live
|
|
5
|
+
* subscription, `🇺🇸 美国01` answered the gstatic check in 472 ms and google in 278 ms — a
|
|
6
|
+
* plausible "fastest node" — while OpenAI was unreachable through it. Choosing on latency
|
|
7
|
+
* therefore produced a node that silently broke one service, and the symptom looked like the
|
|
8
|
+
* plugin being down rather than a wrong node.
|
|
9
|
+
*
|
|
10
|
+
* The fix is to ask the node the same question the workload will ask it. mihomo's
|
|
11
|
+
* `healthcheck` endpoint accepts a URL and reports a delay when the target answers at all,
|
|
12
|
+
* which is exactly the signal needed: measured, a 401 from `api.openai.com` counts as success
|
|
13
|
+
* (`delay: 269`) while a blocked node returns 503. So each required service becomes a probe,
|
|
14
|
+
* and a node is usable only when it passes every probe that matters.
|
|
15
|
+
*
|
|
16
|
+
* Two phases keep this affordable on a 54-node subscription: a cheap gstatic pass over every
|
|
17
|
+
* node, then the full probe set over only the survivors, cheapest first.
|
|
18
|
+
*
|
|
19
|
+
* @module dsh-clash-proxy/select
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Services a node may be asked to carry.
|
|
24
|
+
*
|
|
25
|
+
* These are the ones that actually fail differently per node in practice: a generic 204
|
|
26
|
+
* endpoint says the tunnel works, while the AI APIs reject datacenter ranges and Google is
|
|
27
|
+
* the usual reachability baseline. `custom` extends the list per configuration.
|
|
28
|
+
*
|
|
29
|
+
* `delay` is a display hint only — it orders the probe run, never decides usability.
|
|
30
|
+
*
|
|
31
|
+
* @type {ReadonlyArray<{id: string, label: string, url: string, delay: boolean}>}
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_PROBES = [
|
|
34
|
+
{ id: 'gstatic', label: '基础连通', url: 'http://www.gstatic.com/generate_204', delay: false },
|
|
35
|
+
{ id: 'google', label: 'Google', url: 'http://www.google.com/generate_204', delay: true },
|
|
36
|
+
{ id: 'openai', label: 'OpenAI', url: 'https://api.openai.com/v1/models', delay: true },
|
|
37
|
+
{ id: 'anthropic', label: 'Anthropic', url: 'https://api.anthropic.com/v1/messages', delay: true },
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Parse the user's probe configuration.
|
|
42
|
+
*
|
|
43
|
+
* Accepts `id=url` per line or per comma, so the panel can expose one box instead of a
|
|
44
|
+
* structured editor. An entry without `=` is treated as a bare URL and named after its host.
|
|
45
|
+
*
|
|
46
|
+
* @param text - the configured probe list.
|
|
47
|
+
* @returns probe descriptors, or an empty array when nothing was configured.
|
|
48
|
+
*/
|
|
49
|
+
export function parseProbes(text) {
|
|
50
|
+
const probes = []
|
|
51
|
+
for (const chunk of String(text ?? '').split(/[\n,]+/)) {
|
|
52
|
+
const entry = chunk.trim()
|
|
53
|
+
if (entry === '') continue
|
|
54
|
+
const at = entry.indexOf('=')
|
|
55
|
+
if (at > 0) {
|
|
56
|
+
const id = entry.slice(0, at).trim()
|
|
57
|
+
const url = entry.slice(at + 1).trim()
|
|
58
|
+
if (id === '' || !/^https?:\/\//i.test(url)) continue
|
|
59
|
+
try {
|
|
60
|
+
if (new URL(url).hostname === '') continue
|
|
61
|
+
} catch {
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
probes.push({ id, label: id, url, delay: true })
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
if (!/^https?:\/\//i.test(entry)) continue
|
|
68
|
+
let host
|
|
69
|
+
try {
|
|
70
|
+
host = new URL(entry).hostname
|
|
71
|
+
} catch {
|
|
72
|
+
// 'http://' has a scheme and nothing else; it parses as neither a host nor a target.
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
if (host === '') continue
|
|
76
|
+
probes.push({ id: host, label: host, url: entry, delay: true })
|
|
77
|
+
}
|
|
78
|
+
return probes
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The probe set to run: the built-in services plus any configured extras.
|
|
83
|
+
*
|
|
84
|
+
* @param configured - the `probes` configuration field.
|
|
85
|
+
* @param required - ids that must pass; empty means "every probe in the set".
|
|
86
|
+
* @returns the probes to run and the ids that gate usability.
|
|
87
|
+
*/
|
|
88
|
+
export function resolveProbes(configured, required) {
|
|
89
|
+
const extra = parseProbes(configured)
|
|
90
|
+
const byId = new Map(DEFAULT_PROBES.map((probe) => [probe.id, probe]))
|
|
91
|
+
for (const probe of extra) byId.set(probe.id, probe)
|
|
92
|
+
const wanted = String(required ?? '')
|
|
93
|
+
.split(/[\s,]+/)
|
|
94
|
+
.map((entry) => entry.trim())
|
|
95
|
+
.filter((entry) => entry !== '')
|
|
96
|
+
const all = [...byId.values()]
|
|
97
|
+
if (wanted.length === 0) return { probes: all, required: all.map((probe) => probe.id), all: all.map((probe) => probe.id) }
|
|
98
|
+
// Keep EVERY required id, including ones no probe defines. Filtering them out would make
|
|
99
|
+
// a typo silently weaken the gate — the selector would then choose a node that never had
|
|
100
|
+
// to pass the service the user actually cares about. An undefined id simply can never be
|
|
101
|
+
// satisfied, so the caller reports it instead of choosing a bad node.
|
|
102
|
+
return { probes: all, required: wanted, all: all.map((probe) => probe.id) }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Summarise one node's probe results into a usability verdict.
|
|
107
|
+
*
|
|
108
|
+
* @param results - probe id to delay (number) or null.
|
|
109
|
+
* @param required - ids that must be present in `results`.
|
|
110
|
+
* @returns `{ usable, failed, missing, total }`.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Decide whether repeated probe results show a stable capability.
|
|
114
|
+
*
|
|
115
|
+
* One measurement is not evidence. Measured on a live subscription: the same node returned
|
|
116
|
+
* `401` for `api.openai.com` immediately after switching to it and `000` for six attempts
|
|
117
|
+
* in a row a minute later — the first answer came from a connection the previous node had
|
|
118
|
+
* established, so a single probe reported a blocked node as working. Choosing on one sample
|
|
119
|
+
* therefore selects nodes that fail the moment real traffic arrives.
|
|
120
|
+
*
|
|
121
|
+
* A service counts as reachable only when every attempt in the sample succeeded.
|
|
122
|
+
*
|
|
123
|
+
* @param attempts - one array of delays (number) or failures (null) per probe.
|
|
124
|
+
* @param required - ids that must pass.
|
|
125
|
+
* @returns the same shape as {@link judgeNode}, plus the attempt count.
|
|
126
|
+
*/
|
|
127
|
+
export function judgeNodeStable(attempts, required) {
|
|
128
|
+
const results = {}
|
|
129
|
+
let samples = 0
|
|
130
|
+
for (const id of required) {
|
|
131
|
+
const values = attempts.map((attempt) => attempt?.[id])
|
|
132
|
+
const present = values.filter((value) => value !== undefined)
|
|
133
|
+
samples = Math.max(samples, present.length)
|
|
134
|
+
if (present.length === 0) {
|
|
135
|
+
results[id] = undefined
|
|
136
|
+
continue
|
|
137
|
+
}
|
|
138
|
+
// Every sample must have answered; a single timeout makes the capability unreliable.
|
|
139
|
+
const allAnswered = present.length === values.length && present.every((value) => typeof value === 'number')
|
|
140
|
+
results[id] = allAnswered ? Math.round(present.reduce((sum, value) => sum + value, 0) / present.length) : null
|
|
141
|
+
}
|
|
142
|
+
return { ...judgeNode(results, required), results, samples }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function judgeNode(results, required) {
|
|
146
|
+
const failed = []
|
|
147
|
+
const missing = []
|
|
148
|
+
let total = 0
|
|
149
|
+
for (const id of required) {
|
|
150
|
+
const value = results?.[id]
|
|
151
|
+
if (value === undefined) {
|
|
152
|
+
missing.push(id)
|
|
153
|
+
continue
|
|
154
|
+
}
|
|
155
|
+
total += value
|
|
156
|
+
if (value === null) failed.push(id)
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
usable: failed.length === 0 && missing.length === 0,
|
|
160
|
+
failed,
|
|
161
|
+
missing,
|
|
162
|
+
total: total === 0 ? undefined : total,
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Rank candidates: every probe must pass, then lowest total delay wins.
|
|
168
|
+
*
|
|
169
|
+
* @param matrix - one entry per node: `{ name, results }`.
|
|
170
|
+
* @param required - ids that must pass.
|
|
171
|
+
* @returns usable nodes, best first, each carrying its failed/missing detail.
|
|
172
|
+
*/
|
|
173
|
+
export function rankNodes(matrix, required) {
|
|
174
|
+
const judged = matrix.map((entry) => ({ name: entry.name, results: entry.results, ...judgeNode(entry.results, required) }))
|
|
175
|
+
const usable = judged.filter((entry) => entry.usable).sort((a, b) => (a.total ?? Infinity) - (b.total ?? Infinity))
|
|
176
|
+
const unusable = judged.filter((entry) => !entry.usable).sort((a, b) => a.failed.length - b.failed.length)
|
|
177
|
+
return { usable, unusable }
|
|
178
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
@@ -70,4 +70,4 @@
|
|
|
70
70
|
"test:client": "node test/client-sim.mjs",
|
|
71
71
|
"test:e2e": "node test/e2e.mjs"
|
|
72
72
|
}
|
|
73
|
-
}
|
|
73
|
+
}
|