Skip to content

Commit 7123609

Browse files
committed
quic: use Number() instead of bigint for QuicSocket stats
PR-URL: #34247 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 94372b1 commit 7123609

File tree

5 files changed

+92
-73
lines changed

5 files changed

+92
-73
lines changed

doc/api/quic.md

+60-37
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,7 @@ added: REPLACEME
13191319
-->
13201320

13211321
New instances of `QuicSocket` are created using the `net.createQuicSocket()`
1322-
method.
1323-
1324-
Once created, a `QuicSocket` can be configured to work as both a client and a
1325-
server.
1322+
method, and can be used as both a client and a server.
13261323

13271324
#### Event: `'busy'`
13281325
<!-- YAML
@@ -1477,46 +1474,60 @@ added: REPLACEME
14771474

14781475
* Type: {boolean}
14791476

1480-
Will be `true` if the `QuicSocket` has been successfully bound to the local UDP
1481-
port.
1477+
Will be `true` if the `QuicSocket` has been successfully bound to a local UDP
1478+
port. Initially the value is `false`.
1479+
1480+
`QuicSocket` instances are not bound to a local UDP port until the first time
1481+
eithe `quicsocket.listen()` or `quicsocket.connect()` is called. The `'ready'`
1482+
event will be emitted once the `QuicSocket` has been bound and the value of
1483+
`quicsocket.bound` will become `true`.
1484+
1485+
Read-only.
14821486

14831487
#### quicsocket.boundDuration
14841488
<!-- YAML
14851489
added: REPLACEME
14861490
-->
14871491

1488-
* Type: {bigint}
1492+
* Type: {number}
14891493

1490-
A `BigInt` representing the length of time this `QuicSocket` has been bound
1491-
to a local port.
1494+
The length of time this `QuicSocket` has been bound to a local port.
1495+
1496+
Read-only.
14921497

14931498
#### quicsocket.bytesReceived
14941499
<!-- YAML
14951500
added: REPLACEME
14961501
-->
14971502

1498-
* Type: {bigint}
1503+
* Type: {number}
14991504

1500-
A `BigInt` representing the number of bytes received by this `QuicSocket`.
1505+
The number of bytes received by this `QuicSocket`.
1506+
1507+
Read-only.
15011508

15021509
#### quicsocket.bytesSent
15031510
<!-- YAML
15041511
added: REPLACEME
15051512
-->
15061513

1507-
* Type: {bigint}
1514+
* Type: {number}
1515+
1516+
The number of bytes sent by this `QuicSocket`.
15081517

1509-
A `BigInt` representing the number of bytes sent by this `QuicSocket`.
1518+
Read-only.
15101519

15111520
#### quicsocket.clientSessions
15121521
<!-- YAML
15131522
added: REPLACEME
15141523
-->
15151524

1516-
* Type: {bigint}
1525+
* Type: {number}
1526+
1527+
The number of client `QuicSession` instances that have been associated
1528+
with this `QuicSocket`.
15171529

1518-
A `BigInt` representing the number of client `QuicSession` instances that
1519-
have been associated with this `QuicSocket`.
1530+
Read-only.
15201531

15211532
#### quicsocket.close(\[callback\])
15221533
<!-- YAML
@@ -1690,9 +1701,11 @@ Will be `true` if the `QuicSocket` has been destroyed.
16901701
added: REPLACEME
16911702
-->
16921703

1693-
* Type: {bigint}
1704+
* Type: {number}
1705+
1706+
The length of time this `QuicSocket` has been active,
16941707

1695-
A `BigInt` representing the length of time this `QuicSocket` has been active,
1708+
Read-only.
16961709

16971710
#### quicsocket.endpoints
16981711
<!-- YAML
@@ -1828,10 +1841,11 @@ If a `callback` is given, it is registered as a handler for the
18281841
added: REPLACEME
18291842
-->
18301843

1831-
* Type: {bigint}
1844+
* Type: {number}
18321845

1833-
A `BigInt` representing the length of time this `QuicSocket` has been listening
1834-
for connections.
1846+
The length of time this `QuicSocket` has been listening for connections.
1847+
1848+
Read-only
18351849

18361850
#### quicsocket.listening
18371851
<!-- YAML
@@ -1847,29 +1861,33 @@ Set to `true` if the `QuicSocket` is listening for new connections.
18471861
added: REPLACEME
18481862
-->
18491863

1850-
* Type: {bigint}
1864+
* Type: {number}
18511865

1852-
A `BigInt` representing the number of packets received by this `QuicSocket` that
1853-
have been ignored.
1866+
The number of packets received by this `QuicSocket` that have been ignored.
1867+
1868+
Read-only.
18541869

