Skip to content

Commit dbc0643

Browse files
committed
wip: making the agent client manifest generic
1 parent dc0cc62 commit dbc0643

22 files changed

+135
-63
lines changed

src/audit/Audit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { AuditEventId } from '../ids/types.js';
1212
import type NodeConnectionManager from '../nodes/NodeConnectionManager.js';
1313
import type Discovery from '../discovery/Discovery.js';
1414
import type { AbstractEvent } from '@matrixai/events';
15+
import type { AgentClientManifest } from '../nodes/agent/callers/index.js';
1516
import Logger from '@matrixai/logger';
1617
import { IdInternal } from '@matrixai/id';
1718
import { createDestroyStartStop } from '@matrixai/async-init';
@@ -45,7 +46,7 @@ class Audit {
4546
fresh = false,
4647
}: {
4748
db: DB;
48-
nodeConnectionManager: NodeConnectionManager;
49+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
4950
discovery: Discovery;
5051
logger?: Logger;
5152
fresh?: boolean;
@@ -59,7 +60,7 @@ class Audit {
5960

6061
protected logger: Logger;
6162
protected db: DB;
62-
protected nodeConnectionManager: NodeConnectionManager;
63+
protected nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
6364
protected discovery: Discovery;
6465

6566
protected eventHandlerMap: Map<
@@ -86,7 +87,7 @@ class Audit {
8687
logger,
8788
}: {
8889
db: DB;
89-
nodeConnectionManager: NodeConnectionManager;
90+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
9091
discovery: Discovery;
9192
logger: Logger;
9293
}) {

src/client/handlers/NodesListConnections.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import type {
66
import type NodeConnectionManager from '../../nodes/NodeConnectionManager.js';
77
import type { ContextTimed } from '@matrixai/contexts';
88
import type { JSONValue } from '@matrixai/rpc';
9+
import type { AgentClientManifest } from '../../nodes/agent/callers/index.js';
910
import { ServerHandler } from '@matrixai/rpc';
1011
import * as nodesUtils from '../../nodes/utils.js';
1112

1213
class NodesListConnections extends ServerHandler<
1314
{
14-
nodeConnectionManager: NodeConnectionManager;
15+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
1516
},
1617
ClientRPCRequestParams,
1718
ClientRPCResponseResult<NodeConnectionMessage>
@@ -25,7 +26,7 @@ class NodesListConnections extends ServerHandler<
2526
const {
2627
nodeConnectionManager,
2728
}: {
28-
nodeConnectionManager: NodeConnectionManager;
29+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
2930
} = this.container;
3031
const connections = nodeConnectionManager.listConnections();
3132
for (const connection of connections) {

src/client/handlers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type NodeGraph from '../../nodes/NodeGraph.js';
1515
import type VaultManager from '../../vaults/VaultManager.js';
1616
import type PolykeyAgent from '../../PolykeyAgent.js';
1717
import type { FileSystem } from '../../types.js';
18+
import type { AgentClientManifest } from '../../nodes/agent/callers/index.js';
1819
import AgentLockAll from './AgentLockAll.js';
1920
import AgentStatus from './AgentStatus.js';
2021
import AgentStop from './AgentStop.js';
@@ -108,7 +109,7 @@ const serverManifest = (container: {
108109
audit: Audit;
109110
notificationsManager: NotificationsManager;
110111
nodeManager: NodeManager;
111-
nodeConnectionManager: NodeConnectionManager;
112+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
112113
nodeGraph: NodeGraph;
113114
vaultManager: VaultManager;
114115
fs: FileSystem;

src/nodes/NodeConnectionManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const rpcMethodsWhitelist = ['nodesAuthenticateConnection'];
125125
* The NodeConnectionManager encapsulates `QUICServer`.
126126
* While the NodeConnection encapsulates `QUICClient`.
127127
*/
128+
// eslinti
128129
interface NodeConnectionManager<Manifest extends AgentClientManifestCore>
129130
extends startStop.StartStop {}
130131
@startStop.StartStop({

src/nodes/NodeManager.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
import type NodeConnectionManager from './NodeConnectionManager.js';
3434
import type NodeGraph from './NodeGraph.js';
3535
import type { ServicePOJO } from '@matrixai/mdns';
36+
import type { AgentClientManifest } from './agent/callers/index.js';
3637
import { withF } from '@matrixai/resources';
3738
import { events as mdnsEvents, MDNS, utils as mdnsUtils } from '@matrixai/mdns';
3839
import Logger from '@matrixai/logger';
@@ -100,7 +101,7 @@ class NodeManager {
100101
protected gestaltGraph: GestaltGraph;
101102
protected taskManager: TaskManager;
102103
protected nodeGraph: NodeGraph;
103-
protected nodeConnectionManager: NodeConnectionManager;
104+
protected nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
104105
protected mdnsOptions:
105106
| {
106107
groups: Array<Host>;
@@ -243,7 +244,7 @@ class NodeManager {
243244
);
244245
const successfulConnections = connectionResults.filter(
245246
(r) => r.status === 'fulfilled',
246-
) as Array<PromiseFulfilledResult<NodeConnection>>;
247+
) as Array<PromiseFulfilledResult<NodeConnection<AgentClientManifest>>>;
247248
if (successfulConnections.length === 0) {
248249
const failedConnectionErrors = connectionResults
249250
.filter((r) => r.status === 'rejected')
@@ -343,7 +344,7 @@ class NodeManager {
343344
groups: Array<Host>;
344345
port: Port;
345346
};
346-
nodeConnectionManager: NodeConnectionManager;
347+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
347348
connectionConnectTimeoutTime?: number;
348349
refreshBucketDelayTime?: number;
349350
refreshBucketDelayJitter?: number;
@@ -459,7 +460,7 @@ class NodeManager {
459460
public acquireConnection(
460461
nodeId: NodeId,
461462
ctx: ContextTimed,
462-
): ResourceAcquire<NodeConnection> {
463+
): ResourceAcquire<NodeConnection<AgentClientManifest>> {
463464
if (this.keyRing.getNodeId().equals(nodeId)) {
464465
throw new nodesErrors.ErrorNodeManagerNodeIdOwn();
465466
}
@@ -497,13 +498,13 @@ class NodeManager {
497498
public async withConnF<T>(
498499
nodeId: NodeId,
499500
ctx: Partial<ContextTimedInput> | undefined,
500-
f: (conn: NodeConnection) => Promise<T>,
501+
f: (conn: NodeConnection<AgentClientManifest>) => Promise<T>,
501502
): Promise<T>;
502503
@startStop.ready(new nodesErrors.ErrorNodeManagerNotRunning())
503504
public async withConnF<T>(
504505
nodeId: NodeId,
505506
@decorators.context ctx: ContextTimed,
506-
f: (conn: NodeConnection) => Promise<T>,
507+
f: (conn: NodeConnection<AgentClientManifest>) => Promise<T>,
507508
): Promise<T> {
508509
return await withF(
509510
[this.acquireConnection(nodeId, ctx)],
@@ -525,14 +526,18 @@ class NodeManager {
525526
public withConnG<T, TReturn, TNext>(
526527
nodeId: NodeId,
527528
ctx: Partial<ContextTimedInput> | undefined,
528-
g: (conn: NodeConnection) => AsyncGenerator<T, TReturn, TNext>,
529+
g: (
530+
conn: NodeConnection<AgentClientManifest>,
531+
) => AsyncGenerator<T, TReturn, TNext>,
529532
): AsyncGenerator<T, TReturn, TNext>;
530533
@startStop.ready(new nodesErrors.ErrorNodeManagerNotRunning())
531534
@decorators.timed()
532535
public async *withConnG<T, TReturn, TNext>(
533536
nodeId: NodeId,
534537
@decorators.context ctx: ContextTimed,
535-
g: (conn: NodeConnection) => AsyncGenerator<T, TReturn, TNext>,
538+
g: (
539+
conn: NodeConnection<AgentClientManifest>,
540+
) => AsyncGenerator<T, TReturn, TNext>,
536541
): AsyncGenerator<T, TReturn, TNext> {
537542
const acquire = this.acquireConnection(nodeId, ctx);
538543
const [release, conn] = await acquire();
@@ -707,7 +712,7 @@ class NodeManager {
707712
ctx.signal.throwIfAborted();
708713
const isDone = await nodeConnectionsQueue.withNodeSignal(
709714
async (nodeIdTarget, nodeIdSignaller) => {
710-
let nodeConnection: NodeConnection | undefined;
715+
let nodeConnection: NodeConnection<AgentClientManifest> | undefined;
711716
if (
712717
!this.nodeConnectionManager.hasConnection(nodeIdTarget) &&
713718
nodeIdSignaller != null
@@ -1162,7 +1167,7 @@ class NodeManager {
11621167
@startStop.ready(new nodesErrors.ErrorNodeConnectionManagerNotRunning())
11631168
@decorators.timedCancellable(
11641169
true,
1165-
(nodeConnectionManager: NodeConnectionManager) =>
1170+
(nodeConnectionManager: NodeConnectionManager<AgentClientManifest>) =>
11661171
nodeConnectionManager.connectionConnectTimeoutTime,
11671172
)
11681173
public async pingNode(
@@ -1194,7 +1199,7 @@ class NodeManager {
11941199
@startStop.ready(new nodesErrors.ErrorNodeConnectionManagerNotRunning())
11951200
@decorators.timedCancellable(
11961201
true,
1197-
(nodeConnectionManager: NodeConnectionManager) =>
1202+
(nodeConnectionManager: NodeConnectionManager<AgentClientManifest>) =>
11981203
nodeConnectionManager.connectionConnectTimeoutTime,
11991204
)
12001205
public async pingNodeAddress(

src/nodes/agent/handlers/NodesAuthenticateConnection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import type {
77
} from '../types.js';
88
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager.js';
99
import type { JSONValue } from '../../../types.js';
10+
import type { AgentClientManifest } from '../callers/index.js';
1011
import { DuplexHandler } from '@matrixai/rpc';
1112
import * as agentUtils from '../utils.js';
1213
import * as nodesErrors from '../../errors.js';
1314

1415
class NodesAuthenticateConnection extends DuplexHandler<
1516
{
16-
nodeConnectionManager: NodeConnectionManager;
17+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
1718
},
1819
AgentRPCRequestParams<SuccessMessage | NodesAuthenticateConnectionMessage>,
1920
AgentRPCResponseResult<SuccessMessage | NodesAuthenticateConnectionMessage>
@@ -33,7 +34,7 @@ class NodesAuthenticateConnection extends DuplexHandler<
3334
const {
3435
nodeConnectionManager,
3536
}: {
36-
nodeConnectionManager: NodeConnectionManager;
37+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
3738
} = this.container;
3839

3940
// Connections should always be validated

src/nodes/agent/handlers/NodesClosestActiveConnectionsGet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import type NodeConnectionManager from '../../NodeConnectionManager.js';
99
import type { NodeId } from '../../../ids/index.js';
1010
import type { ActiveConnectionDataMessage } from '../types.js';
11+
import type { AgentClientManifest } from '../callers/index.js';
1112
import { ServerHandler } from '@matrixai/rpc';
1213
import * as utils from '../../../utils/index.js';
1314
import * as ids from '../../../ids/index.js';
@@ -19,7 +20,7 @@ import * as nodesUtils from '../../utils.js';
1920
*/
2021
class NodesClosestActiveConnectionsGet extends ServerHandler<
2122
{
22-
nodeConnectionManager: NodeConnectionManager;
23+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
2324
},
2425
AgentRPCRequestParams<NodeIdMessage>,
2526
AgentRPCResponseResult<ActiveConnectionDataMessage>
@@ -33,7 +34,7 @@ class NodesClosestActiveConnectionsGet extends ServerHandler<
3334
const {
3435
nodeConnectionManager,
3536
}: {
36-
nodeConnectionManager: NodeConnectionManager;
37+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
3738
} = this.container;
3839

3940
const {

src/nodes/agent/handlers/NodesConnectionSignalFinal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import type { NodeId } from '../../../ids/index.js';
99
import type NodeConnectionManager from '../../NodeConnectionManager.js';
1010
import type { Host, Port } from '../../../network/types.js';
11+
import type { AgentClientManifest } from '../callers/index.js';
1112
import { UnaryHandler } from '@matrixai/rpc';
1213
import { validateSync } from '../../../validation/index.js';
1314
import { matchSync } from '../../../utils/index.js';
@@ -18,7 +19,7 @@ import * as nodesErrors from '../../errors.js';
1819

1920
class NodesConnectionSignalFinal extends UnaryHandler<
2021
{
21-
nodeConnectionManager: NodeConnectionManager;
22+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
2223
logger: Logger;
2324
},
2425
AgentRPCRequestParams<HolePunchRequestMessage>,
@@ -33,7 +34,7 @@ class NodesConnectionSignalFinal extends UnaryHandler<
3334
nodeConnectionManager,
3435
logger,
3536
}: {
36-
nodeConnectionManager: NodeConnectionManager;
37+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
3738
logger: Logger;
3839
} = this.container;
3940
// Connections should always be validated

src/nodes/agent/handlers/NodesConnectionSignalInitial.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { NodeId } from '../../../ids/index.js';
88
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager.js';
99
import type { Host, Port } from '../../../network/types.js';
1010
import type { JSONValue } from '../../../types.js';
11+
import type { AgentClientManifest } from '../callers/index.js';
1112
import { UnaryHandler } from '@matrixai/rpc';
1213
import { validateSync } from '../../../validation/index.js';
1314
import { matchSync } from '../../../utils/index.js';
@@ -19,7 +20,7 @@ import * as ids from '../../../ids/index.js';
1920

2021
class NodesConnectionSignalInitial extends UnaryHandler<
2122
{
22-
nodeConnectionManager: NodeConnectionManager;
23+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
2324
},
2425
AgentRPCRequestParams<HolePunchSignalMessage>,
2526
AgentRPCResponseResult<AddressMessage>
@@ -32,7 +33,7 @@ class NodesConnectionSignalInitial extends UnaryHandler<
3233
const {
3334
nodeConnectionManager,
3435
}: {
35-
nodeConnectionManager: NodeConnectionManager;
36+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
3637
} = this.container;
3738
// Connections should always be validated
3839
const requestingNodeId = agentUtils.nodeIdFromMeta(meta);

src/nodes/agent/handlers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type NodeManager from '../../../nodes/NodeManager.js';
99
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager.js';
1010
import type NotificationsManager from '../../../notifications/NotificationsManager.js';
1111
import type VaultManager from '../../../vaults/VaultManager.js';
12+
import type { AgentClientManifest } from '../callers/index.js';
1213
import NodesAuthenticateConnection from './NodesAuthenticateConnection.js';
1314
import NodesAuditEventsGet from './NodesAuditEventsGet.js';
1415
import NodesClaimsGet from './NodesClaimsGet.js';
@@ -33,7 +34,7 @@ const manifestServer = (container: {
3334
nodeGraph: NodeGraph;
3435
acl: ACL;
3536
nodeManager: NodeManager;
36-
nodeConnectionManager: NodeConnectionManager;
37+
nodeConnectionManager: NodeConnectionManager<AgentClientManifest>;
3738
keyRing: KeyRing;
3839
logger: Logger;
3940
notificationsManager: NotificationsManager;

0 commit comments

Comments
 (0)