dsh-clash-subscription 0.8.0 → 0.9.0
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.9.0.md +122 -0
- package/index.js +307 -133
- package/lib/core.js +18 -0
- package/lib/skill.js +12 -5
- package/package.json +4 -4
- package/CHANGELOG-0.8.0.md +0 -120
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# 0.9.0 · 一轮内连续 3 次尝试;不合格就测遍全部节点
|
|
2
|
+
|
|
3
|
+
> 上一版 `0.8.0` · 本版 `0.9.0`
|
|
4
|
+
|
|
5
|
+
## 为什么改
|
|
6
|
+
|
|
7
|
+
0.8.0 把「连续 3 轮不合格」实现成了**跨轮累积**:每 30 秒记一次 strike,攒满 3 次才切换。
|
|
8
|
+
后果是一个坏节点要占着 90 秒以上才被处理,而且中途只要有一次抖动通过,计数清零、从头再攒。
|
|
9
|
+
|
|
10
|
+
用户要的是:**一次检测不合格就立刻再测,还不合格就立刻再测一次,三次都不合格才切换。**
|
|
11
|
+
|
|
12
|
+
## 改了什么
|
|
13
|
+
|
|
14
|
+
### 1. 三次尝试在一轮内连续完成
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
每 30 秒触发一轮:
|
|
18
|
+
attempt 1 → 不合格
|
|
19
|
+
attempt 2 → 立即重试(不等下一个 30 秒)→ 不合格
|
|
20
|
+
attempt 3 → 立即再试 → 不合格
|
|
21
|
+
↓
|
|
22
|
+
测遍【全部未被屏蔽的节点】,切到最优
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
只要任何一次合格就保持,**剩下的次数不再浪费**(省配额)。
|
|
26
|
+
实测间隔:**7.4 秒 / 7.9 秒**,三次总跨度 15.4 秒。
|
|
27
|
+
|
|
28
|
+
| 字段 | 默认 | 说明 |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `healthAttempts` | **3** | 一轮内最多试几次;合格即停 |
|
|
31
|
+
| `healthRoundSeconds` | 30 | 多久触发一轮 |
|
|
32
|
+
| `healthStrikeLimit` | 3 | 保留作为跨轮兜底,正常路径不再依赖它 |
|
|
33
|
+
|
|
34
|
+
### 2. 不合格的定义:不可用 **或** 真实延迟过高
|
|
35
|
+
|
|
36
|
+
| 判定 | 条件 |
|
|
37
|
+
|---|---|
|
|
38
|
+
| 不可用 | 某个门槛探针没通(gstatic 非 204 / GitHub 配额 0 / git 拉不到) |
|
|
39
|
+
| 延迟过高 | Google 实测中位延迟 > `healthMaxDelayMs`(默认 400 ms) |
|
|
40
|
+
|
|
41
|
+
两者都写进 `verdict.failed`,所以面板能说清是哪一条。
|
|
42
|
+
|
|
43
|
+
### 3. 切换时测遍全部未被屏蔽节点
|
|
44
|
+
|
|
45
|
+
`healthSwitchCandidates` 默认从 **12 改成 0 = 全部**。上限会把「找最优出口」变成
|
|
46
|
+
「在前 12 个里找最优」,54 节点的订阅可能因此错过更好的节点。
|
|
47
|
+
|
|
48
|
+
实测:8 节点订阅,去掉当前节点与被屏蔽的,**7/7 全测**。
|
|
49
|
+
|
|
50
|
+
排序规则(这是"最优"的定义):
|
|
51
|
+
|
|
52
|
+
1. 可用优先;
|
|
53
|
+
2. **真实延迟最低**(Google 中位);
|
|
54
|
+
3. 失败探针更少;
|
|
55
|
+
4. 限流优先于不通(配额会重置,线路坏不会)。
|
|
56
|
+
|
|
57
|
+
被屏蔽的节点不参与(`group.all` 本身已排除,代码里再用 `isBlocked` 兜一层)。
|
|
58
|
+
|
|
59
|
+
## 两个被真机测试逼出来的修正
|
|
60
|
+
|
|
61
|
+
### A. 单次延迟采样不可信 → 改中位数
|
|
62
|
+
|
|
63
|
+
同一节点同一分钟连续测 Google:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
2256, 967, 1412, 179, 1190, 180 ms
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
拿一次采样比 400 ms 阈值,基本是掷骰子——慢但没坏的节点会被判死,快但很差的会被放过。
|
|
70
|
+
|
|
71
|
+
改成 **3 次采样取中位数**,且**丢掉第一次**(新内核首次要付 DNS+TCP+TLS,实测 513 ms vs 82 ms)。
|
|
72
|
+
新增 `healthLatencySamples`(默认 3,范围 2–5)。
|
|
73
|
+
|
|
74
|
+
### B. 测不到延迟时阈值会静默失效 → 加回落链
|
|
75
|
+
|
|
76
|
+
`latency === undefined` 时,`tooSlow` 恒为 false,阈值**形同不存在**,一个 Google 不通的慢节点会被永久保留。
|
|
77
|
+
|
|
78
|
+
回落顺序:warm Google 中位 → cold Google → **最快的那条已通过的门槛探针**。
|
|
79
|
+
只有全都没答时才留 undefined,而那种节点已经因为门槛探针失败而被判不合格。
|
|
80
|
+
|
|
81
|
+
`latencySource` 会标 `warm-median` / `cold` / `fallback-probe` / `unreachable`,面板能解释这个数从哪来。
|
|
82
|
+
|
|
83
|
+
## 验收
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
node test/regression-070.mjs → 112 passed, 0 failed
|
|
87
|
+
node test/regression-063.mjs → 31 passed, 0 failed
|
|
88
|
+
node test/e2e-090.mjs → 13 passed, 0 failed(真内核 + 真订阅 + 真请求)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
e2e 真实输出:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
strict round: attempts=3
|
|
95
|
+
attempt 1: usable=false latency=3544
|
|
96
|
+
attempt 2: usable=false latency=3090
|
|
97
|
+
attempt 3: usable=false latency=3445
|
|
98
|
+
gaps between attempts: 7427, 7935 ms ← 立即重试,不是等 30 秒
|
|
99
|
+
三次尝试总跨度: 15362 ms(整轮含全节点实测 74622 ms)
|
|
100
|
+
tested 7 candidate(s) of 7 unblocked non-live node(s) ← 全测
|
|
101
|
+
|
|
102
|
+
measured (usable first, fastest first):
|
|
103
|
+
🇸🇬 新加坡01 usable=true latency=274
|
|
104
|
+
🇺🇸 美国01 usable=true latency=340
|
|
105
|
+
🇸🇬 新加坡02 usable=true latency=346
|
|
106
|
+
🇲🇾 马来西亚01 usable=true latency=352
|
|
107
|
+
🇹🇼 台湾02 usable=true latency=384
|
|
108
|
+
🇺🇸 美国02 usable=false latency=577
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 附带更新
|
|
112
|
+
|
|
113
|
+
- 插件自带的 `clash-proxy-egress` 技能:把「连续 3 轮」改成「一轮内连续 3 次」,
|
|
114
|
+
判据从 `health.lastRound.strikes` 改成 `health.lastRound.attempt`,并写明
|
|
115
|
+
「不合格 = 不可用 或 延迟过高」与「三次全败会测遍全部未屏蔽节点」。
|
|
116
|
+
- `status.health` 新增 `attempts`、`baselineProbe`、`switchCandidates` 字段。
|
|
117
|
+
|
|
118
|
+
## 遗留
|
|
119
|
+
|
|
120
|
+
- `healthStrikeLimit` 仍然存在但正常路径不再驱动切换(同一轮内 3 次尝试已经取代它)。
|
|
121
|
+
保留是为了兼容旧配置不报错,后续版本可以考虑移除。
|
|
122
|
+
- 面板新增字段(`healthAttempts`、`healthLatencySamples`)已接配置层,未在真浏览器里核对渲染。
|
package/index.js
CHANGED
|
@@ -127,6 +127,15 @@ export const CONFIG_DEFAULTS = {
|
|
|
127
127
|
autoSwitch: true,
|
|
128
128
|
/** How often the round runs, in seconds; 0 disables it. */
|
|
129
129
|
healthRoundSeconds: 30,
|
|
130
|
+
/**
|
|
131
|
+
* Consecutive attempts on the live node inside one round before it is given up on.
|
|
132
|
+
*
|
|
133
|
+
* The retries happen **immediately**, not one per timer tick: a node that fails gets its
|
|
134
|
+
* second and third chance seconds later, and only then does the round measure every other
|
|
135
|
+
* node. Spreading the attempts across ticks made a dead node cost a minute and a half before
|
|
136
|
+
* anything was done about it.
|
|
137
|
+
*/
|
|
138
|
+
healthAttempts: 3,
|
|
130
139
|
/** Consecutive failed rounds before the node is given up on. */
|
|
131
140
|
healthStrikeLimit: 3,
|
|
132
141
|
/**
|
|
@@ -146,10 +155,25 @@ export const CONFIG_DEFAULTS = {
|
|
|
146
155
|
* traffic reuses warm state, so the second measurement is the one that means something.
|
|
147
156
|
*/
|
|
148
157
|
healthMaxDelayMs: 400,
|
|
158
|
+
/**
|
|
159
|
+
* Latency samples per attempt; the median of the samples after the first is compared.
|
|
160
|
+
*
|
|
161
|
+
* Measured, consecutive Google probes on one node in one minute returned 2256, 967, 1412, 179,
|
|
162
|
+
* 1190 and 180 ms — a single sample against a 400 ms ceiling decides mostly by luck. Three is
|
|
163
|
+
* the cheapest sample that rejects one outlier; the first sample is dropped from the median
|
|
164
|
+
* because it pays DNS + TCP + TLS on a freshly started core.
|
|
165
|
+
*/
|
|
166
|
+
healthLatencySamples: 3,
|
|
149
167
|
/** Which probe supplies the latency number. Google is the distance baseline, not a gate. */
|
|
150
168
|
healthBaselineProbe: 'google',
|
|
151
|
-
/**
|
|
152
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Cap on how many nodes one switch measures. 0 (the default) measures every unblocked node.
|
|
171
|
+
*
|
|
172
|
+
* A cap turns "find the best exit" into "find the best of the first N", which on a large
|
|
173
|
+
* subscription can pick a worse node than one further down the list. It stays configurable for
|
|
174
|
+
* an operator on a very large subscription who would rather switch fast than switch well.
|
|
175
|
+
*/
|
|
176
|
+
healthSwitchCandidates: 0,
|
|
153
177
|
/** Let a switch proceed even while connections are open. Off by default: it aborts work. */
|
|
154
178
|
switchWhileBusy: false,
|
|
155
179
|
/**
|
|
@@ -205,10 +229,12 @@ async function buildConfigSchema() {
|
|
|
205
229
|
probeTimeoutMs: z.number().default(8000),
|
|
206
230
|
autoSwitch: z.boolean().default(true),
|
|
207
231
|
healthRoundSeconds: z.number().default(30),
|
|
232
|
+
healthAttempts: z.number().default(3),
|
|
208
233
|
healthStrikeLimit: z.number().default(3),
|
|
209
234
|
healthMaxDelayMs: z.number().default(400),
|
|
235
|
+
healthLatencySamples: z.number().default(3),
|
|
210
236
|
healthBaselineProbe: z.string().default('google'),
|
|
211
|
-
healthSwitchCandidates: z.number().default(
|
|
237
|
+
healthSwitchCandidates: z.number().default(0),
|
|
212
238
|
switchWhileBusy: z.boolean().default(false),
|
|
213
239
|
healthSurveyEvery: z.number().default(20),
|
|
214
240
|
})
|
|
@@ -265,8 +291,10 @@ export function resolveConfig(raw) {
|
|
|
265
291
|
config.healthRoundSeconds = clamp(config.healthRoundSeconds, 0, 3_600, 30)
|
|
266
292
|
config.healthStrikeLimit = clamp(config.healthStrikeLimit, 1, 20, 3)
|
|
267
293
|
config.healthMaxDelayMs = clamp(config.healthMaxDelayMs, 0, 30_000, 400)
|
|
294
|
+
config.healthLatencySamples = clamp(config.healthLatencySamples, 2, 5, 3)
|
|
268
295
|
config.healthBaselineProbe = String(config.healthBaselineProbe ?? 'google').trim() || 'google'
|
|
269
|
-
config.
|
|
296
|
+
config.healthAttempts = clamp(config.healthAttempts, 1, 10, 3)
|
|
297
|
+
config.healthSwitchCandidates = clamp(config.healthSwitchCandidates, 0, 200, 0)
|
|
270
298
|
config.healthSurveyEvery = clamp(config.healthSurveyEvery, 0, 10_000, 20)
|
|
271
299
|
// 0.7.0 kept the interval in minutes; carry the value over so an existing profile does not
|
|
272
300
|
// silently fall back to the new 30 s default when someone had deliberately set 15 minutes.
|
|
@@ -491,6 +519,7 @@ export class Runtime {
|
|
|
491
519
|
reselectMinutes: this.config.reselectMinutes,
|
|
492
520
|
autoSwitch: this.config.autoSwitch,
|
|
493
521
|
healthRoundSeconds: this.config.healthRoundSeconds,
|
|
522
|
+
healthAttempts: this.config.healthAttempts,
|
|
494
523
|
healthStrikeLimit: this.config.healthStrikeLimit,
|
|
495
524
|
healthMaxDelayMs: this.config.healthMaxDelayMs,
|
|
496
525
|
healthSwitchCandidates: this.config.healthSwitchCandidates,
|
|
@@ -572,6 +601,7 @@ export class Runtime {
|
|
|
572
601
|
if (
|
|
573
602
|
next.healthRoundSeconds !== previous.healthRoundSeconds ||
|
|
574
603
|
next.autoSwitch !== previous.autoSwitch ||
|
|
604
|
+
next.healthAttempts !== previous.healthAttempts ||
|
|
575
605
|
next.healthStrikeLimit !== previous.healthStrikeLimit ||
|
|
576
606
|
next.healthMaxDelayMs !== previous.healthMaxDelayMs ||
|
|
577
607
|
next.healthSurveyEvery !== previous.healthSurveyEvery
|
|
@@ -684,17 +714,122 @@ export class Runtime {
|
|
|
684
714
|
}
|
|
685
715
|
|
|
686
716
|
/**
|
|
687
|
-
*
|
|
717
|
+
* Measure one node once and turn it into a verdict.
|
|
718
|
+
*
|
|
719
|
+
* Extracted so one round can call it three times in a row without waiting for the next timer
|
|
720
|
+
* tick. "Unqualified" means either test failed:
|
|
688
721
|
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* six unusable nodes as `usable` while five of them had `x-ratelimit-remaining: 0` and two
|
|
692
|
-
* could not complete a git fetch at all. So the round sends the real requests through the
|
|
693
|
-
* probe listener, reads the real status and quota, and records a strike only when a probe
|
|
694
|
-
* that gates usability failed.
|
|
722
|
+
* - a gating probe did not answer (unreachable / reset / wrong status), or
|
|
723
|
+
* - the Google round trip exceeded `healthMaxDelayMs`.
|
|
695
724
|
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
725
|
+
* Both are folded into `usable === false` on the returned verdict, with `failed` naming which,
|
|
726
|
+
* so the caller does not need a second condition.
|
|
727
|
+
*
|
|
728
|
+
* @param name - node to measure.
|
|
729
|
+
* @param plan - the probe plan in force.
|
|
730
|
+
* @returns `{ results, verdict, latency, latencySource, coldLatency, ceiling, baseline }`, or
|
|
731
|
+
* `undefined` when the probe listener did not answer (an instrument fault, not a node fault).
|
|
732
|
+
*/
|
|
733
|
+
async measureNode(name, plan) {
|
|
734
|
+
const { results, verdict } = await this.core.checkNodeReal(name, plan.specs, plan.gating, {
|
|
735
|
+
timeoutMs: this.config.probeTimeoutMs ?? 8000,
|
|
736
|
+
})
|
|
737
|
+
if (Object.keys(results).length === 0) return undefined
|
|
738
|
+
|
|
739
|
+
// Google is not a gating probe, so it is absent from `plan.specs` and from `results`: the
|
|
740
|
+
// node already answered the gating set and Google has to be measured on its own. Two
|
|
741
|
+
// measurements are taken, and the second is the number that means something — the first one
|
|
742
|
+
// on a freshly started core pays DNS + TCP + TLS for that host (measured, 513 ms cold vs
|
|
743
|
+
// 82 ms warm), which is not the node's latency.
|
|
744
|
+
//
|
|
745
|
+
// An unreachable Google is **not** a slow node. The ceiling is skipped for that attempt and
|
|
746
|
+
// the node is judged on the gating probes alone, because inventing a latency for an
|
|
747
|
+
// unreachable host would switch away from a node that may be fast for everything else.
|
|
748
|
+
const baseline = plan.probes.find((spec) => spec.id === this.config.healthBaselineProbe) ?? plan.specs[0]
|
|
749
|
+
let latency
|
|
750
|
+
let latencySource = 'not-measured'
|
|
751
|
+
let coldLatency
|
|
752
|
+
/** Every Google sample taken this attempt, so the panel can show the spread. */
|
|
753
|
+
const samples = []
|
|
754
|
+
if (verdict.usable === true && baseline !== undefined && typeof this.core.remeasure === 'function') {
|
|
755
|
+
try {
|
|
756
|
+
// Pin the probe group to this node first. `probeNodeReal` already does that for the gating
|
|
757
|
+
// probes, but relying on that would make the latency number depend on call order: a
|
|
758
|
+
// candidate measured right after the live node would otherwise get the live node's
|
|
759
|
+
// latency. Moving it here makes `measureNode(name)` self-contained — measure the node you
|
|
760
|
+
// name, no matter what was measured before.
|
|
761
|
+
if (typeof this.core.selectProbe === 'function') await this.core.selectProbe(name)
|
|
762
|
+
|
|
763
|
+
// Three samples, and the number used is the MEDIAN of the last two.
|
|
764
|
+
//
|
|
765
|
+
// Measured on a live node, consecutive Google probes returned 2256, 967, 1412, 179, 1190
|
|
766
|
+
// and 180 ms for the same node in the same minute. A single sample against a 400 ms
|
|
767
|
+
// ceiling therefore decides mostly by luck: it lets a momentarily slow-but-fine node fail,
|
|
768
|
+
// and a momentarily fast-but-bad node pass. The median of a small sample is the standard
|
|
769
|
+
// defence, and it is cheap here because each probe is one request to a static endpoint.
|
|
770
|
+
//
|
|
771
|
+
// The first sample is discarded from the median when there are three, because the first
|
|
772
|
+
// one on a freshly started core pays DNS + TCP + TLS for that host — measured, 513 ms cold
|
|
773
|
+
// against 82 ms warm.
|
|
774
|
+
const wanted = Math.max(2, Math.min(Number(this.config.healthLatencySamples ?? 3), 5))
|
|
775
|
+
for (let i = 0; i < wanted; i += 1) {
|
|
776
|
+
const sample = await this.core.remeasure(baseline, { timeoutMs: this.config.probeTimeoutMs ?? 8000, expectNode: name })
|
|
777
|
+
if (typeof sample?.ms === 'number' && sample.ok === true) samples.push(sample.ms)
|
|
778
|
+
}
|
|
779
|
+
if (samples.length > 0) {
|
|
780
|
+
coldLatency = samples[0]
|
|
781
|
+
const forMedian = samples.length > 1 ? samples.slice(1) : samples
|
|
782
|
+
const sorted = [...forMedian].sort((a, b) => a - b)
|
|
783
|
+
latency = sorted[Math.floor(sorted.length / 2)]
|
|
784
|
+
latencySource = samples.length > 1 ? 'warm-median' : 'cold'
|
|
785
|
+
} else {
|
|
786
|
+
latencySource = 'unreachable'
|
|
787
|
+
}
|
|
788
|
+
} catch (error) {
|
|
789
|
+
latencySource = 'failed'
|
|
790
|
+
this.log(`latency measurement failed on ${name}: ${error?.message ?? error}`)
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
const ceiling = Number(this.config.healthMaxDelayMs ?? 400)
|
|
795
|
+
|
|
796
|
+
// A latency that could not be measured must not be treated as "fast enough".
|
|
797
|
+
//
|
|
798
|
+
// The ceiling is the whole point of "unqualified = unusable OR too slow", so `undefined`
|
|
799
|
+
// silently disabling it would let a node with an unreachable Google stay selected forever.
|
|
800
|
+
// But an unreachable Google is also not proof the node is slow, so it cannot simply fail
|
|
801
|
+
// either — that is what caused a healthy node to be switched away from when the probe itself
|
|
802
|
+
// hiccuped.
|
|
803
|
+
//
|
|
804
|
+
// The resolution is a fallback chain, and what it settles on is what gets compared:
|
|
805
|
+
// 1. the warm Google round trip (the measurement the ceiling is defined against);
|
|
806
|
+
// 2. the cold Google round trip (a real number, just includes connection setup);
|
|
807
|
+
// 3. the fastest gating probe that did answer (gstatic is a static 204 too, and every
|
|
808
|
+
// gating probe already ran, so this costs nothing).
|
|
809
|
+
// Only when nothing at all answered does the latency stay undefined — and a node in that
|
|
810
|
+
// state has already failed its gating probes, so it is unqualified on the other count.
|
|
811
|
+
if (latency === undefined) {
|
|
812
|
+
const fallback = [coldLatency, ...Object.values(results).map((row) => (row?.ok === true ? row?.ms : undefined))]
|
|
813
|
+
.filter((value) => typeof value === 'number' && value >= 0)
|
|
814
|
+
.sort((a, b) => a - b)[0]
|
|
815
|
+
if (typeof fallback === 'number') {
|
|
816
|
+
latency = fallback
|
|
817
|
+
latencySource = latencySource === 'unreachable' ? 'fallback-probe' : latencySource
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const tooSlow = ceiling > 0 && verdict.usable === true && latency !== undefined && latency > ceiling
|
|
822
|
+
const judged = tooSlow ? { ...verdict, usable: false, failed: [...verdict.failed, 'latency'], slow: true } : verdict
|
|
823
|
+
return { results, verdict: judged, latency, latencySource, coldLatency, ceiling, baseline: baseline?.id, samples }
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* Run one real-probe round against the node that is currently carrying traffic.
|
|
828
|
+
*
|
|
829
|
+
* The round retries **immediately**, in the same round, rather than spreading attempts across
|
|
830
|
+
* timer ticks: a node that failed once gets a second and third chance seconds later, and only
|
|
831
|
+
* when all of them fail does the round search for a replacement. That is what makes a bad node
|
|
832
|
+
* cost seconds instead of a minute and a half, while still not switching on a single blip.
|
|
698
833
|
*
|
|
699
834
|
* @param options - `force` ignores the enable flag; `node` overrides the node under test.
|
|
700
835
|
* @returns the round report.
|
|
@@ -714,101 +849,90 @@ export class Runtime {
|
|
|
714
849
|
return { state: 'no-node', required: plan.gating }
|
|
715
850
|
}
|
|
716
851
|
|
|
717
|
-
const
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
852
|
+
const attempts = Math.max(1, Number(this.config.healthAttempts ?? 3))
|
|
853
|
+
const tried = []
|
|
854
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
855
|
+
const measured = await this.measureNode(current, plan)
|
|
856
|
+
if (measured === undefined) {
|
|
857
|
+
// The probe listener is not answering, which says nothing about the node. Reporting a
|
|
858
|
+
// failure here would switch away from a healthy node because the instrument broke.
|
|
859
|
+
return { state: 'probe-unavailable', node: current, attempts: tried }
|
|
860
|
+
}
|
|
861
|
+
const entry = {
|
|
862
|
+
attempt,
|
|
863
|
+
usable: measured.verdict.usable === true,
|
|
864
|
+
latency: measured.latency,
|
|
865
|
+
latencySource: measured.latencySource,
|
|
866
|
+
failed: measured.verdict.failed ?? [],
|
|
867
|
+
slow: measured.verdict.slow === true,
|
|
868
|
+
at: new Date().toISOString(),
|
|
869
|
+
}
|
|
870
|
+
tried.push(entry)
|
|
871
|
+
this.healthRows.set(current, { results: measured.results, verdict: measured.verdict, at: Date.now() })
|
|
872
|
+
this.lastMatrix = [{ name: current, results: measured.results }]
|
|
873
|
+
this.lastCheckAt = Date.now()
|
|
874
|
+
|
|
875
|
+
if (measured.verdict.usable === true) {
|
|
876
|
+
// Kept. One good attempt ends the round; the remaining attempts are not spent, because
|
|
877
|
+
// the node already answered the question this round is asking.
|
|
878
|
+
this.watch.record(current, measured.verdict, { probes: measured.results })
|
|
879
|
+
const report = {
|
|
880
|
+
state: measured.verdict.degraded === true ? 'degraded' : 'ok',
|
|
881
|
+
node: current,
|
|
882
|
+
required: plan.gating,
|
|
883
|
+
results: measured.results,
|
|
884
|
+
verdict: measured.verdict,
|
|
885
|
+
latency: measured.latency,
|
|
886
|
+
latencySource: measured.latencySource,
|
|
887
|
+
coldLatency: measured.coldLatency,
|
|
888
|
+
totalLatency: measured.results && undefined,
|
|
889
|
+
ceiling: measured.ceiling,
|
|
890
|
+
baseline: measured.baseline,
|
|
891
|
+
attempt,
|
|
892
|
+
attempts: tried,
|
|
893
|
+
attemptLimit: attempts,
|
|
894
|
+
giveUp: false,
|
|
895
|
+
at: new Date().toISOString(),
|
|
758
896
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
897
|
+
this.health = report
|
|
898
|
+
this.log(`round ok on ${current} at attempt ${attempt}/${attempts} (${measured.latency ?? '?'} ms)`)
|
|
899
|
+
void this.runSurveyTick()
|
|
900
|
+
return report
|
|
763
901
|
}
|
|
902
|
+
|
|
903
|
+
this.log(
|
|
904
|
+
`round attempt ${attempt}/${attempts} failed on ${current}: ` +
|
|
905
|
+
`${measured.verdict.failed.join(',') || 'no-answer'}` +
|
|
906
|
+
(measured.latency === undefined ? '' : ` (${measured.latency} ms, ceiling ${measured.ceiling} ms)`),
|
|
907
|
+
)
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Every attempt failed.
|
|
911
|
+
this.watch.record(current, { usable: false, failed: tried.at(-1)?.failed ?? [], limited: [], blocked: [], score: 100 })
|
|
912
|
+
const verdictNow = {
|
|
913
|
+
usable: false,
|
|
914
|
+
degraded: false,
|
|
915
|
+
failed: tried.at(-1)?.failed ?? [],
|
|
916
|
+
limited: [],
|
|
917
|
+
blocked: [],
|
|
918
|
+
slow: tried.every((entry) => entry.slow === true),
|
|
764
919
|
}
|
|
765
|
-
const ceiling = Number(this.config.healthMaxDelayMs ?? 400)
|
|
766
|
-
const tooSlow = ceiling > 0 && verdict.usable === true && latency !== undefined && latency > ceiling
|
|
767
|
-
const judged = tooSlow ? { ...verdict, usable: false, failed: [...verdict.failed, 'latency'], slow: true } : verdict
|
|
768
|
-
|
|
769
|
-
this.healthRows.set(current, { results, verdict: judged, at: Date.now() })
|
|
770
|
-
this.lastMatrix = [{ name: current, results }]
|
|
771
|
-
this.lastCheckAt = Date.now()
|
|
772
|
-
const counted = this.watch.record(current, judged, { probes: results })
|
|
773
|
-
// `degraded` is a usable node that is short on quota. It is reported, never acted on:
|
|
774
|
-
// switching away from it would land on an equally short node and lose the connection.
|
|
775
|
-
const state = judged.usable ? (judged.degraded === true ? 'degraded' : 'ok') : judged.slow === true ? 'slow' : 'bad'
|
|
776
920
|
const report = {
|
|
777
|
-
state,
|
|
921
|
+
state: verdictNow.slow ? 'slow' : 'bad',
|
|
778
922
|
node: current,
|
|
779
923
|
required: plan.gating,
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
/** Sum across every gating probe; informational, never compared to the ceiling. */
|
|
789
|
-
totalLatency: verdict.total,
|
|
790
|
-
ceiling,
|
|
791
|
-
baseline: baseline?.id,
|
|
792
|
-
strikes: counted.strikes,
|
|
793
|
-
strikeLimit: counted.limit,
|
|
794
|
-
giveUp: counted.giveUp,
|
|
924
|
+
verdict: verdictNow,
|
|
925
|
+
latency: tried.at(-1)?.latency,
|
|
926
|
+
latencySource: tried.at(-1)?.latencySource,
|
|
927
|
+
ceiling: Number(this.config.healthMaxDelayMs ?? 400),
|
|
928
|
+
attempt: attempts,
|
|
929
|
+
attempts: tried,
|
|
930
|
+
attemptLimit: attempts,
|
|
931
|
+
giveUp: true,
|
|
795
932
|
at: new Date().toISOString(),
|
|
796
933
|
}
|
|
797
934
|
this.health = report
|
|
798
|
-
|
|
799
|
-
this.log(`round ok on ${current} (${latency ?? '?'} ms, ${Object.keys(results).join('/')})`)
|
|
800
|
-
void this.runSurveyTick()
|
|
801
|
-
return report
|
|
802
|
-
}
|
|
803
|
-
if (tooSlow) {
|
|
804
|
-
this.log(`round slow on ${current}: ${latency} ms > ${ceiling} ms ceiling (${counted.strikes}/${counted.limit})`)
|
|
805
|
-
} else {
|
|
806
|
-
this.log(
|
|
807
|
-
`round bad on ${current} ${counted.strikes}/${counted.limit}: ${judged.failed.join(',') || 'no-answer'}` +
|
|
808
|
-
(judged.limited.length > 0 ? ` (limited: ${judged.limited.join(',')})` : ''),
|
|
809
|
-
)
|
|
810
|
-
}
|
|
811
|
-
if (!counted.giveUp) return report
|
|
935
|
+
this.log(`${attempts} attempts all failed on ${current}; searching every unblocked node`)
|
|
812
936
|
return await this.switchAfterStrikes(report, plan, options)
|
|
813
937
|
} finally {
|
|
814
938
|
this.healthRunning = false
|
|
@@ -816,12 +940,22 @@ export class Runtime {
|
|
|
816
940
|
}
|
|
817
941
|
|
|
818
942
|
/**
|
|
819
|
-
* Switch away from a node
|
|
943
|
+
* Switch away from a node that failed every attempt in its round.
|
|
944
|
+
*
|
|
945
|
+
* Every unblocked node is measured, then the best one is chosen. Nothing is capped by default:
|
|
946
|
+
* the point of a switch is to find the best exit that exists right now, and a cap turns that
|
|
947
|
+
* into "the best of the first twelve", which on a 54-node subscription can silently pick a
|
|
948
|
+
* worse node than one further down the list. `healthSwitchCandidates` still exists as an
|
|
949
|
+
* operator escape hatch for a huge subscription, but its default is 0 (everything).
|
|
950
|
+
*
|
|
951
|
+
* "Best" is decided from this round's measurements, in this order:
|
|
952
|
+
*
|
|
953
|
+
* 1. usable (no gating probe failed) before anything else;
|
|
954
|
+
* 2. the lowest warm Google latency — this is the number the ceiling talks about, and the
|
|
955
|
+
* fastest working node is what "最优" means here;
|
|
956
|
+
* 3. fewer failed probes, then a quota-limited node before an unreachable one, as tie-breaks.
|
|
820
957
|
*
|
|
821
|
-
* The
|
|
822
|
-
* a 54-node subscription cannot be probed for real inside one round without spending minutes
|
|
823
|
-
* on nodes that answered worst last time. The node that just failed is excluded from its own
|
|
824
|
-
* replacement, which is the difference between "we tried" and "we picked it again".
|
|
958
|
+
* The node that just failed is not a candidate for its own replacement.
|
|
825
959
|
*
|
|
826
960
|
* Busy-line handling: a switch tears down in-flight connections. When the line is carrying
|
|
827
961
|
* work the switch waits for the next round unless `switchWhileBusy` is on — a broken node that
|
|
@@ -829,14 +963,14 @@ export class Runtime {
|
|
|
829
963
|
*
|
|
830
964
|
* @param report - the failing round.
|
|
831
965
|
* @param plan - the probe plan.
|
|
832
|
-
* @param options - `
|
|
966
|
+
* @param options - `bypassBusy` skips the busy gate.
|
|
833
967
|
* @returns the round report with the switch result attached.
|
|
834
968
|
*/
|
|
835
969
|
async switchAfterStrikes(report, plan, options = {}) {
|
|
836
970
|
const traffic = await this.core.connections().catch(() => undefined)
|
|
837
971
|
const limit = Number(this.config.reselectIdleConnections ?? 2)
|
|
838
|
-
// `force` means "run this round now", not "ignore in-flight work": the two were conflated
|
|
839
|
-
//
|
|
972
|
+
// `force` means "run this round now", not "ignore in-flight work": the two were conflated in
|
|
973
|
+
// an earlier draft and an explicit check aborted a download. Only `bypassBusy` (or the
|
|
840
974
|
// configuration switch) may interrupt traffic.
|
|
841
975
|
const bypassBusy = options.bypassBusy === true || this.config.switchWhileBusy === true
|
|
842
976
|
if (!bypassBusy && traffic !== undefined && traffic.count > limit) {
|
|
@@ -845,36 +979,62 @@ export class Runtime {
|
|
|
845
979
|
}
|
|
846
980
|
|
|
847
981
|
const group = await this.core.group()
|
|
848
|
-
|
|
849
|
-
|
|
982
|
+
// `group.all` is what the core carries, which already excludes blocked nodes — the blocklist
|
|
983
|
+
// is applied as the provider's `exclude-filter`, so a hidden node never enters the table.
|
|
984
|
+
// Filtering again here is belt-and-braces for a table that was built before a blocklist edit.
|
|
985
|
+
const candidates = group.all.filter(
|
|
986
|
+
(name) => name !== 'DIRECT' && name !== 'REJECT' && name !== report.node && !isBlocked(name, this.config.blocklist),
|
|
987
|
+
)
|
|
988
|
+
const cap = Number(this.config.healthSwitchCandidates ?? 0)
|
|
850
989
|
const ordered = cap > 0 ? candidates.slice(0, cap) : candidates
|
|
851
990
|
const startedAt = Date.now()
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
991
|
+
this.log(`measuring ${ordered.length} candidate node(s) for a replacement`)
|
|
992
|
+
|
|
993
|
+
// Measured one at a time, reusing `measureNode` so a candidate is judged exactly like the
|
|
994
|
+
// live node was — same probes, same ceiling, same warm latency. The budget is generous
|
|
995
|
+
// because this path runs once per failure, not on every tick.
|
|
996
|
+
const rows = []
|
|
997
|
+
for (const name of ordered) {
|
|
998
|
+
const measured = await this.measureNode(name, plan)
|
|
999
|
+
if (measured === undefined) continue
|
|
1000
|
+
rows.push({ name, ...measured })
|
|
1001
|
+
this.healthRows.set(name, { results: measured.results, verdict: measured.verdict, at: Date.now() })
|
|
1002
|
+
}
|
|
1003
|
+
this.lastMatrix = rows.map((row) => ({ name: row.name, results: row.results }))
|
|
1004
|
+
|
|
1005
|
+
// Usable first, then fastest warm latency, then fewest failures, then a limited node before
|
|
1006
|
+
// an unreachable one. Missing latency sorts last among usable nodes: a node whose speed could
|
|
1007
|
+
// not be measured is not the one to prefer.
|
|
1008
|
+
const rank = (row) => [
|
|
1009
|
+
row.verdict?.usable === true ? 0 : 1,
|
|
1010
|
+
typeof row.latency === 'number' ? row.latency : Number.POSITIVE_INFINITY,
|
|
1011
|
+
(row.verdict?.failed ?? []).length,
|
|
1012
|
+
(row.verdict?.blocked ?? []).length,
|
|
1013
|
+
]
|
|
1014
|
+
rows.sort((a, b) => {
|
|
1015
|
+
const ra = rank(a)
|
|
1016
|
+
const rb = rank(b)
|
|
1017
|
+
for (let i = 0; i < ra.length; i += 1) {
|
|
1018
|
+
if (ra[i] !== rb[i]) return ra[i] - rb[i]
|
|
1019
|
+
}
|
|
1020
|
+
return a.name.localeCompare(b.name)
|
|
859
1021
|
})
|
|
860
|
-
const best =
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
this.lastMatrix = matrix.rows.map((row) => ({ name: row.name, results: row.results }))
|
|
865
|
-
// `usable` here means "no hard failure". A degraded node (quota spent, tunnel fine) is a
|
|
866
|
-
// legitimate replacement: with every exit address out of GitHub quota, insisting on a
|
|
867
|
-
// quota-clean node leaves the plugin on the node it just gave up on.
|
|
1022
|
+
const best = rows[0]
|
|
1023
|
+
const tested = rows.length
|
|
1024
|
+
const elapsedMs = Date.now() - startedAt
|
|
1025
|
+
|
|
868
1026
|
if (best === undefined || best.verdict?.usable !== true) {
|
|
869
1027
|
this.lastSwitch = {
|
|
870
1028
|
state: 'no-alternative',
|
|
871
1029
|
from: report.node,
|
|
872
1030
|
at: new Date().toISOString(),
|
|
873
|
-
tested
|
|
874
|
-
elapsedMs
|
|
1031
|
+
tested,
|
|
1032
|
+
elapsedMs,
|
|
1033
|
+
// Every candidate's reason, so "no alternative" can be audited instead of trusted.
|
|
1034
|
+
rejected: rows.slice(0, 8).map((row) => ({ name: row.name, failed: row.verdict?.failed ?? [], latency: row.latency })),
|
|
875
1035
|
}
|
|
876
|
-
this.log(`no usable alternative to ${report.node} out of ${
|
|
877
|
-
return { ...report, state: 'no-alternative', tested
|
|
1036
|
+
this.log(`no usable alternative to ${report.node} out of ${tested} tested`)
|
|
1037
|
+
return { ...report, state: 'no-alternative', tested, elapsedMs }
|
|
878
1038
|
}
|
|
879
1039
|
|
|
880
1040
|
await this.core.select(best.name)
|
|
@@ -886,13 +1046,22 @@ export class Runtime {
|
|
|
886
1046
|
to: best.name,
|
|
887
1047
|
at: new Date().toISOString(),
|
|
888
1048
|
failed: report.verdict?.failed ?? [],
|
|
889
|
-
limited: report.verdict?.limited ?? [],
|
|
890
1049
|
degraded: best.verdict?.degraded === true,
|
|
891
|
-
|
|
892
|
-
|
|
1050
|
+
latency: best.latency,
|
|
1051
|
+
tested,
|
|
1052
|
+
elapsedMs,
|
|
1053
|
+
}
|
|
1054
|
+
this.log(`switched ${report.node} -> ${best.name} (${best.latency ?? '?'} ms) after ${report.attemptLimit ?? report.attempts?.length ?? 3} failed attempts`)
|
|
1055
|
+
return {
|
|
1056
|
+
...report,
|
|
1057
|
+
state: 'switched',
|
|
1058
|
+
from: report.node,
|
|
1059
|
+
to: best.name,
|
|
1060
|
+
switchedTo: best.name,
|
|
1061
|
+
toLatency: best.latency,
|
|
1062
|
+
tested,
|
|
1063
|
+
elapsedMs,
|
|
893
1064
|
}
|
|
894
|
-
this.log(`switched ${report.node} -> ${best.name} after ${report.strikes} bad rounds`)
|
|
895
|
-
return { ...report, state: 'switched', from: report.node, to: best.name, switchedTo: best.name, tested: matrix.tested }
|
|
896
1065
|
}
|
|
897
1066
|
|
|
898
1067
|
/**
|
|
@@ -1736,8 +1905,13 @@ export class Runtime {
|
|
|
1736
1905
|
health: {
|
|
1737
1906
|
enabled: this.config.autoSwitch !== false && this.config.healthRoundSeconds > 0,
|
|
1738
1907
|
everySeconds: this.config.healthRoundSeconds,
|
|
1908
|
+
/** Consecutive attempts inside one round before the node is given up on. */
|
|
1909
|
+
attempts: this.config.healthAttempts,
|
|
1739
1910
|
strikeLimit: this.watch.strikeLimit,
|
|
1740
1911
|
maxDelayMs: this.config.healthMaxDelayMs,
|
|
1912
|
+
baselineProbe: this.config.healthBaselineProbe,
|
|
1913
|
+
/** 0 means "measure every unblocked node when switching". */
|
|
1914
|
+
switchCandidates: this.config.healthSwitchCandidates,
|
|
1741
1915
|
surveyEvery: this.config.healthSurveyEvery,
|
|
1742
1916
|
survey: this.lastSurvey ?? null,
|
|
1743
1917
|
lastRound: this.health ?? null,
|
package/lib/core.js
CHANGED
|
@@ -708,6 +708,24 @@ export class Core {
|
|
|
708
708
|
*/
|
|
709
709
|
async remeasure(spec, options = {}) {
|
|
710
710
|
if (this.probePort === undefined || spec === undefined) return undefined
|
|
711
|
+
// The PROBE group must already point at the node under test, and the only caller of
|
|
712
|
+
// `remeasure` is the latency measurement right after `probeNodeReal`. Switching again here
|
|
713
|
+
// would be harmless but would also hide the dependency, so it is asserted instead: a caller
|
|
714
|
+
// that measures latency without first probing that node gets a warning, not a number that
|
|
715
|
+
// silently belongs to a different node.
|
|
716
|
+
if (options.expectNode !== undefined && options.expectNode !== null) {
|
|
717
|
+
try {
|
|
718
|
+
const group = await this.probeGroup()
|
|
719
|
+
if (group.now !== options.expectNode) {
|
|
720
|
+
this.log(
|
|
721
|
+
`remeasure: PROBE group is on ${group.now ?? '(none)'} but the caller expects ${options.expectNode}; re-pointing it`,
|
|
722
|
+
)
|
|
723
|
+
await this.selectProbe(options.expectNode)
|
|
724
|
+
}
|
|
725
|
+
} catch (error) {
|
|
726
|
+
this.log(`remeasure: could not confirm the probe group: ${error?.message ?? error}`)
|
|
727
|
+
}
|
|
728
|
+
}
|
|
711
729
|
const results = await runProbes(this.probePort, [spec], options)
|
|
712
730
|
return results[spec.id]
|
|
713
731
|
}
|
package/lib/skill.js
CHANGED
|
@@ -55,7 +55,8 @@ curl -sS -m 8 http://127.0.0.1:<宿主端口>/clash-proxy/status
|
|
|
55
55
|
| \`routingHealthy\` | 策略 + 内核同时成立 | \`true\` |
|
|
56
56
|
| \`node\` | 当前出口 | 具体节点名,不是 \`DIRECT\` |
|
|
57
57
|
| \`health.lastRound.state\` | 最近一轮真实探测结论 | \`ok\` / \`degraded\` |
|
|
58
|
-
| \`health.lastRound.
|
|
58
|
+
| \`health.lastRound.attempt\` | 本轮第几次尝试通过的 | 1 或 2;3 表示三次都不合格 |
|
|
59
|
+
| \`health.lastRound.attemptLimit\` | 一轮内最多试几次 | 3 |
|
|
59
60
|
|
|
60
61
|
\`routingHealthy: true\` 就**什么都不要做**,直接跑原命令。
|
|
61
62
|
|
|
@@ -124,13 +125,19 @@ clash_proxy action=select node=<精确节点名>
|
|
|
124
125
|
|
|
125
126
|
## 四、自动切换已经在跑,不要抢它
|
|
126
127
|
|
|
127
|
-
插件自己每 30
|
|
128
|
-
|
|
128
|
+
插件自己每 30 秒做一轮。**一轮之内**会连续试当前节点最多 3 次:
|
|
129
|
+
|
|
130
|
+
1. 通过它发真请求(基础连通 204、GitHub API 连配额、git 拉取)+ 测 Google 延迟;
|
|
131
|
+
2. 不合格就**立刻**再试一次,不合格再试第三次——不等下一个 30 秒;
|
|
132
|
+
3. 只要任何一次合格就保持,剩下的次数不浪费;
|
|
133
|
+
4. 三次都不合格,就把**所有未被屏蔽的节点**各测一遍,切到「可用且真实延迟最低」的那个。
|
|
129
134
|
|
|
130
135
|
所以:
|
|
131
136
|
|
|
132
|
-
- 用户问「为什么还没换」,先看 \`health.lastRound.
|
|
133
|
-
-
|
|
137
|
+
- 用户问「为什么还没换」,先看 \`health.lastRound.attempt\`:1 或 2 表示已经通过;3 表示三次全败、正在切换。
|
|
138
|
+
- 不合格 = **不可用**(某个门槛探针没通)**或真实延迟过高**(超过 \`health.maxDelayMs\`,默认 400 ms)。
|
|
139
|
+
- 三次重试是**同一轮内连续**的,所以坏节点几秒内就会被处理,不需要手动介入。
|
|
140
|
+
- 手动换节点会打断正在进行的切换搜索,没必要别动它。
|
|
134
141
|
- 要立刻验证,用 \`action=health\` 强制跑一轮并看明细。
|
|
135
142
|
|
|
136
143
|
## 五、按症状查
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin. Every 30 seconds the live node gets up to three immediate real-request attempts (base connectivity, GitHub quota, git fetch, Google latency median under a 400 ms ceiling); after three failures every unblocked node is measured and the fastest usable one is selected.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
7
7
|
"dsh-plugin",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"locale/*.json",
|
|
35
35
|
"icon.svg",
|
|
36
36
|
"README.md",
|
|
37
|
-
"CHANGELOG-0.
|
|
37
|
+
"CHANGELOG-0.9.0.md",
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"engines": {
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "node test/regression-070.mjs",
|
|
71
71
|
"test:legacy": "node test/regression-063.mjs",
|
|
72
|
-
"test:e2e": "node test/e2e-
|
|
72
|
+
"test:e2e": "node test/e2e-090.mjs"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/CHANGELOG-0.8.0.md
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# 0.8.0 · 一个循环、30 秒、延迟进判定;插件自带技能
|
|
2
|
-
|
|
3
|
-
> 上一版 `0.7.0` · 本版 `0.8.0`
|
|
4
|
-
|
|
5
|
-
## 为什么改
|
|
6
|
-
|
|
7
|
-
0.7.0 有两个定时器做同一件事,而且延迟完全不参与判定:
|
|
8
|
-
|
|
9
|
-
| 0.7.0 的字段 | 实际行为 |
|
|
10
|
-
|---|---|
|
|
11
|
-
| `reselectMinutes: 15` | 每 15 分钟按能力重挑一次节点 |
|
|
12
|
-
| `healthRoundMinutes: 2` | 每 2 分钟真实探测当前节点 |
|
|
13
|
-
| — | 延迟只显示在面板上,**从不影响去留** |
|
|
14
|
-
|
|
15
|
-
后果:一个 1 800 ms 的节点每次都通过探测,于是被永久保留,而所有走它的请求都慢得像卡住。
|
|
16
|
-
两个循环还会互相清零计数,同一个节点得到两份结论。
|
|
17
|
-
|
|
18
|
-
## 改了什么
|
|
19
|
-
|
|
20
|
-
### 1. 合并成一个循环
|
|
21
|
-
|
|
22
|
-
`reselect` 不再是独立定时器,手动 `action=reselect` 变成「立刻跑一轮」。
|
|
23
|
-
删掉了 `scheduleReselect` / `stopReselect`,只留 `scheduleHealthRound`。
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
每 30 秒:
|
|
27
|
-
├─ 通过当前节点发真实请求(gstatic 204 / GitHub 配额 / git 拉取)
|
|
28
|
-
├─ 测 Google 延迟(warm)
|
|
29
|
-
├─ 可用 且 延迟 ≤ 400 ms → 保持,strikes = 0
|
|
30
|
-
├─ 不可用 或 延迟超阈值 → strikes += 1
|
|
31
|
-
└─ strikes ≥ 3 → 排除当前节点,按真实探测结果切到最优
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
| 字段 | 默认 | 说明 |
|
|
35
|
-
|---|---|---|
|
|
36
|
-
| `healthRoundSeconds` | **30** | 轮询间隔(秒)。0 = 关闭 |
|
|
37
|
-
| `healthStrikeLimit` | 3 | 连续几轮不合格才切 |
|
|
38
|
-
| `healthMaxDelayMs` | **400** | 延迟阈值;0 = 只看连通性 |
|
|
39
|
-
| `healthBaselineProbe` | **google** | 延迟取哪个探针 |
|
|
40
|
-
| `healthSurveyEvery` | 20 | 每 N 轮后台巡测其他节点(30 秒间隔下约 10 分钟) |
|
|
41
|
-
|
|
42
|
-
旧的 `healthRoundMinutes` 会自动迁移成秒(2 分钟 → 120 秒),不会静默回落到 30 秒默认。
|
|
43
|
-
|
|
44
|
-
### 2. 延迟改成 Google,且要 warm
|
|
45
|
-
|
|
46
|
-
**基准是 Google 的 `generate_204`**:静态 204,没有 API 处理逻辑,是最接近「这个节点离你多远」的量。
|
|
47
|
-
|
|
48
|
-
但直接测出来是错的,实测两次修正:
|
|
49
|
-
|
|
50
|
-
| 错法 | 实测 | 真因 |
|
|
51
|
-
|---|---|---|
|
|
52
|
-
| 用所有探针的**总和** | 健康节点 1 286 ms,其中 gstatic 只占 90 ms | GitHub 自己的处理时间和三次 TLS 握手都在总和里,节点不背这个锅 |
|
|
53
|
-
| 用**第一次**请求 | 同一节点首轮 513 ms,之后 82 ms | 每个探针都是 `Connection: close`,首次要付 DNS + TCP + TLS;真实流量是复用的 |
|
|
54
|
-
|
|
55
|
-
所以延迟 = **Google 探针的第二次测量**。e2e 实测:`warm 149ms (cold 240ms)`,阈值 400 ms 内保持不动。
|
|
56
|
-
|
|
57
|
-
### 3. Google 不通 ≠ 节点慢
|
|
58
|
-
|
|
59
|
-
Google 不是门槛探针(`gating: false`)。它不通时:
|
|
60
|
-
|
|
61
|
-
- 不判 `slow`,不发明一个延迟;
|
|
62
|
-
- `latencySource` 标为 `unreachable`,面板能解释;
|
|
63
|
-
- 节点只按门槛探针判去留。
|
|
64
|
-
|
|
65
|
-
否则一个 Google 被限、但 GitHub/git 全通的节点会被当成慢节点切走。
|
|
66
|
-
|
|
67
|
-
### 4. 插件自带技能
|
|
68
|
-
|
|
69
|
-
原来这套排障知识只写在 README 和工具描述里,真正需要它的时候没人去翻。
|
|
70
|
-
现在通过 `ctx.skills.register()` 注册成技能 `clash-proxy-egress`,随插件加载/卸载:
|
|
71
|
-
|
|
72
|
-
| 项 | 值 |
|
|
73
|
-
|---|---|
|
|
74
|
-
| 名字 | `clash-proxy-egress` |
|
|
75
|
-
| 何时触发 | 境外命令失败(git/curl/npm/pip/web_fetch)、问代理通不通、问为什么某节点慢、要指定地区出口 |
|
|
76
|
-
| 内容 | 取证三条命令 → 修复阶梯(start → select → restart → refresh,按代价从小到大)→ 按真实探测挑节点 → 不要抢自动切换 → 症状对照表 |
|
|
77
|
-
| 长度 | 3 051 字符,含 8 个代码围栏 |
|
|
78
|
-
|
|
79
|
-
技能里明确写了两条最常犯的错:
|
|
80
|
-
|
|
81
|
-
1. **不要开桌面 Clash Verge 或改系统代理** —— 会和插件抢同一个 dispatcher,表现是「时通时不通」;
|
|
82
|
-
2. **`strikes` 没到上限时不要手动换节点** —— 会把计数清零,坏节点永远攒不满 3 轮。
|
|
83
|
-
|
|
84
|
-
### 5. 新增 `action=restart`
|
|
85
|
-
|
|
86
|
-
「内核在跑但控制 API 不应答」时的一条命令,不用先 stop 再 start。
|
|
87
|
-
|
|
88
|
-
## 验收
|
|
89
|
-
|
|
90
|
-
```
|
|
91
|
-
node test/regression-070.mjs → 106 passed, 0 failed
|
|
92
|
-
node test/regression-063.mjs → 31 passed, 0 failed
|
|
93
|
-
node test/e2e-080.mjs → 21 passed, 0 failed(真内核 + 真订阅 + 真请求)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
e2e 真实输出:
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
round#1: state=ok latency=149ms source=warm ceiling=400 strikes=0
|
|
100
|
-
warm 149ms (cold 240ms) → 用第二次测量
|
|
101
|
-
gstatic 204 / github 200 / git 200
|
|
102
|
-
|
|
103
|
-
strict round (ceiling=1ms): state=slow latency=184ms strikes=1
|
|
104
|
-
前两轮不切换: slow/1 slow/2
|
|
105
|
-
round3: state=switched from=🇸🇬 新加坡01 to=🇺🇸 美国02 tested=7
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## 一个被测试抓住的判据错误(留档)
|
|
109
|
-
|
|
110
|
-
第一版把 `verdict.total`(所有门槛探针耗时之和)当延迟比 400 ms,e2e 立刻报
|
|
111
|
-
`健康节点首轮通过: slow 1286ms`。改用 Google 单探针后又报 `slow 513ms`,
|
|
112
|
-
再查才发现那是冷启动。两次都是判据错,不是节点慢——**如果没在真机上跑一遍,
|
|
113
|
-
上线后会把整批健康节点判成慢节点并疯狂切换**。
|
|
114
|
-
|
|
115
|
-
## 遗留
|
|
116
|
-
|
|
117
|
-
- 面板新增的两个字段(`healthMaxDelayMs` / `healthSurveyEvery`)已接进 `client.js`,
|
|
118
|
-
但**没有在真浏览器里看过渲染**(本轮只跑了逻辑测试)。
|
|
119
|
-
- `healthSurveyEvery` 的后台巡测只做了单元级验证,真机轮次里被设为 0 跳过,
|
|
120
|
-
以避免 e2e 结果受巡测干扰。
|