@streamr/trackerless-network 103.6.0-rc.0 → 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.d.ts CHANGED
@@ -1409,5 +1409,11 @@ declare class NetworkNode {
1409
1409
  createExternalRpcClient<T extends ExternalRpcClient>(clientClass: ExternalRpcClientClass<T>): ProtoRpcClient<T>;
1410
1410
  }
1411
1411
 
1412
- export { AsymmetricEncryptionType, ContentType, ControlLayerInfo, EncryptedGroupKey, EncryptionType, GroupKeyRequest, GroupKeyResponse, MessageID, MessageRef, NetworkNode, NetworkStack, ProxyDirection, SignatureType, StreamMessage, createNetworkNode, streamPartIdToDataKey };
1412
+ declare function setGapDiagnosticsEnabled(val: boolean): void;
1413
+ declare function logGapDiagnosticSampled(layer: string, opts?: {
1414
+ detail?: Record<string, unknown>;
1415
+ outlierThresholdMs?: number;
1416
+ }): void;
1417
+
1418
+ export { AsymmetricEncryptionType, ContentType, ControlLayerInfo, EncryptedGroupKey, EncryptionType, GroupKeyRequest, GroupKeyResponse, MessageID, MessageRef, NetworkNode, NetworkStack, ProxyDirection, SignatureType, StreamMessage, createNetworkNode, logGapDiagnosticSampled, setGapDiagnosticsEnabled as setTrackerlessGapDiagnosticsEnabled, streamPartIdToDataKey };
1413
1419
  export type { ContentDeliveryLayerNeighborInfo, ContentDeliveryManagerOptions, ExternalRpcClient, ExternalRpcClientClass, NetworkOptions, NodeInfo, StreamPartDeliveryOptions, StreamPartitionInfo };
package/dist/exports.js CHANGED
@@ -27,7 +27,7 @@ class ExternalNetworkRpc {
27
27
  }
28
28
  }
29
29
 
30
- var version = "103.6.0-rc.0";
30
+ var version = "103.7.0-rc.2";
31
31
 
32
32
  // @generated message type with reflection information, may provide speed optimized methods
33
33
  class Any$Type extends MessageType {
@@ -2402,12 +2402,72 @@ class NeighborUpdateManager {
2402
2402
  }
2403
2403
  }
2404
2404
 
