1
- import type QUICClient from './QUICClient' ;
2
1
import type QUICServer from './QUICServer' ;
3
2
import type QUICConnection from './QUICConnection' ;
4
3
import type { Crypto , Host , Hostname , Port } from './types' ;
@@ -50,12 +49,12 @@ class QUICSocket extends EventTarget {
50
49
* If it is non-QUIC, we can discard the data.
51
50
* If there are multiple coalesced QUIC packets, it is expected that
52
51
* all packets are intended for the same connection. This means we only
53
- * need to parse the first QUIC packet to determinine what connection to route
52
+ * need to parse the first QUIC packet to determining what connection to route
54
53
* the data to.
55
54
*/
56
55
protected handleSocketMessage = async (
57
56
data : Buffer ,
58
- rinfo : dgram . RemoteInfo ,
57
+ remoteInfo : dgram . RemoteInfo ,
59
58
) => {
60
59
// The data buffer may have multiple coalesced QUIC packets.
61
60
// This header is parsed from the first packet.
@@ -92,9 +91,9 @@ class QUICSocket extends EventTarget {
92
91
quiche . MAX_CONN_ID_LEN ,
93
92
) ;
94
93
95
- const remoteInfo = {
96
- host : rinfo . address as Host ,
97
- port : rinfo . port as Port ,
94
+ const remoteInfo_ = {
95
+ host : remoteInfo . address as Host ,
96
+ port : remoteInfo . port as Port ,
98
97
} ;
99
98
100
99
// Now both must be checked
@@ -107,7 +106,7 @@ class QUICSocket extends EventTarget {
107
106
}
108
107
const conn_ = await this . server . connectionNew (
109
108
data ,
110
- remoteInfo ,
109
+ remoteInfo_ ,
111
110
header ,
112
111
dcid ,
113
112
scid ,
@@ -126,7 +125,7 @@ class QUICSocket extends EventTarget {
126
125
// When we register a client, we have to put the connection in our
127
126
// connection map
128
127
}
129
- await conn . recv ( data , remoteInfo ) ;
128
+ await conn . recv ( data , remoteInfo_ ) ;
130
129
131
130
// The `conn.recv` now may actually destroy the connection
132
131
// In that sense, there's nothing to send
@@ -273,10 +272,16 @@ class QUICSocket extends EventTarget {
273
272
this . logger . info ( `Started ${ this . constructor . name } on ${ address } ` ) ;
274
273
}
275
274
276
- public async stop ( ) : Promise < void > {
275
+ /**
276
+ * Will stop the socket.
277
+ * An `ErrorQUICSocketConnectionsActive` will be thrown if there are active connections.
278
+ * If force is true, it will skip checking connections and stop the socket.
279
+ * @param force - Will force the socket to end even if there are active connections, used for cleaning up after tests.
280
+ */
281
+ public async stop ( force = false ) : Promise < void > {
277
282
const address = utils . buildAddress ( this . _host , this . _port ) ;
278
283
this . logger . info ( `Stop ${ this . constructor . name } on ${ address } ` ) ;
279
- if ( this . connectionMap . size > 0 ) {
284
+ if ( ! force && this . connectionMap . size > 0 ) {
280
285
throw new errors . ErrorQUICSocketConnectionsActive (
281
286
`Cannot stop QUICSocket with ${ this . connectionMap . size } active connection(s)` ,
282
287
) ;
@@ -354,27 +359,6 @@ class QUICSocket extends EventTarget {
354
359
return this . socketSend ( ...params ) ;
355
360
}
356
361
357
- /**
358
- * Registers a client to the socket
359
- * This is a new client, but clients don't die by itself?
360
- */
361
- public registerClient ( client : QUICClient ) {
362
- // So what really this does?
363
- // Is this about creating a connection?
364
- // So we can add the connection to the map?
365
- // And if we are doing
366
- // QUICConnection.createQUICConnection
367
- // Then that means, we are really creating that connection in the async creator
368
- // That means the async creator needs to create teh `connection` and call it too
369
- this . logger . error ( 'registerClient IS NOT IMPLEMENTED!' ) ;
370
- }
371
-
372
- // But we already have a connection map
373
- // well yea, we are checking liveness of connections
374
- // But client destruction is only way to destory connections
375
- // But if the client connection fails
376
- // we need to simultaneously destroy the client
377
-
378
362
/**
379
363
* Sets a single server to the socket
380
364
* You can only have 1 server for the socket
@@ -388,7 +372,7 @@ class QUICSocket extends EventTarget {
388
372
* Just go straight to calling a thing
389
373
* We can call this.server.handleConnection()
390
374
* Why `handleConnection` because technically it's built on top of the handleMessage
391
- * Thatbecomes the key idea there
375
+ * That becomes the key idea there
392
376
* handleNewConnection
393
377
* And all sorts of other stuff!
394
378
* Or whatever it needs to be
0 commit comments