@streamr/dht 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.
@@ -344,8 +344,8 @@ declare class Timestamp$Type extends MessageType<Timestamp> {
344
344
  * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
345
345
  * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
346
346
  * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
347
- * is required. A ProtoJSON serializer should always use UTC (as indicated by
348
- * "Z") when printing the Timestamp type and a ProtoJSON parser should be
347
+ * is required. A proto3 JSON serializer should always use UTC (as indicated by
348
+ * "Z") when printing the Timestamp type and a proto3 JSON parser should be
349
349
  * able to accept both UTC and other timezones (as indicated by an offset).
350
350
  *
351
351
  * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
@@ -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 -62135596800 and 253402300799 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
@@ -1319,5 +1318,11 @@ declare class Handshaker extends EventEmitter<HandshakerEvents> {
1319
1318
 
1320
1319
  declare function installWebrtcBridge(worker: Worker): void;
1321
1320
 
1322
- 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, randomDhtAddress, toDhtAddress, toDhtAddressRaw, toNodeId };
1321
+ declare function setGapDiagnosticsEnabled(val: boolean): void;
1322
+ declare function logGapDiagnosticSampled(layer: string, opts?: {
1323
+ detail?: Record<string, unknown>;
1324
+ outlierThresholdMs?: number;
1325
+ }): void;
1326
+
1327
+ 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 };
1323
1328
  export type { ConnectionLocker, ConnectionsView, DhtAddress, DhtAddressRaw, DhtNodeEvents, DhtNodeOptions, DhtRpcOptions, IConnection, ITransport, IceServer, LockID, PortRange, RingContacts, ServiceID, TlsCertificate, TransportEvents };
@@ -240,6 +240,65 @@ class SendFailed extends Err {
240
240
  constructor(message, originalError) { super(ErrorCode.SEND_FAILED, message, originalError); }
241
241
  }
242
242
 
243
+ let enabled = false;
244
+ function setGapDiagnosticsEnabled(val) {
245
+ enabled = val;
246
+ globalThis.__dhtGapDiagEnabled = val;
247
+ }
248
+ const SUMMARY_INTERVAL_MS = 2000;
249
+ const accumulators = new Map();
250
+ function logGapDiagnosticSampled(layer, opts = {}) {
251
+ if (!enabled)
252
+ return;
253
+ const now = performance.now();
254
+ const threshold = opts.outlierThresholdMs ?? 30;
255
+ let acc = accumulators.get(layer);
256
+ if (acc === undefined) {
257
+ acc = { count: 0, sumDeltaMs: 0, maxDeltaMs: 0, outlierCount: 0, lastReportMs: now, lastEventMs: now };
258
+ accumulators.set(layer, acc);
259
+ return;
260
+ }
261
+ const deltaMs = now - acc.lastEventMs;
262
+ acc.lastEventMs = now;
263
+ acc.count++;
264
+ if (deltaMs > acc.maxDeltaMs)
265
+ acc.maxDeltaMs = deltaMs;
266
+ acc.sumDeltaMs += deltaMs;
267
+ if (deltaMs > threshold)
268
+ acc.outlierCount++;
269
+ if (deltaMs > threshold) {
270
+ const payload = {
271
+ layer,
272
+ timestampMs: now,
273
+ deltaMs: +deltaMs.toFixed(2),
274
+ detail: opts.detail,
275
+ };
276
+ // eslint-disable-next-line no-console
277
+ console.log('[gap-diagnostics]', JSON.stringify(payload));
278
+ }
279
+ if (now - acc.lastReportMs >= SUMMARY_INTERVAL_MS) {
280
+ const summaryDetail = {
281
+ count: acc.count,
282
+ meanDeltaMs: acc.count > 0 ? +(acc.sumDeltaMs / acc.count).toFixed(2) : 0,
283
+ maxDeltaMs: +acc.maxDeltaMs.toFixed(2),
284
+ outlierCount: acc.outlierCount,
285
+ periodMs: +(now - acc.lastReportMs).toFixed(1),
286
+ };
287
+ const summary = {
288
+ layer: `${layer}.summary`,
289
+ timestampMs: now,
290
+ detail: summaryDetail,
291
+ };
292
+ // eslint-disable-next-line no-console
293
+ console.log('[gap-diagnostics]', JSON.stringify(summary));
294
+ acc.count = 0;
295
+ acc.sumDeltaMs = 0;
296
+ acc.maxDeltaMs = 0;
297
+ acc.outlierCount = 0;
298
+ acc.lastReportMs = now;
299
+ }
300
+ }
301
+
243
302
  // @generated message type with reflection information, may provide speed optimized methods