18551870
#### quicsocket.packetsReceived
18561871
<!-- YAML
18571872
added: REPLACEME
18581873
-->
18591874

1860-
* Type: {bigint}
1875+
* Type: {number}
1876+
1877+
The number of packets successfully received by this `QuicSocket`.
18611878

1862-
A `BigInt` representing the number of packets successfully received by this
1863-
`QuicSocket`.
1879+
Read-only
18641880

18651881
#### quicsocket.packetsSent
18661882
<!-- YAML
18671883
added: REPLACEME
18681884
-->
18691885

1870-
* Type: {bigint}
1886+
* Type: {number}
1887+
1888+
The number of packets sent by this `QuicSocket`.
18711889

1872-
A `BigInt` representing the number of packets sent by this `QuicSocket`.
1890+
Read-only
18731891

18741892
#### quicsocket.pending
18751893
<!-- YAML
@@ -1902,20 +1920,23 @@ error code. To begin receiving connections again, disable busy mode by setting
19021920
added: REPLACEME
19031921
-->
19041922

1905-
* Type: {bigint}
1923+
* Type: {number}
1924+
1925+
The number of `QuicSession` instances rejected due to server busy status.
19061926

1907-
A `BigInt` representing the number of `QuicSession` instances rejected
1908-
due to server busy status.
1927+
Read-only.
19091928

19101929
#### quicsocket.serverSessions
19111930
<!-- YAML
19121931
added: REPLACEME
19131932
-->
19141933

1915-
* Type: {bigint}
1934+
* Type: {number}
19161935

1917-
A `BigInt` representing the number of server `QuicSession` instances that
1918-
have been associated with this `QuicSocket`.
1936+
The number of server `QuicSession` instances that have been associated with
1937+
this `QuicSocket`.
1938+
1939+
Read-only.
19191940

19201941
#### quicsocket.setDiagnosticPacketLoss(options)
19211942
<!-- YAML
@@ -1939,9 +1960,11 @@ This method is *not* to be used in production applications.
19391960
added: REPLACEME
19401961
-->
19411962

1942-
* Type: {bigint}
1963+
* Type: {number}
1964+
1965+
The number of stateless resets that have been sent.
19431966

1944-
A `BigInt` that represents the number of stateless resets that have been sent.
1967+
Read-only.
19451968

19461969
#### quicsocket.toggleStatelessReset()
19471970
<!-- YAML

lib/internal/quic/core.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
BigInt64Array,
1515
Error,
1616
Map,
17+
Number,
1718
RegExp,
1819
Set,
1920
Symbol,
@@ -1527,58 +1528,58 @@ class QuicSocket extends EventEmitter {
15271528
get duration() {
15281529
// TODO(@jasnell): If the object is destroyed, it should
15291530
// use a fixed duration rather than calculating from now
1530-
return process.hrtime.bigint() -
1531-
getStats(this, IDX_QUIC_SOCKET_STATS_CREATED_AT);
1531+
return Number(process.hrtime.bigint() -
1532+
getStats(this, IDX_QUIC_SOCKET_STATS_CREATED_AT));
15321533
}
15331534

15341535
get boundDuration() {
15351536
// TODO(@jasnell): If the object is destroyed, it should
15361537
// use a fixed duration rather than calculating from now
1537-
return process.hrtime.bigint() -
1538-
getStats(this, IDX_QUIC_SOCKET_STATS_BOUND_AT);
1538+
return Number(process.hrtime.bigint() -
1539+
getStats(this, IDX_QUIC_SOCKET_STATS_BOUND_AT));
15391540
}
15401541

15411542
get listenDuration() {
15421543
// TODO(@jasnell): If the object is destroyed, it should
15431544
// use a fixed duration rather than calculating from now
1544-
return process.hrtime.bigint() -
1545-
getStats(this, IDX_QUIC_SOCKET_STATS_LISTEN_AT);
1545+
return Number(process.hrtime.bigint() -
1546+
getStats(this, IDX_QUIC_SOCKET_STATS_LISTEN_AT));
15461547
}
15471548

15481549
get bytesReceived() {
1549-
return getStats(this, IDX_QUIC_SOCKET_STATS_BYTES_RECEIVED);
1550+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_BYTES_RECEIVED));
15501551
}
15511552

15521553
get bytesSent() {
1553-
return getStats(this, IDX_QUIC_SOCKET_STATS_BYTES_SENT);
1554+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_BYTES_SENT));
15541555
}
15551556

15561557
get packetsReceived() {
1557-
return getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_RECEIVED);
1558+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_RECEIVED));
15581559
}
15591560

15601561
get packetsSent() {
1561-
return getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_SENT);
1562+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_SENT));
15621563
}
15631564

