panrouter 6.3.6 → 6.3.8
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/package.json +1 -1
- package/pool-worker.mjs +10 -29
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -17,7 +17,13 @@ import path from "node:path";
|
|
|
17
17
|
import fs from "node:fs";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import crypto from "node:crypto";
|
|
20
|
+
import { createRequire } from "node:module";
|
|
20
21
|
import WebSocket from "ws";
|
|
22
|
+
|
|
23
|
+
const _require = createRequire(import.meta.url);
|
|
24
|
+
const _pkg = _require("./package.json");
|
|
25
|
+
const NODE_VERSION = _pkg.version;
|
|
26
|
+
|
|
21
27
|
const ROUTER_PORT = 20128;
|
|
22
28
|
|
|
23
29
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -109,9 +115,10 @@ function connectToHub() {
|
|
|
109
115
|
|
|
110
116
|
const registerMsg = JSON.stringify({
|
|
111
117
|
type: "register",
|
|
112
|
-
nodeId: assignedId || FINGERPRINT,
|
|
118
|
+
nodeId: assignedId || FINGERPRINT,
|
|
113
119
|
fingerprint: FINGERPRINT,
|
|
114
120
|
deviceType: DEVICE_TYPE,
|
|
121
|
+
version: NODE_VERSION,
|
|
115
122
|
secret: AUTH_SECRET,
|
|
116
123
|
});
|
|
117
124
|
ws.send(registerMsg);
|
|
@@ -145,10 +152,6 @@ function connectToHub() {
|
|
|
145
152
|
ws.send(JSON.stringify({ type: "pong" }));
|
|
146
153
|
break;
|
|
147
154
|
|
|
148
|
-
case "test":
|
|
149
|
-
handleTestRequest(msg);
|
|
150
|
-
break;
|
|
151
|
-
|
|
152
155
|
case "upgrade":
|
|
153
156
|
handleUpgrade();
|
|
154
157
|
break;
|
|
@@ -352,29 +355,6 @@ function safeSend(data) {
|
|
|
352
355
|
}
|
|
353
356
|
}
|
|
354
357
|
|
|
355
|
-
// ─── 节点连通性测试 ─────────────────────────────────────────────────────────
|
|
356
|
-
|
|
357
|
-
function handleTestRequest(msg) {
|
|
358
|
-
const testReq = http.request({
|
|
359
|
-
hostname: "127.0.0.1",
|
|
360
|
-
port: SERVER_PORT,
|
|
361
|
-
path: "/dashboard",
|
|
362
|
-
method: "GET",
|
|
363
|
-
timeout: 8000,
|
|
364
|
-
}, (res) => {
|
|
365
|
-
// 只要收到响应就算通
|
|
366
|
-
let body = "";
|
|
367
|
-
res.on("data", (c) => body += c);
|
|
368
|
-
res.on("end", () => {
|
|
369
|
-
safeSend({ type: "test_result", reqId: msg.reqId, ok: true, status: res.statusCode, detail: body.slice(0, 200) });
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
testReq.on("error", (err) => {
|
|
373
|
-
safeSend({ type: "test_result", reqId: msg.reqId, ok: false, error: err.message });
|
|
374
|
-
});
|
|
375
|
-
testReq.end();
|
|
376
|
-
}
|
|
377
|
-
|
|
378
358
|
// ─── 心跳保活(每 25 秒发送 ping,避免 Cloudflare 闲置超时) ─────────────────
|
|
379
359
|
|
|
380
360
|
function startHeartbeat() {
|
|
@@ -604,12 +584,13 @@ export async function start() {
|
|
|
604
584
|
|
|
605
585
|
log("节点看门狗已启动,等待公网入口...", "ON");
|
|
606
586
|
|
|
607
|
-
// 等 9router 起来后打开守护
|
|
587
|
+
// 等 9router 起来后打开守护 + 通知主控就绪
|
|
608
588
|
const checkReady = setInterval(async () => {
|
|
609
589
|
if (_serverReady || (await isPortOpen(SERVER_PORT))) {
|
|
610
590
|
_serverReady = true;
|
|
611
591
|
clearInterval(checkReady);
|
|
612
592
|
startWatchdog();
|
|
593
|
+
safeSend({ type: "ready" });
|
|
613
594
|
log("9router 已就绪,节点可正常处理请求", "ON");
|
|
614
595
|
}
|
|
615
596
|
}, 3000);
|