cfpilot 0.50.0 → 0.60.0-beta.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/assets/cfpilot-kernel-VERSION +2 -2
- package/assets/control.js +28 -37
- package/assets/dataplane.js +14 -23
- package/assets/edge-relay/dashboard-worker.js +6 -0
- package/assets/edge-relay/dashboard.html +204 -0
- package/assets/edge-relay/schema.sql +26 -0
- package/assets/edge-relay/worker.js +890 -0
- package/assets/worker.js +32 -40
- package/dist/cli.js +1076 -99
- package/package.json +2 -2
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.
|
|
90
|
+
VERSION = "0.60.0-beta.1";
|
|
91
91
|
NAME = "cfpilot";
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -217,7 +217,7 @@ async function ask(question, options = {}) {
|
|
|
217
217
|
}
|
|
218
218
|
const suffix = fallback ? c.gray(` [${fallback}]`) : "";
|
|
219
219
|
stdout.write(`${c.cyan("?")} ${question}${suffix}${c.gray(": ")}`);
|
|
220
|
-
return await new Promise((
|
|
220
|
+
return await new Promise((resolve5) => {
|
|
221
221
|
let buf = "";
|
|
222
222
|
const wasRaw = stdin.isRaw;
|
|
223
223
|
const finish = (value) => {
|
|
@@ -225,7 +225,7 @@ async function ask(question, options = {}) {
|
|
|
225
225
|
stdin.setRawMode(wasRaw ?? false);
|
|
226
226
|
stdin.pause();
|
|
227
227
|
stdout.write("\n");
|
|
228
|
-
|
|
228
|
+
resolve5(value);
|
|
229
229
|
};
|
|
230
230
|
const onKey = (str, key) => {
|
|
231
231
|
if (key?.ctrl && key.name === "c") {
|
|
@@ -315,14 +315,14 @@ async function select(question, choices, options = {}) {
|
|
|
315
315
|
`);
|
|
316
316
|
hideCursor();
|
|
317
317
|
render(true);
|
|
318
|
-
return await new Promise((
|
|
318
|
+
return await new Promise((resolve5) => {
|
|
319
319
|
const wasRaw = stdin.isRaw;
|
|
320
320
|
const finish = (value) => {
|
|
321
321
|
stdin.removeListener("keypress", onKey);
|
|
322
322
|
stdin.setRawMode(wasRaw ?? false);
|
|
323
323
|
stdin.pause();
|
|
324
324
|
showCursor();
|
|
325
|
-
|
|
325
|
+
resolve5(value);
|
|
326
326
|
};
|
|
327
327
|
const move = (delta) => {
|
|
328
328
|
let next = cursor;
|
|
@@ -414,14 +414,14 @@ async function multiSelect(question, choices, options = {}) {
|
|
|
414
414
|
`);
|
|
415
415
|
hideCursor();
|
|
416
416
|
render(true);
|
|
417
|
-
return await new Promise((
|
|
417
|
+
return await new Promise((resolve5) => {
|
|
418
418
|
const wasRaw = stdin.isRaw;
|
|
419
419
|
const finish = () => {
|
|
420
420
|
stdin.removeListener("keypress", onKey);
|
|
421
421
|
stdin.setRawMode(wasRaw ?? false);
|
|
422
422
|
stdin.pause();
|
|
423
423
|
showCursor();
|
|
424
|
-
|
|
424
|
+
resolve5([...selected].sort((a, b) => a - b).map((i) => choices[i].value));
|
|
425
425
|
};
|
|
426
426
|
const onKey = (str, key) => {
|
|
427
427
|
if (key?.ctrl && key.name === "c") {
|
|
@@ -705,6 +705,68 @@ var init_cf_api = __esm({
|
|
|
705
705
|
async createKvNamespace(accountId, title) {
|
|
706
706
|
return await this.request("POST", `/accounts/${accountId}/storage/kv/namespaces`, { title });
|
|
707
707
|
}
|
|
708
|
+
/* ---------------------------------------------------------------- */
|
|
709
|
+
/* D1(盲中继 / 云监测台) */
|
|
710
|
+
/* ---------------------------------------------------------------- */
|
|
711
|
+
/**
|
|
712
|
+
* 创建 D1 数据库(POST /accounts/{id}/d1/database,权限 D1 Edit)。
|
|
713
|
+
*
|
|
714
|
+
* 盲中继/监测台的硬编码 D1 ID(别人账户的库)必须换成部署时动态建库。
|
|
715
|
+
* 返回 result.uuid 即 database_id,用于 Worker 的 d1 绑定与后续 query。
|
|
716
|
+
*/
|
|
717
|
+
async createD1Database(accountId, name) {
|
|
718
|
+
return await this.request("POST", `/accounts/${accountId}/d1/database`, { name });
|
|
719
|
+
}
|
|
720
|
+
/** 列出账号下的 D1 数据库(用于重名检测 / 复用) */
|
|
721
|
+
async listD1Databases(accountId, name) {
|
|
722
|
+
const query = name ? `?name=${encodeURIComponent(name)}` : "";
|
|
723
|
+
return await this.request("GET", `/accounts/${accountId}/d1/database${query}`);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* 在 D1 上执行一条 SQL(POST .../d1/database/{id}/query,body {sql})。
|
|
727
|
+
*
|
|
728
|
+
* 用于初始化 schema(CREATE TABLE IF NOT EXISTS 幂等)。DDL 无结果行,
|
|
729
|
+
* 但 Cloudflare 仍会返回 `{ results: [], success: true }`;非 2xx 会由
|
|
730
|
+
* readApiResponse 抛 CloudflareError,调用方据此判定初始化是否成功。
|
|
731
|
+
*/
|
|
732
|
+
async queryD1(accountId, databaseId, sql) {
|
|
733
|
+
const result = await this.request(
|
|
734
|
+
"POST",
|
|
735
|
+
`/accounts/${accountId}/d1/database/${encodeURIComponent(databaseId)}/query`,
|
|
736
|
+
{ sql }
|
|
737
|
+
);
|
|
738
|
+
return Array.isArray(result) ? result : [];
|
|
739
|
+
}
|
|
740
|
+
/* ---------------------------------------------------------------- */
|
|
741
|
+
/* Durable Objects(盲中继房间) */
|
|
742
|
+
/* ---------------------------------------------------------------- */
|
|
743
|
+
/**
|
|
744
|
+
* ⚠️ 已废弃:不要调用本方法创建 DO 命名空间。
|
|
745
|
+
*
|
|
746
|
+
* 真机实测(2026-11-17,测试账号):
|
|
747
|
+
* - 只传 {name, class} → `10100: class cannot be set without script`
|
|
748
|
+
* - 传 {name, script, class} → `10099: Creating new key-value backed Durable Object
|
|
749
|
+
* namespaces is no longer supported on this account. Please create a namespace
|
|
750
|
+
* using a `new_sqlite_classes` migration instead.`
|
|
751
|
+
*
|
|
752
|
+
* 正确做法:Worker 上传时带 `migrations: [{ tag, new_sqlite_classes: ['MeshRoom'] }]`,
|
|
753
|
+
* 平台会自动创建 SQLite 后端的 DO 命名空间。见 `uploadScript` 的 migrations 参数。
|
|
754
|
+
*
|
|
755
|
+
* 本方法仅为 API 完整性保留,调用即抛错,防止 Phase 2 误用走不通的路径。
|
|
756
|
+
*/
|
|
757
|
+
async createDoNamespace() {
|
|
758
|
+
throw new Error(
|
|
759
|
+
"\u624B\u52A8\u521B\u5EFA DO \u547D\u540D\u7A7A\u95F4\u5DF2\u4E0D\u53D7\u5E73\u53F0\u652F\u6301\uFF08\u9700 new_sqlite_classes migration\uFF09\u3002\u8BF7\u5728 uploadScript \u7684 migrations \u53C2\u6570\u91CC\u58F0\u660E new_sqlite_classes\uFF0C\u7531\u5E73\u53F0\u81EA\u52A8\u521B\u5EFA\u3002"
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
/** 列出账号下的 Durable Object 命名空间 */
|
|
763
|
+
async listDoNamespaces(accountId) {
|
|
764
|
+
const result = await this.request(
|
|
765
|
+
"GET",
|
|
766
|
+
`/accounts/${accountId}/workers/durable_objects/namespaces`
|
|
767
|
+
);
|
|
768
|
+
return Array.isArray(result) ? result : [];
|
|
769
|
+
}
|
|
708
770
|
/**
|
|
709
771
|
* 读取 KV 里的一个键值(不存在时返回 null)。
|
|
710
772
|
*
|
|
@@ -774,13 +836,27 @@ var init_cf_api = __esm({
|
|
|
774
836
|
async listScripts(accountId) {
|
|
775
837
|
return await this.request("GET", `/accounts/${accountId}/workers/scripts`);
|
|
776
838
|
}
|
|
777
|
-
/**
|
|
839
|
+
/**
|
|
840
|
+
* 上传 Worker 脚本(ES module,多段上传)。
|
|
841
|
+
*
|
|
842
|
+
* ## Durable Objects 声明方式(真机 2026-11-17 验证)
|
|
843
|
+
* 新版平台用 `exports` 声明 DO 类(declarative DO exports):
|
|
844
|
+
* `{ MeshRoom: { type:'durable-object', state:'created', storage:'sqlite' } }`
|
|
845
|
+
* 这是 wrangler 4 的默认路径。旧 `migrations` 数组在新版解析器下会报
|
|
846
|
+
* `cannot unmarshal array into Metadata.migrations of type reader.ActorMigrations`,
|
|
847
|
+
* 因此优先用 exports;只有显式传 migrations 且无 exports 时才走旧路径(兼容旧账号)。
|
|
848
|
+
*/
|
|
778
849
|
async uploadScript(accountId, scriptName, options) {
|
|
779
850
|
const metadata = {
|
|
780
851
|
main_module: options.mainModule,
|
|
781
852
|
compatibility_date: options.compatibilityDate,
|
|
782
853
|
bindings: options.bindings
|
|
783
854
|
};
|
|
855
|
+
if (options.doExports && Object.keys(options.doExports).length > 0) {
|
|
856
|
+
metadata.exports = options.doExports;
|
|
857
|
+
} else if (options.migrations && options.migrations.length > 0) {
|
|
858
|
+
metadata.migrations = options.migrations;
|
|
859
|
+
}
|
|
784
860
|
const form = new FormData();
|
|
785
861
|
form.set("metadata", new Blob([JSON.stringify(metadata)], { type: "application/json" }), "metadata.json");
|
|
786
862
|
form.set(
|
|
@@ -1021,6 +1097,26 @@ var init_cf_api = __esm({
|
|
|
1021
1097
|
form
|
|
1022
1098
|
);
|
|
1023
1099
|
}
|
|
1100
|
+
/**
|
|
1101
|
+
* 上传静态文件部署 Pages(监测面板 index.html 用)。
|
|
1102
|
+
*
|
|
1103
|
+
* 与 deployPagesWorker 的区别:这里直接把文件作为 multipart 段上传,
|
|
1104
|
+
* 不带 _worker.bundle。字段名即文件名(如 index.html)。
|
|
1105
|
+
* 表单结构参考 wrangler 的 pages deploy(branch + manifest + 文件段)。
|
|
1106
|
+
*/
|
|
1107
|
+
async deployPagesStatic(accountId, name, files) {
|
|
1108
|
+
const form = new FormData();
|
|
1109
|
+
form.set("branch", "main");
|
|
1110
|
+
form.set("manifest", "{}");
|
|
1111
|
+
for (const [path, content] of Object.entries(files)) {
|
|
1112
|
+
form.set(path, new Blob([content], { type: "text/html" }), path);
|
|
1113
|
+
}
|
|
1114
|
+
return await this.request(
|
|
1115
|
+
"POST",
|
|
1116
|
+
`/accounts/${accountId}/pages/projects/${name}/deployments`,
|
|
1117
|
+
form
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1024
1120
|
/** 查询 Pages 部署状态 */
|
|
1025
1121
|
async getPagesDeployments(accountId, name) {
|
|
1026
1122
|
return await this.request("GET", `/accounts/${accountId}/pages/projects/${name}/deployments`);
|
|
@@ -2267,6 +2363,7 @@ var init_kernel_remote = __esm({
|
|
|
2267
2363
|
// src/deploy/pages-deploy.ts
|
|
2268
2364
|
var pages_deploy_exports = {};
|
|
2269
2365
|
__export(pages_deploy_exports, {
|
|
2366
|
+
LEGACY_RESOURCE_DEFAULTS: () => LEGACY_RESOURCE_DEFAULTS,
|
|
2270
2367
|
MANIFEST_KEY: () => MANIFEST_KEY,
|
|
2271
2368
|
assertKvOwnership: () => assertKvOwnership,
|
|
2272
2369
|
deployOnce: () => deployOnce,
|
|
@@ -2274,6 +2371,7 @@ __export(pages_deploy_exports, {
|
|
|
2274
2371
|
detachAllPagesDomains: () => detachAllPagesDomains,
|
|
2275
2372
|
inspectKvOwnership: () => inspectKvOwnership,
|
|
2276
2373
|
listCfPilotNamespaces: () => listCfPilotNamespaces,
|
|
2374
|
+
migrateLegacyResourceDefaults: () => migrateLegacyResourceDefaults,
|
|
2277
2375
|
readManifest: () => readManifest
|
|
2278
2376
|
});
|
|
2279
2377
|
import { randomBytes as randomBytes2, randomUUID } from "node:crypto";
|
|
@@ -2408,6 +2506,19 @@ async function assertKvOwnership(client, accountId, namespaceId, options) {
|
|
|
2408
2506
|
\u26A0 \u5DF2\u6307\u5B9A\u5F3A\u5236\u8986\u76D6\uFF0C\u7EE7\u7EED\u6267\u884C\u2014\u2014\u539F\u5B9E\u4F8B\u7684\u914D\u7F6E\u5C06\u88AB\u672C\u6B21\u90E8\u7F72\u6539\u5199\u3002`);
|
|
2409
2507
|
return info;
|
|
2410
2508
|
}
|
|
2509
|
+
function migrateLegacyResourceDefaults(existing) {
|
|
2510
|
+
const config = { ...existing };
|
|
2511
|
+
const applied = [];
|
|
2512
|
+
for (const rule2 of LEGACY_RESOURCE_DEFAULTS) {
|
|
2513
|
+
const raw = config[rule2.field];
|
|
2514
|
+
if (raw === void 0 || raw === null) continue;
|
|
2515
|
+
const value = Number(raw);
|
|
2516
|
+
if (!Number.isFinite(value) || value !== rule2.legacy) continue;
|
|
2517
|
+
config[rule2.field] = rule2.next;
|
|
2518
|
+
applied.push({ field: rule2.field, from: rule2.legacy, to: rule2.next });
|
|
2519
|
+
}
|
|
2520
|
+
return { config, applied };
|
|
2521
|
+
}
|
|
2411
2522
|
async function writeEffectiveConfig(client, accountId, namespaceId, effective, options, warnings, log) {
|
|
2412
2523
|
let existing = {};
|
|
2413
2524
|
let raw;
|
|
@@ -2432,8 +2543,13 @@ async function writeEffectiveConfig(client, accountId, namespaceId, effective, o
|
|
|
2432
2543
|
warnings.push("\u65E2\u6709 KV \u914D\u7F6E\u4E0D\u662F\u5408\u6CD5 JSON\uFF0C\u5DF2\u6309\u7A7A\u914D\u7F6E\u91CD\u5199");
|
|
2433
2544
|
}
|
|
2434
2545
|
}
|
|
2546
|
+
const migrated = migrateLegacyResourceDefaults(existing);
|
|
2547
|
+
if (migrated.applied.length > 0) {
|
|
2548
|
+
const detail = migrated.applied.map((m) => `${m.field} ${m.from}\u2192${m.to}`).join("\u3001");
|
|
2549
|
+
log(`\xB7 \u5DF2\u5347\u7EA7\u65E7\u9ED8\u8BA4\u8D44\u6E90\u503C\uFF1A${detail}\uFF08\u5982\u9700\u5173\u95ED\u6216\u8C03\u6574\uFF0C\u53EF\u5728\u9762\u677F\u6539\u56DE\uFF09`);
|
|
2550
|
+
}
|
|
2435
2551
|
const merged = {
|
|
2436
|
-
...
|
|
2552
|
+
...migrated.config,
|
|
2437
2553
|
uuid: effective.uuid,
|
|
2438
2554
|
trojanPassword: effective.trojanPassword,
|
|
2439
2555
|
wsPath: effective.wsPath,
|
|
@@ -3073,7 +3189,7 @@ async function deployOnce(params) {
|
|
|
3073
3189
|
}
|
|
3074
3190
|
return null;
|
|
3075
3191
|
}
|
|
3076
|
-
var MANIFEST_KEY;
|
|
3192
|
+
var MANIFEST_KEY, LEGACY_RESOURCE_DEFAULTS;
|
|
3077
3193
|
var init_pages_deploy = __esm({
|
|
3078
3194
|
"src/deploy/pages-deploy.ts"() {
|
|
3079
3195
|
"use strict";
|
|
@@ -3084,6 +3200,10 @@ var init_pages_deploy = __esm({
|
|
|
3084
3200
|
init_version_util();
|
|
3085
3201
|
init_version();
|
|
3086
3202
|
MANIFEST_KEY = "CFP_DEPLOY_MANIFEST";
|
|
3203
|
+
LEGACY_RESOURCE_DEFAULTS = [
|
|
3204
|
+
{ field: "dataBudgetMB", legacy: 0, next: 512 },
|
|
3205
|
+
{ field: "relayRedialMax", legacy: 4, next: 2 }
|
|
3206
|
+
];
|
|
3087
3207
|
}
|
|
3088
3208
|
});
|
|
3089
3209
|
|
|
@@ -3767,6 +3887,26 @@ function isRegionGroup(code) {
|
|
|
3767
3887
|
function countryOfColo(colo) {
|
|
3768
3888
|
return coloToCountry.get(colo.toUpperCase()) ?? "";
|
|
3769
3889
|
}
|
|
3890
|
+
function colosCanUseIPv6(want) {
|
|
3891
|
+
if (want.size === 0) return true;
|
|
3892
|
+
for (const colo of want) {
|
|
3893
|
+
if (IPV6_ACTIVE_COLOS.has(colo.toUpperCase())) return true;
|
|
3894
|
+
}
|
|
3895
|
+
return false;
|
|
3896
|
+
}
|
|
3897
|
+
function colosOfCountryFilter(countries) {
|
|
3898
|
+
const out2 = /* @__PURE__ */ new Set();
|
|
3899
|
+
for (const code of normalizeCountryFilter(countries)) {
|
|
3900
|
+
for (const colo of COUNTRY_COLOS[code] ?? []) out2.add(colo);
|
|
3901
|
+
}
|
|
3902
|
+
for (const raw of countries) {
|
|
3903
|
+
const code = String(raw ?? "").trim().toUpperCase();
|
|
3904
|
+
if (!isKnownCountry(code) && !isRegionGroup(code) && code.length === 3 && countryOfColo(code) === "") {
|
|
3905
|
+
out2.add(code);
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
return out2;
|
|
3909
|
+
}
|
|
3770
3910
|
function isKnownCountry(code) {
|
|
3771
3911
|
return Object.prototype.hasOwnProperty.call(COUNTRY_COLOS, code.toUpperCase());
|
|
3772
3912
|
}
|
|
@@ -3795,7 +3935,7 @@ function normalizeCountryFilter(input) {
|
|
|
3795
3935
|
function coloCity(colo) {
|
|
3796
3936
|
return COLO_CITIES[colo.toUpperCase()] ?? "";
|
|
3797
3937
|
}
|
|
3798
|
-
var COUNTRY_COLOS, REGION_GROUPS, REGION_GROUP_NAMES, coloToCountry, SUPPORTED_COUNTRIES, COLO_CITIES;
|
|
3938
|
+
var COUNTRY_COLOS, REGION_GROUPS, REGION_GROUP_NAMES, coloToCountry, IPV6_ACTIVE_COLOS, SUPPORTED_COUNTRIES, COLO_CITIES;
|
|
3799
3939
|
var init_countries = __esm({
|
|
3800
3940
|
"src/scan/countries.ts"() {
|
|
3801
3941
|
"use strict";
|
|
@@ -3847,6 +3987,7 @@ var init_countries = __esm({
|
|
|
3847
3987
|
for (const [country, colos] of Object.entries(COUNTRY_COLOS)) {
|
|
3848
3988
|
for (const colo of colos) coloToCountry.set(colo, country);
|
|
3849
3989
|
}
|
|
3990
|
+
IPV6_ACTIVE_COLOS = /* @__PURE__ */ new Set(["AMS", "FRA", "SIN", "SJC"]);
|
|
3850
3991
|
SUPPORTED_COUNTRIES = Object.keys(COUNTRY_COLOS);
|
|
3851
3992
|
COLO_CITIES = {
|
|
3852
3993
|
HKG: "\u9999\u6E2F",
|
|
@@ -3922,15 +4063,15 @@ var init_countries = __esm({
|
|
|
3922
4063
|
|
|
3923
4064
|
// src/scan/true-probe.ts
|
|
3924
4065
|
import * as tls from "node:tls";
|
|
3925
|
-
import * as
|
|
4066
|
+
import * as crypto2 from "node:crypto";
|
|
3926
4067
|
function extractColo(text2) {
|
|
3927
4068
|
const match = /cf-ray:\s*[0-9a-f]+-([A-Z]{3})/i.exec(text2);
|
|
3928
4069
|
return match ? match[1].toUpperCase() : "";
|
|
3929
4070
|
}
|
|
3930
4071
|
function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
|
|
3931
|
-
return new Promise((
|
|
4072
|
+
return new Promise((resolve5) => {
|
|
3932
4073
|
const started = Date.now();
|
|
3933
|
-
const key =
|
|
4074
|
+
const key = crypto2.randomBytes(16).toString("base64");
|
|
3934
4075
|
let settled = false;
|
|
3935
4076
|
let received = "";
|
|
3936
4077
|
const finish = (result) => {
|
|
@@ -3941,7 +4082,7 @@ function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
|
|
|
3941
4082
|
socket.destroy();
|
|
3942
4083
|
} catch {
|
|
3943
4084
|
}
|
|
3944
|
-
|
|
4085
|
+
resolve5({ ...result, latencyMs: Date.now() - started });
|
|
3945
4086
|
};
|
|
3946
4087
|
const request3 = [
|
|
3947
4088
|
`GET ${path} HTTP/1.1`,
|
|
@@ -3996,7 +4137,7 @@ function probeWs101(ip, port, host, timeoutMs = 3e3, path = "/__edge_probe") {
|
|
|
3996
4137
|
});
|
|
3997
4138
|
}
|
|
3998
4139
|
function encodeWsFrame(payload, opcode = 2) {
|
|
3999
|
-
const mask =
|
|
4140
|
+
const mask = crypto2.randomBytes(4);
|
|
4000
4141
|
const masked = Buffer.alloc(payload.length);
|
|
4001
4142
|
for (let i = 0; i < payload.length; i++) {
|
|
4002
4143
|
masked[i] = payload[i] ^ mask[i % 4];
|
|
@@ -4044,9 +4185,9 @@ function decodeWsFrame(buf) {
|
|
|
4044
4185
|
return { frame, rest };
|
|
4045
4186
|
}
|
|
4046
4187
|
function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
4047
|
-
return new Promise((
|
|
4188
|
+
return new Promise((resolve5) => {
|
|
4048
4189
|
const started = Date.now();
|
|
4049
|
-
const key =
|
|
4190
|
+
const key = crypto2.randomBytes(16).toString("base64");
|
|
4050
4191
|
let settled = false;
|
|
4051
4192
|
let handshakeDone = false;
|
|
4052
4193
|
let buf = Buffer.alloc(0);
|
|
@@ -4059,7 +4200,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
|
4059
4200
|
socket.destroy();
|
|
4060
4201
|
} catch {
|
|
4061
4202
|
}
|
|
4062
|
-
|
|
4203
|
+
resolve5({ ...result, latencyMs: Date.now() - started });
|
|
4063
4204
|
};
|
|
4064
4205
|
const request3 = [
|
|
4065
4206
|
`GET ${path} HTTP/1.1`,
|
|
@@ -4170,7 +4311,7 @@ function probeWsPing(ip, port, host, timeoutMs = 5e3, path = "/__edge_probe") {
|
|
|
4170
4311
|
});
|
|
4171
4312
|
}
|
|
4172
4313
|
function probeTlsHandshake(ip, port, host, timeoutMs = 4e3, alpn = "http/1.1") {
|
|
4173
|
-
return new Promise((
|
|
4314
|
+
return new Promise((resolve5) => {
|
|
4174
4315
|
const started = Date.now();
|
|
4175
4316
|
let settled = false;
|
|
4176
4317
|
const finish = (result) => {
|
|
@@ -4181,7 +4322,7 @@ function probeTlsHandshake(ip, port, host, timeoutMs = 4e3, alpn = "http/1.1") {
|
|
|
4181
4322
|
socket.destroy();
|
|
4182
4323
|
} catch {
|
|
4183
4324
|
}
|
|
4184
|
-
|
|
4325
|
+
resolve5({ ip, tlsMs: result.tlsMs ?? Date.now() - started, ...result });
|
|
4185
4326
|
};
|
|
4186
4327
|
const expect = alpn === "h2" ? "h2" : "http/1.1";
|
|
4187
4328
|
const socket = tls.connect(
|
|
@@ -4222,7 +4363,7 @@ function measureThroughput(options) {
|
|
|
4222
4363
|
minBytes = 32 * 1024
|
|
4223
4364
|
} = options;
|
|
4224
4365
|
const connCount = Math.max(1, Math.min(16, connections));
|
|
4225
|
-
return new Promise((
|
|
4366
|
+
return new Promise((resolve5) => {
|
|
4226
4367
|
const started = Date.now();
|
|
4227
4368
|
let settled = false;
|
|
4228
4369
|
const meter = new WindowMeter({ startedAt: started, warmupMs, windowMs });
|
|
@@ -4254,7 +4395,7 @@ function measureThroughput(options) {
|
|
|
4254
4395
|
else if (totalBytes === 0) error = lastError || "\u672A\u6536\u5230\u6570\u636E";
|
|
4255
4396
|
else error = lastError || `\u8F7D\u8377\u4E0D\u8DB3\uFF08${totalBytes}/${minBytes} \u5B57\u8282\uFF09`;
|
|
4256
4397
|
}
|
|
4257
|
-
|
|
4398
|
+
resolve5({
|
|
4258
4399
|
ok,
|
|
4259
4400
|
bytes: totalBytes,
|
|
4260
4401
|
ms: now - started,
|
|
@@ -4396,7 +4537,7 @@ function buildVlessTunnelPayload(uuid, targetHost, targetPort, request3) {
|
|
|
4396
4537
|
]);
|
|
4397
4538
|
}
|
|
4398
4539
|
function buildTrojanTunnelPayload(password, targetHost, targetPort, request3) {
|
|
4399
|
-
const digest =
|
|
4540
|
+
const digest = crypto2.createHash("sha224").update(password).digest("hex");
|
|
4400
4541
|
const hostBuf = Buffer.from(targetHost, "utf8");
|
|
4401
4542
|
return Buffer.concat([
|
|
4402
4543
|
Buffer.from(digest + "\r\n", "ascii"),
|
|
@@ -4417,9 +4558,9 @@ function verifyTunnel(options) {
|
|
|
4417
4558
|
const { ip, port, host, wsPath, uuid, trojanPassword, targetHost = "baidu.com", targetPort = 80, timeoutMs = 8e3 } = options;
|
|
4418
4559
|
const payload = uuid ? buildVlessTunnelPayload(uuid, targetHost, targetPort, tunnelTargetRequest(targetHost)) : trojanPassword ? buildTrojanTunnelPayload(trojanPassword, targetHost, targetPort, tunnelTargetRequest(targetHost)) : null;
|
|
4419
4560
|
if (!payload) return Promise.resolve({ ok: false, stage: "protocol", latencyMs: 0, error: "\u7F3A\u5C11 uuid / trojanPassword" });
|
|
4420
|
-
return new Promise((
|
|
4561
|
+
return new Promise((resolve5) => {
|
|
4421
4562
|
const started = Date.now();
|
|
4422
|
-
const key =
|
|
4563
|
+
const key = crypto2.randomBytes(16).toString("base64");
|
|
4423
4564
|
let settled = false;
|
|
4424
4565
|
let handshakeDone = false;
|
|
4425
4566
|
let buf = Buffer.alloc(0);
|
|
@@ -4431,7 +4572,7 @@ function verifyTunnel(options) {
|
|
|
4431
4572
|
socket.destroy();
|
|
4432
4573
|
} catch {
|
|
4433
4574
|
}
|
|
4434
|
-
|
|
4575
|
+
resolve5({ ...r, latencyMs: Date.now() - started });
|
|
4435
4576
|
};
|
|
4436
4577
|
const socket = tls.connect({ host: ip, port, servername: host, rejectUnauthorized: false, ALPNProtocols: ["http/1.1"] }, () => {
|
|
4437
4578
|
socket.write(tunnelUpgradeRequest(host, wsPath, key));
|
|
@@ -4481,7 +4622,7 @@ function verifyTunnel(options) {
|
|
|
4481
4622
|
});
|
|
4482
4623
|
}
|
|
4483
4624
|
function randomXhttpSession() {
|
|
4484
|
-
return "sess-" +
|
|
4625
|
+
return "sess-" + crypto2.randomBytes(8).toString("hex");
|
|
4485
4626
|
}
|
|
4486
4627
|
function h2Authority(ip, port) {
|
|
4487
4628
|
return `https://${ip.includes(":") ? `[${ip}]` : ip}:${port}`;
|
|
@@ -4492,7 +4633,7 @@ function extractColoFromHeaders(headers) {
|
|
|
4492
4633
|
return m ? m[1] : "";
|
|
4493
4634
|
}
|
|
4494
4635
|
function probeXhttpEndpoint(ip, port, host, xhttpPath, timeoutMs = 3e3) {
|
|
4495
|
-
return new Promise((
|
|
4636
|
+
return new Promise((resolve5) => {
|
|
4496
4637
|
void (async () => {
|
|
4497
4638
|
const started = Date.now();
|
|
4498
4639
|
const session = randomXhttpSession();
|
|
@@ -4511,7 +4652,7 @@ function probeXhttpEndpoint(ip, port, host, xhttpPath, timeoutMs = 3e3) {
|
|
|
4511
4652
|
client?.destroy();
|
|
4512
4653
|
} catch {
|
|
4513
4654
|
}
|
|
4514
|
-
|
|
4655
|
+
resolve5({ ...r, latencyMs: Date.now() - started });
|
|
4515
4656
|
};
|
|
4516
4657
|
const timer = setTimeout(() => {
|
|
4517
4658
|
finish({ ok: false, colo: "", status: 0, error: "XHTTP \u63E1\u624B\u8D85\u65F6" });
|
|
@@ -4577,7 +4718,7 @@ function verifyXhttpTunnel(options) {
|
|
|
4577
4718
|
if (!payload) {
|
|
4578
4719
|
return Promise.resolve({ ok: false, stage: "protocol", latencyMs: 0, error: "\u7F3A\u5C11 uuid" });
|
|
4579
4720
|
}
|
|
4580
|
-
return new Promise((
|
|
4721
|
+
return new Promise((resolve5) => {
|
|
4581
4722
|
void (async () => {
|
|
4582
4723
|
const started = Date.now();
|
|
4583
4724
|
const session = randomXhttpSession();
|
|
@@ -4596,7 +4737,7 @@ function verifyXhttpTunnel(options) {
|
|
|
4596
4737
|
client?.destroy();
|
|
4597
4738
|
} catch {
|
|
4598
4739
|
}
|
|
4599
|
-
|
|
4740
|
+
resolve5({ ...r, latencyMs: Date.now() - started });
|
|
4600
4741
|
};
|
|
4601
4742
|
const timer = setTimeout(() => {
|
|
4602
4743
|
finish({
|
|
@@ -4857,7 +4998,7 @@ function schemeForPort(port) {
|
|
|
4857
4998
|
return port === 443 || port === 2053 || port === 2083 || port === 2087 || port === 2096 || port === 8443 ? "https" : "http";
|
|
4858
4999
|
}
|
|
4859
5000
|
function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
|
|
4860
|
-
return new Promise((
|
|
5001
|
+
return new Promise((resolve5) => {
|
|
4861
5002
|
let settled = false;
|
|
4862
5003
|
let received = "";
|
|
4863
5004
|
const finish = (available, status2, error) => {
|
|
@@ -4868,7 +5009,7 @@ function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
|
|
|
4868
5009
|
socket.destroy();
|
|
4869
5010
|
} catch {
|
|
4870
5011
|
}
|
|
4871
|
-
|
|
5012
|
+
resolve5({ available, status: status2, error });
|
|
4872
5013
|
};
|
|
4873
5014
|
const path = parsed.path.includes("bytes=") ? parsed.path.replace(/bytes=\d+/, "bytes=1024") : parsed.path;
|
|
4874
5015
|
const request3 = [
|
|
@@ -4949,7 +5090,7 @@ var init_speed_url = __esm({
|
|
|
4949
5090
|
import * as tls3 from "node:tls";
|
|
4950
5091
|
function probeUnlock(options) {
|
|
4951
5092
|
const { ip, port = 443, host, token, timeoutMs = 12e3 } = options;
|
|
4952
|
-
return new Promise((
|
|
5093
|
+
return new Promise((resolve5) => {
|
|
4953
5094
|
let settled = false;
|
|
4954
5095
|
let raw = Buffer.alloc(0);
|
|
4955
5096
|
const finish = (result) => {
|
|
@@ -4959,7 +5100,7 @@ function probeUnlock(options) {
|
|
|
4959
5100
|
socket.destroy();
|
|
4960
5101
|
} catch {
|
|
4961
5102
|
}
|
|
4962
|
-
|
|
5103
|
+
resolve5(result);
|
|
4963
5104
|
};
|
|
4964
5105
|
const socket = tls3.connect(
|
|
4965
5106
|
{
|
|
@@ -5582,7 +5723,7 @@ function countFailure(into, stage, error) {
|
|
|
5582
5723
|
bucket[key] = (bucket[key] ?? 0) + 1;
|
|
5583
5724
|
}
|
|
5584
5725
|
async function tcpPing(ip, port, timeoutMs) {
|
|
5585
|
-
return new Promise((
|
|
5726
|
+
return new Promise((resolve5) => {
|
|
5586
5727
|
const started = Date.now();
|
|
5587
5728
|
let settled = false;
|
|
5588
5729
|
const socket = new net2.Socket();
|
|
@@ -5593,7 +5734,7 @@ async function tcpPing(ip, port, timeoutMs) {
|
|
|
5593
5734
|
socket.destroy();
|
|
5594
5735
|
} catch {
|
|
5595
5736
|
}
|
|
5596
|
-
|
|
5737
|
+
resolve5({ ip, ok, latency: Date.now() - started });
|
|
5597
5738
|
};
|
|
5598
5739
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
5599
5740
|
socket.once("connect", () => done(true));
|
|
@@ -5894,7 +6035,7 @@ async function runScan(options) {
|
|
|
5894
6035
|
}
|
|
5895
6036
|
let wsFiltered = wsOk;
|
|
5896
6037
|
let appliedCountries = [];
|
|
5897
|
-
let
|
|
6038
|
+
let countryFilterNoMatch = false;
|
|
5898
6039
|
if (hasCountryFilter && wsOk.length > 0) {
|
|
5899
6040
|
const matched = wsOk.filter((r) => countryFilter.includes(countryOfColo(r.colo || r.probe?.colo || "")));
|
|
5900
6041
|
if (matched.length > 0) {
|
|
@@ -5908,14 +6049,17 @@ async function runScan(options) {
|
|
|
5908
6049
|
message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")}\uFF1A\u4FDD\u7559 ${matched.length}/${wsOk.length}\uFF0C\u8FDB\u5165\u6D4B\u901F`
|
|
5909
6050
|
});
|
|
5910
6051
|
} else {
|
|
5911
|
-
|
|
6052
|
+
countryFilterNoMatch = true;
|
|
5912
6053
|
report({
|
|
5913
6054
|
type: "progress",
|
|
5914
6055
|
stage: 2,
|
|
5915
6056
|
done: wsOk.length,
|
|
5916
6057
|
total: wsOk.length,
|
|
5917
|
-
message: `\
|
|
6058
|
+
message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")} \u540E 0 \u547D\u4E2D\uFF08${wsOk.length} \u4E2A\u53EF\u7528\u8282\u70B9\u5747\u4E0D\u5728\u6240\u9009\u673A\u623F\uFF09\uFF0C\u672A\u653E\u5BBD\u4E3A\u5176\u5B83\u5730\u533A`
|
|
5918
6059
|
});
|
|
6060
|
+
throw new Error(
|
|
6061
|
+
`\u6240\u9009\u5730\u533A\u672C\u8F6E 0 \u547D\u4E2D\uFF1A${wsOk.length} \u4E2A\u53EF\u7528\u8282\u70B9\u5747\u843D\u5728\u5176\u5B83\u673A\u623F\uFF0C\u672A\u653E\u5BBD\u4E3A\u5176\u5B83\u5730\u533A\u3002\u53EF\u52A0\u5927 --sample \u6216\u6362\u4E00\u4E2A\u5730\u533A\u91CD\u8BD5`
|
|
6062
|
+
);
|
|
5919
6063
|
}
|
|
5920
6064
|
}
|
|
5921
6065
|
const rankedByLatency = wsFiltered.sort(
|
|
@@ -6115,8 +6259,10 @@ async function runScan(options) {
|
|
|
6115
6259
|
elapsedMs: Date.now() - started,
|
|
6116
6260
|
countries: appliedCountries,
|
|
6117
6261
|
wsFiltered: wsFiltered.length,
|
|
6118
|
-
/**
|
|
6119
|
-
countryFilterRelaxed,
|
|
6262
|
+
/** 国家筛选未命中任何候选、已放宽为全量(严格模式下恒为 false,会直接抛错) */
|
|
6263
|
+
countryFilterRelaxed: false,
|
|
6264
|
+
/** 国家筛选 0 命中、严格不放宽(保留字段供调用方兼容,实际本轮已抛错) */
|
|
6265
|
+
countryFilterNoMatch,
|
|
6120
6266
|
/** 因已攒够目标国家节点而提前结束阶段二 */
|
|
6121
6267
|
stoppedEarly,
|
|
6122
6268
|
/** 各阶段失败原因分布 */
|
|
@@ -6449,7 +6595,7 @@ var init_callback = __esm({
|
|
|
6449
6595
|
import * as net3 from "node:net";
|
|
6450
6596
|
import { execFile } from "node:child_process";
|
|
6451
6597
|
function isPortListening(port, timeoutMs = 400) {
|
|
6452
|
-
return new Promise((
|
|
6598
|
+
return new Promise((resolve5) => {
|
|
6453
6599
|
const socket = new net3.Socket();
|
|
6454
6600
|
let settled = false;
|
|
6455
6601
|
const done = (open2) => {
|
|
@@ -6459,7 +6605,7 @@ function isPortListening(port, timeoutMs = 400) {
|
|
|
6459
6605
|
socket.destroy();
|
|
6460
6606
|
} catch {
|
|
6461
6607
|
}
|
|
6462
|
-
|
|
6608
|
+
resolve5(open2);
|
|
6463
6609
|
};
|
|
6464
6610
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
6465
6611
|
socket.once("connect", () => done(true));
|
|
@@ -6473,12 +6619,12 @@ function isPortListening(port, timeoutMs = 400) {
|
|
|
6473
6619
|
}
|
|
6474
6620
|
async function readSystemProxy() {
|
|
6475
6621
|
if (process.platform !== "win32") return "";
|
|
6476
|
-
const query = (key) => new Promise((
|
|
6622
|
+
const query = (key) => new Promise((resolve5) => {
|
|
6477
6623
|
execFile(
|
|
6478
6624
|
"reg",
|
|
6479
6625
|
["query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "/v", key],
|
|
6480
6626
|
{ timeout: 3e3, windowsHide: true },
|
|
6481
|
-
(err, stdout2) =>
|
|
6627
|
+
(err, stdout2) => resolve5(err ? "" : String(stdout2))
|
|
6482
6628
|
);
|
|
6483
6629
|
});
|
|
6484
6630
|
try {
|
|
@@ -6557,8 +6703,8 @@ async function detectProxyInterference(host) {
|
|
|
6557
6703
|
}
|
|
6558
6704
|
const probeHost = host?.trim() || "www.cloudflare.com";
|
|
6559
6705
|
try {
|
|
6560
|
-
const { resolve4 } = await import("node:dns/promises");
|
|
6561
|
-
const ips = await
|
|
6706
|
+
const { resolve4: resolve42 } = await import("node:dns/promises");
|
|
6707
|
+
const ips = await resolve42(probeHost).catch(() => []);
|
|
6562
6708
|
const fake = ips.find((ip) => isFakeIp(ip));
|
|
6563
6709
|
if (fake) {
|
|
6564
6710
|
findings.push({
|
|
@@ -7121,10 +7267,10 @@ function findGlobalIPv6() {
|
|
|
7121
7267
|
}
|
|
7122
7268
|
async function probeDefaultRoute(timeoutMs = 800) {
|
|
7123
7269
|
const platform = process.platform;
|
|
7124
|
-
const run = (cmd, args) => new Promise((
|
|
7270
|
+
const run = (cmd, args) => new Promise((resolve5, reject) => {
|
|
7125
7271
|
const child = execFile2(cmd, args, { timeout: timeoutMs, windowsHide: true, maxBuffer: 1 << 20 }, (err, stdout2) => {
|
|
7126
7272
|
if (err && !stdout2) reject(err);
|
|
7127
|
-
else
|
|
7273
|
+
else resolve5(String(stdout2 ?? ""));
|
|
7128
7274
|
});
|
|
7129
7275
|
child.on("error", reject);
|
|
7130
7276
|
});
|
|
@@ -7144,7 +7290,7 @@ async function probeDefaultRoute(timeoutMs = 800) {
|
|
|
7144
7290
|
}
|
|
7145
7291
|
}
|
|
7146
7292
|
function tcpReachable(address, port, timeoutMs) {
|
|
7147
|
-
return new Promise((
|
|
7293
|
+
return new Promise((resolve5) => {
|
|
7148
7294
|
let settled = false;
|
|
7149
7295
|
const done = (ok) => {
|
|
7150
7296
|
if (settled) return;
|
|
@@ -7153,7 +7299,7 @@ function tcpReachable(address, port, timeoutMs) {
|
|
|
7153
7299
|
socket.destroy();
|
|
7154
7300
|
} catch {
|
|
7155
7301
|
}
|
|
7156
|
-
|
|
7302
|
+
resolve5(ok);
|
|
7157
7303
|
};
|
|
7158
7304
|
const socket = new net4.Socket();
|
|
7159
7305
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
@@ -7342,12 +7488,12 @@ async function discoverIPv6Prefixes(hosts, timeoutMs = 6e3) {
|
|
|
7342
7488
|
return [...out2].sort();
|
|
7343
7489
|
}
|
|
7344
7490
|
function withTimeout(promise, ms) {
|
|
7345
|
-
return new Promise((
|
|
7491
|
+
return new Promise((resolve5, reject) => {
|
|
7346
7492
|
const timer = setTimeout(() => reject(new Error("timeout")), ms);
|
|
7347
7493
|
promise.then(
|
|
7348
7494
|
(value) => {
|
|
7349
7495
|
clearTimeout(timer);
|
|
7350
|
-
|
|
7496
|
+
resolve5(value);
|
|
7351
7497
|
},
|
|
7352
7498
|
(error) => {
|
|
7353
7499
|
clearTimeout(timer);
|
|
@@ -7679,12 +7825,12 @@ function startBridge(options = {}) {
|
|
|
7679
7825
|
sendJson(res, 500, { ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
7680
7826
|
});
|
|
7681
7827
|
});
|
|
7682
|
-
return new Promise((
|
|
7828
|
+
return new Promise((resolve5, reject) => {
|
|
7683
7829
|
server.once("error", reject);
|
|
7684
7830
|
server.listen(port, host, () => {
|
|
7685
7831
|
const address = server.address();
|
|
7686
7832
|
const boundPort = typeof address === "object" && address !== null ? address.port : port;
|
|
7687
|
-
|
|
7833
|
+
resolve5({
|
|
7688
7834
|
server,
|
|
7689
7835
|
port: boundPort,
|
|
7690
7836
|
token,
|
|
@@ -7979,7 +8125,8 @@ scan \u9009\u9879:
|
|
|
7979
8125
|
\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\u3002
|
|
7980
8126
|
\u5E26\u6B64\u53C2\u6570\u4F1A\u81EA\u52A8\u6269\u5927 101 \u6821\u9A8C\u7684\u5019\u9009\u6C60\uFF08120 \u2192 \u6700\u591A 500\uFF09\uFF0C
|
|
7981
8127
|
\u5426\u5219\u76EE\u6807\u5730\u533A\u53EF\u80FD\u56E0\u5EF6\u8FDF\u6392\u5E8F\u88AB\u63D0\u524D\u622A\u65AD\uFF1B
|
|
7982
|
-
\
|
|
8128
|
+
\u6240\u9009\u673A\u623F\u5728 IPv6 \u6D3B\u8DC3\u6BB5\u6CA1\u6709\u5BF9\u5E94\u65F6\u4F1A\u81EA\u52A8\u8DF3\u8FC7 IPv6\uFF08\u4E1C\u4E9A\u673A\u623F\u65E0 v6 \u6BB5\uFF09\uFF1B
|
|
8129
|
+
\u7B5B\u4E0D\u5230\u65F6\u660E\u786E\u62A5\u9519\u300C0 \u547D\u4E2D\u3001\u672A\u653E\u5BBD\u300D\uFF0C\u4E0D\u4F1A\u6DF7\u5165\u5176\u5B83\u5730\u533A\u8282\u70B9
|
|
7983
8130
|
--min-speed <MB/s> \u4E0B\u884C\u901F\u5EA6\u4E0B\u9650\uFF0C\u9ED8\u8BA4 0\uFF08\u4E0D\u8FC7\u6EE4\uFF09
|
|
7984
8131
|
\u6309**\u7A33\u6001**\u4E0B\u884C\u901F\u5EA6\u6DD8\u6C70\uFF0C\u5355\u4F4D MB/s\uFF0C0.1 \u5373\u53EF\u8FC7\u6EE4\u6389
|
|
7985
8132
|
\u7EDD\u5927\u591A\u6570\u300C\u63E1\u624B\u80FD\u8FC7\u4F46\u5E26\u5BBD\u4E0D\u53EF\u7528\u300D\u7684 IP\u3002
|
|
@@ -8436,7 +8583,7 @@ var init_pool2 = __esm({
|
|
|
8436
8583
|
V6_NETS = BUILTIN_IPV6_CIDRS.map(parseCidr).filter(
|
|
8437
8584
|
(v) => v !== null && v.family === 6
|
|
8438
8585
|
);
|
|
8439
|
-
sleep = (ms) => new Promise((
|
|
8586
|
+
sleep = (ms) => new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
8440
8587
|
}
|
|
8441
8588
|
});
|
|
8442
8589
|
|
|
@@ -8964,7 +9111,7 @@ function withTimeout2(promise, ms, label) {
|
|
|
8964
9111
|
]);
|
|
8965
9112
|
}
|
|
8966
9113
|
function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
8967
|
-
return new Promise((
|
|
9114
|
+
return new Promise((resolve5, reject) => {
|
|
8968
9115
|
const started = Date.now();
|
|
8969
9116
|
const ws = new WebSocket(wsUrl);
|
|
8970
9117
|
ws.binaryType = "arraybuffer";
|
|
@@ -8992,7 +9139,7 @@ function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
|
8992
9139
|
clearTimeout(timer);
|
|
8993
9140
|
const rest = bytes.subarray(Math.min(headerLen, bytes.byteLength));
|
|
8994
9141
|
if (rest.byteLength > 0) push(rest);
|
|
8995
|
-
|
|
9142
|
+
resolve5({ ws, duplex, tunnelMs: Date.now() - started, first: sniff });
|
|
8996
9143
|
return;
|
|
8997
9144
|
}
|
|
8998
9145
|
if (sniff.first.length === 0) sniff.first = Buffer.from(bytes);
|
|
@@ -9017,7 +9164,7 @@ function openTunnel(wsUrl, uuid, ip, port, timeoutMs) {
|
|
|
9017
9164
|
});
|
|
9018
9165
|
}
|
|
9019
9166
|
function readHttp(socket, timeoutMs) {
|
|
9020
|
-
return new Promise((
|
|
9167
|
+
return new Promise((resolve5, reject) => {
|
|
9021
9168
|
let text2 = "";
|
|
9022
9169
|
let done = false;
|
|
9023
9170
|
const finish = () => {
|
|
@@ -9029,7 +9176,7 @@ function readHttp(socket, timeoutMs) {
|
|
|
9029
9176
|
const head = sep >= 0 ? text2.slice(0, sep) : text2;
|
|
9030
9177
|
const body = sep >= 0 ? text2.slice(sep + 4) : "";
|
|
9031
9178
|
const matched = /^HTTP\/1\.[01] (\d{3})/.exec(head);
|
|
9032
|
-
|
|
9179
|
+
resolve5({ status: matched ? Number(matched[1]) : 0, body, raw: text2 });
|
|
9033
9180
|
};
|
|
9034
9181
|
const timer = setTimeout(finish, timeoutMs);
|
|
9035
9182
|
const onData = (chunk) => {
|
|
@@ -9079,7 +9226,7 @@ async function probeOne(opts, ip, timeoutMs) {
|
|
|
9079
9226
|
out2.tunnelMs = tunnel.tunnelMs;
|
|
9080
9227
|
const tlsStarted = Date.now();
|
|
9081
9228
|
socket = await withTimeout2(
|
|
9082
|
-
new Promise((
|
|
9229
|
+
new Promise((resolve5, reject) => {
|
|
9083
9230
|
const s = tls4.connect(
|
|
9084
9231
|
{
|
|
9085
9232
|
socket: tunnel.duplex,
|
|
@@ -9088,7 +9235,7 @@ async function probeOne(opts, ip, timeoutMs) {
|
|
|
9088
9235
|
// 这一条通过,就等于证明「这个候选确实把 SNI=我们的域名 转到了 CF」。
|
|
9089
9236
|
rejectUnauthorized: true
|
|
9090
9237
|
},
|
|
9091
|
-
() =>
|
|
9238
|
+
() => resolve5(s)
|
|
9092
9239
|
);
|
|
9093
9240
|
s.once("error", reject);
|
|
9094
9241
|
}),
|
|
@@ -9206,7 +9353,7 @@ async function verifyOne(opts, ip, verifyHost, timeoutMs) {
|
|
|
9206
9353
|
try {
|
|
9207
9354
|
const tunnel = await openTunnel(opts.wsUrl, opts.uuid, ip, 443, timeoutMs);
|
|
9208
9355
|
ws = tunnel.ws;
|
|
9209
|
-
socket = await new Promise((
|
|
9356
|
+
socket = await new Promise((resolve5, reject) => {
|
|
9210
9357
|
const s = tls4.connect(
|
|
9211
9358
|
{
|
|
9212
9359
|
socket: tunnel.duplex,
|
|
@@ -9214,7 +9361,7 @@ async function verifyOne(opts, ip, verifyHost, timeoutMs) {
|
|
|
9214
9361
|
// 校验网址是公网站点:证书链 + 主机名照常校验
|
|
9215
9362
|
rejectUnauthorized: true
|
|
9216
9363
|
},
|
|
9217
|
-
() =>
|
|
9364
|
+
() => resolve5(s)
|
|
9218
9365
|
);
|
|
9219
9366
|
s.once("error", reject);
|
|
9220
9367
|
});
|
|
@@ -9527,8 +9674,8 @@ var init_relay = __esm({
|
|
|
9527
9674
|
];
|
|
9528
9675
|
resolve4Async = async (host) => {
|
|
9529
9676
|
const dns = await import("node:dns");
|
|
9530
|
-
return new Promise((
|
|
9531
|
-
dns.resolve4(host, (err, addrs) => err ? reject(err) :
|
|
9677
|
+
return new Promise((resolve5, reject) => {
|
|
9678
|
+
dns.resolve4(host, (err, addrs) => err ? reject(err) : resolve5(addrs));
|
|
9532
9679
|
});
|
|
9533
9680
|
};
|
|
9534
9681
|
WAF_BLOCK_MARKS = /* @__PURE__ */ new Set(["IPv6"]);
|
|
@@ -9661,16 +9808,23 @@ async function resolveCandidatesFromArgs(args, extraHosts = [], port = 443) {
|
|
|
9661
9808
|
note: ipFile ? `\u5019\u9009\u6765\u81EA\u6587\u4EF6 ${ipFile}\uFF08\u672A\u505A\u7F51\u6BB5\u91C7\u6837\uFF0C\u4E5F\u672A\u505A IPv6 \u9884\u68C0\uFF09` : `\u5019\u9009\u6765\u81EA\u94FE\u63A5 ${ipUrl}\uFF08\u672A\u505A\u7F51\u6BB5\u91C7\u6837\uFF0C\u4E5F\u672A\u505A IPv6 \u9884\u68C0\uFF09`
|
|
9662
9809
|
};
|
|
9663
9810
|
}
|
|
9811
|
+
const countryFlags = flagList(args, "countries");
|
|
9812
|
+
const baseFamily = familyFromArgs(args);
|
|
9813
|
+
let family = baseFamily;
|
|
9814
|
+
if (countryFlags.length > 0 && family !== "v4" && !colosCanUseIPv6(colosOfCountryFilter(countryFlags))) {
|
|
9815
|
+
process.stderr.write("\u203B \u6240\u9009\u5730\u533A\u5728 IPv6 \u6D3B\u8DC3\u6BB5\u6CA1\u6709\u5BF9\u5E94\u673A\u623F\uFF0C\u5DF2\u8DF3\u8FC7 IPv6 \u91C7\u6837\uFF08\u907F\u514D\u5176\u5B83\u5730\u533A\u8282\u70B9\u6DF7\u5165\uFF09\n");
|
|
9816
|
+
family = "v4";
|
|
9817
|
+
}
|
|
9664
9818
|
const base = {
|
|
9665
9819
|
// 选国家时**自动中性采样**:采样发生在阶段一之前、那时还不知道机房,
|
|
9666
9820
|
// 若某国家的 IP 集中在低权重网段,候选会被压少 → 可能「扫了几千个还是找不到 HKG/NRT」。
|
|
9667
|
-
neutral: args.flags["neutral-sampling"] !== void 0 ||
|
|
9821
|
+
neutral: args.flags["neutral-sampling"] !== void 0 || countryFlags.length > 0,
|
|
9668
9822
|
sample: flagNumber(args, "sample", 6556),
|
|
9669
9823
|
cidr: flagList(args, "cidr"),
|
|
9670
9824
|
// ⚠️ 不传 seed = 每次随机(默认)。只有用户显式给了 --seed 才固定,
|
|
9671
9825
|
// 否则「每次跑都测同一批 IP」——那批落在劣质路由段上时永远测不出好 IP。
|
|
9672
9826
|
seed: seedFromArgs(args),
|
|
9673
|
-
family
|
|
9827
|
+
family,
|
|
9674
9828
|
extraHosts
|
|
9675
9829
|
};
|
|
9676
9830
|
if (!flagBool(args, "adaptive")) return resolveCandidatePlan(base);
|
|
@@ -10934,6 +11088,817 @@ var init_main = __esm({
|
|
|
10934
11088
|
}
|
|
10935
11089
|
});
|
|
10936
11090
|
|
|
11091
|
+
// src/deploy/edge-relay-schema.ts
|
|
11092
|
+
function splitSchemaSql(sql) {
|
|
11093
|
+
const withoutComments = sql.split("\n").filter((line) => !line.trimStart().startsWith("--")).join("\n");
|
|
11094
|
+
return withoutComments.split(";").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
11095
|
+
}
|
|
11096
|
+
var SCHEMA_DEVICES_SQL, SCHEMA_AUTH_SQL, EDGE_RELAY_SCHEMAS;
|
|
11097
|
+
var init_edge_relay_schema = __esm({
|
|
11098
|
+
"src/deploy/edge-relay-schema.ts"() {
|
|
11099
|
+
"use strict";
|
|
11100
|
+
SCHEMA_DEVICES_SQL = `-- \u4E91\u76D1\u6D4B\u53F0 D1 schema\uFF08\u6765\u81EA edge-relay/migrations/0001_init.sql\uFF09
|
|
11101
|
+
CREATE TABLE IF NOT EXISTS devices (
|
|
11102
|
+
node_id TEXT PRIMARY KEY,
|
|
11103
|
+
alias TEXT,
|
|
11104
|
+
virtual_ipv4 TEXT,
|
|
11105
|
+
version TEXT,
|
|
11106
|
+
last_ip TEXT,
|
|
11107
|
+
online INTEGER NOT NULL DEFAULT 0,
|
|
11108
|
+
last_seen_ms INTEGER NOT NULL,
|
|
11109
|
+
updated_at_ms INTEGER NOT NULL
|
|
11110
|
+
);
|
|
11111
|
+
CREATE INDEX IF NOT EXISTS idx_devices_last_seen ON devices(last_seen_ms DESC);`;
|
|
11112
|
+
SCHEMA_AUTH_SQL = `-- \u4E91\u76D1\u6D4B\u53F0\u9274\u6743 D1 schema\uFF08\u6765\u81EA edge-relay/migrations/0002_auth.sql\uFF09
|
|
11113
|
+
CREATE TABLE IF NOT EXISTS auth (
|
|
11114
|
+
id INTEGER PRIMARY KEY,
|
|
11115
|
+
password_hash TEXT,
|
|
11116
|
+
salt TEXT,
|
|
11117
|
+
updated_at_ms INTEGER NOT NULL
|
|
11118
|
+
);
|
|
11119
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
11120
|
+
token TEXT PRIMARY KEY,
|
|
11121
|
+
created_at_ms INTEGER NOT NULL,
|
|
11122
|
+
expires_at_ms INTEGER NOT NULL
|
|
11123
|
+
);
|
|
11124
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at_ms);`;
|
|
11125
|
+
EDGE_RELAY_SCHEMAS = [SCHEMA_DEVICES_SQL, SCHEMA_AUTH_SQL];
|
|
11126
|
+
}
|
|
11127
|
+
});
|
|
11128
|
+
|
|
11129
|
+
// src/edge/deploy.ts
|
|
11130
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
11131
|
+
import { resolve as resolve3 } from "node:path";
|
|
11132
|
+
function loadAsset(name) {
|
|
11133
|
+
const candidates = [
|
|
11134
|
+
resolve3(process.cwd(), "assets", "edge-relay", name),
|
|
11135
|
+
resolve3(process.cwd(), "packages", "cli", "assets", "edge-relay", name)
|
|
11136
|
+
];
|
|
11137
|
+
for (const p of candidates) {
|
|
11138
|
+
try {
|
|
11139
|
+
return readFileSync6(p, "utf8");
|
|
11140
|
+
} catch {
|
|
11141
|
+
}
|
|
11142
|
+
}
|
|
11143
|
+
throw new Error(`\u7F3A\u5C11\u5185\u7F6E\u8D44\u4EA7 assets/edge-relay/${name}\uFF0C\u8BF7\u5148\u8FD0\u884C node scripts/build-edge-relay.mjs`);
|
|
11144
|
+
}
|
|
11145
|
+
function randomToken(bytes = 24) {
|
|
11146
|
+
const arr = new Uint8Array(bytes);
|
|
11147
|
+
crypto.getRandomValues(arr);
|
|
11148
|
+
return Array.from(arr, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
11149
|
+
}
|
|
11150
|
+
function isTransientD1Error(err) {
|
|
11151
|
+
if (err instanceof CloudflareError) {
|
|
11152
|
+
if (err.status === 408 || err.status === 425 || err.status === 429 || err.status >= 500) return true;
|
|
11153
|
+
return /(?:d1|database).*(?:not found|not ready|not available|unavailable|provision)/i.test(err.message);
|
|
11154
|
+
}
|
|
11155
|
+
if (err instanceof TypeError) return true;
|
|
11156
|
+
return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
11157
|
+
}
|
|
11158
|
+
function errorMessage(err) {
|
|
11159
|
+
return err instanceof Error ? err.message : String(err);
|
|
11160
|
+
}
|
|
11161
|
+
function isTransientHttpStatus(status2) {
|
|
11162
|
+
return status2 === 408 || status2 === 425 || status2 === 429 || status2 >= 500;
|
|
11163
|
+
}
|
|
11164
|
+
async function setupMonitorPasswordWithRetry(workerUrl, password, report) {
|
|
11165
|
+
const deadline = Date.now() + MONITOR_SETUP_TIMEOUT_MS;
|
|
11166
|
+
let delayMs = D1_RETRY_INITIAL_DELAY_MS;
|
|
11167
|
+
let attempts = 0;
|
|
11168
|
+
let lastError = "";
|
|
11169
|
+
while (Date.now() < deadline) {
|
|
11170
|
+
attempts += 1;
|
|
11171
|
+
try {
|
|
11172
|
+
const setupResp = await fetch(`${workerUrl}/auth/setup`, {
|
|
11173
|
+
method: "POST",
|
|
11174
|
+
headers: { "Content-Type": "application/json" },
|
|
11175
|
+
body: JSON.stringify({ password }),
|
|
11176
|
+
signal: AbortSignal.timeout(Math.min(15e3, Math.max(1, deadline - Date.now())))
|
|
11177
|
+
});
|
|
11178
|
+
if (setupResp.ok) {
|
|
11179
|
+
return false;
|
|
11180
|
+
}
|
|
11181
|
+
if (setupResp.status === 409) {
|
|
11182
|
+
return true;
|
|
11183
|
+
}
|
|
11184
|
+
const text2 = await setupResp.text().catch(() => "");
|
|
11185
|
+
lastError = `HTTP ${setupResp.status}: ${text2.slice(0, 300)}`;
|
|
11186
|
+
if (!isTransientHttpStatus(setupResp.status)) {
|
|
11187
|
+
throw new Error(`\u8BBE\u7F6E\u76D1\u6D4B\u53F0\u5BC6\u7801\u5931\u8D25\uFF08${lastError}\uFF09`);
|
|
11188
|
+
}
|
|
11189
|
+
} catch (err) {
|
|
11190
|
+
if (err instanceof Error && err.message.startsWith("\u8BBE\u7F6E\u76D1\u6D4B\u53F0\u5BC6\u7801\u5931\u8D25\uFF08")) throw err;
|
|
11191
|
+
lastError = errorMessage(err);
|
|
11192
|
+
}
|
|
11193
|
+
const remainingMs = deadline - Date.now();
|
|
11194
|
+
if (remainingMs <= 0) break;
|
|
11195
|
+
const waitMs = Math.min(delayMs, remainingMs);
|
|
11196
|
+
report(`Worker/D1 \u5C1A\u672A\u5C31\u7EEA\uFF0C${(waitMs / 1e3).toFixed(waitMs % 1e3 === 0 ? 0 : 1)} \u79D2\u540E\u91CD\u8BD5\u76D1\u6D4B\u53F0\u521D\u59CB\u5316\uFF08\u7B2C ${attempts + 1} \u6B21\uFF09`);
|
|
11197
|
+
await new Promise((resolve5) => setTimeout(resolve5, waitMs));
|
|
11198
|
+
delayMs = Math.min(delayMs * 2, D1_RETRY_MAX_DELAY_MS);
|
|
11199
|
+
}
|
|
11200
|
+
throw new Error(`\u8BBE\u7F6E\u76D1\u6D4B\u53F0\u5BC6\u7801\u5728 ${MONITOR_SETUP_TIMEOUT_MS / 1e3} \u79D2\u5185\u672A\u5B8C\u6210\uFF08\u5DF2\u5C1D\u8BD5 ${attempts} \u6B21\uFF09\uFF1A${lastError}`);
|
|
11201
|
+
}
|
|
11202
|
+
async function queryD1WithRetry(client, accountId, databaseId, sql, deadline, operation, report) {
|
|
11203
|
+
let delayMs = D1_RETRY_INITIAL_DELAY_MS;
|
|
11204
|
+
let attempts = 0;
|
|
11205
|
+
while (true) {
|
|
11206
|
+
attempts += 1;
|
|
11207
|
+
try {
|
|
11208
|
+
await client.queryD1(accountId, databaseId, sql);
|
|
11209
|
+
return;
|
|
11210
|
+
} catch (err) {
|
|
11211
|
+
if (!isTransientD1Error(err)) {
|
|
11212
|
+
throw new Error(`${operation}\u5931\u8D25\uFF1A${errorMessage(err)}`);
|
|
11213
|
+
}
|
|
11214
|
+
const remainingMs = deadline - Date.now();
|
|
11215
|
+
if (remainingMs <= 0) {
|
|
11216
|
+
throw new Error(`${operation}\u5728 ${D1_READY_TIMEOUT_MS / 1e3} \u79D2\u5185\u672A\u5B8C\u6210\uFF08\u5DF2\u91CD\u8BD5 ${attempts - 1} \u6B21\uFF09\uFF1A${errorMessage(err)}`);
|
|
11217
|
+
}
|
|
11218
|
+
const waitMs = Math.min(delayMs, remainingMs);
|
|
11219
|
+
report(`D1 \u6682\u4E0D\u53EF\u7528\uFF0C${(waitMs / 1e3).toFixed(waitMs % 1e3 === 0 ? 0 : 1)} \u79D2\u540E\u91CD\u8BD5${operation}\uFF08\u7B2C ${attempts + 1} \u6B21\uFF09`);
|
|
11220
|
+
await new Promise((resolve5) => setTimeout(resolve5, waitMs));
|
|
11221
|
+
delayMs = Math.min(delayMs * 2, D1_RETRY_MAX_DELAY_MS);
|
|
11222
|
+
}
|
|
11223
|
+
}
|
|
11224
|
+
}
|
|
11225
|
+
async function deployEdgeRelay(client, opts) {
|
|
11226
|
+
const report = opts.onProgress ?? (() => {
|
|
11227
|
+
});
|
|
11228
|
+
const accountId = opts.accountId;
|
|
11229
|
+
const workerName = (opts.workerName || "mobihop-edge-relay").trim();
|
|
11230
|
+
const domain = opts.domain.trim();
|
|
11231
|
+
if (!domain) throw new Error("\u76F2\u4E2D\u7EE7\u5FC5\u987B\u63D0\u4F9B\u81EA\u5B9A\u4E49\u57DF\u540D\uFF08*.workers.dev \u56FD\u5185\u88AB\u6C61\u67D3\uFF09");
|
|
11232
|
+
if (opts.monitorPassword.length < 8) throw new Error("\u76D1\u6D4B\u53F0\u5BC6\u7801\u81F3\u5C11 8 \u4F4D");
|
|
11233
|
+
const workerCode = loadAsset("worker.js");
|
|
11234
|
+
const monitorToken = opts.monitorToken || randomToken();
|
|
11235
|
+
const d1Name = `${workerName}-monitor`;
|
|
11236
|
+
report("\u6B65\u9AA4 1/5\uFF1A\u521B\u5EFA\u76D1\u6D4B\u6570\u636E\u5E93\uFF08D1\uFF09");
|
|
11237
|
+
let db;
|
|
11238
|
+
try {
|
|
11239
|
+
db = await client.createD1Database(accountId, d1Name);
|
|
11240
|
+
} catch (createError) {
|
|
11241
|
+
const existing = await client.listD1Databases(accountId, d1Name).catch(() => []);
|
|
11242
|
+
db = existing.find((candidate) => candidate.name === d1Name);
|
|
11243
|
+
if (!db) throw createError;
|
|
11244
|
+
report(`D1 \u5DF2\u5B58\u5728\uFF0C\u590D\u7528\uFF1A${db.name} (${db.uuid.slice(0, 8)}\u2026)`);
|
|
11245
|
+
}
|
|
11246
|
+
if (!db) throw new Error(`\u521B\u5EFA\u6216\u590D\u7528 D1 \u5931\u8D25\uFF1A${d1Name}`);
|
|
11247
|
+
report(`D1 \u5DF2\u521B\u5EFA\uFF1A${db.name} (${db.uuid.slice(0, 8)}\u2026)\uFF0C\u521D\u59CB\u5316 schema`);
|
|
11248
|
+
const d1Deadline = Date.now() + D1_READY_TIMEOUT_MS;
|
|
11249
|
+
report("\u7B49\u5F85 D1 \u5C31\u7EEA");
|
|
11250
|
+
await queryD1WithRetry(client, accountId, db.uuid, "SELECT 1", d1Deadline, "D1 \u5C31\u7EEA\u68C0\u67E5", report);
|
|
11251
|
+
report("D1 \u5DF2\u5C31\u7EEA\uFF0C\u5F00\u59CB\u521D\u59CB\u5316 schema");
|
|
11252
|
+
for (const schema of EDGE_RELAY_SCHEMAS) {
|
|
11253
|
+
for (const sql of splitSchemaSql(schema)) {
|
|
11254
|
+
await queryD1WithRetry(
|
|
11255
|
+
client,
|
|
11256
|
+
accountId,
|
|
11257
|
+
db.uuid,
|
|
11258
|
+
sql,
|
|
11259
|
+
d1Deadline,
|
|
11260
|
+
`D1 schema \u521D\u59CB\u5316\u5931\u8D25\uFF08${sql.slice(0, 40)}\u2026\uFF09`,
|
|
11261
|
+
report
|
|
11262
|
+
);
|
|
11263
|
+
}
|
|
11264
|
+
}
|
|
11265
|
+
report("D1 schema \u521D\u59CB\u5316\u5B8C\u6210\uFF085 \u6761\u8BED\u53E5\uFF09");
|
|
11266
|
+
report("\u6B65\u9AA4 2/5\uFF1A\u90E8\u7F72\u76F2\u4E2D\u7EE7 Worker\uFF08\u542B Durable Objects \u623F\u95F4\uFF09");
|
|
11267
|
+
const bindings = [
|
|
11268
|
+
{ name: "DB", type: "d1", id: db.uuid },
|
|
11269
|
+
{ name: "MESH_ROOM", type: "durable_object_namespace", class_name: DEFAULT_DO_CLASS },
|
|
11270
|
+
{ name: "MONITOR_TOKEN", type: "plain_text", text: monitorToken },
|
|
11271
|
+
{ name: "WINDOW_MS", type: "plain_text", text: opts.limits?.windowMs ?? "1000" },
|
|
11272
|
+
{ name: "MAX_BYTES_PER_WINDOW", type: "plain_text", text: opts.limits?.maxBytesPerWindow ?? "1048576" },
|
|
11273
|
+
{ name: "MAX_PACKETS_PER_WINDOW", type: "plain_text", text: opts.limits?.maxPacketsPerWindow ?? "2000" },
|
|
11274
|
+
{ name: "MAX_PEERS_PER_ROOM", type: "plain_text", text: opts.limits?.maxPeersPerRoom ?? "512" }
|
|
11275
|
+
];
|
|
11276
|
+
const doExports = {
|
|
11277
|
+
[DEFAULT_DO_CLASS]: { type: "durable-object", state: "created", storage: "sqlite" }
|
|
11278
|
+
};
|
|
11279
|
+
try {
|
|
11280
|
+
await client.uploadScript(accountId, workerName, {
|
|
11281
|
+
mainModule: "worker.js",
|
|
11282
|
+
code: workerCode,
|
|
11283
|
+
compatibilityDate: EDGE_RELAY_COMPAT_DATE,
|
|
11284
|
+
bindings,
|
|
11285
|
+
doExports
|
|
11286
|
+
});
|
|
11287
|
+
} catch (err) {
|
|
11288
|
+
throw new Error(
|
|
11289
|
+
`\u76F2\u4E2D\u7EE7 Worker \u4E0A\u4F20\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
|
|
11290
|
+
);
|
|
11291
|
+
}
|
|
11292
|
+
report("Worker \u5DF2\u4E0A\u4F20\uFF08Durable Objects \u623F\u95F4\u5DF2\u5C31\u7EEA\uFF09");
|
|
11293
|
+
const workerUrl = `https://${domain}`;
|
|
11294
|
+
const wssEndpoint = `wss://${domain}/mesh/<network_hash>?peer_id=<16hex>`;
|
|
11295
|
+
if (opts.zoneId) {
|
|
11296
|
+
report(`\u6B65\u9AA4 3/5\uFF1A\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540D ${domain}`);
|
|
11297
|
+
await client.attachCustomDomain(accountId, {
|
|
11298
|
+
hostname: domain,
|
|
11299
|
+
service: workerName,
|
|
11300
|
+
zoneId: opts.zoneId
|
|
11301
|
+
});
|
|
11302
|
+
report("\u57DF\u540D\u7ED1\u5B9A\u5DF2\u53D7\u7406\uFF08\u9700\u518D\u6821\u9A8C\u771F\u5B9E\u53EF\u8FBE\uFF09");
|
|
11303
|
+
} else {
|
|
11304
|
+
report("\u6B65\u9AA4 3/5\uFF1A\u8DF3\u8FC7\u57DF\u540D\u7ED1\u5B9A\uFF08\u8BF7\u5728 Cloudflare \u63A7\u5236\u53F0\u624B\u52A8\u7ED1\u5B9A\uFF0C\u6216\u63D0\u4F9B --zone-id\uFF09");
|
|
11305
|
+
}
|
|
11306
|
+
report("\u6B65\u9AA4 4/5\uFF1A\u8BBE\u7F6E\u76D1\u6D4B\u53F0\u521D\u59CB\u5BC6\u7801");
|
|
11307
|
+
const monitorAlreadySetup = await setupMonitorPasswordWithRetry(workerUrl, opts.monitorPassword, report);
|
|
11308
|
+
if (monitorAlreadySetup) {
|
|
11309
|
+
report("\u76D1\u6D4B\u53F0\u5DF2\u6709\u5BC6\u7801\uFF0C\u8DF3\u8FC7\u521D\u59CB\u5316\uFF08\u5E42\u7B49\uFF09");
|
|
11310
|
+
} else {
|
|
11311
|
+
report("\u76D1\u6D4B\u53F0\u5BC6\u7801\u5DF2\u8BBE\u7F6E");
|
|
11312
|
+
}
|
|
11313
|
+
let dashboardUrl = null;
|
|
11314
|
+
if (opts.withDashboard !== false) {
|
|
11315
|
+
const project = (opts.dashboardProject || `${workerName}-dashboard`).trim();
|
|
11316
|
+
report(`\u6B65\u9AA4 5/5\uFF1A\u90E8\u7F72\u76D1\u6D4B\u9762\u677F Pages\uFF08${project}\uFF09`);
|
|
11317
|
+
let dashWorkerCode = loadAsset("dashboard-worker.js");
|
|
11318
|
+
dashWorkerCode = dashWorkerCode.replace(
|
|
11319
|
+
/const DEFAULT_API = (?:'[^']*'|location\.origin)/,
|
|
11320
|
+
`const DEFAULT_API = '${workerUrl}'`
|
|
11321
|
+
);
|
|
11322
|
+
await deployDashboard(client, accountId, project, dashWorkerCode, report);
|
|
11323
|
+
dashboardUrl = `https://${project}.pages.dev`;
|
|
11324
|
+
report(`\u76D1\u6D4B\u9762\u677F\u5DF2\u90E8\u7F72\uFF1A${dashboardUrl}`);
|
|
11325
|
+
} else {
|
|
11326
|
+
report("\u6B65\u9AA4 5/5\uFF1A\u8DF3\u8FC7\u76D1\u6D4B\u9762\u677F\u90E8\u7F72");
|
|
11327
|
+
}
|
|
11328
|
+
return {
|
|
11329
|
+
workerName,
|
|
11330
|
+
workerUrl,
|
|
11331
|
+
wssEndpoint,
|
|
11332
|
+
d1Name: db.name,
|
|
11333
|
+
d1Uuid: db.uuid,
|
|
11334
|
+
doClass: DEFAULT_DO_CLASS,
|
|
11335
|
+
dashboardUrl,
|
|
11336
|
+
monitorToken,
|
|
11337
|
+
monitorPassword: opts.monitorPassword
|
|
11338
|
+
};
|
|
11339
|
+
}
|
|
11340
|
+
async function deployDashboard(client, accountId, project, workerCode, report) {
|
|
11341
|
+
try {
|
|
11342
|
+
await client.getPagesProject(accountId, project);
|
|
11343
|
+
} catch (err) {
|
|
11344
|
+
const status2 = typeof err === "object" && err !== null && "status" in err ? err.status : void 0;
|
|
11345
|
+
if (status2 === 404) {
|
|
11346
|
+
await client.createPagesProject(accountId, { name: project });
|
|
11347
|
+
} else {
|
|
11348
|
+
throw err;
|
|
11349
|
+
}
|
|
11350
|
+
}
|
|
11351
|
+
await client.deployPagesWorker(accountId, project, { code: workerCode });
|
|
11352
|
+
report("\u9762\u677F Worker \u5DF2\u4E0A\u4F20");
|
|
11353
|
+
}
|
|
11354
|
+
function formatEdgeDeploySummary(r) {
|
|
11355
|
+
return [
|
|
11356
|
+
"",
|
|
11357
|
+
"================ \u76F2\u4E2D\u7EE7 / \u4E91\u76D1\u6D4B\u53F0\u90E8\u7F72\u5B8C\u6210 ================",
|
|
11358
|
+
`Worker \u540D\u79F0: ${r.workerName}`,
|
|
11359
|
+
`\u76D1\u6D4B API: ${r.workerUrl}`,
|
|
11360
|
+
`WSS \u7AEF\u70B9: ${r.wssEndpoint}`,
|
|
11361
|
+
`D1 \u6570\u636E\u5E93: ${r.d1Name} (${r.d1Uuid.slice(0, 8)}\u2026)`,
|
|
11362
|
+
`Durable Object: ${r.doClass}`,
|
|
11363
|
+
r.dashboardUrl ? `\u76D1\u6D4B\u9762\u677F: ${r.dashboardUrl}` : "\u76D1\u6D4B\u9762\u677F: \uFF08\u672A\u90E8\u7F72\uFF09",
|
|
11364
|
+
`\u4E0A\u62A5\u4EE4\u724C: ${r.monitorToken}`,
|
|
11365
|
+
`\u76D1\u6D4B\u53F0\u5BC6\u7801: ${r.monitorPassword}`,
|
|
11366
|
+
"",
|
|
11367
|
+
"\u8BF7\u59A5\u5584\u4FDD\u5B58\u4E0A\u62A5\u4EE4\u724C\u4E0E\u5BC6\u7801\uFF1A\u4EE4\u724C/\u5BC6\u7801\u4E0D\u4F1A\u518D\u6B21\u660E\u6587\u663E\u793A\u3002",
|
|
11368
|
+
"WSS \u57DF\u540D\u9700\u5728 Cloudflare \u63A7\u5236\u53F0\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540E\u4F7F\u7528\uFF08*.workers.dev \u56FD\u5185\u4E0D\u53EF\u8FBE\uFF09\u3002",
|
|
11369
|
+
"========================================================"
|
|
11370
|
+
].join("\n");
|
|
11371
|
+
}
|
|
11372
|
+
var EDGE_RELAY_COMPAT_DATE, DEFAULT_DO_CLASS, D1_READY_TIMEOUT_MS, D1_RETRY_INITIAL_DELAY_MS, D1_RETRY_MAX_DELAY_MS, MONITOR_SETUP_TIMEOUT_MS;
|
|
11373
|
+
var init_deploy2 = __esm({
|
|
11374
|
+
"src/edge/deploy.ts"() {
|
|
11375
|
+
"use strict";
|
|
11376
|
+
init_cf_api();
|
|
11377
|
+
init_edge_relay_schema();
|
|
11378
|
+
EDGE_RELAY_COMPAT_DATE = "2026-01-01";
|
|
11379
|
+
DEFAULT_DO_CLASS = "MeshRoom";
|
|
11380
|
+
D1_READY_TIMEOUT_MS = 9e4;
|
|
11381
|
+
D1_RETRY_INITIAL_DELAY_MS = 500;
|
|
11382
|
+
D1_RETRY_MAX_DELAY_MS = 5e3;
|
|
11383
|
+
MONITOR_SETUP_TIMEOUT_MS = 9e4;
|
|
11384
|
+
}
|
|
11385
|
+
});
|
|
11386
|
+
|
|
11387
|
+
// src/edge/detect.ts
|
|
11388
|
+
function isEdgeRelayBindings(bindings) {
|
|
11389
|
+
const hasToken = bindings.some(
|
|
11390
|
+
(b) => b.name === "MONITOR_TOKEN" && (b.type === "plain_text" || bindingType(b) === "secret_text")
|
|
11391
|
+
);
|
|
11392
|
+
const hasRoom = bindings.some(
|
|
11393
|
+
(b) => b.type === "durable_object_namespace" && (b.name === "MESH_ROOM" || b.class_name === DO_CLASS)
|
|
11394
|
+
) || bindings.some((b) => b.type === "d1" && b.name === "DB");
|
|
11395
|
+
return hasToken && hasRoom;
|
|
11396
|
+
}
|
|
11397
|
+
function bindingType(b) {
|
|
11398
|
+
return typeof b.type === "string" ? String(b.type) : "";
|
|
11399
|
+
}
|
|
11400
|
+
function readPlainText(bindings, name) {
|
|
11401
|
+
const hit = bindings.find((b) => b.type === "plain_text" && b.name === name);
|
|
11402
|
+
return typeof hit?.text === "string" ? hit.text : "";
|
|
11403
|
+
}
|
|
11404
|
+
function readD1BindingID(bindings) {
|
|
11405
|
+
const hit = bindings.find((b) => b.type === "d1" && b.name === "DB");
|
|
11406
|
+
return typeof hit?.id === "string" ? hit.id : "";
|
|
11407
|
+
}
|
|
11408
|
+
function settingsBindings(settings) {
|
|
11409
|
+
if (!settings || typeof settings !== "object") return [];
|
|
11410
|
+
const raw = settings.bindings;
|
|
11411
|
+
if (!Array.isArray(raw)) return [];
|
|
11412
|
+
return raw.filter((b) => !!b && typeof b === "object" && typeof b.name === "string");
|
|
11413
|
+
}
|
|
11414
|
+
function looksLikeRelayScript(name) {
|
|
11415
|
+
return /(edge[-_]?relay|mobihop|relay)/i.test(name);
|
|
11416
|
+
}
|
|
11417
|
+
function matchZone(domain, zones) {
|
|
11418
|
+
const d = domain.trim().toLowerCase().replace(/\.$/, "");
|
|
11419
|
+
if (!d) return null;
|
|
11420
|
+
let best = null;
|
|
11421
|
+
for (const z of zones) {
|
|
11422
|
+
const name = (z.name || "").trim().toLowerCase().replace(/\.$/, "");
|
|
11423
|
+
if (!name) continue;
|
|
11424
|
+
if (d === name || d.endsWith("." + name)) {
|
|
11425
|
+
if (!best || name.length > best.name.length) best = z;
|
|
11426
|
+
}
|
|
11427
|
+
}
|
|
11428
|
+
return best;
|
|
11429
|
+
}
|
|
11430
|
+
function pickWorkerDomain(domains, workerName) {
|
|
11431
|
+
const hits = domains.filter((d) => d.service === workerName && d.hostname).sort((a, b) => {
|
|
11432
|
+
const ae = a.enabled === false ? 1 : 0;
|
|
11433
|
+
const be = b.enabled === false ? 1 : 0;
|
|
11434
|
+
if (ae !== be) return ae - be;
|
|
11435
|
+
return a.hostname.localeCompare(b.hostname);
|
|
11436
|
+
});
|
|
11437
|
+
return hits[0]?.hostname || "";
|
|
11438
|
+
}
|
|
11439
|
+
function pickDashboardProject(projects, workerName) {
|
|
11440
|
+
const exact = projects.find((p) => p.name === `${workerName}-dashboard`);
|
|
11441
|
+
if (exact) return { project: exact.name, guessed: false };
|
|
11442
|
+
const fuzzy = projects.filter((p) => /(dashboard|monitor)/i.test(p.name || ""));
|
|
11443
|
+
if (fuzzy.length === 1) return { project: fuzzy[0].name, guessed: true };
|
|
11444
|
+
return { project: "", guessed: false };
|
|
11445
|
+
}
|
|
11446
|
+
function rankScriptNames(names, workerName) {
|
|
11447
|
+
const wanted = (workerName || "").trim();
|
|
11448
|
+
return [...names].sort((a, b) => {
|
|
11449
|
+
const score = (n) => {
|
|
11450
|
+
if (wanted && n === wanted) return 0;
|
|
11451
|
+
if (looksLikeRelayScript(n)) return 1;
|
|
11452
|
+
return 2;
|
|
11453
|
+
};
|
|
11454
|
+
const sa = score(a);
|
|
11455
|
+
const sb = score(b);
|
|
11456
|
+
if (sa !== sb) return sa - sb;
|
|
11457
|
+
return a.localeCompare(b);
|
|
11458
|
+
});
|
|
11459
|
+
}
|
|
11460
|
+
async function probeRelay(baseUrl) {
|
|
11461
|
+
const out2 = { reachable: false, dashboardReady: false, passwordSet: false };
|
|
11462
|
+
try {
|
|
11463
|
+
const health = await fetch(`${baseUrl}/health`, { signal: AbortSignal.timeout(6e3) });
|
|
11464
|
+
if (!health.ok) return out2;
|
|
11465
|
+
out2.reachable = true;
|
|
11466
|
+
} catch {
|
|
11467
|
+
return out2;
|
|
11468
|
+
}
|
|
11469
|
+
try {
|
|
11470
|
+
const root = await fetch(`${baseUrl}/`, { signal: AbortSignal.timeout(6e3) });
|
|
11471
|
+
const contentType = root.headers.get("content-type") || "";
|
|
11472
|
+
if (root.ok && /text\/html/i.test(contentType)) {
|
|
11473
|
+
const html = await root.text();
|
|
11474
|
+
out2.dashboardReady = /<!doctype\s+html|<html\b/i.test(html);
|
|
11475
|
+
}
|
|
11476
|
+
} catch {
|
|
11477
|
+
}
|
|
11478
|
+
try {
|
|
11479
|
+
const status2 = await fetch(`${baseUrl}/auth/status`, { signal: AbortSignal.timeout(6e3) });
|
|
11480
|
+
if (status2.ok) {
|
|
11481
|
+
const body = await status2.json();
|
|
11482
|
+
out2.passwordSet = body.setupRequired === false;
|
|
11483
|
+
}
|
|
11484
|
+
} catch {
|
|
11485
|
+
}
|
|
11486
|
+
return out2;
|
|
11487
|
+
}
|
|
11488
|
+
async function detectEdgeRelay(client, opts) {
|
|
11489
|
+
const warnings = [];
|
|
11490
|
+
const accountId = opts.accountId;
|
|
11491
|
+
const probeFn = opts.probeFn ?? probeRelay;
|
|
11492
|
+
const doProbe = opts.probe !== false;
|
|
11493
|
+
let names = [];
|
|
11494
|
+
try {
|
|
11495
|
+
names = await client.listScripts(accountId);
|
|
11496
|
+
} catch (err) {
|
|
11497
|
+
throw new Error(
|
|
11498
|
+
`\u8BFB\u53D6 Worker \u811A\u672C\u5217\u8868\u5931\u8D25\uFF08\u9700\u8981 Workers Scripts / Read \u6743\u9650\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}`
|
|
11499
|
+
);
|
|
11500
|
+
}
|
|
11501
|
+
if (!Array.isArray(names)) names = [];
|
|
11502
|
+
let domains = [];
|
|
11503
|
+
try {
|
|
11504
|
+
domains = await client.listWorkerDomains(accountId);
|
|
11505
|
+
} catch (err) {
|
|
11506
|
+
warnings.push(`\u8BFB\u53D6 Worker \u57DF\u540D\u7ED1\u5B9A\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
11507
|
+
}
|
|
11508
|
+
let d1List = [];
|
|
11509
|
+
try {
|
|
11510
|
+
d1List = await client.listD1Databases(accountId);
|
|
11511
|
+
} catch (err) {
|
|
11512
|
+
warnings.push(`\u8BFB\u53D6 D1 \u6570\u636E\u5E93\u5217\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
11513
|
+
}
|
|
11514
|
+
let projects = [];
|
|
11515
|
+
try {
|
|
11516
|
+
projects = await client.listPagesProjects(accountId);
|
|
11517
|
+
} catch (err) {
|
|
11518
|
+
warnings.push(`\u8BFB\u53D6 Pages \u9879\u76EE\u5217\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
11519
|
+
}
|
|
11520
|
+
let zones = [];
|
|
11521
|
+
try {
|
|
11522
|
+
zones = await client.listZones();
|
|
11523
|
+
} catch (err) {
|
|
11524
|
+
warnings.push(`\u8BFB\u53D6 Zone \u5217\u8868\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
11525
|
+
}
|
|
11526
|
+
let workersSubdomain = "";
|
|
11527
|
+
try {
|
|
11528
|
+
workersSubdomain = await client.getWorkersSubdomain(accountId);
|
|
11529
|
+
} catch {
|
|
11530
|
+
}
|
|
11531
|
+
const ranked = rankScriptNames(names, opts.workerName || "");
|
|
11532
|
+
const toProbe = ranked.slice(0, MAX_SETTINGS_PROBES);
|
|
11533
|
+
if (ranked.length > toProbe.length) {
|
|
11534
|
+
warnings.push(
|
|
11535
|
+
`\u8D26\u53F7\u4E0B\u6709 ${ranked.length} \u4E2A Worker \u811A\u672C\uFF0C\u53EA\u68C0\u67E5\u4E86\u524D ${toProbe.length} \u4E2A\uFF08\u4F18\u5148\u540D\u5B57\u50CF\u76F2\u4E2D\u7EE7\u7684\uFF09`
|
|
11536
|
+
);
|
|
11537
|
+
}
|
|
11538
|
+
const instances = [];
|
|
11539
|
+
for (const name of toProbe) {
|
|
11540
|
+
let bindings;
|
|
11541
|
+
try {
|
|
11542
|
+
const settings = await client.getScriptSettings(accountId, name);
|
|
11543
|
+
bindings = settingsBindings(settings);
|
|
11544
|
+
} catch {
|
|
11545
|
+
continue;
|
|
11546
|
+
}
|
|
11547
|
+
if (!isEdgeRelayBindings(bindings)) continue;
|
|
11548
|
+
const w = [];
|
|
11549
|
+
const domain = pickWorkerDomain(domains, name);
|
|
11550
|
+
if (!domain) {
|
|
11551
|
+
w.push("\u672A\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540D\uFF1Aworkers.dev \u751F\u4EA7\u94FE\u8DEF\u88AB\u963B\u65AD\uFF0C\u8282\u70B9\u8FDE\u4E0D\u4E0A");
|
|
11552
|
+
}
|
|
11553
|
+
const zone = matchZone(domain, zones);
|
|
11554
|
+
const dash = pickDashboardProject(projects, name);
|
|
11555
|
+
const d1ID = readD1BindingID(bindings);
|
|
11556
|
+
const d1 = d1List.find((db) => db.uuid === d1ID) ?? d1List.find((db) => db.name === `${name}-monitor`);
|
|
11557
|
+
if (!d1) w.push("\u6CA1\u627E\u5230\u76D1\u6D4B\u6570\u636E\u5E93\uFF08D1\uFF09\uFF0C\u76D1\u6D4B\u53F0\u53EF\u80FD\u4E0D\u53EF\u7528");
|
|
11558
|
+
const monitorToken = readPlainText(bindings, "MONITOR_TOKEN");
|
|
11559
|
+
if (!monitorToken) {
|
|
11560
|
+
w.push("\u4E0A\u62A5\u4EE4\u724C\u4EE5 secret \u5B58\u50A8\u6216\u5DF2\u88AB\u79FB\u9664\uFF0C\u65E0\u6CD5\u56DE\u586B \u2014\u2014 \u8BF7\u5230 Worker \u7AEF\u6838\u5BF9 MONITOR_TOKEN");
|
|
11561
|
+
}
|
|
11562
|
+
let workerUrl = domain ? `https://${domain}` : "";
|
|
11563
|
+
if (!workerUrl && workersSubdomain) {
|
|
11564
|
+
workerUrl = `https://${name}.${workersSubdomain}.workers.dev`;
|
|
11565
|
+
}
|
|
11566
|
+
let reachable = false;
|
|
11567
|
+
let dashboardReady = false;
|
|
11568
|
+
let passwordSet = false;
|
|
11569
|
+
if (doProbe && domain) {
|
|
11570
|
+
try {
|
|
11571
|
+
const probe = await probeFn(workerUrl);
|
|
11572
|
+
reachable = probe.reachable;
|
|
11573
|
+
dashboardReady = probe.dashboardReady;
|
|
11574
|
+
passwordSet = probe.passwordSet;
|
|
11575
|
+
if (!reachable) {
|
|
11576
|
+
w.push("\u672C\u673A\u8BBF\u95EE\u4E0D\u5230\u8BE5\u57DF\u540D\uFF08\u53EF\u80FD\u9700\u8981\u4EE3\u7406\uFF09\uFF0C\u914D\u7F6E\u4ECD\u53EF\u56DE\u586B");
|
|
11577
|
+
}
|
|
11578
|
+
if (reachable && !dashboardReady) {
|
|
11579
|
+
w.push("\u76D1\u6D4B\u53F0\u672A\u90E8\u7F72\uFF1A\u76F2\u4E2D\u7EE7\u6839\u8DEF\u5F84\u5C1A\u672A\u8FD4\u56DE\u76D1\u6D4B\u9875\u9762");
|
|
11580
|
+
}
|
|
11581
|
+
} catch (err) {
|
|
11582
|
+
w.push(`\u53EF\u8FBE\u6027\u63A2\u6D4B\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`);
|
|
11583
|
+
}
|
|
11584
|
+
}
|
|
11585
|
+
instances.push({
|
|
11586
|
+
workerName: name,
|
|
11587
|
+
domain,
|
|
11588
|
+
workerUrl,
|
|
11589
|
+
wssEndpoint: domain ? `wss://${domain}/mesh/<network_hash>?peer_id=<16hex>` : "",
|
|
11590
|
+
zoneId: zone?.id || "",
|
|
11591
|
+
zoneName: zone?.name || "",
|
|
11592
|
+
dashboardProject: dash.project,
|
|
11593
|
+
dashboardUrl: dashboardReady ? workerUrl : "",
|
|
11594
|
+
dashboardReady,
|
|
11595
|
+
d1Name: d1?.name || "",
|
|
11596
|
+
d1Uuid: d1?.uuid || "",
|
|
11597
|
+
doClass: DO_CLASS,
|
|
11598
|
+
monitorToken,
|
|
11599
|
+
limits: {
|
|
11600
|
+
windowMs: readPlainText(bindings, "WINDOW_MS"),
|
|
11601
|
+
maxBytes: readPlainText(bindings, "MAX_BYTES_PER_WINDOW"),
|
|
11602
|
+
maxPackets: readPlainText(bindings, "MAX_PACKETS_PER_WINDOW"),
|
|
11603
|
+
maxPeers: readPlainText(bindings, "MAX_PEERS_PER_ROOM")
|
|
11604
|
+
},
|
|
11605
|
+
reachable,
|
|
11606
|
+
passwordSet,
|
|
11607
|
+
warnings: w
|
|
11608
|
+
});
|
|
11609
|
+
}
|
|
11610
|
+
const wantedDomain = (opts.domain || "").trim().toLowerCase();
|
|
11611
|
+
const wantedWorker = (opts.workerName || "").trim();
|
|
11612
|
+
let filtered = instances;
|
|
11613
|
+
if (wantedDomain || wantedWorker) {
|
|
11614
|
+
const hit = instances.filter(
|
|
11615
|
+
(i) => wantedDomain && i.domain.toLowerCase() === wantedDomain || wantedWorker && i.workerName === wantedWorker
|
|
11616
|
+
);
|
|
11617
|
+
if (hit.length > 0) filtered = hit;
|
|
11618
|
+
}
|
|
11619
|
+
filtered.sort((a, b) => a.workerName.localeCompare(b.workerName));
|
|
11620
|
+
return { instances: filtered, warnings };
|
|
11621
|
+
}
|
|
11622
|
+
function formatEdgeDetectSummary(result) {
|
|
11623
|
+
const lines = [""];
|
|
11624
|
+
if (result.instances.length === 0) {
|
|
11625
|
+
lines.push("\u6CA1\u6709\u68C0\u6D4B\u5230\u76F2\u4E2D\u7EE7\u5B9E\u4F8B\uFF08\u8BE5\u8D26\u53F7\u4E0B\u6682\u65E0\u5339\u914D\u7684 Worker\uFF09\u3002");
|
|
11626
|
+
lines.push("\u5982\u679C\u662F\u521A\u90E8\u7F72\u4F46\u8FD9\u91CC\u67E5\u4E0D\u5230\uFF1A\u786E\u8BA4 Token \u5177\u5907 Workers Scripts / Read \u6743\u9650\u3002");
|
|
11627
|
+
} else {
|
|
11628
|
+
lines.push(`\u68C0\u6D4B\u5230 ${result.instances.length} \u4E2A\u76F2\u4E2D\u7EE7\u5B9E\u4F8B\uFF1A`);
|
|
11629
|
+
result.instances.forEach((ins, i) => {
|
|
11630
|
+
const token = ins.monitorToken ? `${ins.monitorToken.slice(0, 8)}\u2026\uFF08${ins.monitorToken.length} \u4F4D\uFF09` : "\uFF08\u4E0D\u53EF\u8BFB\u53D6\uFF09";
|
|
11631
|
+
lines.push("");
|
|
11632
|
+
lines.push(`[${i + 1}] ${ins.workerName}`);
|
|
11633
|
+
lines.push(` \u57DF\u540D: ${ins.domain || "\uFF08\u672A\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540D\uFF09"}`);
|
|
11634
|
+
lines.push(` \u76D1\u6D4B API: ${ins.workerUrl || "\uFF08\u672A\u77E5\uFF09"}`);
|
|
11635
|
+
lines.push(` WSS \u7AEF\u70B9: ${ins.wssEndpoint || "\uFF08\u9700\u5148\u7ED1\u5B9A\u57DF\u540D\uFF09"}`);
|
|
11636
|
+
lines.push(` Zone: ${ins.zoneName ? `${ins.zoneName} (${ins.zoneId})` : "\uFF08\u672A\u5339\u914D\uFF09"}`);
|
|
11637
|
+
lines.push(` \u76D1\u6D4B\u53F0: ${ins.dashboardReady ? ins.dashboardUrl : "\u672A\u90E8\u7F72 / \u6839\u8DEF\u5F84\u4E0D\u53EF\u7528"}`);
|
|
11638
|
+
lines.push(` D1: ${ins.d1Name || "\uFF08\u672A\u627E\u5230\uFF09"}`);
|
|
11639
|
+
lines.push(` \u4E0A\u62A5\u4EE4\u724C: ${token}`);
|
|
11640
|
+
lines.push(
|
|
11641
|
+
` \u53EF\u8FBE\u6027: ${ins.reachable ? "\u53EF\u8FBE" : "\u672C\u673A\u4E0D\u53EF\u8FBE"} \xB7 \u76D1\u6D4B\u53F0\u5BC6\u7801: ${ins.passwordSet ? "\u5DF2\u8BBE\u7F6E" : "\u672A\u8BBE\u7F6E / \u672A\u77E5"}`
|
|
11642
|
+
);
|
|
11643
|
+
for (const w of ins.warnings) lines.push(` \u63D0\u793A: ${w}`);
|
|
11644
|
+
});
|
|
11645
|
+
}
|
|
11646
|
+
if (result.warnings.length > 0) {
|
|
11647
|
+
lines.push("");
|
|
11648
|
+
lines.push("\u5176\u5B83\u63D0\u793A\uFF1A");
|
|
11649
|
+
for (const w of result.warnings) lines.push(` - ${w}`);
|
|
11650
|
+
}
|
|
11651
|
+
lines.push("");
|
|
11652
|
+
lines.push("\u8BF4\u660E\uFF1A\u76D1\u6D4B\u53F0\u5BC6\u7801\u53EA\u4FDD\u5B58\u54C8\u5E0C\uFF0C\u65E0\u6CD5\u8BFB\u53D6\uFF1B\u9700\u8981\u91CD\u7F6E\u8BF7\u91CD\u65B0\u90E8\u7F72\u6216\u5728\u76D1\u6D4B\u53F0\u91CC\u6539\u5BC6\u3002");
|
|
11653
|
+
return lines.join("\n") + "\n";
|
|
11654
|
+
}
|
|
11655
|
+
var DO_CLASS, MAX_SETTINGS_PROBES;
|
|
11656
|
+
var init_detect = __esm({
|
|
11657
|
+
"src/edge/detect.ts"() {
|
|
11658
|
+
"use strict";
|
|
11659
|
+
DO_CLASS = "MeshRoom";
|
|
11660
|
+
MAX_SETTINGS_PROBES = 12;
|
|
11661
|
+
}
|
|
11662
|
+
});
|
|
11663
|
+
|
|
11664
|
+
// src/edge/command.ts
|
|
11665
|
+
var command_exports3 = {};
|
|
11666
|
+
__export(command_exports3, {
|
|
11667
|
+
runEdgeCommand: () => runEdgeCommand
|
|
11668
|
+
});
|
|
11669
|
+
function randomPassword2(bytes = 12) {
|
|
11670
|
+
const arr = new Uint8Array(bytes);
|
|
11671
|
+
crypto.getRandomValues(arr);
|
|
11672
|
+
return Array.from(arr, (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
11673
|
+
}
|
|
11674
|
+
async function runEdgeCommand(args) {
|
|
11675
|
+
const action = args.positionals[0] ?? (flagBool(args, "h") || flagBool(args, "help") ? "help" : "deploy");
|
|
11676
|
+
if (action === "help" || flagBool(args, "h") || flagBool(args, "help")) {
|
|
11677
|
+
process.stdout.write(EDGE_HELP);
|
|
11678
|
+
return;
|
|
11679
|
+
}
|
|
11680
|
+
if (action === "status") {
|
|
11681
|
+
await runEdgeStatus(args);
|
|
11682
|
+
return;
|
|
11683
|
+
}
|
|
11684
|
+
if (action !== "deploy") {
|
|
11685
|
+
process.stderr.write(`\u672A\u77E5 edge \u52A8\u4F5C\uFF1A${action}
|
|
11686
|
+
|
|
11687
|
+
`);
|
|
11688
|
+
process.stderr.write(EDGE_HELP);
|
|
11689
|
+
process.exitCode = 1;
|
|
11690
|
+
return;
|
|
11691
|
+
}
|
|
11692
|
+
const token = flagString(args, "token") || process.env.CLOUDFLARE_API_TOKEN || "";
|
|
11693
|
+
if (!token) {
|
|
11694
|
+
process.stderr.write("\u7F3A\u5C11 --token \u53C2\u6570\uFF08\u6216\u8BBE\u7F6E CLOUDFLARE_API_TOKEN\uFF09\n");
|
|
11695
|
+
process.exitCode = 1;
|
|
11696
|
+
return;
|
|
11697
|
+
}
|
|
11698
|
+
const domain = flagString(args, "domain").trim();
|
|
11699
|
+
if (!domain) {
|
|
11700
|
+
process.stderr.write("\u7F3A\u5C11 --domain\uFF08\u76F2\u4E2D\u7EE7\u5FC5\u987B\u81EA\u5B9A\u4E49\u57DF\u540D\uFF09\n");
|
|
11701
|
+
process.exitCode = 1;
|
|
11702
|
+
return;
|
|
11703
|
+
}
|
|
11704
|
+
const client = new CloudflareClient({ token });
|
|
11705
|
+
let accountId = flagString(args, "account").trim();
|
|
11706
|
+
if (!accountId) {
|
|
11707
|
+
const accounts = await client.listAccounts();
|
|
11708
|
+
if (accounts.length === 0) {
|
|
11709
|
+
process.stderr.write("\u8D26\u53F7\u5217\u8868\u4E3A\u7A7A\uFF0C\u8BF7\u7528 --account \u6307\u5B9A\n");
|
|
11710
|
+
process.exitCode = 1;
|
|
11711
|
+
return;
|
|
11712
|
+
}
|
|
11713
|
+
const account = accounts[0];
|
|
11714
|
+
accountId = account.id;
|
|
11715
|
+
process.stderr.write(`\u4F7F\u7528\u8D26\u53F7\uFF1A${account.name}\uFF08${accountId.slice(0, 8)}\u2026\uFF09
|
|
11716
|
+
`);
|
|
11717
|
+
}
|
|
11718
|
+
let zoneId = flagString(args, "zone-id").trim();
|
|
11719
|
+
if (!zoneId) {
|
|
11720
|
+
const zones = await client.listZones();
|
|
11721
|
+
const normalizedDomain = domain.toLowerCase().replace(/\.$/, "");
|
|
11722
|
+
const match = zones.filter((z) => normalizedDomain === z.name.toLowerCase() || normalizedDomain.endsWith("." + z.name.toLowerCase())).sort((a, b) => b.name.length - a.name.length)[0];
|
|
11723
|
+
if (match) {
|
|
11724
|
+
zoneId = match.id;
|
|
11725
|
+
process.stderr.write(`\u627E\u5230 zone\uFF1A${match.name}\uFF0C\u5C06\u81EA\u52A8\u7ED1\u5B9A\u57DF\u540D
|
|
11726
|
+
`);
|
|
11727
|
+
} else {
|
|
11728
|
+
process.stderr.write(`\u672A\u627E\u5230\u8986\u76D6 ${domain} \u7684 zone\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u7ED1\u5B9A\uFF1B\u8BF7\u90E8\u7F72\u540E\u5728\u63A7\u5236\u53F0\u624B\u52A8\u7ED1\u5B9A ${domain}
|
|
11729
|
+
`);
|
|
11730
|
+
}
|
|
11731
|
+
}
|
|
11732
|
+
let password = flagString(args, "monitor-password").trim();
|
|
11733
|
+
let generatedPw = false;
|
|
11734
|
+
if (!password) {
|
|
11735
|
+
password = randomPassword2();
|
|
11736
|
+
generatedPw = true;
|
|
11737
|
+
}
|
|
11738
|
+
if (password.length < 8) {
|
|
11739
|
+
process.stderr.write("\u76D1\u6D4B\u53F0\u5BC6\u7801\u81F3\u5C11 8 \u4F4D\n");
|
|
11740
|
+
process.exitCode = 1;
|
|
11741
|
+
return;
|
|
11742
|
+
}
|
|
11743
|
+
const result = await deployEdgeRelay(client, {
|
|
11744
|
+
accountId,
|
|
11745
|
+
domain,
|
|
11746
|
+
workerName: flagString(args, "worker-name").trim() || void 0,
|
|
11747
|
+
monitorPassword: password,
|
|
11748
|
+
monitorToken: flagString(args, "monitor-token").trim() || void 0,
|
|
11749
|
+
dashboardProject: flagString(args, "dashboard-project").trim() || void 0,
|
|
11750
|
+
withDashboard: !flagBool(args, "no-dashboard"),
|
|
11751
|
+
zoneId: zoneId || void 0,
|
|
11752
|
+
limits: {
|
|
11753
|
+
windowMs: flagNumber(args, "window-ms", 1e3).toString(),
|
|
11754
|
+
maxBytesPerWindow: flagNumber(args, "max-bytes", 1048576).toString(),
|
|
11755
|
+
maxPacketsPerWindow: flagNumber(args, "max-packets", 2e3).toString(),
|
|
11756
|
+
maxPeersPerRoom: flagNumber(args, "max-peers", 512).toString()
|
|
11757
|
+
},
|
|
11758
|
+
onProgress: (m) => process.stdout.write(`[edge] ${m}
|
|
11759
|
+
`)
|
|
11760
|
+
});
|
|
11761
|
+
process.stdout.write(formatEdgeDeploySummary(result));
|
|
11762
|
+
if (generatedPw) {
|
|
11763
|
+
process.stdout.write("\uFF08\u76D1\u6D4B\u53F0\u5BC6\u7801\u4E3A\u81EA\u52A8\u751F\u6210\uFF0C\u4E0A\u65B9\u5DF2\u663E\u793A\uFF0C\u8BF7\u7ACB\u5373\u4FDD\u5B58\uFF09\n");
|
|
11764
|
+
}
|
|
11765
|
+
}
|
|
11766
|
+
async function runEdgeStatus(args) {
|
|
11767
|
+
const token = flagString(args, "token") || process.env.CLOUDFLARE_API_TOKEN || "";
|
|
11768
|
+
if (!token) {
|
|
11769
|
+
process.stderr.write("\u7F3A\u5C11 --token \u53C2\u6570\uFF08\u6216\u8BBE\u7F6E CLOUDFLARE_API_TOKEN\uFF09\n");
|
|
11770
|
+
process.exitCode = 1;
|
|
11771
|
+
return;
|
|
11772
|
+
}
|
|
11773
|
+
const client = new CloudflareClient({ token });
|
|
11774
|
+
let accountId = flagString(args, "account").trim();
|
|
11775
|
+
if (!accountId) {
|
|
11776
|
+
const accounts = await client.listAccounts();
|
|
11777
|
+
if (accounts.length === 0) {
|
|
11778
|
+
process.stderr.write("\u8D26\u53F7\u5217\u8868\u4E3A\u7A7A\uFF0C\u8BF7\u7528 --account \u6307\u5B9A\n");
|
|
11779
|
+
process.exitCode = 1;
|
|
11780
|
+
return;
|
|
11781
|
+
}
|
|
11782
|
+
accountId = accounts[0].id;
|
|
11783
|
+
process.stderr.write(`\u4F7F\u7528\u8D26\u53F7\uFF1A${accounts[0].name}\uFF08${accountId.slice(0, 8)}\u2026\uFF09
|
|
11784
|
+
`);
|
|
11785
|
+
}
|
|
11786
|
+
const result = await detectEdgeRelay(client, {
|
|
11787
|
+
accountId,
|
|
11788
|
+
domain: flagString(args, "domain").trim() || void 0,
|
|
11789
|
+
workerName: flagString(args, "worker-name").trim() || void 0,
|
|
11790
|
+
probe: !flagBool(args, "no-probe")
|
|
11791
|
+
});
|
|
11792
|
+
if (flagBool(args, "json")) {
|
|
11793
|
+
process.stdout.write(JSON.stringify({ ok: true, accountId, ...result }, null, 2) + "\n");
|
|
11794
|
+
return;
|
|
11795
|
+
}
|
|
11796
|
+
process.stdout.write(formatEdgeDetectSummary(result));
|
|
11797
|
+
}
|
|
11798
|
+
var EDGE_HELP;
|
|
11799
|
+
var init_command3 = __esm({
|
|
11800
|
+
"src/edge/command.ts"() {
|
|
11801
|
+
"use strict";
|
|
11802
|
+
init_args();
|
|
11803
|
+
init_cf_api();
|
|
11804
|
+
init_deploy2();
|
|
11805
|
+
init_detect();
|
|
11806
|
+
EDGE_HELP = `
|
|
11807
|
+
cfpilot edge \u2014\u2014 \u76F2\u4E2D\u7EE7 / \u4E91\u76D1\u6D4B\u53F0\u90E8\u7F72\uFF08MobiHop \u8FB9\u7F18\u5DE5\u7A0B\uFF09
|
|
11808
|
+
|
|
11809
|
+
\u7528\u6CD5:
|
|
11810
|
+
cfpilot edge deploy [\u9009\u9879] \u90E8\u7F72\u76F2\u4E2D\u7EE7 Worker + \u76D1\u6D4B\u9762\u677F
|
|
11811
|
+
cfpilot edge status [\u9009\u9879] \u68C0\u6D4B\u5DF2\u90E8\u7F72\u7684\u76F2\u4E2D\u7EE7\u5B9E\u4F8B\uFF08\u53EA\u8BFB\uFF0C\u7EDD\u4E0D\u90E8\u7F72\uFF09
|
|
11812
|
+
cfpilot edge help \u663E\u793A\u672C\u5E2E\u52A9
|
|
11813
|
+
|
|
11814
|
+
status \u9009\u9879:
|
|
11815
|
+
--token <token> Cloudflare API Token\uFF08\u6216 CLOUDFLARE_API_TOKEN\uFF09
|
|
11816
|
+
--account <id> \u76EE\u6807\u8D26\u53F7 ID\uFF08\u4E0D\u4F20\u5219\u53D6\u8D26\u53F7\u5217\u8868\u7B2C\u4E00\u4E2A\uFF09
|
|
11817
|
+
--domain <host> \u53EA\u770B\u8FD9\u4E2A\u57DF\u540D\u5BF9\u5E94\u7684\u5B9E\u4F8B
|
|
11818
|
+
--worker-name <name> \u53EA\u770B\u8FD9\u4E2A Worker
|
|
11819
|
+
--no-probe \u8DF3\u8FC7\u57DF\u540D\u53EF\u8FBE\u6027\u63A2\u6D4B\uFF08\u79BB\u7EBF\u6392\u67E5\u65F6\u7528\uFF09
|
|
11820
|
+
--json \u4EE5 JSON \u8F93\u51FA\uFF08\u5199\u811A\u672C\u7528\uFF09
|
|
11821
|
+
|
|
11822
|
+
deploy \u9009\u9879:
|
|
11823
|
+
--token <token> Cloudflare API Token\uFF08\u6216 CLOUDFLARE_API_TOKEN\uFF09
|
|
11824
|
+
--account <id> \u76EE\u6807\u8D26\u53F7 ID\uFF08\u4E0D\u4F20\u5219\u53D6\u8D26\u53F7\u5217\u8868\u7B2C\u4E00\u4E2A\uFF09
|
|
11825
|
+
--domain <host> \u76F2\u4E2D\u7EE7\u81EA\u5B9A\u4E49\u57DF\u540D\uFF08\u5FC5\u586B\uFF1B*.workers.dev \u56FD\u5185\u88AB\u6C61\u67D3\uFF09
|
|
11826
|
+
--worker-name <name> Worker \u540D\uFF08\u9ED8\u8BA4 mobihop-edge-relay\uFF09
|
|
11827
|
+
--monitor-password <pw> \u76D1\u6D4B\u53F0\u521D\u59CB\u5BC6\u7801\uFF08\u22658 \u4F4D\uFF1B\u7559\u7A7A\u5219\u968F\u673A\u751F\u6210\uFF09
|
|
11828
|
+
--monitor-token <t> \u4E0A\u62A5\u4EE4\u724C\uFF08\u7559\u7A7A\u5219\u968F\u673A\u751F\u6210\uFF09
|
|
11829
|
+
--dashboard-project <n> \u76D1\u6D4B\u9762\u677F Pages \u9879\u76EE\u540D\uFF08\u9ED8\u8BA4 <worker-name>-dashboard\uFF09
|
|
11830
|
+
--no-dashboard \u53EA\u90E8\u7F72 Worker\uFF0C\u4E0D\u90E8\u7F72\u76D1\u6D4B\u9762\u677F
|
|
11831
|
+
--zone-id <id> \u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540D\u6240\u9700 zone ID\uFF08\u4E0D\u4F20\u5219\u6309\u57DF\u540D\u4E3B\u57DF\u67E5\uFF1B\u67E5\u4E0D\u5230\u4F1A\u63D0\u793A\u624B\u7ED1\uFF09
|
|
11832
|
+
--window-ms <n> \u6ED1\u52A8\u7A97\u53E3 ms\uFF08\u9ED8\u8BA4 1000\uFF09
|
|
11833
|
+
--max-bytes <n> \u7A97\u53E3\u5B57\u8282\u4E0A\u9650\uFF08\u9ED8\u8BA4 1048576\uFF09
|
|
11834
|
+
--max-packets <n> \u7A97\u53E3\u5305\u6570\u4E0A\u9650\uFF08\u9ED8\u8BA4 2000\uFF09
|
|
11835
|
+
--max-peers <n> \u5355\u623F\u95F4\u8FDE\u63A5\u4E0A\u9650\uFF08\u9ED8\u8BA4 512\uFF09
|
|
11836
|
+
|
|
11837
|
+
Token \u6743\u9650\uFF08\u65B0\u589E\uFF0C\u57FA\u7840\u4EE3\u7406\u90E8\u7F72\u4E0D\u9700\u8981\uFF09:
|
|
11838
|
+
Workers Scripts / Edit \xB7 Durable Objects / Edit \xB7 D1 / Edit \xB7 Pages / Edit
|
|
11839
|
+
Zone & DNS / Edit\uFF08\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u65F6\u9700\u8981\uFF09
|
|
11840
|
+
|
|
11841
|
+
\u793A\u4F8B:
|
|
11842
|
+
cfpilot edge deploy --token <TOKEN> --domain relay.example.com --monitor-password <PW>
|
|
11843
|
+
`;
|
|
11844
|
+
}
|
|
11845
|
+
});
|
|
11846
|
+
|
|
11847
|
+
// src/mesh/command.ts
|
|
11848
|
+
var command_exports4 = {};
|
|
11849
|
+
__export(command_exports4, {
|
|
11850
|
+
runMeshCommand: () => runMeshCommand
|
|
11851
|
+
});
|
|
11852
|
+
async function runMeshCommand(args) {
|
|
11853
|
+
const raw = (args.positionals[0] ?? "help").toLowerCase();
|
|
11854
|
+
if (flagBool(args, "h") || flagBool(args, "help") || raw === "help") {
|
|
11855
|
+
process.stdout.write(MESH_HELP);
|
|
11856
|
+
return;
|
|
11857
|
+
}
|
|
11858
|
+
if (!SUBCOMMANDS.includes(raw)) {
|
|
11859
|
+
process.stderr.write(`\u672A\u77E5 mesh \u52A8\u4F5C\uFF1A${raw}
|
|
11860
|
+
|
|
11861
|
+
${MESH_HELP}`);
|
|
11862
|
+
process.exitCode = 1;
|
|
11863
|
+
return;
|
|
11864
|
+
}
|
|
11865
|
+
const sub = raw;
|
|
11866
|
+
if (sub === "join" && !(args.positionals[1] ?? "").trim()) {
|
|
11867
|
+
process.stderr.write("mesh join \u9700\u8981 <uri> \u53C2\u6570\uFF08mobihop://join/v1/...\uFF09\n");
|
|
11868
|
+
process.exitCode = 1;
|
|
11869
|
+
return;
|
|
11870
|
+
}
|
|
11871
|
+
process.stdout.write(`[mesh:${sub}] ${PHASE_3B_NOTICE}
|
|
11872
|
+
`);
|
|
11873
|
+
}
|
|
11874
|
+
var MESH_HELP, SUBCOMMANDS, PHASE_3B_NOTICE;
|
|
11875
|
+
var init_command4 = __esm({
|
|
11876
|
+
"src/mesh/command.ts"() {
|
|
11877
|
+
"use strict";
|
|
11878
|
+
init_args();
|
|
11879
|
+
MESH_HELP = `
|
|
11880
|
+
cfpilot mesh \u2014\u2014 MobiHop \u7EC4\u7F51\uFF08CFPilot +mesh \u53D8\u4F53\uFF0C\u9AA8\u67B6\u9636\u6BB5\uFF09
|
|
11881
|
+
|
|
11882
|
+
\u26A0\uFE0F \u5F53\u524D\u7248\u672C\u4E3A\u5DE5\u7A0B\u9AA8\u67B6\uFF1A\u547D\u4EE4\u6846\u67B6\u5DF2\u5C31\u4F4D\uFF0C\u7EC4\u7F51\u534F\u8BAE\u5B9E\u73B0\u5F85 Phase 3b \u5B8C\u6210\u3002
|
|
11883
|
+
\u5C4A\u65F6\u672C\u547D\u4EE4\u5C06\u4E0E MobiHop \u8282\u70B9\u5B57\u8282\u7EA7\u4E92\u901A\uFF0832B \u5E27 / Noise IKpsk2 / AEAD / \u6253\u6D1E / \u9009\u8DEF\uFF09\u3002
|
|
11884
|
+
|
|
11885
|
+
\u7528\u6CD5:
|
|
11886
|
+
cfpilot mesh help \u663E\u793A\u672C\u5E2E\u52A9
|
|
11887
|
+
cfpilot mesh status \u67E5\u770B\u7EC4\u7F51\u72B6\u6001\uFF08\u5F85 3b\uFF09
|
|
11888
|
+
cfpilot mesh peers \u67E5\u770B\u5BF9\u7B49\u8282\u70B9\uFF08\u5F85 3b\uFF09
|
|
11889
|
+
cfpilot mesh up \u542F\u52A8\u7EC4\u7F51\uFF08\u9700\u7BA1\u7406\u5458/root\uFF1B\u5F85 3b\uFF09
|
|
11890
|
+
cfpilot mesh down \u505C\u6B62\u7EC4\u7F51\uFF08\u5F85 3b\uFF09
|
|
11891
|
+
cfpilot mesh invite \u751F\u6210\u5165\u7F51\u9080\u8BF7\uFF08\u5F85 3b\uFF09
|
|
11892
|
+
cfpilot mesh join <uri> \u52A0\u5165\u7F51\u7EDC\uFF08\u5F85 3b\uFF09
|
|
11893
|
+
|
|
11894
|
+
TUN \u865A\u62DF\u7F51\u5361\u9700\u8981\u7BA1\u7406\u5458/root \u6743\u9650\uFF1B\u65E5\u5E38\u4F7F\u7528\u5EFA\u8BAE\u684C\u9762\u7248 +mesh \u53D8\u4F53\uFF08\u56FE\u5F62\u5F15\u5BFC\u63D0\u6743\uFF09\u3002
|
|
11895
|
+
\u534F\u8BAE\u6743\u5A01\uFF1AE:\\Projects\\MobiHop\uFF08docs/MESH_INTEGRATION_CONTRACT.md\uFF09\u3002
|
|
11896
|
+
`;
|
|
11897
|
+
SUBCOMMANDS = ["help", "status", "peers", "up", "down", "invite", "join"];
|
|
11898
|
+
PHASE_3B_NOTICE = "mesh \u547D\u4EE4\u5904\u4E8E Phase 3a \u9AA8\u67B6\u9636\u6BB5\uFF1A\u534F\u8BAE\u5B9E\u73B0\uFF08\u542B\u4E0E MobiHop \u8282\u70B9\u4E92\u901A\uFF09\u5F85 Phase 3b \u5B8C\u6210\u3002\u5F53\u524D\u4EC5\u9A8C\u8BC1\u547D\u4EE4\u5206\u53D1\u4E0E\u53C2\u6570\u6821\u9A8C\u3002";
|
|
11899
|
+
}
|
|
11900
|
+
});
|
|
11901
|
+
|
|
10937
11902
|
// src/sources/builtin.generated.ts
|
|
10938
11903
|
var BUILTIN_SOURCES_JSON;
|
|
10939
11904
|
var init_builtin_generated = __esm({
|
|
@@ -10947,7 +11912,7 @@ var init_builtin_generated = __esm({
|
|
|
10947
11912
|
import {
|
|
10948
11913
|
existsSync as existsSync3,
|
|
10949
11914
|
mkdirSync as mkdirSync3,
|
|
10950
|
-
readFileSync as
|
|
11915
|
+
readFileSync as readFileSync7,
|
|
10951
11916
|
renameSync as renameSync2,
|
|
10952
11917
|
unlinkSync as unlinkSync2,
|
|
10953
11918
|
writeFileSync as writeFileSync4
|
|
@@ -10970,7 +11935,7 @@ function blankSources() {
|
|
|
10970
11935
|
}
|
|
10971
11936
|
function readSourcesRaw() {
|
|
10972
11937
|
try {
|
|
10973
|
-
return
|
|
11938
|
+
return readFileSync7(sourcesPath(), "utf8");
|
|
10974
11939
|
} catch {
|
|
10975
11940
|
return "";
|
|
10976
11941
|
}
|
|
@@ -11599,7 +12564,7 @@ async function syncSources(options = {}) {
|
|
|
11599
12564
|
const spec = PROVIDERS[source.type];
|
|
11600
12565
|
if (spec && lastType === source.type) {
|
|
11601
12566
|
const wait = spec.minIntervalMs - (Date.now() - lastAt);
|
|
11602
|
-
if (wait > 0) await new Promise((
|
|
12567
|
+
if (wait > 0) await new Promise((resolve5) => setTimeout(resolve5, wait));
|
|
11603
12568
|
}
|
|
11604
12569
|
lastType = source.type;
|
|
11605
12570
|
lastAt = Date.now();
|
|
@@ -11773,14 +12738,14 @@ __export(light_exports, {
|
|
|
11773
12738
|
});
|
|
11774
12739
|
import { Socket as Socket3 } from "node:net";
|
|
11775
12740
|
function tcpProbeOnce(ip, port, timeoutMs) {
|
|
11776
|
-
return new Promise((
|
|
12741
|
+
return new Promise((resolve5) => {
|
|
11777
12742
|
const socket = new Socket3();
|
|
11778
12743
|
let settled = false;
|
|
11779
12744
|
const done = (ok) => {
|
|
11780
12745
|
if (settled) return;
|
|
11781
12746
|
settled = true;
|
|
11782
12747
|
socket.destroy();
|
|
11783
|
-
|
|
12748
|
+
resolve5(ok);
|
|
11784
12749
|
};
|
|
11785
12750
|
socket.setTimeout(timeoutMs, () => done(false));
|
|
11786
12751
|
socket.once("error", () => done(false));
|
|
@@ -11865,8 +12830,8 @@ var init_light = __esm({
|
|
|
11865
12830
|
});
|
|
11866
12831
|
|
|
11867
12832
|
// src/sources/command.ts
|
|
11868
|
-
var
|
|
11869
|
-
__export(
|
|
12833
|
+
var command_exports5 = {};
|
|
12834
|
+
__export(command_exports5, {
|
|
11870
12835
|
runSourceCommand: () => runSourceCommand
|
|
11871
12836
|
});
|
|
11872
12837
|
function out(text2) {
|
|
@@ -12055,7 +13020,7 @@ ${HELP}`);
|
|
|
12055
13020
|
}
|
|
12056
13021
|
}
|
|
12057
13022
|
var HELP;
|
|
12058
|
-
var
|
|
13023
|
+
var init_command5 = __esm({
|
|
12059
13024
|
"src/sources/command.ts"() {
|
|
12060
13025
|
"use strict";
|
|
12061
13026
|
init_args();
|
|
@@ -12106,7 +13071,7 @@ cfpilot source <\u52A8\u4F5C> [\u9009\u9879] \u5916\u90E8 IP \u6570\u636E\u
|
|
|
12106
13071
|
// src/scan/single.ts
|
|
12107
13072
|
import * as net6 from "node:net";
|
|
12108
13073
|
function probeTcp(ip, port, timeoutMs) {
|
|
12109
|
-
return new Promise((
|
|
13074
|
+
return new Promise((resolve5) => {
|
|
12110
13075
|
const started = Date.now();
|
|
12111
13076
|
let settled = false;
|
|
12112
13077
|
const finish = (result) => {
|
|
@@ -12116,7 +13081,7 @@ function probeTcp(ip, port, timeoutMs) {
|
|
|
12116
13081
|
socket.destroy();
|
|
12117
13082
|
} catch {
|
|
12118
13083
|
}
|
|
12119
|
-
|
|
13084
|
+
resolve5({ stage: "TCP \u5EFA\u8FDE", ms: Date.now() - started, ...result });
|
|
12120
13085
|
};
|
|
12121
13086
|
const socket = net6.connect({ host: ip, port });
|
|
12122
13087
|
socket.setTimeout(timeoutMs, () => finish({ ok: false, error: "\u8D85\u65F6" }));
|
|
@@ -12391,7 +13356,7 @@ function validateIdentityResponse(value, now) {
|
|
|
12391
13356
|
};
|
|
12392
13357
|
}
|
|
12393
13358
|
function readExactly(socket, length) {
|
|
12394
|
-
return new Promise((
|
|
13359
|
+
return new Promise((resolve5, reject) => {
|
|
12395
13360
|
let data = Buffer.alloc(0);
|
|
12396
13361
|
const cleanup = () => {
|
|
12397
13362
|
socket.off("data", onData);
|
|
@@ -12412,7 +13377,7 @@ function readExactly(socket, length) {
|
|
|
12412
13377
|
socket.pause();
|
|
12413
13378
|
cleanup();
|
|
12414
13379
|
if (data.length > length) socket.unshift(data.subarray(length));
|
|
12415
|
-
|
|
13380
|
+
resolve5(data.subarray(0, length));
|
|
12416
13381
|
};
|
|
12417
13382
|
socket.on("data", onData);
|
|
12418
13383
|
socket.once("error", onError);
|
|
@@ -12484,7 +13449,7 @@ function identifyEgress(options) {
|
|
|
12484
13449
|
} catch {
|
|
12485
13450
|
return Promise.resolve(fail2("config", "\u8BC6\u522B\u914D\u7F6E\u65E0\u6548\uFF1A\u9700\u8981 HTTPS\u3001\u6709\u6548\u77ED\u671F\u4EE4\u724C\u548C\u53EF\u9009 SOCKS5 \u5730\u5740"));
|
|
12486
13451
|
}
|
|
12487
|
-
return new Promise((
|
|
13452
|
+
return new Promise((resolve5) => {
|
|
12488
13453
|
let settled = false;
|
|
12489
13454
|
let request3;
|
|
12490
13455
|
let socket;
|
|
@@ -12496,7 +13461,7 @@ function identifyEgress(options) {
|
|
|
12496
13461
|
request3?.destroy();
|
|
12497
13462
|
socket?.destroy();
|
|
12498
13463
|
agent.destroy();
|
|
12499
|
-
|
|
13464
|
+
resolve5(result);
|
|
12500
13465
|
};
|
|
12501
13466
|
const timer = setTimeout(() => finish(fail2("timeout", "\u51FA\u53E3\u8BC6\u522B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97")), timeoutMs);
|
|
12502
13467
|
if (proxy) {
|
|
@@ -12682,7 +13647,7 @@ function probeWebsite(target, options = {}) {
|
|
|
12682
13647
|
} catch {
|
|
12683
13648
|
return Promise.resolve({ ...base, error: "\u7F51\u7AD9\u68C0\u6D4B\u914D\u7F6E\u65E0\u6548" });
|
|
12684
13649
|
}
|
|
12685
|
-
return new Promise((
|
|
13650
|
+
return new Promise((resolve5) => {
|
|
12686
13651
|
let settled = false;
|
|
12687
13652
|
let socket;
|
|
12688
13653
|
let request3;
|
|
@@ -12694,7 +13659,7 @@ function probeWebsite(target, options = {}) {
|
|
|
12694
13659
|
request3?.destroy();
|
|
12695
13660
|
socket?.destroy();
|
|
12696
13661
|
agent.destroy();
|
|
12697
|
-
|
|
13662
|
+
resolve5({ ...base, ...patch, ms: Date.now() - started });
|
|
12698
13663
|
};
|
|
12699
13664
|
const onError = (error) => finish({ status: tlsFailure(error) ? "tls_error" : "http_error", error: tlsFailure(error) ? "\u7F51\u7AD9 TLS \u6821\u9A8C\u5931\u8D25" : "\u6307\u5B9A\u8DEF\u5F84\u8FDE\u63A5\u5931\u8D25" });
|
|
12700
13665
|
const timer = setTimeout(() => finish({ status: "timeout", error: "\u7F51\u7AD9\u68C0\u6D4B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97" }), timeout);
|
|
@@ -12920,22 +13885,22 @@ var init_token_command = __esm({
|
|
|
12920
13885
|
});
|
|
12921
13886
|
|
|
12922
13887
|
// src/vps/command.ts
|
|
12923
|
-
var
|
|
12924
|
-
__export(
|
|
13888
|
+
var command_exports6 = {};
|
|
13889
|
+
__export(command_exports6, {
|
|
12925
13890
|
runVpsCommand: () => runVpsCommand
|
|
12926
13891
|
});
|
|
12927
13892
|
import { spawn } from "node:child_process";
|
|
12928
|
-
import { existsSync as existsSync4, readFileSync as
|
|
12929
|
-
import { dirname as dirname4, resolve as
|
|
13893
|
+
import { existsSync as existsSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
13894
|
+
import { dirname as dirname4, resolve as resolve4 } from "node:path";
|
|
12930
13895
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
12931
13896
|
function loadScript() {
|
|
12932
13897
|
const here = dirname4(fileURLToPath3(import.meta.url));
|
|
12933
13898
|
const candidates = [
|
|
12934
|
-
|
|
12935
|
-
|
|
13899
|
+
resolve4(here, "../assets/vps-socks5.sh"),
|
|
13900
|
+
resolve4(here, "../../assets/vps-socks5.sh")
|
|
12936
13901
|
];
|
|
12937
13902
|
for (const path of candidates) {
|
|
12938
|
-
if (existsSync4(path)) return
|
|
13903
|
+
if (existsSync4(path)) return readFileSync8(path, "utf8");
|
|
12939
13904
|
}
|
|
12940
13905
|
throw new Error("\u5185\u7F6E\u811A\u672C\u7F3A\u5931\uFF08assets/vps-socks5.sh\uFF09\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6216\u5347\u7EA7 cfpilot");
|
|
12941
13906
|
}
|
|
@@ -12991,7 +13956,7 @@ async function runVpsCommand(args) {
|
|
|
12991
13956
|
}
|
|
12992
13957
|
return;
|
|
12993
13958
|
}
|
|
12994
|
-
const out2 =
|
|
13959
|
+
const out2 = resolve4(process.cwd(), flagString(args, "out") ?? "cfpilot-vps-socks5.sh");
|
|
12995
13960
|
writeFileSync5(out2, script, { mode: 493 });
|
|
12996
13961
|
process.stdout.write(
|
|
12997
13962
|
`
|
|
@@ -13015,7 +13980,7 @@ async function runVpsCommand(args) {
|
|
|
13015
13980
|
);
|
|
13016
13981
|
}
|
|
13017
13982
|
var HELP5;
|
|
13018
|
-
var
|
|
13983
|
+
var init_command6 = __esm({
|
|
13019
13984
|
"src/vps/command.ts"() {
|
|
13020
13985
|
"use strict";
|
|
13021
13986
|
init_args();
|
|
@@ -13060,7 +14025,9 @@ Cloudflare Pages \u4EE3\u7406\u90E8\u7F72\u4E0E\u4F18\u9009\u5DE5\u5177
|
|
|
13060
14025
|
|
|
13061
14026
|
\u7528\u6CD5:
|
|
13062
14027
|
${NAME} \u4EA4\u4E92\u83DC\u5355\uFF08\u63A8\u8350\u9996\u6B21\u4F7F\u7528\uFF09
|
|
13063
|
-
${NAME} deploy [\u9009\u9879] \u90E8\u7F72 Pages \u53CC\u9879\u76EE
|
|
14028
|
+
${NAME} deploy [\u9009\u9879] \u90E8\u7F72 Pages \u53CC\u9879\u76EE\uFF08CFPilot \u4EE3\u7406\u5B9E\u4F8B\uFF09
|
|
14029
|
+
${NAME} edge <\u52A8\u4F5C> [\u9009\u9879] \u90E8\u7F72\u76F2\u4E2D\u7EE7 / \u4E91\u76D1\u6D4B\u53F0\uFF08MobiHop \u8FB9\u7F18\u5DE5\u7A0B\uFF09
|
|
14030
|
+
${NAME} mesh <\u52A8\u4F5C> \u7EC4\u7F51\uFF08+mesh \u53D8\u4F53\uFF1B\u5F53\u524D\u9AA8\u67B6\uFF0C\u534F\u8BAE\u5F85 3b\uFF09
|
|
13064
14031
|
${NAME} scan [\u9009\u9879] \u672C\u5730\u771F\u8FDE\u63A5\u4F18\u9009
|
|
13065
14032
|
${NAME} source <\u52A8\u4F5C> \u5916\u90E8 IP \u6570\u636E\u6E90\u4E0E\u672C\u5730\u5019\u9009\u6C60\u7BA1\u7406
|
|
13066
14033
|
${NAME} test [\u9009\u9879] \u6D4B\u8BD5\u5355\u4E2A IP \u7684\u5B8C\u6574\u94FE\u8DEF
|
|
@@ -13111,13 +14078,23 @@ async function main() {
|
|
|
13111
14078
|
await runDeployCommand2(args);
|
|
13112
14079
|
return;
|
|
13113
14080
|
}
|
|
14081
|
+
case "edge": {
|
|
14082
|
+
const { runEdgeCommand: runEdgeCommand2 } = await Promise.resolve().then(() => (init_command3(), command_exports3));
|
|
14083
|
+
await runEdgeCommand2(args);
|
|
14084
|
+
return;
|
|
14085
|
+
}
|
|
14086
|
+
case "mesh": {
|
|
14087
|
+
const { runMeshCommand: runMeshCommand2 } = await Promise.resolve().then(() => (init_command4(), command_exports4));
|
|
14088
|
+
await runMeshCommand2(args);
|
|
14089
|
+
return;
|
|
14090
|
+
}
|
|
13114
14091
|
case "scan": {
|
|
13115
14092
|
const { runScanCommand: runScanCommand2 } = await Promise.resolve().then(() => (init_command2(), command_exports2));
|
|
13116
14093
|
await runScanCommand2(args);
|
|
13117
14094
|
return;
|
|
13118
14095
|
}
|
|
13119
14096
|
case "source": {
|
|
13120
|
-
const { runSourceCommand: runSourceCommand2 } = await Promise.resolve().then(() => (
|
|
14097
|
+
const { runSourceCommand: runSourceCommand2 } = await Promise.resolve().then(() => (init_command5(), command_exports5));
|
|
13121
14098
|
await runSourceCommand2(args);
|
|
13122
14099
|
return;
|
|
13123
14100
|
}
|
|
@@ -13152,7 +14129,7 @@ async function main() {
|
|
|
13152
14129
|
return;
|
|
13153
14130
|
}
|
|
13154
14131
|
case "vps": {
|
|
13155
|
-
const { runVpsCommand: runVpsCommand2 } = await Promise.resolve().then(() => (
|
|
14132
|
+
const { runVpsCommand: runVpsCommand2 } = await Promise.resolve().then(() => (init_command6(), command_exports6));
|
|
13156
14133
|
await runVpsCommand2(args);
|
|
13157
14134
|
return;
|
|
13158
14135
|
}
|