2405
+ let enabled = false;
2406
+ function setGapDiagnosticsEnabled(val) {
2407
+ enabled = val;
2408
+ globalThis.__trackerlessGapDiagEnabled = val;
2409
+ }
2410
+ const SUMMARY_INTERVAL_MS = 2000;
2411
+ const accumulators = new Map();
2412
+ function logGapDiagnosticSampled(layer, opts = {}) {
2413
+ if (!enabled)
2414
+ return;
2415
+ const now = performance.now();
2416
+ const threshold = opts.outlierThresholdMs ?? 30;
2417
+ let acc = accumulators.get(layer);
2418
+ if (acc === undefined) {
2419
+ acc = { count: 0, sumDeltaMs: 0, maxDeltaMs: 0, outlierCount: 0, lastReportMs: now, lastEventMs: now };
2420
+ accumulators.set(layer, acc);
2421
+ return;
2422
+ }
2423
+ const deltaMs = now - acc.lastEventMs;
2424
+ acc.lastEventMs = now;
2425
+ acc.count++;
2426
+ if (deltaMs > acc.maxDeltaMs)
2427
+ acc.maxDeltaMs = deltaMs;
2428
+ acc.sumDeltaMs += deltaMs;
2429
+ if (deltaMs > threshold)
2430
+ acc.outlierCount++;
2431
+ if (deltaMs > threshold) {
2432
+ const payload = {
2433
+ layer,
2434
+ timestampMs: now,
2435
+ deltaMs: +deltaMs.toFixed(2),
2436
+ detail: opts.detail,
2437
+ };
2438
+ // eslint-disable-next-line no-console
2439
+ console.log('[gap-diagnostics]', JSON.stringify(payload));
2440
+ }
2441
+ if (now - acc.lastReportMs >= SUMMARY_INTERVAL_MS) {
2442
+ const summaryDetail = {
2443
+ count: acc.count,
2444
+ meanDeltaMs: acc.count > 0 ? +(acc.sumDeltaMs / acc.count).toFixed(2) : 0,
2445
+ maxDeltaMs: +acc.maxDeltaMs.toFixed(2),
2446
+ outlierCount: acc.outlierCount,
2447
+ periodMs: +(now - acc.lastReportMs).toFixed(1),
2448
+ };
2449
+ const summary = {
2450
+ layer: `${layer}.summary`,
2451
+ timestampMs: now,
2452
+ detail: summaryDetail,
2453
+ };
2454
+ // eslint-disable-next-line no-console
2455
+ console.log('[gap-diagnostics]', JSON.stringify(summary));
2456
+ acc.count = 0;
2457
+ acc.sumDeltaMs = 0;
2458
+ acc.maxDeltaMs = 0;
2459
+ acc.outlierCount = 0;
2460
+ acc.lastReportMs = now;
2461
+ }
2462
+ }
2463
+
2405
2464
  class ContentDeliveryRpcLocal {
2406
2465
  options;
2407
2466
  constructor(options) {
2408
2467
  this.options = options;
2409
2468
  }
2410
2469
  async sendStreamMessage(message, context) {
2470
+ logGapDiagnosticSampled('trackerless.rpcLocal.sendStreamMessage');
2411
2471
  const previousNode = context.incomingSourceDescriptor;
2412
2472
  const previousNodeId = toNodeId(previousNode);
2413
2473
  this.options.markForInspection(previousNodeId, message.messageId);
@@ -2768,11 +2828,16 @@ class ContentDeliveryLayerNode extends EventEmitter {
2768
2828
  this.options.neighborFinder.stop();
2769
2829
  this.options.neighborUpdateManager.stop();
2770
2830
  this.options.inspector.stop();
2831
+ this.duplicateDetectors.clear();
2771
2832
  }
2772
2833
  broadcast(msg, previousNode) {
2773
2834
  if (!previousNode) {
2835
+ logGapDiagnosticSampled('trackerless.cdNode.broadcastOut');
2774
2836
  markAndCheckDuplicate(this.duplicateDetectors, msg.messageId, msg.previousMessageRef);
2775
2837
  }
2838
+ else {
2839
+ logGapDiagnosticSampled('trackerless.cdNode.broadcastIn');
2840
+ }
2776
2841
  this.emit('message', msg);
2777
2842
  const skipBackPropagation = previousNode !== undefined && !this.options.temporaryConnectionRpcLocal.hasNode(previousNode);
2778
2843
  this.options.propagation.feedUnseenMessage(msg, this.getPropagationTargets(msg), skipBackPropagation ? previousNode : null);
@@ -3070,6 +3135,7 @@ class Propagation {
3070
3135
  }
3071
3136
  sendAndAwaitThenMark({ message, source, handledNeighbors }, neighborId) {
3072
3137
  if (!handledNeighbors.has(neighborId) && neighborId !== source) {
3138
+ logGapDiagnosticSampled('trackerless.propagation.sendToNeighbor');
3073
3139
  (async () => {
3074
3140
  try {
3075
3141
  await this.sendToNeighbor(neighborId, message);
@@ -3627,6 +3693,9 @@ class PlumtreeManager extends EventEmitter {
3627
3693
  stop() {
3628
3694
  this.abortController.abort();
3629
3695
  this.neighbors.off('nodeRemoved', this.onNeighborRemoved);
3696
+ this.latestMessages.clear();
3697
+ this.recoveryState.clear();
3698
+ this.recoveryCooldownUntil.clear();
3630
3699
  }
3631
3700
  }
3632
3701
 
@@ -4568,5 +4637,5 @@ class NetworkNode {
4568
4637
  }
4569
4638
  }
4570
4639
 
4571
- export { AsymmetricEncryptionType, ContentType, ControlLayerInfo, EncryptedGroupKey, EncryptionType, GroupKeyRequest, GroupKeyResponse, MessageID, MessageRef, NetworkNode, NetworkStack, ProxyDirection, SignatureType, StreamMessage, createNetworkNode, streamPartIdToDataKey };
4640
+ export { AsymmetricEncryptionType, ContentType, ControlLayerInfo, EncryptedGroupKey, EncryptionType, GroupKeyRequest, GroupKeyResponse, MessageID, MessageRef, NetworkNode, NetworkStack, ProxyDirection, SignatureType, StreamMessage, createNetworkNode, logGapDiagnosticSampled, setGapDiagnosticsEnabled as setTrackerlessGapDiagnosticsEnabled, streamPartIdToDataKey };
4572
4641
  //# sourceMappingURL=exports.js.map