dshost-plugin 0.1.0 → 0.1.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/lib/core.js +19 -3
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import http from 'http';
|
|
6
6
|
import os from 'os';
|
|
7
7
|
import fs from 'fs';
|
|
8
|
+
import crypto from 'crypto';
|
|
8
9
|
import { execFileSync } from 'child_process';
|
|
9
10
|
import WebSocket from 'ws';
|
|
10
11
|
import { send, b64, un64, sanitizeCloseCode } from './protocol.js';
|
|
@@ -35,9 +36,24 @@ function localIPv4() {
|
|
|
35
36
|
// (user saw an offline page for an online host).
|
|
36
37
|
let cachedInstanceId = null;
|
|
37
38
|
function getInstanceId() {
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
if (cachedInstanceId) return cachedInstanceId;
|
|
40
|
+
// 稳定实例 ID:hostname + 主 MAC 哈希前缀。进程/机器重启后不变 —— 此前的
|
|
41
|
+
// 随机后缀在 agent 每次重启时都会让浏览器标签页的 dsh_instance 引用失效,
|
|
42
|
+
// 造成无限 503 重试风暴(生产单日 992 次 502)。同名主机(如两台都叫
|
|
43
|
+
// "debian")由 MAC 区分。
|
|
44
|
+
let mac = '';
|
|
45
|
+
try {
|
|
46
|
+
const macs = [];
|
|
47
|
+
for (const addrs of Object.values(os.networkInterfaces())) {
|
|
48
|
+
for (const a of addrs || []) {
|
|
49
|
+
if (a && !a.internal && a.mac && a.mac !== '00:00:00:00:00:00') macs.push(a.mac);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
macs.sort();
|
|
53
|
+
mac = macs[0] || '';
|
|
54
|
+
} catch {}
|
|
55
|
+
const h = crypto.createHash('sha256').update(os.hostname() + '|' + mac).digest('hex');
|
|
56
|
+
cachedInstanceId = os.hostname() + '-' + parseInt(h.slice(0, 8), 16).toString(36).slice(0, 4);
|
|
41
57
|
return cachedInstanceId;
|
|
42
58
|
}
|
|
43
59
|
|
package/package.json
CHANGED