cfpilot 0.15.4 → 0.15.7

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/dist/cli.js CHANGED
@@ -87,7 +87,7 @@ var VERSION, NAME;
87
87
  var init_version = __esm({
88
88
  "src/shared/version.ts"() {
89
89
  "use strict";
90
- VERSION = "0.15.4";
90
+ VERSION = "0.15.7";
91
91
  NAME = "cfpilot";
92
92
  }
93
93
  });
@@ -5477,10 +5477,15 @@ async function runScan(options) {
5477
5477
  });
5478
5478
  }
5479
5479
  }
5480
- const stage2 = pickWithDiversity(
5481
- wsFiltered.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency),
5482
- speedLimit
5480
+ const rankedByLatency = wsFiltered.sort(
5481
+ (a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency
5483
5482
  );
5483
+ let stage2;
5484
+ if (options.twoStageSpeed && !options.skipSpeed) {
5485
+ stage2 = await coarsePreRank(options, rankedByLatency, speedLimit, report, strictProbePath);
5486
+ } else {
5487
+ stage2 = pickWithDiversity(rankedByLatency, speedLimit);
5488
+ }
5484
5489
  let speedResults;
5485
5490
  const speedMode = options.speedMode ?? "probe";
5486
5491
  if (options.skipSpeed) {
@@ -5683,6 +5688,83 @@ function formatCopyable(entries) {
5683
5688
  function formatEntries(entries) {
5684
5689
  return entries.map((e) => `${formatHost(e.ip)}:${e.port}#${preferredRemark(e)}`);
5685
5690
  }
5691
+ function rankByCoarseSpeed(items, coarse, limit) {
5692
+ const sorted = [...items].sort(
5693
+ (a, b) => (coarse.get(b.ip) ?? 0) - (coarse.get(a.ip) ?? 0)
5694
+ );
5695
+ if (sorted.length <= limit) return sorted;
5696
+ return pickWithDiversity(sorted, limit);
5697
+ }
5698
+ async function coarsePreRank(options, candidates, speedLimit, report, probePath) {
5699
+ const limit = Math.max(1, options.coarseSpeedLimit ?? COARSE_SPEED_DEFAULTS.limit);
5700
+ const poolInput = pickWithDiversity(candidates, limit);
5701
+ const startedAt = Date.now();
5702
+ const budgetMs = options.coarseBudgetMs ?? COARSE_SPEED_DEFAULTS.budgetMs;
5703
+ const coarse = /* @__PURE__ */ new Map();
5704
+ let done = 0;
5705
+ let budgetHit = false;
5706
+ report({ type: "stage", stage: 2, name: "\u5168\u91CF\u7C97\u7B5B\uFF08\u77ED\u6D4B\u7C97\u6392\uFF09", total: poolInput.length });
5707
+ await pool(poolInput, 1, async (item) => {
5708
+ if (Date.now() - startedAt > budgetMs) {
5709
+ if (!budgetHit) {
5710
+ budgetHit = true;
5711
+ report({
5712
+ type: "progress",
5713
+ stage: 2,
5714
+ done,
5715
+ total: poolInput.length,
5716
+ message: `\u7C97\u7B5B\u5DF2\u8FBE\u603B\u9884\u7B97 ${Math.round(budgetMs / 1e3)}s\uFF0C\u5269\u4F59\u5019\u9009\u6309\u5EF6\u8FDF\u515C\u5E95`
5717
+ });
5718
+ }
5719
+ return;
5720
+ }
5721
+ let speed = 0;
5722
+ try {
5723
+ const common = {
5724
+ ip: item.ip,
5725
+ port: options.port,
5726
+ connections: options.coarseConnections ?? COARSE_SPEED_DEFAULTS.connections,
5727
+ durationMs: options.coarseDurationMs ?? COARSE_SPEED_DEFAULTS.durationMs,
5728
+ warmupMs: COARSE_SPEED_DEFAULTS.warmupMs,
5729
+ windowMs: COARSE_SPEED_DEFAULTS.windowMs,
5730
+ timeoutMs: options.coarseTimeoutMs ?? COARSE_SPEED_DEFAULTS.timeoutMs
5731
+ };
5732
+ if ((options.speedMode ?? "probe") === "url") {
5733
+ const parsed = parseSpeedUrl(
5734
+ options.speedUrl ?? DEFAULT_SPEED_URL,
5735
+ schemeForPort(options.port)
5736
+ );
5737
+ const one = await measureThroughput({
5738
+ ...common,
5739
+ sniHost: parsed.host,
5740
+ requestHost: parsed.host,
5741
+ path: withBytes(parsed, options.speedBytes ?? 104857600)
5742
+ });
5743
+ if (one.ok) speed = one.steadyMBps;
5744
+ } else {
5745
+ const one = await measureProbeThroughput({
5746
+ ...common,
5747
+ host: options.host,
5748
+ bytes: options.speedBytes ?? 5 * 1024 * 1024,
5749
+ path: probePath,
5750
+ token: options.uuid
5751
+ });
5752
+ if (one.ok) speed = one.steadyMBps;
5753
+ }
5754
+ } catch {
5755
+ }
5756
+ coarse.set(item.ip, speed);
5757
+ done++;
5758
+ report({
5759
+ type: "progress",
5760
+ stage: 2,
5761
+ done,
5762
+ total: poolInput.length,
5763
+ message: `\u7C97\u7B5B ${done}/${poolInput.length} \xB7 \u77ED\u6D4B ${speed.toFixed(1)} MB/s`
5764
+ });
5765
+ });
5766
+ return rankByCoarseSpeed(candidates, coarse, speedLimit);
5767
+ }
5686
5768
  function pickWithDiversity(ranked, top) {
5687
5769
  if (top <= 0) return [];
5688
5770
  const v4 = ranked.filter((item) => !item.ip.includes(":"));
@@ -5725,6 +5807,7 @@ function roundRobinBy(ranked, top, keyOf) {
5725
5807
  }
5726
5808
  return out;
5727
5809
  }
5810
+ var COARSE_SPEED_DEFAULTS;
5728
5811
  var init_scan = __esm({
5729
5812
  "src/scan/scan.ts"() {
5730
5813
  "use strict";
@@ -5733,6 +5816,22 @@ var init_scan = __esm({
5733
5816
  init_countries();
5734
5817
  init_unlock();
5735
5818
  init_ip_ranges();
5819
+ COARSE_SPEED_DEFAULTS = {
5820
+ /** 粗筛最多测多少个 101 通过候选(预算上限) */
5821
+ limit: 120,
5822
+ /** 单次粗筛测量时长:精测 6s 的 1/5 */
5823
+ durationMs: 1200,
5824
+ /** 丢弃的慢启动样本:短测不能沿用精测的 1s,否则几乎没有稳态样本 */
5825
+ warmupMs: 300,
5826
+ /** 结算窗口:与短测时长匹配 */
5827
+ windowMs: 300,
5828
+ /** 连接数:精测 8 条的 1/4,只求相对排序、不求绝对带宽 */
5829
+ connections: 2,
5830
+ /** 单次整体预算(含拨号 / TLS / 传输),失败候选最多占 3s */
5831
+ timeoutMs: 3e3,
5832
+ /** 整个粗筛阶段的总预算,到点停止派发,剩余候选按延迟兜底 */
5833
+ budgetMs: 24e4
5834
+ };
5736
5835
  }
5737
5836
  });
5738
5837
 
@@ -7346,6 +7445,16 @@ scan \u9009\u9879:
7346
7445
  \u5E26\u5BBD\u7531\u6574\u6761\u94FE\u8DEF\u5171\u4EAB\uFF1A\u5E76\u884C\u6D4B\u591A\u4E2A\u5019\u9009\u4F1A\u4E92\u76F8\u62A2\u5E26\u5BBD\uFF0C
7347
7446
  \u6BCF\u4E2A\u90FD\u53EA\u80FD\u6D4B\u5230 1/N\uFF0C\u6570\u503C\u666E\u904D\u504F\u4F4E\uFF08\u8001\u7248\u672C\u62A5\u51FA
7348
7447
  0.1 MB/s \u7684\u4E3B\u56E0\uFF09\u3002>1 \u53EA\u5728\u5343\u5146\u4EE5\u4E0A\u94FE\u8DEF\u624D\u6709\u610F\u4E49
7448
+ --two-stage-speed \u4E24\u8F6E\u6D4B\u901F\uFF08\u9ED8\u8BA4\u5173\u95ED\uFF09\uFF1A\u5BF9**\u5168\u90E8** 101 \u901A\u8FC7\u5019\u9009\u5148\u505A\u77ED\u6D4B\u7C97\u6392\uFF0C
7449
+ \u518D\u5BF9\u7C97\u6392\u524D --speed-limit \u540D\u505A\u5B8C\u6574\u7CBE\u6D4B
7450
+ \u89E3\u51B3\u300C\u63E1\u624B\u7A0D\u6162\u4F46\u4E0B\u884C\u660E\u663E\u66F4\u5FEB\u7684 IP \u88AB\u5EF6\u8FDF\u6392\u5E8F\u622A\u6389\u300D
7451
+ \u7C97\u7B5B\u4E32\u884C 1.2s \xD7 2 \u8FDE\u63A5\uFF0C\u6700\u591A 120 \u4E2A\u3001\u603B\u9884\u7B97 4 \u5206\u949F\uFF1B
7452
+ \u7C97\u6D4B\u901F\u5EA6\u53EA\u7528\u4E8E\u6392\u5E8F\uFF0C**\u4E0D\u5199\u8FDB\u7ED3\u679C**\uFF0C\u901F\u5EA6\u4ECD\u6765\u81EA\u7CBE\u6D4B
7453
+ --coarse-speed-limit <n> \u7C97\u7B5B\u5019\u9009\u4E0A\u9650\uFF0C\u9ED8\u8BA4 120
7454
+ --coarse-duration <ms> \u7C97\u7B5B\u5355\u6B21\u65F6\u957F\uFF0C\u9ED8\u8BA4 1200
7455
+ --coarse-conns <n> \u7C97\u7B5B\u8FDE\u63A5\u6570\uFF0C\u9ED8\u8BA4 2
7456
+ --coarse-timeout <ms> \u7C97\u7B5B\u5355\u6B21\u6574\u4F53\u9884\u7B97\uFF0C\u9ED8\u8BA4 3000
7457
+ --coarse-budget <ms> \u7C97\u7B5B\u9636\u6BB5\u603B\u9884\u7B97\uFF0C\u9ED8\u8BA4 240000\uFF08\u5230\u70B9\u5269\u4F59\u6309\u5EF6\u8FDF\u515C\u5E95\uFF09
7349
7458
  --retries <n> \u6BCF\u4E2A\u63A2\u6D4B\u7684\u5C1D\u8BD5\u6B21\u6570\uFF08\u542B\u9996\u6B21\uFF09\uFF0C\u9ED8\u8BA4 2
7350
7459
  \u771F\u673A\u5076\u53D1\u5931\u8D25\u7387 3~5%\uFF0C\u91CD\u8BD5\u53D6\u7B2C\u4E00\u6B21\u6210\u529F\u7684\u7ED3\u679C
7351
7460
  --no-verify \u9636\u6BB5\u4E8C\u53EA\u505A 101 \u63E1\u624B\uFF0C\u8DF3\u8FC7\u54CD\u5E94\u4F53\u6821\u9A8C
@@ -8769,6 +8878,14 @@ ${NAME} v${VERSION}
8769
8878
  probeLimit: flagNumber(args, "probe-limit", 120),
8770
8879
  probeTimeoutMs: flagNumber(args, "probe-timeout", 3e3),
8771
8880
  speedLimit: flagNumber(args, "speed-limit", 30),
8881
+ // 两轮测速:默认关闭(脚本行为不变),--two-stage-speed 开启。
8882
+ // 桌面版界面默认开启,两边语义一致:true = 全量短测粗排 + 前 N 精测。
8883
+ twoStageSpeed: flagBool(args, "two-stage-speed"),
8884
+ coarseSpeedLimit: flagNumber(args, "coarse-speed-limit", COARSE_SPEED_DEFAULTS.limit),
8885
+ coarseDurationMs: flagNumber(args, "coarse-duration", COARSE_SPEED_DEFAULTS.durationMs),
8886
+ coarseConnections: flagNumber(args, "coarse-conns", COARSE_SPEED_DEFAULTS.connections),
8887
+ coarseTimeoutMs: flagNumber(args, "coarse-timeout", COARSE_SPEED_DEFAULTS.timeoutMs),
8888
+ coarseBudgetMs: flagNumber(args, "coarse-budget", COARSE_SPEED_DEFAULTS.budgetMs),
8772
8889
  speedTimeoutMs: flagNumber(args, "speed-timeout", 12e3),
8773
8890
  speedBytes: flagNumber(args, "speed-bytes", 5 * 1024 * 1024),
8774
8891
  speedMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfpilot",
3
- "version": "0.15.4",
3
+ "version": "0.15.7",
4
4
  "description": "CFPilot —— Cloudflare Pages 代理部署与优选工具(交互菜单 + 子命令)",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",