Skip to content

Commit ee1a20a

Browse files
committed
src, lib: add stats to dtls
1 parent 1c0b4f6 commit ee1a20a

10 files changed

Lines changed: 798 additions & 7 deletions

File tree

doc/api/dtls.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ Shared state object with properties:
178178
* `sessionCount` {number}
179179
* `busy` {boolean}
180180

181+
### `endpoint.stats`
182+
183+
<!-- YAML
184+
added: REPLACEME
185+
-->
186+
187+
* Type: {DTLSEndpoint.Stats}
188+
189+
The statistics collected for this endpoint. Read only. The stats object is
190+
live and updated by the C++ internals as data flows through the endpoint.
191+
181192
### `endpoint.busy`
182193

183194
* {boolean}
@@ -204,6 +215,99 @@ Immediately destroys the endpoint without sending `close_notify` alerts.
204215

205216
Equivalent to calling `endpoint.close()`.
206217

218+
## Class: `DTLSEndpoint.Stats`
219+
220+
<!-- YAML
221+
added: REPLACEME
222+
-->
223+
224+
A view of the collected statistics for an endpoint.
225+
226+
### `endpointStats.createdAt`
227+
228+
<!-- YAML
229+
added: REPLACEME
230+
-->
231+
232+
* Type: {bigint} A timestamp indicating when the endpoint was created. Read only.
233+
234+
### `endpointStats.destroyedAt`
235+
236+
<!-- YAML
237+
added: REPLACEME
238+
-->
239+
240+
* Type: {bigint} A timestamp indicating when the endpoint was destroyed. Read only.
241+
242+
### `endpointStats.bytesReceived`
243+
244+
<!-- YAML
245+
added: REPLACEME
246+
-->
247+
248+
* Type: {bigint} The total number of bytes received by this endpoint. Read only.
249+
250+
### `endpointStats.bytesSent`
251+
252+
<!-- YAML
253+
added: REPLACEME
254+
-->
255+
256+
* Type: {bigint} The total number of bytes sent by this endpoint. Read only.
257+
258+
### `endpointStats.packetsReceived`
259+
260+
<!-- YAML
261+
added: REPLACEME
262+
-->
263+
264+
* Type: {bigint} The total number of UDP packets received by this endpoint. Read only.
265+
266+
### `endpointStats.packetsSent`
267+
268+
<!-- YAML
269+
added: REPLACEME
270+
-->
271+
272+
* Type: {bigint} The total number of UDP packets sent by this endpoint. Read only.
273+
274+
### `endpointStats.serverSessions`
275+
276+
<!-- YAML
277+
added: REPLACEME
278+
-->
279+
280+
* Type: {bigint} The total number of peer-initiated sessions accepted by this
281+
endpoint. Read only.
282+
283+
### `endpointStats.clientSessions`
284+
285+
<!-- YAML
286+
added: REPLACEME
287+
-->
288+
289+
* Type: {bigint} The total number of sessions initiated by this endpoint. Read only.
290+
291+
### `endpointStats.serverBusyCount`
292+
293+
<!-- YAML
294+
added: REPLACEME
295+
-->
296+
297+
* Type: {bigint} The total number of incoming connections rejected because the
298+
endpoint was marked busy. Read only.
299+
300+
### `endpointStats.isConnected`
301+
302+
<!-- YAML
303+
added: REPLACEME
304+
-->
305+
306+
* Type: {boolean}
307+
308+
`true` if the stats object is still connected to the underlying endpoint.
309+
Once the endpoint is destroyed, the stats become a stale snapshot.
310+
207311
## Class: `DTLSSession`
208312

209313
<!-- YAML
@@ -264,6 +368,17 @@ Immediately destroys the session without sending `close_notify`.
264368

265369
* Returns: {string|undefined} The negotiated SRTP protection profile name.
266370

371+
### `session.stats`
372+
373+
<!-- YAML
374+
added: REPLACEME
375+
-->
376+
377+
* Type: {DTLSSession.Stats}
378+
379+
The statistics collected for this session. Read only. The stats object is
380+
live and updated as data flows through the session.
381+
267382
### `session.exportKeyingMaterial(length, label[, context])`
268383

269384
* `length` {number} Number of bytes to export.
@@ -275,6 +390,97 @@ Exports keying material from the DTLS session, as defined in
275390
[RFC 5705][]. This is commonly used with DTLS-SRTP to derive
276391
encryption keys for media streams.
277392

