Skip to content

Commit 1096f1c

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
fix: reverted some event bus removal changes
[ci skip]
1 parent 1a27f0e commit 1096f1c

File tree

5 files changed

+7
-75
lines changed

5 files changed

+7
-75
lines changed

src/PolykeyAgent.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ class PolykeyAgent {
322322
(await Sigchain.createSigchain({
323323
db,
324324
keyRing,
325-
certManager,
326325
logger: logger.getChild(Sigchain.name),
327326
fresh,
328327
}));
@@ -370,7 +369,6 @@ class PolykeyAgent {
370369
new NodeConnectionManager({
371370
keyRing,
372371
nodeGraph,
373-
certManager,
374372
tlsConfig,
375373
seedNodes: optionsDefaulted.seedNodes,
376374
connectionFindConcurrencyLimit:
@@ -397,7 +395,6 @@ class PolykeyAgent {
397395
nodeConnectionManager,
398396
taskManager,
399397
gestaltGraph,
400-
certManager,
401398
logger: logger.getChild(NodeManager.name),
402399
});
403400
await nodeManager.start();
@@ -621,11 +618,15 @@ class PolykeyAgent {
621618
await this.status.updateStatusLive({
622619
nodeId: data.nodeId,
623620
});
621+
await this.nodeManager.resetBuckets();
622+
// Update the sigchain
623+
await this.sigchain.onKeyRingChange();
624624
const tlsConfig: TLSConfig = {
625625
keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey),
626626
certChainPem: await this.certManager.getCertPEMsChainPEM(),
627627
};
628628
this.webSocketServerClient.setTlsConfig(tlsConfig);
629+
this.nodeConnectionManager.updateTlsConfig(tlsConfig);
629630
this.logger.info(`${KeyRing.name} change propagated`);
630631
};
631632

src/bootstrap/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ async function bootstrapState({
161161
const sigchain = await Sigchain.createSigchain({
162162
db,
163163
keyRing,
164-
certManager,
165164
logger: logger.getChild(Sigchain.name),
166165
fresh,
167166
});

src/nodes/NodeConnectionManager.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
SeedNodes,
1313
} from './types';
1414
import type KeyRing from '../keys/KeyRing';
15-
import type CertManager from '../keys/CertManager';
1615
import type { Key, CertificatePEM } from '../keys/types';
1716
import type { ConnectionData, Host, Hostname, Port } from '../network/types';
1817
import type { TLSConfig } from '../network/types';
@@ -37,7 +36,6 @@ import * as networkUtils from '../network/utils';
3736
import { clientManifest as agentClientManifest } from '../agent/handlers/clientManifest';
3837
import * as utils from '../utils';
3938
import config from '../config';
40-
import * as keysEvents from '../keys/events';
4139

4240
type AgentClientManifest = typeof agentClientManifest;
4341

@@ -125,7 +123,6 @@ class NodeConnectionManager {
125123
protected logger: Logger;
126124
protected keyRing: KeyRing;
127125
protected nodeGraph: NodeGraph;
128-
protected certManager?: CertManager;
129126
protected tlsConfig: TLSConfig;
130127
protected seedNodes: SeedNodes;
131128

@@ -177,21 +174,9 @@ class NodeConnectionManager {
177174
this.dispatchEvent(event.clone());
178175
};
179176

180-
protected handleEventsCertManagerCertChange = async (
181-
evt: keysEvents.EventsCertManagerCertChange,
182-
) => {
183-
const data = evt.detail;
184-
const tlsConfig: TLSConfig = {
185-
keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey),
186-
certChainPem: await this.certManager!.getCertPEMsChainPEM(),
187-
};
188-
this.updateTlsConfig(tlsConfig);
189-
};
190-
191177
public constructor({
192178
keyRing,
193179
nodeGraph,
194-
certManager,
195180
tlsConfig,
196181
seedNodes = {},
197182
connectionFindConcurrencyLimit = config.defaultsSystem
@@ -210,7 +195,6 @@ class NodeConnectionManager {
210195
}: {
211196
keyRing: KeyRing;
212197
nodeGraph: NodeGraph;
213-
certManager?: CertManager;
214198
tlsConfig: TLSConfig;
215199
seedNodes?: SeedNodes;
216200
connectionFindConcurrencyLimit?: number;
@@ -224,7 +208,6 @@ class NodeConnectionManager {
224208
this.logger = logger ?? new Logger(this.constructor.name);
225209
this.keyRing = keyRing;
226210
this.nodeGraph = nodeGraph;
227-
this.certManager = certManager;
228211
this.tlsConfig = tlsConfig;
229212
// Filter out own node ID
230213
const nodeIdEncodedOwn = nodesUtils.encodeNodeId(keyRing.getNodeId());
@@ -356,21 +339,13 @@ class NodeConnectionManager {
356339
EventDefault.name,
357340
this.handleQUICServerEvents,
358341
);
359-
this.certManager?.addEventListener(
360-
keysEvents.EventsCertManagerCertChange.name,
361-
this.handleEventsCertManagerCertChange,
362-
);
363342

364343
this.logger.info(`Started ${this.constructor.name}`);
365344
}
366345

367346
public async stop() {
368347
this.logger.info(`Stop ${this.constructor.name}`);
369348

370-
this.certManager?.removeEventListener(
371-
keysEvents.EventsCertManagerCertChange.name,
372-
this.handleEventsCertManagerCertChange,
373-
);
374349
this.quicServer.removeEventListener(
375350
EventDefault.name,
376351
this.handleQUICServerEvents,

src/nodes/NodeManager.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { DB, DBTransaction } from '@matrixai/db';
22
import type NodeConnectionManager from './NodeConnectionManager';
33
import type NodeGraph from './NodeGraph';
44
import type KeyRing from '../keys/KeyRing';
5-
import type CertManager from '../keys/CertManager';
65
import type Sigchain from '../sigchain/Sigchain';
76
import type {
87
NodeId,
@@ -22,7 +21,6 @@ import type GestaltGraph from '../gestalts/GestaltGraph';
2221
import type { TaskHandler, TaskHandlerId, Task } from '../tasks/types';
2322
import type { ContextTimed } from '@matrixai/contexts';
2423
import type { PromiseCancellable } from '@matrixai/async-cancellable';
25-
import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
2624
import type { Host, Port } from '../network/types';
2725
import type { SignedTokenEncoded } from '../tokens/types';
2826
import type { ClaimLinkNode } from '../claims/payloads/index';
@@ -31,6 +29,7 @@ import type {
3129
AgentRPCRequestParams,
3230
AgentRPCResponseResult,
3331
} from '../agent/types';
32+
import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
3433
import Logger from '@matrixai/logger';
3534
import { StartStop, ready } from '@matrixai/async-init/dist/StartStop';
3635
import { Semaphore, Lock } from '@matrixai/async-locks';
@@ -43,7 +42,6 @@ import * as claimsUtils from '../claims/utils';
4342
import * as tasksErrors from '../tasks/errors';
4443
import * as claimsErrors from '../claims/errors';
4544
import * as keysUtils from '../keys/utils';
46-
import * as keysEvents from '../keys/events';
4745
import { never, promise } from '../utils/utils';
4846
import {
4947
decodeClaimId,
@@ -62,7 +60,6 @@ class NodeManager {
6260
protected logger: Logger;
6361
protected sigchain: Sigchain;
6462
protected keyRing: KeyRing;
65-
protected certManager?: CertManager;
6663
protected nodeConnectionManager: NodeConnectionManager;
6764
protected nodeGraph: NodeGraph;
6865
protected taskManager: TaskManager;
@@ -213,10 +210,6 @@ class NodeManager {
213210
);
214211
};
215212

216-
protected handleEventsCertManagerCertChange = async () => {
217-
await this.resetBuckets();
218-
};
219-
220213
constructor({
221214
db,
222215
keyRing,
@@ -225,7 +218,6 @@ class NodeManager {
225218
nodeGraph,
226219
taskManager,
227220
gestaltGraph,
228-
certManager,
229221
refreshBucketDelay = 3600000, // 1 hour in milliseconds
230222
refreshBucketDelayJitter = 0.5, // Multiple of refreshBucketDelay to jitter by
231223
retrySeedConnectionsDelay = 120000, // 2 minuets
@@ -238,7 +230,6 @@ class NodeManager {
238230
nodeGraph: NodeGraph;
239231
taskManager: TaskManager;
240232
gestaltGraph: GestaltGraph;
241-
certManager?: CertManager;
242233
refreshBucketDelay?: number;
243234
refreshBucketDelayJitter?: number;
244235
retrySeedConnectionsDelay?: number;
@@ -253,7 +244,6 @@ class NodeManager {
253244
this.nodeGraph = nodeGraph;
254245
this.taskManager = taskManager;
255246
this.gestaltGraph = gestaltGraph;
256-
this.certManager = certManager;
257247
this.refreshBucketDelay = refreshBucketDelay;
258248
// Clamped from 0 to 1 inclusive
259249
this.refreshBucketDelayJitter = Math.max(
@@ -294,20 +284,12 @@ class NodeManager {
294284
nodesEvents.EventNodeConnectionManagerConnection.name,
295285
this.handleNodeConnectionEvent,
296286
);
297-
this.certManager?.addEventListener(
298-
keysEvents.EventsCertManagerCertChange.name,
299-
this.handleEventsCertManagerCertChange,
300-
);
301287
this.logger.info(`Started ${this.constructor.name}`);
302288
}
303289

304290
public async stop() {
305291
this.logger.info(`Stopping ${this.constructor.name}`);
306292
// Remove handling for connections
307-
this.certManager?.removeEventListener(
308-
keysEvents.EventsCertManagerCertChange.name,
309-
this.handleEventsCertManagerCertChange,
310-
);
311293
this.nodeConnectionManager.removeEventListener(
312294
nodesEvents.EventNodeConnectionManagerConnection.name,
313295
this.handleNodeConnectionEvent,

src/sigchain/Sigchain.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { DB, DBTransaction, LevelPath, KeyPath } from '@matrixai/db';
22
import type { ClaimInput } from './types';
33
import type KeyRing from '../keys/KeyRing';
4-
import type CertManager from '../keys/CertManager';
54
import type { TokenSignature, TokenHeaderSignatureJSON } from '../tokens/types';
65
import type {
76
ClaimId,
@@ -19,7 +18,6 @@ import * as sigchainErrors from './errors';
1918
import Token from '../tokens/Token';
2019
import * as claimsUtils from '../claims/utils';
2120
import * as utils from '../utils';
22-
import * as keysEvents from '../keys/events';
2321

2422
interface Sigchain extends CreateDestroyStartStop {}
2523
@CreateDestroyStartStop(
@@ -30,23 +28,16 @@ class Sigchain {
3028
public static async createSigchain({
3129
db,
3230
keyRing,
33-
certManager,
3431
logger = new Logger(this.name),
3532
fresh = false,
3633
}: {
3734
db: DB;
3835
keyRing: KeyRing;
39-
certManager: CertManager;
4036
logger?: Logger;
4137
fresh?: boolean;
4238
}): Promise<Sigchain> {
4339
logger.info(`Creating ${this.name}`);
44-
const sigchain = new this({
45-
db,
46-
keyRing,
47-
certManager,
48-
logger,
49-
});
40+
const sigchain = new this({ db, keyRing, logger });
5041
await sigchain.start({ fresh });
5142
logger.info(`Created ${this.name}`);
5243
return sigchain;
@@ -55,7 +46,6 @@ class Sigchain {
5546
protected logger: Logger;
5647
protected keyRing: KeyRing;
5748
protected db: DB;
58-
protected certManager?: CertManager;
5949
protected generateClaimId: () => ClaimId;
6050
protected generateSequenceNumber: () => number;
6151
protected dbPath: LevelPath = [this.constructor.name];
@@ -84,25 +74,18 @@ class Sigchain {
8474
'lastSequenceNumber',
8575
];
8676

87-
protected handleEventsCertManagerCertChange = async () => {
88-
await this.onKeyRingChange();
89-
};
90-
9177
constructor({
9278
db,
9379
keyRing,
94-
certManager,
9580
logger,
9681
}: {
9782
db: DB;
9883
keyRing: KeyRing;
99-
certManager?: CertManager;
10084
logger: Logger;
10185
}) {
86+
this.logger = logger;
10287
this.db = db;
10388
this.keyRing = keyRing;
104-
this.certManager = certManager;
105-
this.logger = logger;
10689
}
10790

10891
public async start({
@@ -124,19 +107,11 @@ class Sigchain {
124107
lastSequenceNumber += 1;
125108
return lastSequenceNumber;
126109
};
127-
this.certManager?.addEventListener(
128-
keysEvents.EventsCertManagerCertChange.name,
129-
this.handleEventsCertManagerCertChange,
130-
);
131110
this.logger.info(`Started ${this.constructor.name}`);
132111
}
133112

134113
public async stop() {
135114
this.logger.info(`Stopping ${this.constructor.name}`);
136-
this.certManager?.removeEventListener(
137-
keysEvents.EventsCertManagerCertChange.name,
138-
this.handleEventsCertManagerCertChange,
139-
);
140115
this.logger.info(`Stopped ${this.constructor.name}`);
141116
}
142117

0 commit comments

Comments
 (0)