244
303
  class Empty$Type extends MessageType {
245
304
  constructor() {
@@ -2284,6 +2343,7 @@ class ConnectionManager extends EventEmitter {
2284
2343
  if ((this.state === ConnectionManagerState.STOPPED || this.state === ConnectionManagerState.STOPPING) && !opts.sendIfStopped) {
2285
2344
  return;
2286
2345
  }
2346
+ logGapDiagnosticSampled('dht.connMgr.send');
2287
2347
  const peerDescriptor = message.targetDescriptor;
2288
2348
  if (this.isConnectionToSelf(peerDescriptor)) {
2289
2349
  throw new CannotConnectToSelf('Cannot send to self');
@@ -2359,6 +2419,7 @@ class ConnectionManager extends EventEmitter {
2359
2419
  this.rpcCommunicator?.handleMessageFromPeer(message);
2360
2420
  }
2361
2421
  else {
2422
+ logGapDiagnosticSampled('dht.connMgr.emitMessage');
2362
2423
  logger$A.trace('emit "message" ' + toNodeId(message.sourceDescriptor)
2363
2424
  + ' ' + message.serviceId + ' ' + message.messageId);
2364
2425
  this.emit('message', message);
@@ -2368,6 +2429,7 @@ class ConnectionManager extends EventEmitter {
2368
2429
  if (this.state === ConnectionManagerState.STOPPED) {
2369
2430
  return;
2370
2431
  }
2432
+ logGapDiagnosticSampled('dht.connMgr.onData');
2371
2433
  this.metrics.receiveBytesPerSecond.record(data.byteLength);
2372
2434
  this.metrics.receiveMessagesPerSecond.record(1);
2373
2435
  let message;
@@ -2801,7 +2863,7 @@ const parseVersion = (version) => {
2801
2863
  }
2802
2864
  };
2803
2865
 
2804
- var version = "103.6.0-rc.0";
2866
+ var version = "103.7.0-rc.2";
2805
2867
 
2806
2868
  const logger$y = new Logger('Handshaker');
2807
2869
  // Optimally the Outgoing and Incoming Handshakers could be their own separate classes
@@ -3259,6 +3321,9 @@ class DirectWebrtcConnection extends EventEmitter {
3259
3321
  }
3260
3322
  send(data) {
3261
3323
  if (this.lastState === 'connected') {
3324
+ logGapDiagnosticSampled('dht.dc.send', {
3325
+ detail: { bufferedAmount: this.dataChannel.bufferedAmount, queueLen: this.messageQueue.length }
3326
+ });
3262
3327
  if (this.dataChannel.bufferedAmount > this.bufferThresholdHigh) {
3263
3328
  this.messageQueue.push(data);
3264
3329
  }
@@ -3287,6 +3352,7 @@ class DirectWebrtcConnection extends EventEmitter {
3287
3352
  };
3288
3353
  dataChannel.onmessage = (msg) => {
3289
3354
  logger$v.trace('dc.onmessage');
3355
+ logGapDiagnosticSampled('dht.dc.onmessage');
3290
3356
  this.emit('data', new Uint8Array(msg.data));
3291
3357
  };
3292
3358
  dataChannel.onbufferedamountlow = () => {
@@ -3581,7 +3647,7 @@ class WorkerWebrtcConnection extends EventEmitter {
3581
3647
  if (state === DisconnectedState.CLOSED ||
3582
3648
  state === DisconnectedState.DISCONNECTED ||
3583
3649
  state === DisconnectedState.FAILED) {
3584
- this.doClose(false);
3650
+ this.doClose(false, `pcState=${state}`);
3585
3651
  }
3586
3652
  },
3587
3653
  onDataChannel: (channel) => {
@@ -3634,6 +3700,9 @@ class WorkerWebrtcConnection extends EventEmitter {
3634
3700
  }
3635
3701
  send(data) {
3636
3702
  if (this.connected && this.dataChannel) {
3703
+ logGapDiagnosticSampled('dht.dc.send', {
3704
+ detail: { bufferedAmount: this.dataChannel.bufferedAmount, queueLen: this.messageQueue.length }
3705
+ });
3637
3706
  if (this.dataChannel.bufferedAmount > this.bufferThresholdHigh) {
3638
3707
  this.messageQueue.push(data);
3639
3708
  }
@@ -3663,13 +3732,14 @@ class WorkerWebrtcConnection extends EventEmitter {
3663
3732
  };
3664
3733
  dataChannel.onclose = () => {
3665
3734
  logger$u.trace('dc.onClosed (worker)');
3666
- this.doClose(false);
3735
+ this.doClose(false, 'dataChannel.onclose');
3667
3736
  };
3668
3737
  dataChannel.onerror = (err) => {
3669
3738
  logger$u.warn('Data channel error (worker)', { err });
3670
3739
  };
3671
3740
  dataChannel.onmessage = (msg) => {
3672
3741
  logger$u.trace('dc.onmessage (worker)');
3742
+ logGapDiagnosticSampled('dht.dc.onmessage');
3673
3743
  this.emit('data', new Uint8Array(msg.data));
3674
3744
  };
3675
3745
  dataChannel.onbufferedamountlow = () => {
@@ -5939,7 +6009,7 @@ class PeerDiscovery {
5939
6009
  logger$d.debug(`Ring join on ${this.options.serviceId} timed out`);
5940
6010
  }
5941
6011
  finally {
5942
- sessions.forEach((session) => this.ongoingDiscoverySessions.delete(session.id));
6012
+ sessions.forEach((session) => this.ongoingRingDiscoverySessions.delete(session.id));
5943
6013
  }
5944
6014
  }
5945
6015
  async rejoinDht(entryPoint, contactedPeers = new Set(), distantJoinContactPeers = new Set()) {
@@ -8036,5 +8106,5 @@ class SimulatorTransport extends ConnectionManager {
8036
8106
  }
8037
8107
  }
8038
8108
 
8039
- 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, randomDhtAddress, toDhtAddress, toDhtAddressRaw, toNodeId };
8109
+ 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 };
8040
8110
  //# sourceMappingURL=exports-browser.js.map