Skip to content

Commit dc30d95

Browse files
committed
fix: review fixes
- moved `withMonitor` utility to `QUICConnection` - fixes to `withMonitor` utility - renamed `fun()` to `f()` - renamed `connectionConnectTime` to `connectTimeoutTime`
1 parent 7ee5f94 commit dc30d95

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

src/QUICConnection.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class QUICConnection extends EventTarget {
531531
this.stopKeepAliveIntervalTimer();
532532

533533
// Trigger closing connection in the background and await close later.
534-
void utils.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
534+
void this.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
535535
await mon.withF(this.lockCode, async (mon) => {
536536
// If this is already closed, then `Done` will be thrown
537537
// Otherwise it can send `CONNECTION_CLOSE` frame
@@ -663,7 +663,7 @@ class QUICConnection extends EventTarget {
663663
remoteInfo: RemoteInfo,
664664
mon?: Monitor<RWLockWriter>,
665665
): Promise<void> {
666-
await utils.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
666+
await this.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
667667
if (!mon.isLocked(this.lockCode)) {
668668
return mon.withF(this.lockCode, async (mon) => {
669669
return this.recv(data, remoteInfo, mon);
@@ -773,7 +773,7 @@ class QUICConnection extends EventTarget {
773773
* @internal
774774
*/
775775
public async send(mon?: Monitor<RWLockWriter>): Promise<void> {
776-
await utils.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
776+
await this.withMonitor(mon, this.lockbox, RWLockWriter, async (mon) => {
777777
if (!mon.isLocked(this.lockCode)) {
778778
return mon.withF(this.lockCode, async (mon) => {
779779
return this.send(mon);
@@ -1081,6 +1081,26 @@ class QUICConnection extends EventTarget {
10811081
return quicStream;
10821082
});
10831083
}
1084+
1085+
/**
1086+
* Used as a clean way to create a new monitor if it doesn't exist, otherwise uses the existing one.
1087+
*/
1088+
protected async withMonitor<T>(
1089+
mon: Monitor<RWLockWriter> | undefined,
1090+
lockBox: LockBox<RWLockWriter>,
1091+
lockConstructor: { new (): RWLockWriter },
1092+
f: (mon: Monitor<RWLockWriter>) => Promise<T>,
1093+
locksPending?: Map<string, { count: number }>,
1094+
): Promise<T> {
1095+
if (mon == null) {
1096+
return await withF(
1097+
[contextsUtils.monitor(lockBox, lockConstructor, locksPending)],
1098+
([mon]) => f(mon),
1099+
);
1100+
} else {
1101+
return f(mon);
1102+
}
1103+
}
10841104
}
10851105

10861106
export default QUICConnection;

src/QUICServer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class QUICServer extends EventTarget {
5353
protected codeToReason: StreamCodeToReason | undefined;
5454
protected verifyCallback: VerifyCallback | undefined;
5555
protected connectionMap: QUICConnectionMap;
56-
protected connectionConnectTime: number;
56+
protected connectTimeoutTime: number;
5757
// Used to track address string for logging ONLY
5858
protected address: string;
5959

@@ -110,7 +110,7 @@ class QUICServer extends EventTarget {
110110
reasonToCode,
111111
codeToReason,
112112
verifyCallback,
113-
connectionConnectTime = 2000,
113+
connectTimeoutTime = 15000,
114114
logger,
115115
}: {
116116
crypto: {
@@ -126,7 +126,7 @@ class QUICServer extends EventTarget {
126126
reasonToCode?: StreamReasonToCode;
127127
codeToReason?: StreamCodeToReason;
128128
verifyCallback?: VerifyCallback;
129-
connectionConnectTime?: number;
129+
connectTimeoutTime?: number;
130130
logger?: Logger;
131131
}) {
132132
super();
@@ -154,7 +154,7 @@ class QUICServer extends EventTarget {
154154
this.reasonToCode = reasonToCode;
155155
this.codeToReason = codeToReason;
156156
this.verifyCallback = verifyCallback;
157-
this.connectionConnectTime = connectionConnectTime;
157+
this.connectTimeoutTime = connectTimeoutTime;
158158
}
159159

160160
@ready(new errors.ErrorQUICServerNotRunning())
@@ -379,7 +379,7 @@ class QUICServer extends EventTarget {
379379
.slice(32)}-${clientConnRef}`,
380380
),
381381
},
382-
{ timer: this.connectionConnectTime },
382+
{ timer: this.connectTimeoutTime },
383383
);
384384
} catch (e) {
385385
// Ignoring any errors here as a failure to connect

src/utils.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ import type {
88
ServerCrypto,
99
} from './types';
1010
import type { Connection } from './native';
11-
import type { LockBox, RWLockWriter } from '@matrixai/async-locks';
12-
import type { Monitor } from '@matrixai/async-locks';
1311
import dns from 'dns';
1412
import { IPv4, IPv6, Validator } from 'ip-num';
15-
import { withF } from '@matrixai/resources';
16-
import { utils as contextsUtils } from '@matrixai/contexts';
1713
import QUICConnectionId from './QUICConnectionId';
1814
import * as errors from './errors';
1915

@@ -466,28 +462,6 @@ function streamStats(
466462
`;
467463
}
468464

469-
/**
470-
* Used as a clean way to create a new monitor if it doesn't exist, otherwise uses the existing one.
471-
*/
472-
async function withMonitor<T>(
473-
mon: Monitor<RWLockWriter> | undefined,
474-
lockBox: LockBox<RWLockWriter>,
475-
lockConstructor: { new (): RWLockWriter },
476-
fun: (mon: Monitor<RWLockWriter>) => Promise<T>,
477-
locksPending?: Map<string, { count: number }>,
478-
): Promise<T> {
479-
if (mon == null) {
480-
return await withF(
481-
[contextsUtils.monitor(lockBox, lockConstructor, locksPending)],
482-
async ([mon]) => {
483-
return await fun(mon);
484-
},
485-
);
486-
} else {
487-
return await fun(mon);
488-
}
489-
}
490-
491465
export {
492466
isIPv4,
493467
isIPv6,
@@ -519,5 +493,4 @@ export {
519493
validateToken,
520494
sleep,
521495
streamStats,
522-
withMonitor,
523496
};

0 commit comments

Comments
 (0)