15641565
get packetsIgnored() {
1565-
return getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_IGNORED);
1566+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_PACKETS_IGNORED));
15661567
}
15671568

15681569
get serverSessions() {
1569-
return getStats(this, IDX_QUIC_SOCKET_STATS_SERVER_SESSIONS);
1570+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_SERVER_SESSIONS));
15701571
}
15711572

15721573
get clientSessions() {
1573-
return getStats(this, IDX_QUIC_SOCKET_STATS_CLIENT_SESSIONS);
1574+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_CLIENT_SESSIONS));
15741575
}
15751576

15761577
get statelessResetCount() {
1577-
return getStats(this, IDX_QUIC_SOCKET_STATS_STATELESS_RESET_COUNT);
1578+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_STATELESS_RESET_COUNT));
15781579
}
15791580

15801581
get serverBusyCount() {
1581-
return getStats(this, IDX_QUIC_SOCKET_STATS_SERVER_BUSY_COUNT);
1582+
return Number(getStats(this, IDX_QUIC_SOCKET_STATS_SERVER_BUSY_COUNT));
15821583
}
15831584

15841585
// Diagnostic packet loss is a testing mechanism that allows simulating

test/parallel/test-quic-maxconnectionsperhost.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const kALPN = 'zzz';
5656
server.on('session', common.mustCall(() => {}, kMaxConnectionsPerHost));
5757

5858
server.on('close', common.mustCall(() => {
59-
assert.strictEqual(server.serverBusyCount, 1n);
59+
assert.strictEqual(server.serverBusyCount, 1);
6060
}));
6161

6262
server.on('ready', common.mustCall(() => {

test/parallel/test-quic-quicsocket-serverbusy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ server.on('busy', common.mustCall((busy) => {
3232

3333
// When the server is set as busy, all connections
3434
// will be rejected with a SERVER_BUSY response.
35-
server.setServerBusy();
35+
server.serverBusy = true;
3636
server.listen();
3737

3838
server.on('close', common.mustCall());

test/parallel/test-quic-quicsocket.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ assert(!socket.pending);
3131
// Socket is not destroyed
3232
assert(!socket.destroyed);
3333

34-
assert.strictEqual(typeof socket.duration, 'bigint');
35-
assert.strictEqual(typeof socket.boundDuration, 'bigint');
36-
assert.strictEqual(typeof socket.listenDuration, 'bigint');
37-
assert.strictEqual(typeof socket.bytesReceived, 'bigint');
38-
assert.strictEqual(socket.bytesReceived, 0n);
39-
assert.strictEqual(socket.bytesSent, 0n);
40-
assert.strictEqual(socket.packetsReceived, 0n);
41-
assert.strictEqual(socket.packetsSent, 0n);
42-
assert.strictEqual(socket.serverSessions, 0n);
43-
assert.strictEqual(socket.clientSessions, 0n);
34+
assert.strictEqual(typeof socket.duration, 'number');
35+
assert.strictEqual(typeof socket.boundDuration, 'number');
36+
assert.strictEqual(typeof socket.listenDuration, 'number');
37+
assert.strictEqual(typeof socket.bytesReceived, 'number');
38+
assert.strictEqual(socket.bytesReceived, 0);
39+
assert.strictEqual(socket.bytesSent, 0);
40+
assert.strictEqual(socket.packetsReceived, 0);
41+
assert.strictEqual(socket.packetsSent, 0);
42+
assert.strictEqual(socket.serverSessions, 0);
43+
assert.strictEqual(socket.clientSessions, 0);
4444

4545
const endpoint = socket.endpoints[0];
4646
assert(endpoint);
@@ -83,8 +83,8 @@ assert(endpoint);
8383
});
8484
});
8585

86-
[1, 1n, [], {}, null].forEach((args) => {
87-
assert.throws(() => socket.setServerBusy(args), {
86+
[1, 1n, [], {}, null].forEach((arg) => {
87+
assert.throws(() => socket.serverBusy = arg, {
8888
code: 'ERR_INVALID_ARG_TYPE'
8989
});
9090
});
@@ -143,12 +143,7 @@ socket.on('close', common.mustCall(() => {
143143
});
144144
});
145145

146-
[
147-
'setServerBusy',
148-
].forEach((op) => {
149-
assert.throws(() => socket[op](), {
150-
code: 'ERR_QUICSOCKET_DESTROYED',
151-
message: `Cannot call ${op} after a QuicSocket has been destroyed`
152-
});
146+
assert.throws(() => { socket.serverBusy = true; }, {
147+
code: 'ERR_QUICSOCKET_DESTROYED'
153148
});
154149
}));

0 commit comments

Comments
 (0)