dshost-plugin 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/lib/core.js +24 -15
  2. package/package.json +1 -1
package/lib/core.js CHANGED
@@ -37,22 +37,31 @@ function localIPv4() {
37
37
  let cachedInstanceId = null;
38
38
  function getInstanceId() {
39
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);
40
+ // 稳定实例 ID:hostname + systemd machine-id 的哈希前缀。machine-id 由系统
41
+ // 安装时生成、跨重启持久 —— 此前两版(纯随机 / 首个MAC哈希)分别败于 agent
42
+ // 重启与 Docker/虚拟网卡导致的 MAC 集合变化,都会让浏览器标签页的实例引用
43
+ // 失效并触发 503 重试风暴。同名主机由 machine-id 区分。
44
+ let mid = '';
45
+ for (const f of ['/etc/machine-id', '/var/lib/dbus/machine-id']) {
46
+ try {
47
+ const s = fs.readFileSync(f, 'utf8').trim();
48
+ if (s) { mid = s; break; }
49
+ } catch {}
50
+ }
51
+ if (!mid) {
52
+ // 无 machine-id 的兜底:全部非内部 MAC 的联合哈希(排序拼接,不依赖
53
+ // 枚举顺序与单个网卡的存在性)
54
+ try {
55
+ const macs = [];
56
+ for (const addrs of Object.values(os.networkInterfaces())) {
57
+ for (const a of addrs || []) {
58
+ if (a && !a.internal && a.mac && a.mac !== '00:00:00:00:00:00') macs.push(a.mac);
59
+ }
50
60
  }
51
- }
52
- macs.sort();
53
- mac = macs[0] || '';
54
- } catch {}
55
- const h = crypto.createHash('sha256').update(os.hostname() + '|' + mac).digest('hex');
61
+ mid = 'mac:' + macs.sort().join(',');
62
+ } catch {}
63
+ }
64
+ const h = crypto.createHash('sha256').update(os.hostname() + '|' + mid).digest('hex');
56
65
  cachedInstanceId = os.hostname() + '-' + parseInt(h.slice(0, 8), 16).toString(36).slice(0, 4);
57
66
  return cachedInstanceId;
58
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dshost-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Official remote cloud relay plugin for DSHost (dshost.me): securely access your dsh Web UI from anywhere",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",