@@ -25,11 +25,6 @@ const { createQuicSocket } = require('net');
25
25
// Create the QUIC UDP IPv4 socket bound to local IP port 1234
26
26
const socket = createQuicSocket ({ endpoint: { port: 1234 } });
27
27
28
- // Tell the socket to operate as a server using the given
29
- // key and certificate to secure new connections, using
30
- // the fictional 'hello' application protocol.
31
- socket .listen ({ key, cert, alpn: ' hello' });
32
-
33
28
socket .on (' session' , (session ) => {
34
29
// A new server side session has been created!
35
30
@@ -53,9 +48,14 @@ socket.on('session', (session) => {
53
48
});
54
49
});
55
50
56
- socket .on (' listening' , () => {
57
- // The socket is listening for sessions!
58
- });
51
+ // Tell the socket to operate as a server using the given
52
+ // key and certificate to secure new connections, using
53
+ // the fictional 'hello' application protocol.
54
+ (async function () {
55
+ await socket .listen ({ key, cert, alpn: ' hello' });
56
+ console .log (' The socket is listening for sessions!' );
57
+ })();
58
+
59
59
```
60
60
61
61
## QUIC Basics
@@ -110,11 +110,13 @@ const { createQuicSocket } = require('net');
110
110
// Create a QuicSocket associated with localhost and port 1234
111
111
const socket = createQuicSocket ({ endpoint: { port: 1234 } });
112
112
113
- const client = socket .connect ({
114
- address: ' example.com' ,
115
- port: 4567 ,
116
- alpn: ' foo'
117
- });
113
+ (async function () {
114
+ const client = await socket .connect ({
115
+ address: ' example.com' ,
116
+ port: 4567 ,
117
+ alpn: ' foo'
118
+ });
119
+ })();
118
120
```
119
121
120
122
As soon as the ` QuicClientSession ` is created, the ` address ` provided in
@@ -135,20 +137,22 @@ New instances of `QuicServerSession` are created internally by the
135
137
using the ` listen() ` method.
136
138
137
139
``` js
140
+ const { createQuicSocket } = require (' net' );
141
+
138
142
const key = getTLSKeySomehow ();
139
143
const cert = getTLSCertSomehow ();
140
144
141
- socket .listen ({
142
- key,
143
- cert,
144
- alpn: ' foo'
145
- });
145
+ const socket = createQuicSocket ();
146
146
147
147
socket .on (' session' , (session ) => {
148
148
session .on (' secure' , () => {
149
149
// The QuicServerSession can now be used for application data
150
150
});
151
151
});
152
+
153
+ (async function () {
154
+ await socket .listen ({ key, cert, alpn: ' foo' });
155
+ })();
152
156
```
153
157
154
158
As with client ` QuicSession ` instances, the ` QuicServerSession ` cannot be
@@ -1275,20 +1279,17 @@ added: REPLACEME
1275
1279
Set to ` true ` if the ` QuicClientSession ` is ready for use. False if the
1276
1280
` QuicSocket ` has not yet been bound.
1277
1281
1278
- #### quicclientsession.setSocket(socket, callback ] )
1282
+ #### quicclientsession.setSocket(socket] )
1279
1283
<!-- YAML
1280
1284
added: REPLACEME
1281
1285
-->
1282
1286
1283
1287
* ` socket ` {QuicSocket} A ` QuicSocket ` instance to move this session to.
1284
- * ` callback ` {Function} A callback function that will be invoked once the
1285
- migration to the new ` QuicSocket ` is complete.
1288
+ * Returns: {Promise}
1286
1289
1287
1290
Migrates the ` QuicClientSession ` to the given ` QuicSocket ` instance. If the new
1288
1291
` QuicSocket ` has not yet been bound to a local UDP port, it will be bound prior
1289
- to attempting the migration. If the ` QuicClientSession ` is not yet ready to
1290
- migrate, the callback will be invoked with an ` Error ` using the code
1291
- ` ERR_OPERATION_FAILED ` .
1292
+ to attempting the migration.
1292
1293
1293
1294
### Class: QuicServerSession extends QuicSession
1294
1295
<!-- YAML
@@ -1394,7 +1395,7 @@ added: REPLACEME
1394
1395
1395
1396
Emitted after the ` QuicSocket ` has been destroyed and is no longer usable.
1396
1397
1397
- The ` 'close' ` event will not be emitted multiple times .
1398
+ The ` 'close' ` event will only ever be emitted once .
1398
1399
1399
1400
#### Event: ` 'endpointClose' `
1400
1401
<!-- YAML
@@ -1419,7 +1420,7 @@ added: REPLACEME
1419
1420
Emitted before the ` 'close' ` event if the ` QuicSocket ` was destroyed with an
1420
1421
` error ` .
1421
1422
1422
- The ` 'error' ` event will not be emitted multiple times .
1423
+ The ` 'error' ` event will only ever be emitted once .
1423
1424
1424
1425
#### Event: ` 'listening' `
1425
1426
<!-- YAML
@@ -1430,7 +1431,7 @@ Emitted after `quicsocket.listen()` is called and the `QuicSocket` has started
1430
1431
listening for incoming ` QuicServerSession ` s. The callback is invoked with
1431
1432
no arguments.
1432
1433
1433
- The ` 'listening' ` event will not be emitted multiple times .
1434
+ The ` 'listening' ` event will only ever be emitted once .
1434
1435
1435
1436
#### Event: ` 'ready' `
1436
1437
<!-- YAML
@@ -1439,7 +1440,7 @@ added: REPLACEME
1439
1440
1440
1441
Emitted once the ` QuicSocket ` has been bound to a local UDP port.
1441
1442
1442
- The ` 'ready' ` event will not be emitted multiple times .
1443
+ The ` 'ready' ` event will only ever be emitted once .
1443
1444
1444
1445
#### Event: ` 'session' `
1445
1446
<!-- YAML
@@ -1455,11 +1456,12 @@ const { createQuicSocket } = require('net');
1455
1456
1456
1457
const options = getOptionsSomehow ();
1457
1458
const server = createQuicSocket ({ server: options });
1458
- server .listen ();
1459
1459
1460
1460
server .on (' session' , (session ) => {
1461
1461
// Attach session event listeners.
1462
1462
});
1463
+
1464
+ server .listen ();
1463
1465
```
1464
1466
1465
1467
The ` 'session' ` event will be emitted multiple times.
@@ -1517,7 +1519,7 @@ added: REPLACEME
1517
1519
1518
1520
Creates and adds a new ` QuicEndpoint ` to the ` QuicSocket ` instance. An
1519
1521
error will be thrown if ` quicsock.addEndpoint() ` is called either after
1520
- the ` QuicSocket ` has already started binding to the local ports or after
1522
+ the ` QuicSocket ` has already started binding to the local ports, or after
1521
1523
the ` QuicSocket ` has been destroyed.
1522
1524
1523
1525
#### quicsocket.bound
@@ -1721,10 +1723,9 @@ added: REPLACEME
1721
1723
* ` type ` : {string} Identifies the type of UDP socket. The value must either
1722
1724
be ` 'udp4' ` , indicating UDP over IPv4, or ` 'udp6' ` , indicating UDP over
1723
1725
IPv6. ** Default** : ` 'udp4' ` .
1726
+ * Returns: {Promise}
1724
1727
1725
- Create a new ` QuicClientSession ` . This function can be called multiple times
1726
- to create sessions associated with different endpoints on the same
1727
- client endpoint.
1728
+ Returns a ` Promise ` that resolves a new ` QuicClientSession ` .
1728
1729
1729
1730
#### quicsocket.destroy(\[ error\] )
1730
1731
<!-- YAML
@@ -1745,6 +1746,8 @@ added: REPLACEME
1745
1746
1746
1747
Will be ` true ` if the ` QuicSocket ` has been destroyed.
1747
1748
1749
+ Read-only.
1750
+
1748
1751
#### quicsocket.duration
1749
1752
<!-- YAML
1750
1753
added: REPLACEME
@@ -1765,7 +1768,9 @@ added: REPLACEME
1765
1768
1766
1769
An array of ` QuicEndpoint ` instances associated with the ` QuicSocket ` .
1767
1770
1768
- #### quicsocket.listen(\[ options\]\[ , callback\] )
1771
+ Read-only.
1772
+
1773
+ #### quicsocket.listen(\[ options\] )
1769
1774
<!-- YAML
1770
1775
added: REPLACEME
1771
1776
-->
@@ -1877,13 +1882,10 @@ added: REPLACEME
1877
1882
[ OpenSSL Options] [ ] .
1878
1883
* ` sessionIdContext ` {string} Opaque identifier used by servers to ensure
1879
1884
session state is not shared between applications. Unused by clients.
1885
+ * Returns: {Promise}
1880
1886
1881
- * ` callback ` {Function}
1882
-
1883
- Listen for new peer-initiated sessions.
1884
-
1885
- If a ` callback ` is given, it is registered as a handler for the
1886
- ` 'session' ` event.
1887
+ Listen for new peer-initiated sessions. Returns a ` Promise ` that is resolved
1888
+ once the ` QuicSocket ` is actively listening.
1887
1889
1888
1890
#### quicsocket.listenDuration
1889
1891
<!-- YAML
@@ -1905,6 +1907,8 @@ added: REPLACEME
1905
1907
1906
1908
Set to ` true ` if the ` QuicSocket ` is listening for new connections.
1907
1909
1910
+ Read-only.
1911
+
1908
1912
#### quicsocket.packetsIgnored
1909
1913
<!-- YAML
1910
1914
added: REPLACEME
@@ -1947,6 +1951,8 @@ added: REPLACEME
1947
1951
1948
1952
Set to ` true ` if the socket is not yet bound to the local UDP port.
1949
1953
1954
+ Read-only.
1955
+
1950
1956
#### quicsocket.ref()
1951
1957
<!-- YAML
1952
1958
added: REPLACEME
@@ -2004,30 +2010,30 @@ by artificially dropping received or transmitted packets.
2004
2010
2005
2011
This method is * not* to be used in production applications.
2006
2012
2007
- #### quicsocket.statelessResetCount
2013
+ #### quicsocket.statelessReset
2008
2014
<!-- YAML
2009
2015
added: REPLACEME
2010
2016
-->
2011
2017
2012
- * Type: {number}
2013
-
2014
- The number of stateless resets that have been sent.
2018
+ * Type: {boolean} ` true ` if stateless reset processing is enabled; ` false `
2019
+ if disabled.
2015
2020
2016
- Read-only.
2021
+ By default, a listening ` QuicSocket ` will generate stateless reset tokens when
2022
+ appropriate. The ` disableStatelessReset ` option may be set when the
2023
+ ` QuicSocket ` is created to disable generation of stateless resets. The
2024
+ ` quicsocket.statelessReset ` property allows stateless reset to be turned on and
2025
+ off dynamically through the lifetime of the ` QuicSocket ` .
2017
2026
2018
- #### quicsocket.toggleStatelessReset()
2027
+ #### quicsocket.statelessResetCount
2019
2028
<!-- YAML
2020
2029
added: REPLACEME
2021
2030
-->
2022
2031
2023
- * Returns {boolean} ` true ` if stateless reset processing is enabled; ` false `
2024
- if disabled.
2032
+ * Type: {number}
2025
2033
2026
- By default, a listening ` QuicSocket ` will generate stateless reset tokens when
2027
- appropriate. The ` disableStatelessReset ` option may be set when the
2028
- ` QuicSocket ` is created to disable generation of stateless resets. The
2029
- ` toggleStatelessReset() ` function allows stateless reset to be turned on and
2030
- off dynamically through the lifetime of the ` QuicSocket ` .
2034
+ The number of stateless resets that have been sent.
2035
+
2036
+ Read-only.
2031
2037
2032
2038
#### quicsocket.unref();
2033
2039
<!-- YAML
0 commit comments