@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.
@@ -367,18 +367,17 @@ declare class Timestamp$Type extends MessageType<Timestamp> {
367
367
  */
368
368
  interface Timestamp {
369
369
  /**
370
- * Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must
371
- * be between -315576000000 and 315576000000 inclusive (which corresponds to
372
- * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).
370
+ * Represents seconds of UTC time since Unix epoch
371
+ * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
372
+ * 9999-12-31T23:59:59Z inclusive.
373
373
  *
374
374
  * @generated from protobuf field: int64 seconds = 1
375
375
  */
376
376
  seconds: number;
377
377
  /**
378
- * Non-negative fractions of a second at nanosecond resolution. This field is
379
- * the nanosecond portion of the duration, not an alternative to seconds.
380
- * Negative second values with fractions must still have non-negative nanos
381
- * values that count forward in time. Must be between 0 and 999,999,999
378
+ * Non-negative fractions of a second at nanosecond resolution. Negative
379
+ * second values with fractions must still have non-negative nanos values
380
+ * that count forward in time. Must be from 0 to 999,999,999
382
381
  * inclusive.
383
382
  *
384
383
  * @generated from protobuf field: int32 nanos = 2
@@ -1317,5 +1316,16 @@ declare class Handshaker extends EventEmitter<HandshakerEvents> {
1317
1316
  stop(): void;
1318
1317
  }
1319
1318
 
1320
- export { ConnectionManager, ConnectionType, DataEntry, DefaultConnectorFacade, DhtCallContext, DhtNode, EXISTING_CONNECTION_TIMEOUT, LatencyType, ListeningRpcCommunicator, ManagedConnection, Message, NodeType, PeerDescriptor, PendingConnection, RoutingRpcCommunicator, RpcRemote, Simulator, SimulatorTransport, WebsocketClientConnection, areEqualPeerDescriptors, createOutgoingHandshaker, getRandomRegion, getRegionDelayMatrix, randomDhtAddress, toDhtAddress, toDhtAddressRaw, toNodeId };
1319
+ /**
1320
+ * Stub for the Node.js build — `installWebrtcBridge` is a browser-only API.
1321
+ */
1322
+ declare function installWebrtcBridge(_worker: unknown): void;
1323
+
1324
+ declare function setGapDiagnosticsEnabled(val: boolean): void;
1325
+ declare function logGapDiagnosticSampled(layer: string, opts?: {
1326
+ detail?: Record<string, unknown>;
1327
+ outlierThresholdMs?: number;
1328
+ }): void;
1329
+
1330
+ export { ConnectionManager, ConnectionType, DataEntry, DefaultConnectorFacade, DhtCallContext, DhtNode, EXISTING_CONNECTION_TIMEOUT, LatencyType, ListeningRpcCommunicator, ManagedConnection, Message, NodeType, PeerDescriptor, PendingConnection, RoutingRpcCommunicator, RpcRemote, Simulator, SimulatorTransport, WebsocketClientConnection, areEqualPeerDescriptors, createOutgoingHandshaker, getRandomRegion, getRegionDelayMatrix, installWebrtcBridge, logGapDiagnosticSampled, randomDhtAddress, setGapDiagnosticsEnabled, toDhtAddress, toDhtAddressRaw, toNodeId };
1321
1331
  export type { ConnectionLocker, ConnectionsView, DhtAddress, DhtAddressRaw, DhtNodeEvents, DhtNodeOptions, DhtRpcOptions, IConnection, ITransport, IceServer, LockID, PortRange, RingContacts, ServiceID, TlsCertificate, TransportEvents };
@@ -249,6 +249,65 @@ class SendFailed extends Err {
249
249
  constructor(message, originalError) { super(ErrorCode.SEND_FAILED, message, originalError); }
250
250
  }
251
251
 
252
+ let enabled = false;
253
+ function setGapDiagnosticsEnabled(val) {
254
+ enabled = val;
255
+ globalThis.__dhtGapDiagEnabled = val;
256
+ }
257
+ const SUMMARY_INTERVAL_MS = 2000;
258
+ const accumulators = new Map();
259
+ function logGapDiagnosticSampled(layer, opts = {}) {
260
+ if (!enabled)
261
+ return;
262
+ const now = performance.now();
263
+ const threshold = opts.outlierThresholdMs ?? 30;
264
+ let acc = accumulators.get(layer);
265
+ if (acc === undefined) {
266
+ acc = { count: 0, sumDeltaMs: 0, maxDeltaMs: 0, outlierCount: 0, lastReportMs: now, lastEventMs: now };
267
+ accumulators.set(layer, acc);
268
+ return;
269
+ }
270
+ const deltaMs = now - acc.lastEventMs;
271
+ acc.lastEventMs = now;
272
+ acc.count++;
273
+ if (deltaMs > acc.maxDeltaMs)
274
+ acc.maxDeltaMs = deltaMs;
275
+ acc.sumDeltaMs += deltaMs;
276
+ if (deltaMs > threshold)
277
+ acc.outlierCount++;
278
+ if (deltaMs > threshold) {
279
+ const payload = {
280
+ layer,
281
+ timestampMs: now,
282
+ deltaMs: +deltaMs.toFixed(2),
283
+ detail: opts.detail,
284
+ };
285
+ // eslint-disable-next-line no-console
286
+ console.log('[gap-diagnostics]', JSON.stringify(payload));
287
+ }
288
+ if (now - acc.lastReportMs >= SUMMARY_INTERVAL_MS) {
289
+ const summaryDetail = {
290
+ count: acc.count,
291
+ meanDeltaMs: acc.count > 0 ? +(acc.sumDeltaMs / acc.count).toFixed(2) : 0,
292
+ maxDeltaMs: +acc.maxDeltaMs.toFixed(2),
293
+ outlierCount: acc.outlierCount,
294
+ periodMs: +(now - acc.lastReportMs).toFixed(1),
295
+ };
296
+ const summary = {
297
+ layer: `${layer}.summary`,
298
+ timestampMs: now,
299
+ detail: summaryDetail,
300
+ };
301
+ // eslint-disable-next-line no-console
302
+ console.log('[gap-diagnostics]', JSON.stringify(summary));
303
+ acc.count = 0;
304
+ acc.sumDeltaMs = 0;
305
+ acc.maxDeltaMs = 0;
306
+ acc.outlierCount = 0;
307
+ acc.lastReportMs = now;
308
+ }
309
+ }
310
+
252
311
  // @generated message type with reflection information, may provide speed optimized methods
253
312
  class Empty$Type extends MessageType {
254
313
  constructor() {
@@ -2293,6 +2352,7 @@ class ConnectionManager extends EventEmitter {
2293
2352
  if ((this.state === ConnectionManagerState.STOPPED || this.state === ConnectionManagerState.STOPPING) && !opts.sendIfStopped) {
2294
2353
  return;
2295
2354
  }
2355
+ logGapDiagnosticSampled('dht.connMgr.send');
2296
2356
  const peerDescriptor = message.targetDescriptor;
2297
2357
  if (this.isConnectionToSelf(peerDescriptor)) {
2298
2358
  throw new CannotConnectToSelf('Cannot send to self');
@@ -2368,6 +2428,7 @@ class ConnectionManager extends EventEmitter {
2368
2428
  this.rpcCommunicator?.handleMessageFromPeer(message);
2369
2429
  }
2370
2430
  else {
2431
+ logGapDiagnosticSampled('dht.connMgr.emitMessage');
2371
2432
  logger$B.trace('emit "message" ' + toNodeId(message.sourceDescriptor)
2372
2433
  + ' ' + message.serviceId + ' ' + message.messageId);
2373
2434
  this.emit('message', message);
@@ -2377,6 +2438,7 @@ class ConnectionManager extends EventEmitter {
2377
2438
  if (this.state === ConnectionManagerState.STOPPED) {
2378
2439
  return;
2379
2440
  }
2441
+ logGapDiagnosticSampled('dht.connMgr.onData');
2380
2442
  this.metrics.receiveBytesPerSecond.record(data.byteLength);
2381
2443
  this.metrics.receiveMessagesPerSecond.record(1);
2382
2444
  let message;
@@ -2810,7 +2872,7 @@ const parseVersion = (version) => {
2810
2872
  }
2811
2873
  };
2812
2874
 
2813
- var version = "103.3.1";
2875
+ var version = "103.7.0-rc.2";
2814
2876
 
2815
2877
  const logger$z = new Logger('Handshaker');
2816
2878
  // Optimally the Outgoing and Incoming Handshakers could be their own separate classes
@@ -5714,7 +5776,7 @@ class PeerDiscovery {
5714
5776
  logger$d.debug(`Ring join on ${this.options.serviceId} timed out`);
5715
5777
  }
5716
5778
  finally {
5717
- sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.id));
5779
+ sessions.forEach((session) => this.ongoingRingDiscoverySessions.delete(session.id));
5718
5780
  }
5719
5781
  }
5720
5782
  async rejoinDht(entryPoint, contactedPeers = new Set(), distantJoinContactPeers = new Set()) {
@@ -7805,5 +7867,12 @@ class SimulatorTransport extends ConnectionManager {
7805
7867
  }
7806
7868
  }
7807
7869
 
7808
- export { ConnectionManager, ConnectionType, DataEntry, DefaultConnectorFacade, DhtCallContext, DhtNode, EXISTING_CONNECTION_TIMEOUT, LatencyType, ListeningRpcCommunicator, ManagedConnection, Message, NodeType, PeerDescriptor, PendingConnection, RoutingRpcCommunicator, RpcRemote, Simulator, SimulatorTransport, WebsocketClientConnection, areEqualPeerDescriptors, createOutgoingHandshaker, getRandomRegion, getRegionDelayMatrix, randomDhtAddress, toDhtAddress, toDhtAddressRaw, toNodeId };
7870
+ /**
7871
+ * Stub for the Node.js build — `installWebrtcBridge` is a browser-only API.
7872
+ */
7873
+ function installWebrtcBridge(_worker) {
7874
+ throw new Error('installWebrtcBridge is only supported in browser environments');
7875
+ }
7876
+
7877
+ export { ConnectionManager, ConnectionType, DataEntry, DefaultConnectorFacade, DhtCallContext, DhtNode, EXISTING_CONNECTION_TIMEOUT, LatencyType, ListeningRpcCommunicator, ManagedConnection, Message, NodeType, PeerDescriptor, PendingConnection, RoutingRpcCommunicator, RpcRemote, Simulator, SimulatorTransport, WebsocketClientConnection, areEqualPeerDescriptors, createOutgoingHandshaker, getRandomRegion, getRegionDelayMatrix, installWebrtcBridge, logGapDiagnosticSampled, randomDhtAddress, setGapDiagnosticsEnabled, toDhtAddress, toDhtAddressRaw, toNodeId };
7809
7878
  //# sourceMappingURL=exports-nodejs.js.map