11import type { PromiseCancellable } from '@matrixai/async-cancellable' ;
22import type { ContextTimed , ContextTimedInput } from '@matrixai/contexts' ;
33import type QUICSocket from './QUICSocket' ;
4- import type QUICConnectionId from './QUICConnectionId' ;
54import type {
65 Host ,
76 Port ,
@@ -25,6 +24,7 @@ import {
2524} from '@matrixai/async-init/dist/StartStop' ;
2625import { timedCancellable , context } from '@matrixai/contexts/dist/decorators' ;
2726import { buildQuicheConfig , minIdleTimeout } from './config' ;
27+ import QUICConnectionId from './QUICConnectionId' ;
2828import QUICStream from './QUICStream' ;
2929import { quiche , ConnectionErrorCode } from './native' ;
3030import * as utils from './utils' ;
@@ -44,11 +44,6 @@ class QUICConnection {
4444 */
4545 public readonly type : 'client' | 'server' ;
4646
47- /**
48- * This is the source connection ID.
49- */
50- public readonly connectionId : QUICConnectionId ;
51-
5247 /**
5348 * Resolves once the connection has closed.
5449 */
@@ -186,19 +181,8 @@ class QUICConnection {
186181 ) => {
187182 const error = evt . detail ;
188183 this . errorLast = error ;
189- if (
190- ( error instanceof errors . ErrorQUICConnectionLocal ||
191- error instanceof errors . ErrorQUICConnectionPeer ) &&
192- ( ( ! error . data . isApp &&
193- error . data . errorCode === ConnectionErrorCode . NoError ) ||
194- ( error . data . isApp && error . data . errorCode === 0 ) )
195- ) {
196- // Log out the excpetion as an info when it is graceful
197- this . logger . info ( utils . formatError ( error ) ) ;
198- } else {
199- // Log out the exception as an error when it is not graceful
200- this . logger . error ( utils . formatError ( error ) ) ;
201- }
184+ // Log out error for debugging
185+ this . logger . info ( utils . formatError ( error ) ) ;
202186 if ( error instanceof errors . ErrorQUICConnectionInternal ) {
203187 throw error ;
204188 }
@@ -381,7 +365,6 @@ class QUICConnection {
381365 }
382366 this . type = type ;
383367 this . conn = conn ! ;
384- this . connectionId = scid ;
385368 this . socket = socket ;
386369 this . config = config ;
387370 if ( this . config . cert != null ) {
@@ -413,6 +396,49 @@ class QUICConnection {
413396 this . resolveClosedP = resolveClosedP ;
414397 }
415398
399+ /**
400+ * This is the source connection ID.
401+ */
402+ public get connectionId ( ) {
403+ const sourceId = this . conn . sourceId ( ) ;
404+ // Zero copy construction of QUICConnectionId
405+ return new QUICConnectionId (
406+ sourceId . buffer ,
407+ sourceId . byteOffset ,
408+ sourceId . byteLength ,
409+ ) ;
410+ }
411+
412+ /**
413+ * This is the destination connection ID.
414+ * This is only fully known after establishing the connection
415+ */
416+ @ready ( new errors . ErrorQUICConnectionNotRunning ( ) )
417+ public get connectionIdPeer ( ) {
418+ const destinationId = this . conn . destinationId ( ) ;
419+ // Zero copy construction of QUICConnectionId
420+ return new QUICConnectionId (
421+ destinationId . buffer ,
422+ destinationId . byteOffset ,
423+ destinationId . byteLength ,
424+ ) ;
425+ }
426+
427+ /**
428+ * A common ID between the client and server connection.
429+ * Used to identify connection pairs more easily.
430+ */
431+ @ready ( new errors . ErrorQUICConnectionNotRunning ( ) )
432+ public get connectionIdShared ( ) {
433+ const sourceId = this . conn . sourceId ( ) ;
434+ const destinationId = this . conn . destinationId ( ) ;
435+ if ( Buffer . compare ( sourceId , destinationId ) <= 0 ) {
436+ return new QUICConnectionId ( Buffer . concat ( [ sourceId , destinationId ] ) ) ;
437+ } else {
438+ return new QUICConnectionId ( Buffer . concat ( [ destinationId , sourceId ] ) ) ;
439+ }
440+ }
441+
416442 public get remoteHost ( ) : Host {
417443 return this . _remoteHost ;
418444 }
0 commit comments