Skip to content

Commit 01e182a

Browse files
committed
fix: small fixes and clean up
1 parent 83e18d7 commit 01e182a

File tree

6 files changed

+37
-52
lines changed

6 files changed

+37
-52
lines changed

src/QUICClient.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import type { PromiseCancellable } from '@matrixai/async-cancellable';
22
import type { ContextTimed } from '@matrixai/contexts';
3-
import type {
4-
ClientCrypto,
5-
Host,
6-
VerifyCallback,
7-
} from './types';
3+
import type { ClientCrypto, Host, Port, VerifyCallback } from './types';
84
import type { Config } from './native/types';
95
import type QUICConnectionMap from './QUICConnectionMap';
106
import type {
@@ -137,12 +133,9 @@ class QUICClient extends EventTarget {
137133
const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
138134
await crypto.ops.randomBytes(scidBuffer);
139135
const scid = new QUICConnectionId(scidBuffer);
140-
// validating host and port types
136+
// Validating host and port types
141137
let [host_] = await utils.resolveHost(host, resolveHostname);
142-
let [localHost_] = await utils.resolveHost(host, resolveHostname);
143-
if (!utils.isPort(port) || !utils.isPort(localPort)) {
144-
throw Error('TMP Not a valid port number');
145-
}
138+
const [localHost_] = await utils.resolveHost(localHost, resolveHostname);
146139
// If the target host is in fact a zero IP, it cannot be used
147140
// as a target host, so we need to resolve it to a non-zero IP
148141
// in this case, 0.0.0.0 is resolved to 127.0.0.1 and :: and ::0 is
@@ -215,7 +208,7 @@ class QUICClient extends EventTarget {
215208
socket,
216209
remoteInfo: {
217210
host: host_,
218-
port,
211+
port: port as Port,
219212
},
220213
config: quicConfig,
221214
reasonToCode,

src/QUICServer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type {
22
Host,
3-
Hostname,
4-
Port,
53
RemoteInfo,
64
StreamCodeToReason,
75
StreamReasonToCode,

src/QUICSocket.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class QUICSocket extends EventTarget {
202202
host,
203203
this.resolveHostname,
204204
);
205-
if (!utils.isPort(port)) throw Error('TMP invalid port');
206205
this.socket = dgram.createSocket({
207206
type: udpType,
208207
reuseAddr,

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
ConnectionId,
55
ConnectionIdString,
66
Host,
7-
Hostname,
87
Port,
98
ServerCrypto,
109
} from './types';

tests/QUICClient.test.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ describe(QUICClient.name, () => {
163163
connectionEventProm.resolveP(e),
164164
);
165165
await server.start({
166-
host: '::' ,
167-
port: 0 ,
166+
host: '::',
167+
port: 0,
168168
});
169169
const client = await QUICClient.createQUICClient({
170-
host: '::' , // Will resolve to ::1
170+
host: '::', // Will resolve to ::1
171171
port: server.port,
172-
localHost: '::' ,
172+
localHost: '::',
173173
crypto: {
174174
ops: clientCrypto,
175175
},
@@ -194,7 +194,7 @@ describe(QUICClient.name, () => {
194194
await expect(
195195
QUICClient.createQUICClient({
196196
host: localhost,
197-
port: 56666 ,
197+
port: 56666,
198198
localHost: localhost,
199199
crypto: {
200200
ops: clientCrypto,
@@ -212,7 +212,7 @@ describe(QUICClient.name, () => {
212212
await expect(
213213
QUICClient.createQUICClient({
214214
host: localhost,
215-
port: 56666 ,
215+
port: 56666,
216216
localHost: localhost,
217217
crypto: {
218218
ops: clientCrypto,
@@ -229,7 +229,7 @@ describe(QUICClient.name, () => {
229229
await expect(
230230
QUICClient.createQUICClient({
231231
host: localhost,
232-
port: 56666 ,
232+
port: 56666,
233233
localHost: localhost,
234234
crypto: {
235235
ops: clientCrypto,
@@ -246,7 +246,7 @@ describe(QUICClient.name, () => {
246246
await expect(
247247
QUICClient.createQUICClient({
248248
host: localhost,
249-
port: 56666 ,
249+
port: 56666,
250250
localHost: localhost,
251251
crypto: {
252252
ops: clientCrypto,
@@ -265,7 +265,7 @@ describe(QUICClient.name, () => {
265265
QUICClient.createQUICClient(
266266
{
267267
host: localhost,
268-
port: 56666 ,
268+
port: 56666,
269269
localHost: localhost,
270270
crypto: {
271271
ops: clientCrypto,
@@ -287,7 +287,7 @@ describe(QUICClient.name, () => {
287287
QUICClient.createQUICClient(
288288
{
289289
host: localhost,
290-
port: 56666 ,
290+
port: 56666,
291291
localHost: localhost,
292292
crypto: {
293293
ops: clientCrypto,
@@ -306,7 +306,7 @@ describe(QUICClient.name, () => {
306306
QUICClient.createQUICClient(
307307
{
308308
host: localhost,
309-
port: 56666 ,
309+
port: 56666,
310310
localHost: localhost,
311311
crypto: {
312312
ops: clientCrypto,
@@ -324,7 +324,7 @@ describe(QUICClient.name, () => {
324324
await expect(
325325
QUICClient.createQUICClient({
326326
host: localhost,
327-
port: 56666 ,
327+
port: 56666,
328328
localHost: localhost,
329329
crypto: {
330330
ops: clientCrypto,
@@ -343,7 +343,7 @@ describe(QUICClient.name, () => {
343343
const clientProm = QUICClient.createQUICClient(
344344
{
345345
host: localhost,
346-
port: 56666 ,
346+
port: 56666,
347347
localHost: localhost,
348348
crypto: {
349349
ops: clientCrypto,
@@ -754,9 +754,9 @@ describe(QUICClient.name, () => {
754754
host: localhost,
755755
});
756756
const client = await QUICClient.createQUICClient({
757-
host: '::ffff:127.0.0.1' ,
757+
host: '::ffff:127.0.0.1',
758758
port: server.port,
759-
localHost: '::' ,
759+
localHost: '::',
760760
crypto: {
761761
ops: clientCrypto,
762762
},
@@ -862,9 +862,9 @@ describe(QUICClient.name, () => {
862862
host: localhost,
863863
});
864864
const client = await QUICClient.createQUICClient({
865-
host: '::ffff:127.0.0.1' ,
865+
host: '::ffff:127.0.0.1',
866866
port: server.port,
867-
localHost: '::' ,
867+
localHost: '::',
868868
crypto: {
869869
ops: clientCrypto,
870870
},
@@ -1180,9 +1180,9 @@ describe(QUICClient.name, () => {
11801180
host: localhost,
11811181
});
11821182
const client = await QUICClient.createQUICClient({
1183-
host: '::ffff:127.0.0.1' ,
1183+
host: '::ffff:127.0.0.1',
11841184
port: server.port,
1185-
localHost: '::' ,
1185+
localHost: '::',
11861186
crypto: {
11871187
ops: clientCrypto,
11881188
},
@@ -1240,9 +1240,9 @@ describe(QUICClient.name, () => {
12401240
host: localhost,
12411241
});
12421242
const client = await QUICClient.createQUICClient({
1243-
host: '::ffff:127.0.0.1' ,
1243+
host: '::ffff:127.0.0.1',
12441244
port: server.port,
1245-
localHost: '::' ,
1245+
localHost: '::',
12461246
crypto: {
12471247
ops: clientCrypto,
12481248
},
@@ -1300,9 +1300,9 @@ describe(QUICClient.name, () => {
13001300
host: localhost,
13011301
});
13021302
const client = await QUICClient.createQUICClient({
1303-
host: '::ffff:127.0.0.1' ,
1303+
host: '::ffff:127.0.0.1',
13041304
port: server.port,
1305-
localHost: '::' ,
1305+
localHost: '::',
13061306
crypto: {
13071307
ops: clientCrypto,
13081308
},
@@ -1363,9 +1363,9 @@ describe(QUICClient.name, () => {
13631363
host: localhost,
13641364
});
13651365
const client = await QUICClient.createQUICClient({
1366-
host: '::ffff:127.0.0.1' ,
1366+
host: '::ffff:127.0.0.1',
13671367
port: server.port,
1368-
localHost: '::' ,
1368+
localHost: '::',
13691369
crypto: {
13701370
ops: clientCrypto,
13711371
},
@@ -1423,9 +1423,9 @@ describe(QUICClient.name, () => {
14231423
host: localhost,
14241424
});
14251425
const client = await QUICClient.createQUICClient({
1426-
host: '::ffff:127.0.0.1' ,
1426+
host: '::ffff:127.0.0.1',
14271427
port: server.port,
1428-
localHost: '::' ,
1428+
localHost: '::',
14291429
crypto: {
14301430
ops: clientCrypto,
14311431
},
@@ -1461,9 +1461,9 @@ describe(QUICClient.name, () => {
14611461
});
14621462
test('Keep alive does not prevent connection timeout', async () => {
14631463
const clientProm = QUICClient.createQUICClient({
1464-
host: '::ffff:127.0.0.1' ,
1465-
port: 54444 ,
1466-
localHost: '::' ,
1464+
host: '::ffff:127.0.0.1',
1465+
port: 54444,
1466+
localHost: '::',
14671467
crypto: {
14681468
ops: clientCrypto,
14691469
},
@@ -1661,7 +1661,7 @@ describe(QUICClient.name, () => {
16611661
);
16621662
await server.start({
16631663
host: localhost,
1664-
port: 55555 ,
1664+
port: 55555,
16651665
});
16661666
// Connection should fail
16671667
const clientProm = QUICClient.createQUICClient({
@@ -1719,7 +1719,7 @@ describe(QUICClient.name, () => {
17191719
);
17201720
await server.start({
17211721
host: localhost,
1722-
port: 55555 ,
1722+
port: 55555,
17231723
});
17241724
// If the server is slow to respond then this will time out.
17251725
// Then main cause of this was the server not processing the initial packet

tests/concurrency.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type * as events from '@/events';
2-
import type {
3-
ClientCrypto,
4-
ServerCrypto,
5-
StreamReasonToCode,
6-
} from '@';
2+
import type { ClientCrypto, ServerCrypto, StreamReasonToCode } from '@';
73
import type { Messages, StreamData } from './utils';
84
import type { QUICConfig } from '@';
95
import { fc, testProp } from '@fast-check/jest';

0 commit comments

Comments
 (0)