393+
## Class: `DTLSSession.Stats`
394+
395+
<!-- YAML
396+
added: REPLACEME
397+
-->
398+
399+
A view of the collected statistics for a session.
400+
401+
### `sessionStats.createdAt`
402+
403+
<!-- YAML
404+
added: REPLACEME
405+
-->
406+
407+
* Type: {bigint} A timestamp indicating when the session was created. Read only.
408+
409+
### `sessionStats.destroyedAt`
410+
411+
<!-- YAML
412+
added: REPLACEME
413+
-->
414+
415+
* Type: {bigint} A timestamp indicating when the session was destroyed. Read only.
416+
417+
### `sessionStats.closingAt`
418+
419+
<!-- YAML
420+
added: REPLACEME
421+
-->
422+
423+
* Type: {bigint} A timestamp indicating when `close()` was called. Read only.
424+
425+
### `sessionStats.handshakeCompletedAt`
426+
427+
<!-- YAML
428+
added: REPLACEME
429+
-->
430+
431+
* Type: {bigint} A timestamp indicating when the DTLS handshake completed. Read only.
432+
433+
### `sessionStats.bytesReceived`
434+
435+
<!-- YAML
436+
added: REPLACEME
437+
-->
438+
439+
* Type: {bigint} The total number of application data bytes received. Read only.
440+
441+
### `sessionStats.bytesSent`
442+
443+
<!-- YAML
444+
added: REPLACEME
445+
-->
446+
447+
* Type: {bigint} The total number of application data bytes sent. Read only.
448+
449+
### `sessionStats.messagesReceived`
450+
451+
<!-- YAML
452+
added: REPLACEME
453+
-->
454+
455+
* Type: {bigint} The total number of application messages received. Read only.
456+
457+
### `sessionStats.messagesSent`
458+
459+
<!-- YAML
460+
added: REPLACEME
461+
-->
462+
463+
* Type: {bigint} The total number of application messages sent. Read only.
464+
465+
### `sessionStats.retransmitCount`
466+
467+
<!-- YAML
468+
added: REPLACEME
469+
-->
470+
471+
* Type: {bigint} The total number of DTLS handshake retransmissions. Read only.
472+
473+
### `sessionStats.isConnected`
474+
475+
<!-- YAML
476+
added: REPLACEME
477+
-->
478+
479+
* Type: {boolean}
480+
481+
`true` if the stats object is still connected to the underlying session.
482+
Once the session is destroyed, the stats become a stale snapshot.
483+
278484
### Callback properties
279485

280486
#### `session.onmessage`

lib/internal/dtls/dtls.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ const {
4242
DTLSSessionState,
4343
} = require('internal/dtls/state');
4444

45+
const {
46+
DTLSEndpointStats,
47+
DTLSSessionStats,
48+
} = require('internal/dtls/stats');
49+
4550
const {
4651
kOwner,
4752
kPrivateConstructor,
@@ -70,6 +75,7 @@ class DTLSSession {
7075
#handle;
7176
#endpoint;
7277
#state;
78+
#stats;
7379
#pendingOpen;
7480
#pendingClose;
7581
#onmessage;
@@ -88,6 +94,8 @@ class DTLSSession {
8894
this.#endpoint = endpoint;
8995
this.#state = new DTLSSessionState(
9096
kPrivateConstructor, handle.getState());
97+
this.#stats = new DTLSSessionStats(
98+
kPrivateConstructor, handle.getStats());
9199
this.#pendingOpen = PromiseWithResolvers();
92100
this.#pendingClose = PromiseWithResolvers();
93101
}
@@ -218,6 +226,7 @@ class DTLSSession {
218226
}
219227

220228
get state() { return this.#state; }
229+
get stats() { return this.#stats; }
221230
get endpoint() { return this.#endpoint; }
222231

223232
exportKeyingMaterial(length, label, context) {
@@ -287,6 +296,7 @@ class DTLSSession {
287296
class DTLSEndpoint {
288297
#handle;
289298
#state;
299+
#stats;
290300
#sessions = new SafeSet();
291301
#pendingClose;
292302
#onsession;
@@ -297,6 +307,8 @@ class DTLSEndpoint {
297307
this.#handle[kOwner] = this;
298308
this.#state = new DTLSEndpointState(
299309
kPrivateConstructor, this.#handle.getState());
310+
this.#stats = new DTLSEndpointStats(
311+
kPrivateConstructor, this.#handle.getStats());
300312
this.#pendingClose = PromiseWithResolvers();
301313

302314
if (options.mtu !== undefined) {
@@ -392,6 +404,7 @@ class DTLSEndpoint {
392404
}
393405

394406
get state() { return this.#state; }
407+
get stats() { return this.#stats; }
395408
get sessions() { return this.#sessions; }
396409

397410
get onerror() { return this.#onerror; }

0 commit comments

Comments
 (0)