@streamr/dht 103.3.1 → 103.7.0-rc.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.
- package/dist/exports-browser.cjs +621 -101
- package/dist/exports-browser.cjs.map +1 -1
- package/dist/exports-browser.d.ts +15 -8
- package/dist/exports-browser.js +600 -102
- package/dist/exports-browser.js.map +1 -1
- package/dist/exports-nodejs.cjs +74 -2
- package/dist/exports-nodejs.cjs.map +1 -1
- package/dist/exports-nodejs.d.ts +18 -8
- package/dist/exports-nodejs.js +72 -3
- package/dist/exports-nodejs.js.map +1 -1
- package/package.json +12 -8
package/dist/exports-nodejs.cjs
CHANGED
|
@@ -251,6 +251,65 @@ class SendFailed extends Err {
|
|
|
251
251
|
constructor(message, originalError) { super(ErrorCode.SEND_FAILED, message, originalError); }
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
let enabled = false;
|
|
255
|
+
function setGapDiagnosticsEnabled(val) {
|
|
256
|
+
enabled = val;
|
|
257
|
+
globalThis.__dhtGapDiagEnabled = val;
|
|
258
|
+
}
|
|
259
|
+
const SUMMARY_INTERVAL_MS = 2000;
|
|
260
|
+
const accumulators = new Map();
|
|
261
|
+
function logGapDiagnosticSampled(layer, opts = {}) {
|
|
262
|
+
if (!enabled)
|
|
263
|
+
return;
|
|
264
|
+
const now = performance.now();
|
|
265
|
+
const threshold = opts.outlierThresholdMs ?? 30;
|
|
266
|
+
let acc = accumulators.get(layer);
|
|
267
|
+
if (acc === undefined) {
|
|
268
|
+
acc = { count: 0, sumDeltaMs: 0, maxDeltaMs: 0, outlierCount: 0, lastReportMs: now, lastEventMs: now };
|
|
269
|
+
accumulators.set(layer, acc);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const deltaMs = now - acc.lastEventMs;
|
|
273
|
+
acc.lastEventMs = now;
|
|
274
|
+
acc.count++;
|
|
275
|
+
if (deltaMs > acc.maxDeltaMs)
|
|
276
|
+
acc.maxDeltaMs = deltaMs;
|
|
277
|
+
acc.sumDeltaMs += deltaMs;
|
|
278
|
+
if (deltaMs > threshold)
|
|
279
|
+
acc.outlierCount++;
|
|
280
|
+
if (deltaMs > threshold) {
|
|
281
|
+
const payload = {
|
|
282
|
+
layer,
|
|
283
|
+
timestampMs: now,
|
|
284
|
+
deltaMs: +deltaMs.toFixed(2),
|
|
285
|
+
detail: opts.detail,
|
|
286
|
+
};
|
|
287
|
+
// eslint-disable-next-line no-console
|
|
288
|
+
console.log('[gap-diagnostics]', JSON.stringify(payload));
|
|
289
|
+
}
|
|
290
|
+
if (now - acc.lastReportMs >= SUMMARY_INTERVAL_MS) {
|
|
291
|
+
const summaryDetail = {
|
|
292
|
+
count: acc.count,
|
|
293
|
+
meanDeltaMs: acc.count > 0 ? +(acc.sumDeltaMs / acc.count).toFixed(2) : 0,
|
|
294
|
+
maxDeltaMs: +acc.maxDeltaMs.toFixed(2),
|
|
295
|
+
outlierCount: acc.outlierCount,
|
|
296
|
+
periodMs: +(now - acc.lastReportMs).toFixed(1),
|
|
297
|
+
};
|
|
298
|
+
const summary = {
|
|
299
|
+
layer: `${layer}.summary`,
|
|
300
|
+
timestampMs: now,
|
|
301
|
+
detail: summaryDetail,
|
|
302
|
+
};
|
|
303
|
+
// eslint-disable-next-line no-console
|
|
304
|
+
console.log('[gap-diagnostics]', JSON.stringify(summary));
|
|
305
|
+
acc.count = 0;
|
|
306
|
+
acc.sumDeltaMs = 0;
|
|
307
|
+
acc.maxDeltaMs = 0;
|
|
308
|
+
acc.outlierCount = 0;
|
|
309
|
+
acc.lastReportMs = now;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
254
313
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
255
314
|
class Empty$Type extends runtime.MessageType {
|
|
256
315
|
constructor() {
|
|
@@ -2295,6 +2354,7 @@ class ConnectionManager extends eventemitter3.EventEmitter {
|
|
|
2295
2354
|
if ((this.state === ConnectionManagerState.STOPPED || this.state === ConnectionManagerState.STOPPING) && !opts.sendIfStopped) {
|
|
2296
2355
|
return;
|
|
2297
2356
|
}
|
|
2357
|
+
logGapDiagnosticSampled('dht.connMgr.send');
|
|
2298
2358
|
const peerDescriptor = message.targetDescriptor;
|
|
2299
2359
|
if (this.isConnectionToSelf(peerDescriptor)) {
|
|
2300
2360
|
throw new CannotConnectToSelf('Cannot send to self');
|
|
@@ -2370,6 +2430,7 @@ class ConnectionManager extends eventemitter3.EventEmitter {
|
|
|
2370
2430
|
this.rpcCommunicator?.handleMessageFromPeer(message);
|
|
2371
2431
|
}
|
|
2372
2432
|
else {
|
|
2433
|
+
logGapDiagnosticSampled('dht.connMgr.emitMessage');
|
|
2373
2434
|
logger$B.trace('emit "message" ' + toNodeId(message.sourceDescriptor)
|
|
2374
2435
|
+ ' ' + message.serviceId + ' ' + message.messageId);
|
|
2375
2436
|
this.emit('message', message);
|
|
@@ -2379,6 +2440,7 @@ class ConnectionManager extends eventemitter3.EventEmitter {
|
|
|
2379
2440
|
if (this.state === ConnectionManagerState.STOPPED) {
|
|
2380
2441
|
return;
|
|
2381
2442
|
}
|
|
2443
|
+
logGapDiagnosticSampled('dht.connMgr.onData');
|
|
2382
2444
|
this.metrics.receiveBytesPerSecond.record(data.byteLength);
|
|
2383
2445
|
this.metrics.receiveMessagesPerSecond.record(1);
|
|
2384
2446
|
let message;
|
|
@@ -2812,7 +2874,7 @@ const parseVersion = (version) => {
|
|
|
2812
2874
|
}
|
|
2813
2875
|
};
|
|
2814
2876
|
|
|
2815
|
-
var version = "103.
|
|
2877
|
+
var version = "103.7.0-rc.2";
|
|
2816
2878
|
|
|
2817
2879
|
const logger$z = new utils.Logger('Handshaker');
|
|
2818
2880
|
// Optimally the Outgoing and Incoming Handshakers could be their own separate classes
|
|
@@ -5716,7 +5778,7 @@ class PeerDiscovery {
|
|
|
5716
5778
|
logger$d.debug(`Ring join on ${this.options.serviceId} timed out`);
|
|
5717
5779
|
}
|
|
5718
5780
|
finally {
|
|
5719
|
-
sessions.forEach((session) => this.
|
|
5781
|
+
sessions.forEach((session) => this.ongoingRingDiscoverySessions.delete(session.id));
|
|
5720
5782
|
}
|
|
5721
5783
|
}
|
|
5722
5784
|
async rejoinDht(entryPoint, contactedPeers = new Set(), distantJoinContactPeers = new Set()) {
|
|
@@ -7807,6 +7869,13 @@ class SimulatorTransport extends ConnectionManager {
|
|
|
7807
7869
|
}
|
|
7808
7870
|
}
|
|
7809
7871
|
|
|
7872
|
+
/**
|
|
7873
|
+
* Stub for the Node.js build — `installWebrtcBridge` is a browser-only API.
|
|
7874
|
+
*/
|
|
7875
|
+
function installWebrtcBridge(_worker) {
|
|
7876
|
+
throw new Error('installWebrtcBridge is only supported in browser environments');
|
|
7877
|
+
}
|
|
7878
|
+
|
|
7810
7879
|
exports.ConnectionManager = ConnectionManager;
|
|
7811
7880
|
exports.DataEntry = DataEntry;
|
|
7812
7881
|
exports.DefaultConnectorFacade = DefaultConnectorFacade;
|
|
@@ -7827,7 +7896,10 @@ exports.areEqualPeerDescriptors = areEqualPeerDescriptors;
|
|
|
7827
7896
|
exports.createOutgoingHandshaker = createOutgoingHandshaker;
|
|
7828
7897
|
exports.getRandomRegion = getRandomRegion;
|
|
7829
7898
|
exports.getRegionDelayMatrix = getRegionDelayMatrix;
|
|
7899
|
+
exports.installWebrtcBridge = installWebrtcBridge;
|
|
7900
|
+
exports.logGapDiagnosticSampled = logGapDiagnosticSampled;
|
|
7830
7901
|
exports.randomDhtAddress = randomDhtAddress;
|
|
7902
|
+
exports.setGapDiagnosticsEnabled = setGapDiagnosticsEnabled;
|
|
7831
7903
|
exports.toDhtAddress = toDhtAddress;
|
|
7832
7904
|
exports.toDhtAddressRaw = toDhtAddressRaw;
|
|
7833
7905
|
exports.toNodeId = toNodeId;
|