Skip to content

Commit d5ba823

Browse files
committed
syntax: major linting
[ci skip]
1 parent e1cc9f3 commit d5ba823

22 files changed

+941
-1036
lines changed

src/QUICClient.ts

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import type { ConnectionId, ConnectionIdString, Crypto, Host, Hostname, Port } from './types';
2-
import type { Header, Config, Connection } from './native/types';
1+
import type { Crypto, Host, Hostname, Port } from './types';
2+
import type { Config } from './native/types';
33
import type { QUICConfig } from './config';
4+
import type QUICConnectionMap from './QUICConnectionMap';
45
import Logger from '@matrixai/logger';
5-
import {
6-
CreateDestroy,
7-
ready,
8-
status
9-
} from '@matrixai/async-init/dist/CreateDestroy';
6+
import { CreateDestroy, ready } from '@matrixai/async-init/dist/CreateDestroy';
107
import { running } from '@matrixai/async-init';
11-
import { Quiche, quiche, Type } from './native';
8+
import { quiche } from './native';
129
import * as utils from './utils';
1310
import * as errors from './errors';
1411
import * as events from './events';
1512
import { clientDefault } from './config';
1613
import QUICSocket from './QUICSocket';
1714
import QUICConnection from './QUICConnection';
18-
import QUICConnectionMap from './QUICConnectionMap';
1915
import QUICConnectionId from './QUICConnectionId';
2016

