Skip to content

Commit c68c955

Browse files
committed
fix: fixing usage of Host and Port types to be internal
[ci skip]
1 parent 4f545d2 commit c68c955

49 files changed

Lines changed: 339 additions & 381 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"@matrixai/resources": "^1.1.5",
9090
"@matrixai/timer": "^1.1.1",
9191
"@matrixai/workers": "^1.3.7",
92-
"@matrixai/quic": "^0.0.12",
92+
"@matrixai/quic": "^0.0.13",
9393
"@peculiar/asn1-pkcs8": "^2.3.0",
9494
"@peculiar/asn1-schema": "^2.3.0",
9595
"@peculiar/asn1-x509": "^2.3.0",

src/PolykeyAgent.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ import { serverManifest as agentServerManifest } from './agent/handlers';
4949

5050
type NetworkConfig = {
5151
// Agent QUICSocket config
52-
agentHost?: Host;
53-
agentPort?: Port;
52+
agentHost?: string;
53+
agentPort?: number;
5454
ipv6Only?: boolean;
5555
// RPCServer for client service
56-
clientHost?: Host;
57-
clientPort?: Port;
56+
clientHost?: string;
57+
clientPort?: number;
5858
// Websocket server config
5959
maxReadableStreamBytes?: number;
6060
connectionIdleTimeoutTime?: number;
@@ -905,8 +905,8 @@ class PolykeyAgent {
905905
if (nodeId == null) throw Error('failed to extract NodeId from cert');
906906
const data: ConnectionData = {
907907
remoteNodeId: nodeId,
908-
remoteHost: connection.remoteHost as unknown as Host,
909-
remotePort: connection.remotePort as unknown as Port,
908+
remoteHost: connection.remoteHost as Host,
909+
remotePort: connection.remotePort as Port,
910910
};
911911
await this.events.emitAsync(
912912
PolykeyAgent.eventSymbols.QUICServer,
@@ -970,8 +970,8 @@ class PolykeyAgent {
970970
nodeId: this.keyRing.getNodeId(),
971971
clientHost: this.webSocketServerClient.getHost(),
972972
clientPort: this.webSocketServerClient.getPort(),
973-
agentHost: this.quicSocket.host as unknown as Host,
974-
agentPort: this.quicSocket.port as unknown as Port,
973+
agentHost: this.quicSocket.host,
974+
agentPort: this.quicSocket.port,
975975
});
976976
this.logger.info(`Started ${this.constructor.name}`);
977977
} catch (e) {

src/bin/utils/processors.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { FileSystem } from '../../types';
22
import type { RecoveryCode } from '../../keys/types';
33
import type { NodeId } from '../../ids/types';
4-
import type { Host, Port } from '../../network/types';
54
import type {
65
StatusStarting,
76
StatusLive,
@@ -203,14 +202,14 @@ async function processRecoveryCode(
203202
async function processClientOptions(
204203
nodePath: string,
205204
nodeId?: NodeId,
206-
clientHost?: Host,
207-
clientPort?: Port,
205+
clientHost?: string,
206+
clientPort?: number,
208207
fs = require('fs'),
209208
logger = new Logger(processClientOptions.name),
210209
): Promise<{
211210
nodeId: NodeId;
212-
clientHost: Host;
213-
clientPort: Port;
211+
clientHost: string;
212+
clientPort: number;
214213
}> {
215214
if (nodeId != null && clientHost != null && clientPort != null) {
216215
return {
@@ -266,31 +265,31 @@ async function processClientOptions(
266265
async function processClientStatus(
267266
nodePath: string,
268267
nodeId?: NodeId,
269-
clientHost?: Host,
270-
clientPort?: Port,
268+
clientHost?: string,
269+
clientPort?: number,
271270
fs = require('fs'),
272271
logger = new Logger(processClientStatus.name),
273272
): Promise<
274273
| {
275274
statusInfo: StatusStarting | StatusStopping | StatusDead;
276275
status: Status;
277276
nodeId: NodeId | undefined;
278-
clientHost: Host | undefined;
279-
clientPort: Port | undefined;
277+
clientHost: string | undefined;
278+
clientPort: number | undefined;
280279
}
281280
| {
282281
statusInfo: StatusLive;
283282
status: Status;
284283
nodeId: NodeId;
285-
clientHost: Host;
286-
clientPort: Port;
284+
clientHost: string;
285+
clientPort: number;
287286
}
288287
| {
289288
statusInfo: undefined;
290289
status: undefined;
291290
nodeId: NodeId;
292-
clientHost: Host;
293-
clientPort: Port;
291+
clientHost: string;
292+
clientPort: number;
294293
}
295294
> {
296295
if (nodeId != null && clientHost != null && clientPort != null) {

src/client/handlers/agentStatus.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ClientRPCRequestParams, ClientRPCResponseResult } from '../types';
22
import type { StatusResultMessage } from './types';
33
import type PolykeyAgent from '../../PolykeyAgent';
4-
import type { Host, Port } from '../../network/types';
54
import * as nodesUtils from '../../nodes/utils';
65
import * as keysUtils from '../../keys/utils';
76
import { UnaryHandler } from '../../rpc/handlers';
@@ -21,8 +20,8 @@ class AgentStatusHandler extends UnaryHandler<
2120
nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()),
2221
clientHost: pkAgent.webSocketServerClient.getHost(),
2322
clientPort: pkAgent.webSocketServerClient.getPort(),
24-
agentHost: pkAgent.quicSocket.host as unknown as Host,
25-
agentPort: pkAgent.quicSocket.port as unknown as Port,
23+
agentHost: pkAgent.quicSocket.host,
24+
agentPort: pkAgent.quicSocket.port,
2625
publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey),
2726
certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(),
2827
};

src/client/handlers/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ import type {
1010
} from '../../keys/types';
1111
import type { Notification } from '../../notifications/types';
1212
import type { CommitId, VaultAction, VaultName } from '../../vaults/types';
13-
import type { Host, Port } from '../../network/types';
1413

1514
// Agent messages
1615
export type StatusResultMessage = {
1716
pid: number;
1817
} & NodeIdMessage &
1918
PublicKeyMessage & {
20-
clientHost: Host;
21-
clientPort: Port;
22-
agentHost: Host;
23-
agentPort: Port;
19+
clientHost: string;
20+
clientPort: number;
21+
agentHost: string;
22+
agentPort: number;
2423
certChainPEM: CertificatePEMChain;
2524
};
2625

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ const config = {
9191
},
9292
networkConfig: {
9393
// Config for the QUICSocket
94-
agentHost: '127.0.0.1' as Host,
95-
agentPort: 0 as Port,
94+
agentHost: '127.0.0.1',
95+
agentPort: 0,
9696
ipv6Only: false,
9797
// Config for the websocket server
98-
clientHost: '127.0.0.1' as Host,
99-
clientPort: 0 as Port,
98+
clientHost: '127.0.0.1',
99+
clientPort: 0,
100100
// Websocket server config
101101
maxReadableStreamBytes: 1_000_000_000, // About 1 GB
102102
connectionIdleTimeoutTime: 120, // 2 minutes

src/nodes/NodeConnection.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import type { NodeId, QUICClientConfig } from './types';
44
import type { Host, Hostname, Port } from '../network/types';
55
import type { CertificatePEM } from '../keys/types';
66
import type { ClientManifest } from '../rpc/types';
7-
import type {
8-
Host as QUICHost,
9-
Port as QUICPort,
10-
QUICSocket,
11-
ClientCrypto,
12-
} from '@matrixai/quic';
7+
import type { QUICSocket, ClientCrypto } from '@matrixai/quic';
138
import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
149
import type { X509Certificate } from '@peculiar/x509';
1510
import Logger from '@matrixai/logger';
@@ -115,8 +110,8 @@ class NodeConnection<M extends ClientManifest> extends EventTarget {
115110
let validatedNodeId: NodeId | undefined;
116111
const quicClient = await QUICClient.createQUICClient(
117112
{
118-
host: targetHost as unknown as QUICHost,
119-
port: targetPort as unknown as QUICPort,
113+
host: targetHost,
114+
port: targetPort,
120115
socket: quicSocket,
121116
config: {
122117
verifyPeer: true,
@@ -161,8 +156,8 @@ class NodeConnection<M extends ClientManifest> extends EventTarget {
161156
nodeId,
162157
host: targetHost,
163158
port: targetPort,
164-
localHost: connection.localHost as unknown as Host,
165-
localPort: connection.localPort as unknown as Port,
159+
localHost: connection.localHost as Host,
160+
localPort: connection.localPort as Port,
166161
certChain,
167162
hostname: targetHostname,
168163
quicClient,

src/nodes/NodeConnectionManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ class NodeConnectionManager {
678678
const connectionMap = this.quicSocket.connectionMap;
679679
// Checking existing connections
680680
for (const [, connection] of connectionMap.serverConnections) {
681-
const connectionHost = connection.remoteHost as unknown as Host;
682-
const connectionPort = connection.remotePort as unknown as Port;
681+
const connectionHost = connection.remoteHost;
682+
const connectionPort = connection.remotePort;
683683
if (host === connectionHost && port === connectionPort) {
684684
// Connection exists, return early
685685
return;

src/status/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ type StatusLive = {
1414
data: {
1515
pid: number;
1616
nodeId: NodeId;
17-
clientHost: Host;
18-
clientPort: Port;
19-
agentHost: Host;
20-
agentPort: Port;
17+
clientHost: string;
18+
clientPort: number;
19+
agentHost: string;
20+
agentPort: number;
2121
[key: string]: any;
2222
};
2323
};

0 commit comments

Comments
 (0)