Skip to content

Commit

Permalink
fix: reverted some event bus removal changes
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed Oct 4, 2023
1 parent d5d2993 commit fed1d49
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 75 deletions.
7 changes: 4 additions & 3 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ class PolykeyAgent {
(await Sigchain.createSigchain({
db,
keyRing,
certManager,
logger: logger.getChild(Sigchain.name),
fresh,
}));
Expand Down Expand Up @@ -370,7 +369,6 @@ class PolykeyAgent {
new NodeConnectionManager({
keyRing,
nodeGraph,
certManager,
tlsConfig,
seedNodes: optionsDefaulted.seedNodes,
connectionFindConcurrencyLimit:
Expand All @@ -397,7 +395,6 @@ class PolykeyAgent {
nodeConnectionManager,
taskManager,
gestaltGraph,
certManager,
logger: logger.getChild(NodeManager.name),
});
await nodeManager.start();
Expand Down Expand Up @@ -621,11 +618,15 @@ class PolykeyAgent {
await this.status.updateStatusLive({
nodeId: data.nodeId,
});
await this.nodeManager.resetBuckets();
// Update the sigchain
await this.sigchain.onKeyRingChange();
const tlsConfig: TLSConfig = {
keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey),
certChainPem: await this.certManager.getCertPEMsChainPEM(),
};
this.webSocketServerClient.setTlsConfig(tlsConfig);
this.nodeConnectionManager.updateTlsConfig(tlsConfig);
this.logger.info(`${KeyRing.name} change propagated`);
};

Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ async function bootstrapState({
const sigchain = await Sigchain.createSigchain({
db,
keyRing,
certManager,
logger: logger.getChild(Sigchain.name),
fresh,
});
Expand Down
25 changes: 0 additions & 25 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {
SeedNodes,
} from './types';
import type KeyRing from '../keys/KeyRing';
import type CertManager from '../keys/CertManager';
import type { Key, CertificatePEM } from '../keys/types';
import type { ConnectionData, Host, Hostname, Port } from '../network/types';
import type { TLSConfig } from '../network/types';
Expand All @@ -37,7 +36,6 @@ import * as networkUtils from '../network/utils';
import { clientManifest as agentClientManifest } from '../agent/handlers/clientManifest';
import * as utils from '../utils';
import config from '../config';
import * as keysEvents from '../keys/events';

type AgentClientManifest = typeof agentClientManifest;

Expand Down Expand Up @@ -125,7 +123,6 @@ class NodeConnectionManager {
protected logger: Logger;
protected keyRing: KeyRing;
protected nodeGraph: NodeGraph;
protected certManager?: CertManager;
protected tlsConfig: TLSConfig;
protected seedNodes: SeedNodes;

Expand Down Expand Up @@ -177,21 +174,9 @@ class NodeConnectionManager {
this.dispatchEvent(event.clone());
};

protected handleEventsCertManagerCertChange = async (
evt: keysEvents.EventsCertManagerCertChange,
) => {
const data = evt.detail;
const tlsConfig: TLSConfig = {
keyPrivatePem: keysUtils.privateKeyToPEM(data.keyPair.privateKey),
certChainPem: await this.certManager!.getCertPEMsChainPEM(),
};
this.updateTlsConfig(tlsConfig);
};

public constructor({
keyRing,
nodeGraph,
certManager,
tlsConfig,
seedNodes = {},
connectionFindConcurrencyLimit = config.defaultsSystem
Expand All @@ -210,7 +195,6 @@ class NodeConnectionManager {
}: {
keyRing: KeyRing;
nodeGraph: NodeGraph;
certManager?: CertManager;
tlsConfig: TLSConfig;
seedNodes?: SeedNodes;
connectionFindConcurrencyLimit?: number;
Expand All @@ -224,7 +208,6 @@ class NodeConnectionManager {
this.logger = logger ?? new Logger(this.constructor.name);
this.keyRing = keyRing;
this.nodeGraph = nodeGraph;
this.certManager = certManager;
this.tlsConfig = tlsConfig;
// Filter out own node ID
const nodeIdEncodedOwn = nodesUtils.encodeNodeId(keyRing.getNodeId());
Expand Down Expand Up @@ -356,21 +339,13 @@ class NodeConnectionManager {
EventDefault.name,
this.handleQUICServerEvents,
);
this.certManager?.addEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);

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

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

this.certManager?.removeEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);
this.quicServer.removeEventListener(
EventDefault.name,
this.handleQUICServerEvents,
Expand Down
20 changes: 1 addition & 19 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { DB, DBTransaction } from '@matrixai/db';
import type NodeConnectionManager from './NodeConnectionManager';
import type NodeGraph from './NodeGraph';
import type KeyRing from '../keys/KeyRing';
import type CertManager from '../keys/CertManager';
import type Sigchain from '../sigchain/Sigchain';
import type {
NodeId,
Expand All @@ -22,7 +21,6 @@ import type GestaltGraph from '../gestalts/GestaltGraph';
import type { TaskHandler, TaskHandlerId, Task } from '../tasks/types';
import type { ContextTimed } from '@matrixai/contexts';
import type { PromiseCancellable } from '@matrixai/async-cancellable';
import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
import type { Host, Port } from '../network/types';
import type { SignedTokenEncoded } from '../tokens/types';
import type { ClaimLinkNode } from '../claims/payloads/index';
Expand All @@ -31,6 +29,7 @@ import type {
AgentRPCRequestParams,
AgentRPCResponseResult,
} from '../agent/types';
import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
import Logger from '@matrixai/logger';
import { StartStop, ready } from '@matrixai/async-init/dist/StartStop';
import { Semaphore, Lock } from '@matrixai/async-locks';
Expand All @@ -43,7 +42,6 @@ import * as claimsUtils from '../claims/utils';
import * as tasksErrors from '../tasks/errors';
import * as claimsErrors from '../claims/errors';
import * as keysUtils from '../keys/utils';
import * as keysEvents from '../keys/events';
import { never, promise } from '../utils/utils';
import {
decodeClaimId,
Expand All @@ -62,7 +60,6 @@ class NodeManager {
protected logger: Logger;
protected sigchain: Sigchain;
protected keyRing: KeyRing;
protected certManager?: CertManager;
protected nodeConnectionManager: NodeConnectionManager;
protected nodeGraph: NodeGraph;
protected taskManager: TaskManager;
Expand Down Expand Up @@ -213,10 +210,6 @@ class NodeManager {
);
};

protected handleEventsCertManagerCertChange = async () => {
await this.resetBuckets();
};

constructor({
db,
keyRing,
Expand All @@ -225,7 +218,6 @@ class NodeManager {
nodeGraph,
taskManager,
gestaltGraph,
certManager,
refreshBucketDelay = 3600000, // 1 hour in milliseconds
refreshBucketDelayJitter = 0.5, // Multiple of refreshBucketDelay to jitter by
retrySeedConnectionsDelay = 120000, // 2 minuets
Expand All @@ -238,7 +230,6 @@ class NodeManager {
nodeGraph: NodeGraph;
taskManager: TaskManager;
gestaltGraph: GestaltGraph;
certManager?: CertManager;
refreshBucketDelay?: number;
refreshBucketDelayJitter?: number;
retrySeedConnectionsDelay?: number;
Expand All @@ -253,7 +244,6 @@ class NodeManager {
this.nodeGraph = nodeGraph;
this.taskManager = taskManager;
this.gestaltGraph = gestaltGraph;
this.certManager = certManager;
this.refreshBucketDelay = refreshBucketDelay;
// Clamped from 0 to 1 inclusive
this.refreshBucketDelayJitter = Math.max(
Expand Down Expand Up @@ -294,20 +284,12 @@ class NodeManager {
nodesEvents.EventNodeConnectionManagerConnection.name,
this.handleNodeConnectionEvent,
);
this.certManager?.addEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);
this.logger.info(`Started ${this.constructor.name}`);
}

public async stop() {
this.logger.info(`Stopping ${this.constructor.name}`);
// Remove handling for connections
this.certManager?.removeEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);
this.nodeConnectionManager.removeEventListener(
nodesEvents.EventNodeConnectionManagerConnection.name,
this.handleNodeConnectionEvent,
Expand Down
29 changes: 2 additions & 27 deletions src/sigchain/Sigchain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { DB, DBTransaction, LevelPath, KeyPath } from '@matrixai/db';
import type { ClaimInput } from './types';
import type KeyRing from '../keys/KeyRing';
import type CertManager from '../keys/CertManager';
import type { TokenSignature, TokenHeaderSignatureJSON } from '../tokens/types';
import type {
ClaimId,
Expand All @@ -19,7 +18,6 @@ import * as sigchainErrors from './errors';
import Token from '../tokens/Token';
import * as claimsUtils from '../claims/utils';
import * as utils from '../utils';
import * as keysEvents from '../keys/events';

interface Sigchain extends CreateDestroyStartStop {}
@CreateDestroyStartStop(
Expand All @@ -30,23 +28,16 @@ class Sigchain {
public static async createSigchain({
db,
keyRing,
certManager,
logger = new Logger(this.name),
fresh = false,
}: {
db: DB;
keyRing: KeyRing;
certManager: CertManager;
logger?: Logger;
fresh?: boolean;
}): Promise<Sigchain> {
logger.info(`Creating ${this.name}`);
const sigchain = new this({
db,
keyRing,
certManager,
logger,
});
const sigchain = new this({ db, keyRing, logger });
await sigchain.start({ fresh });
logger.info(`Created ${this.name}`);
return sigchain;
Expand All @@ -55,7 +46,6 @@ class Sigchain {
protected logger: Logger;
protected keyRing: KeyRing;
protected db: DB;
protected certManager?: CertManager;
protected generateClaimId: () => ClaimId;
protected generateSequenceNumber: () => number;
protected dbPath: LevelPath = [this.constructor.name];
Expand Down Expand Up @@ -84,25 +74,18 @@ class Sigchain {
'lastSequenceNumber',
];

protected handleEventsCertManagerCertChange = async () => {
await this.onKeyRingChange();
};

constructor({
db,
keyRing,
certManager,
logger,
}: {
db: DB;
keyRing: KeyRing;
certManager?: CertManager;
logger: Logger;
}) {
this.logger = logger;
this.db = db;
this.keyRing = keyRing;
this.certManager = certManager;
this.logger = logger;
}

public async start({
Expand All @@ -124,19 +107,11 @@ class Sigchain {
lastSequenceNumber += 1;
return lastSequenceNumber;
};
this.certManager?.addEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);
this.logger.info(`Started ${this.constructor.name}`);
}

public async stop() {
this.logger.info(`Stopping ${this.constructor.name}`);
this.certManager?.removeEventListener(
keysEvents.EventsCertManagerCertChange.name,
this.handleEventsCertManagerCertChange,
);
this.logger.info(`Stopped ${this.constructor.name}`);
}

Expand Down

0 comments on commit fed1d49

Please sign in to comment.