2117
/**
@@ -29,7 +25,6 @@ import QUICConnectionId from './QUICConnectionId';
2925
interface QUICClient extends CreateDestroy {}
3026
@CreateDestroy()
3127
class QUICClient extends EventTarget {
32-
3328
public readonly isSocketShared: boolean;
3429
protected socket: QUICSocket;
3530
protected logger: Logger;
@@ -60,22 +55,22 @@ class QUICClient extends EventTarget {
6055
logger = new Logger(`${this.name}`),
6156
config = {},
6257
}: {
63-
host: Host | Hostname,
64-
port: Port,
65-
localHost?: Host | Hostname,
66-
localPort?: Port,
58+
host: Host | Hostname;
59+
port: Port;
60+
localHost?: Host | Hostname;
61+
localPort?: Port;
6762
crypto: {
6863
key: ArrayBuffer;
6964
ops: Crypto;
70-
},
65+
};
7166
socket?: QUICSocket;
7267
resolveHostname?: (hostname: Hostname) => Host | PromiseLike<Host>;
7368
logger?: Logger;
7469
config?: Partial<QUICConfig>;
7570
}) {
7671
const quicConfig = {
7772
...clientDefault,
78-
...config
73+
...config,
7974
};
8075
const scidBuffer = new ArrayBuffer(quiche.MAX_CONN_ID_LEN);
8176
await crypto.ops.randomBytes(scidBuffer);
@@ -88,10 +83,7 @@ class QUICClient extends EventTarget {
8883
// in this case, 0.0.0.0 is resolved to 127.0.0.1 and :: and ::0 is
8984
// resolved to ::1
9085
host_ = utils.resolvesZeroIP(host_);
91-
const {
92-
p: errorP,
93-
rejectP: rejectErrorP
94-
} = utils.promise<never>();
86+
const { p: errorP, rejectP: rejectErrorP } = utils.promise<never>();
9587
const handleQUICSocketError = (e: events.QUICSocketErrorEvent) => {
9688
rejectErrorP(e.detail);
9789
};
@@ -103,13 +95,9 @@ class QUICClient extends EventTarget {
10395
socket = new QUICSocket({
10496
crypto,
10597
resolveHostname,
106-
logger: logger.getChild(QUICSocket.name)
98+
logger: logger.getChild(QUICSocket.name),
10799
});
108-
socket.addEventListener(
109-
'error',
110-
handleQUICSocketError,
111-
{ once: true }
112-
);
100+
socket.addEventListener('error', handleQUICSocketError, { once: true });
113101
isSocketShared = false;
114102
await socket.start({
115103
host: localHost,
@@ -124,7 +112,8 @@ class QUICClient extends EventTarget {
124112
// Check that the target `host` is compatible with the bound socket host
125113
if (
126114
socket.type === 'ipv4' &&
127-
(!utils.isIPv4(host_) && !utils.isIPv4MappedIPv6(host_))
115+
!utils.isIPv4(host_) &&
116+
!utils.isIPv4MappedIPv6(host_)
128117
) {
129118
throw new errors.ErrorQUICClientInvalidHost(
130119
`Cannot connect to ${host_} on an IPv4 QUICClient`,
@@ -136,10 +125,7 @@ class QUICClient extends EventTarget {
136125
throw new errors.ErrorQUICClientInvalidHost(
137126
`Cannot connect to ${host_} on an IPv6 QUICClient`,
138127
);
139-
} else if (
140-
socket.type === 'ipv4&ipv6' &&
141-
!utils.isIPv6(host_)
142-
) {
128+
} else if (socket.type === 'ipv4&ipv6' && !utils.isIPv6(host_)) {
143129
throw new errors.ErrorQUICClientInvalidHost(
144130
`Cannot send to ${host_} on a dual stack QUICClient`,
145131
);
@@ -157,16 +143,14 @@ class QUICClient extends EventTarget {
157143
socket,
158144
remoteInfo: {
159145
host: host_,
160-
port
146+
port,
161147
},
162148
config: quicConfig,
163-
logger: logger.getChild(`${QUICConnection.name} ${scid.toString().slice(32)}`)
149+
logger: logger.getChild(
150+
`${QUICConnection.name} ${scid.toString().slice(32)}`,
151+
),
164152
});
165-
connection.addEventListener(
166-
'error',
167-
handleConnectionError,
168-
{ once: true }
169-
);
153+
connection.addEventListener('error', handleConnectionError, { once: true });
170154
logger.debug('CLIENT TRIGGER SEND');
171155
// This will not raise an error
172156
await connection.send();
@@ -175,17 +159,19 @@ class QUICClient extends EventTarget {
175159
await Promise.race([connection.establishedP, errorP]);
176160
} catch (e) {
177161
logger.error(e.toString());
178-
// console.error(e);
162+
// Console.error(e);
179163
logger.debug(`Is shared?: ${isSocketShared}`);
180164
// Waiting for connection to destroy
181165
const destroyedProm = utils.promise<void>();
182-
connection.addEventListener('destroy', ()=> {
166+
connection.addEventListener(
167+
'destroy',
168+
() => {
183169
destroyedProm.resolveP();
184170
},
185171
{
186172
once: true,
187173
},
188-
)
174+
);
189175
await destroyedProm.p;
190176
if (!isSocketShared) {
191177
// Stop our own socket
@@ -207,7 +193,7 @@ class QUICClient extends EventTarget {
207193
socket,
208194
connection,
209195
isSocketShared,
210-
logger
196+
logger,
211197
});
212198
address = utils.buildAddress(host_, port);
213199
logger.info(`Created ${this.name} to ${address}`);
@@ -224,8 +210,8 @@ class QUICClient extends EventTarget {
224210
protected handleQUICSocketError = (e: events.QUICSocketErrorEvent) => {
225211
this.dispatchEvent(
226212
new events.QUICClientErrorEvent({
227-
detail: e
228-
})
213+
detail: e,
214+
}),
229215
);
230216
};
231217

@@ -234,11 +220,13 @@ class QUICClient extends EventTarget {
234220
* This is always used because QUICClient is
235221
* one to one with QUICConnection
236222
*/
237-
protected handleQUICConnectionError = (e: events.QUICConnectionErrorEvent) => {
223+
protected handleQUICConnectionError = (
224+
e: events.QUICConnectionErrorEvent,
225+
) => {
238226
this.dispatchEvent(
239227
new events.QUICClientErrorEvent({
240-
detail: e
241-
})
228+
detail: e,
229+
}),
242230
);
243231
};
244232

@@ -266,16 +254,10 @@ class QUICClient extends EventTarget {
266254
// Registers itself to the socket
267255
this.socket.registerClient(this);
268256
if (!isSocketShared) {
269-
this.socket.addEventListener(
270-
'error',
271-
this.handleQUICSocketError
272-
);
257+
this.socket.addEventListener('error', this.handleQUICSocketError);
273258
}
274259
this._connection = connection;
275-
this._connection.addEventListener(
276-
'error',
277-
this.handleQUICConnectionError
278-
);
260+
this._connection.addEventListener('error', this.handleQUICConnectionError);
279261
}
280262

281263
@ready(new errors.ErrorQUICClientDestroyed())
@@ -313,7 +295,6 @@ class QUICClient extends EventTarget {
313295
// Unlike the server
314296
// upon a connection failing/destroying
315297
// it should result in the CLIENT also being destroyed
316-
317298
}
318299

319300
export default QUICClient;

0 commit comments

Comments
 (0)