@mmmbuto/nexuscrew 0.8.47 → 0.8.48
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/CHANGELOG.md +62 -0
- package/frontend/dist/assets/{index-BAq6N1Md.css → index-43DFO1EH.css} +1 -1
- package/frontend/dist/assets/index-C_SyIZ78.js +93 -0
- package/frontend/dist/index.html +2 -2
- package/frontend/dist/version.json +1 -1
- package/lib/cells/routes.js +18 -1
- package/lib/fleet/builtin.js +7 -1
- package/lib/fleet/definitions.js +16 -0
- package/lib/fleet/runtime.js +3 -1
- package/lib/mcp/cells.js +11 -0
- package/lib/mcp/tools.js +1 -1
- package/lib/nodes/inventory.js +5 -0
- package/lib/nodes/reverse-rotation.js +22 -1
- package/lib/nodes/reverse-slot-listeners.js +10 -1
- package/lib/nodes/reverse-slot-proof.js +10 -0
- package/lib/nodes/topology-cache.js +11 -2
- package/lib/proxy/federation.js +98 -10
- package/lib/server.js +27 -7
- package/lib/settings/routes.js +58 -5
- package/lib/ws/bridge.js +26 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-Db2ivuxA.js +0 -93
package/lib/ws/bridge.js
CHANGED
|
@@ -10,6 +10,8 @@ function clamp(n, lo, hi, def) {
|
|
|
10
10
|
return Math.max(lo, Math.min(hi, Math.round(n)));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const ATTACH_TIMEOUT_MS = 15000;
|
|
14
|
+
|
|
13
15
|
function bindWs(ws, deps) {
|
|
14
16
|
const { openAttach, verifyToken, isValidSession = () => true, runAction = () => false, countClients = () => 0, defaults = {}, onAttach = () => {} } = deps;
|
|
15
17
|
let pty = null;
|
|
@@ -17,10 +19,31 @@ function bindWs(ws, deps) {
|
|
|
17
19
|
let session = null;
|
|
18
20
|
|
|
19
21
|
function fail(code, reason) {
|
|
22
|
+
// Si spegne anche la scadenza pre-attach: un frame rifiutato (token o
|
|
23
|
+
// handshake non validi) chiude gia' il socket, e lasciare il timer vivo
|
|
24
|
+
// fino al close event tiene in piedi un handle senza scopo.
|
|
25
|
+
clearAttachTimer();
|
|
20
26
|
try { ws.send(JSON.stringify({ type: 'error', reason })); } catch (_) {}
|
|
21
27
|
try { ws.close(code, reason); } catch (_) {}
|
|
22
28
|
}
|
|
23
29
|
|
|
30
|
+
// L'upgrade viene accettato prima dell'autenticazione: il token arriva nel
|
|
31
|
+
// primo frame. Senza una scadenza un socket che non manda MAI l'attach resta
|
|
32
|
+
// aperto e non autenticato a tempo indefinito, e il costo si moltiplica su
|
|
33
|
+
// ogni listener che serve l'app. La finestra e' generosa (un client reale
|
|
34
|
+
// manda l'attach all'apertura) ma non infinita.
|
|
35
|
+
const attachTimeoutMs = Number.isFinite(defaults.attachTimeoutMs)
|
|
36
|
+
? Math.max(1000, defaults.attachTimeoutMs) : ATTACH_TIMEOUT_MS;
|
|
37
|
+
let attachTimer = setTimeout(() => {
|
|
38
|
+
attachTimer = null;
|
|
39
|
+
if (!attached) fail(4408, 'attach timeout');
|
|
40
|
+
}, attachTimeoutMs);
|
|
41
|
+
if (typeof attachTimer.unref === 'function') attachTimer.unref();
|
|
42
|
+
// Dichiarazione (hoisted): `fail` la chiama ed e' definita piu' sopra.
|
|
43
|
+
function clearAttachTimer() {
|
|
44
|
+
if (attachTimer) { clearTimeout(attachTimer); attachTimer = null; }
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
function onMessage(data, isBinary) {
|
|
25
48
|
if (!attached) {
|
|
26
49
|
if (isBinary) return fail(1002, 'binary before attach');
|
|
@@ -30,6 +53,7 @@ function bindWs(ws, deps) {
|
|
|
30
53
|
if (!verifyToken(msg.token)) return fail(4401, 'bad token');
|
|
31
54
|
if (!isValidSession(msg.session)) return fail(4404, 'no such session');
|
|
32
55
|
attached = true;
|
|
56
|
+
clearAttachTimer();
|
|
33
57
|
session = msg.session;
|
|
34
58
|
onAttach(session, ws);
|
|
35
59
|
// Resize default: when nobody else is attached, drive the session size so a
|
|
@@ -83,7 +107,7 @@ function bindWs(ws, deps) {
|
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
ws.on('message', onMessage);
|
|
86
|
-
ws.on('close', () => { if (pty) pty.kill(); pty = null; });
|
|
87
|
-
ws.on('error', () => { if (pty) pty.kill(); pty = null; });
|
|
110
|
+
ws.on('close', () => { clearAttachTimer(); if (pty) pty.kill(); pty = null; });
|
|
111
|
+
ws.on('error', () => { clearAttachTimer(); if (pty) pty.kill(); pty = null; });
|
|
88
112
|
}
|
|
89
113
|
module.exports = { bindWs, clamp };
|