Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ToolSocketNB.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
const { MESSAGE_BUNDLE_SCHEMA } = require('./schemas.js');

let nodeCrypto = null;
if (!isBrowser) { try { nodeCrypto = require('crypto'); } catch (_e) { /* no integrity */ } }

Check warning on line 73 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 73 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 73 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

This line has 3 statements. Maximum allowed is 1
const nowMs = (!isBrowser && typeof process !== 'undefined' && process.hrtime)
? () => Number(process.hrtime.bigint()) / 1e6 // sub-ms precision for rate/RTT estimation
: () => Date.now();
Expand Down Expand Up @@ -109,8 +109,8 @@

const DEFAULTS = {
chunkSize: 256 * 1024, // hard-capped at 4MB below; 256KB = 4x fewer chunks than 64KB (less per-chunk
// scheduler/framing CPU on the legacy-fallback path), ~4ms preemption @1Gbit /

Check warning on line 112 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

Expected indentation of 4 spaces but found 33

Check warning on line 112 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

Expected indentation of 4 spaces but found 33

Check warning on line 112 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

Expected indentation of 4 spaces but found 33
// ~40ms @100Mbit — realtime still preempts bulk at chunk boundaries

Check warning on line 113 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

Expected indentation of 4 spaces but found 33

Check warning on line 113 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

Expected indentation of 4 spaces but found 33

Check warning on line 113 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

Expected indentation of 4 spaces but found 33
ackWindow: 4, // INITIAL chunks in flight per transfer (0 = flood/disable flow control)
adaptiveWindow: true, // grow/shrink the per-transfer window from measured ack RTT + delivery rate
latencyBudgetMs: 250, // adaptive cap: keep in-flight <= bandwidth x this budget (bounds JSON delay)
Expand All @@ -127,8 +127,8 @@
helloTimeoutMs: 3000, // peer capability handshake timeout -> legacy fallback
transferTimeoutMs: 120000, // GC for stale partial transfers at the receiver
integrity: false, // end-to-end sha256 (Node only); off by default — wss/TCP cover the wire,
// and structural checks (tid/seq/count/length) still catch protocol bugs.

Check warning on line 130 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

Expected indentation of 4 spaces but found 33

Check warning on line 130 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

Expected indentation of 4 spaces but found 33

Check warning on line 130 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

Expected indentation of 4 spaces but found 33
// Turn on during development of transport changes.

Check warning on line 131 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

Expected indentation of 4 spaces but found 33

Check warning on line 131 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

Expected indentation of 4 spaces but found 33

Check warning on line 131 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

Expected indentation of 4 spaces but found 33
reconnect: true, // auto-reconnect outgoing sockets
holdResumeJitterMs: 2000, // client-side random delay before the resume(false) callback fires (herd control)
maxPayload: 16 * MB, // ws frame cap: chunks are <=4MB, so 16MB is a guard rail
Expand Down Expand Up @@ -255,12 +255,12 @@
this.maybeLow();
if (!isBrowser) {
let pending = frames.length;
const next = () => { if (--pending === 0) defer(step); };

Check warning on line 258 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

This line has 2 statements. Maximum allowed is 1

Check warning on line 258 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

This line has 2 statements. Maximum allowed is 1

Check warning on line 258 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

This line has 2 statements. Maximum allowed is 1
for (const f of frames) {
try { sock.send(f, next); } catch (_e) { next(); }

Check warning on line 260 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 260 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 260 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

This line has 3 statements. Maximum allowed is 1
}
} else {
for (const f of frames) { try { sock.send(f); } catch (_e) { /* closed */ } }

Check warning on line 263 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 263 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

This line has 3 statements. Maximum allowed is 1

Check warning on line 263 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

This line has 3 statements. Maximum allowed is 1
setTimeout(step, 0); // browsers: pace via bufferedAmount check above
}
};
Expand Down Expand Up @@ -331,8 +331,8 @@
minHoldMs: 2000 // never release a hold faster than this (flap guard)
};
const P = { cfg, held: false, seq: 0, manual: null, entries: new Set(),
listeners: new Set(), timer: null, heldSince: 0, last: { aggBytes: 0, rss: 0 } };

Check warning on line 334 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

Expected indentation of 8 spaces but found 16

Check warning on line 334 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

Expected indentation of 8 spaces but found 16

Check warning on line 334 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

Expected indentation of 8 spaces but found 16
function emit(ev) { for (const cb of P.listeners) { try { cb(ev); } catch (_e) { /* listener error */ } } }

Check warning on line 335 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (22.x)

This line has 4 statements. Maximum allowed is 1

Check warning on line 335 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (20.x)

This line has 4 statements. Maximum allowed is 1

Check warning on line 335 in src/ToolSocketNB.js

View workflow job for this annotation

GitHub Actions / Jest (18.x)

This line has 4 statements. Maximum allowed is 1
function broadcast() {
for (const e of P.entries) { try { if (e.ready()) e.sendHold(P.held, P.seq); } catch (_e) { /* socket race */ } }
}
Expand Down Expand Up @@ -814,7 +814,14 @@
}
}
}, 10000);
// unref() keeps the timer from holding the process open, but it stays in
// the timer list - a GC root - so without this the interval's closure
// pins nb/sched/opts and the whole socket forever. Guarded exactly like
// the pressure entry above: an auto-reconnecting outgoing socket keeps
// its gc timer across reconnects, while an incoming socket (url === null)
// never comes back and must release it.
if (gc.unref) gc.unref();
ts.addEventListener('close', () => { if (!(opts.reconnect && ts.url)) clearInterval(gc); });

// ---------- public backpressure / flow-control API ----------
ts.getBackpressure = () => sched.stats();
Expand Down
Loading