Skip to content

Commit

Permalink
linting: fixed linting problems
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed Oct 4, 2023
1 parent 44609b9 commit abc177a
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 252 deletions.
8 changes: 3 additions & 5 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class PolykeyAgent {
logger: logger.getChild(NodeManager.name),
});
await nodeManager.start();
// add seed nodes to the nodeGraph
// Add seed nodes to the nodeGraph
const setNodeProms = new Array<Promise<void>>();
for (const nodeIdEncoded in optionsDefaulted.seedNodes) {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
Expand Down Expand Up @@ -424,7 +424,7 @@ class PolykeyAgent {
});
} catch (e) {
logger.warn(`Failed Creating ${this.name}`);
await rpcServerAgent?.destroy({ force: true });
await rpcServerAgent?.destroy({ force: true });
await rpcServerClient?.destroy();
await webSocketServerClient?.stop(true);
await sessionManager?.stop();
Expand Down Expand Up @@ -848,6 +848,4 @@ class PolykeyAgent {

export default PolykeyAgent;

export type {
PolykeyAgentOptions,
};
export type { PolykeyAgentOptions };
2 changes: 1 addition & 1 deletion src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RecoveryCode, Key, KeysOptions } from '../keys/types';
import path from 'path';
import Logger from '@matrixai/logger';
import { DB } from '@matrixai/db';
import * as bootstrapErrors from './errors';
import TaskManager from '../tasks/TaskManager';
import IdentitiesManager from '../identities/IdentitiesManager';
import SessionManager from '../sessions/SessionManager';
Expand All @@ -21,7 +22,6 @@ import NotificationsManager from '../notifications/NotificationsManager';
import config from '../config';
import * as utils from '../utils';
import * as errors from '../errors';
import * as bootstrapErrors from './errors';

type BootstrapOptions = {
nodePath: string;
Expand Down
4 changes: 2 additions & 2 deletions src/keys/KeyRing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class KeyRing {
}: {
keysPath: string;
password: string;
options: Partial<KeyRingOptions>
options: Partial<KeyRingOptions>;
workerManager?: PolykeyWorkerManagerInterface;
fs?: FileSystem;
logger?: Logger;
Expand All @@ -73,7 +73,7 @@ class KeyRing {
fs,
logger,
});
await keyRing.start({password, fresh});
await keyRing.start({ password, fresh });
logger.info(`Created ${this.name}`);
return keyRing;
}
Expand Down
22 changes: 13 additions & 9 deletions src/keys/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { X509Certificate } from '@peculiar/x509';
import type { NodeId } from '../ids/types';
import type { Opaque, InverseRecord } from '../types';
import type { Opaque, InverseRecord, ObjectEmpty } from '../types';

/**
* Locked buffer wrapper type for sensitive in-memory data.
Expand Down Expand Up @@ -265,7 +265,7 @@ type CertManagerChangeData = {
/**
* Used by the PolykeyAgent for it's top level options
*/
type KeysOptions = KeyRingOptions & CertManagerOptions
type KeysOptions = KeyRingOptions & CertManagerOptions;

/**
* Options for the KeyRing
Expand All @@ -275,13 +275,17 @@ type KeyRingOptions = {
passwordMemLimit?: PasswordMemLimit;
strictMemoryLock: boolean;
} & (
{} | {
recoveryCode: RecoveryCode;
} | {
privateKey: PrivateKey;
} | {
privateKeyPath: string;
});
| ObjectEmpty
| {
recoveryCode: RecoveryCode;
}
| {
privateKey: PrivateKey;
}
| {
privateKeyPath: string;
}
);

/**
* Options for the CertManager
Expand Down
2 changes: 1 addition & 1 deletion src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import dns from 'dns';
import { IPv4, IPv6, Validator } from 'ip-num';
import { timedCancellable } from '@matrixai/contexts/dist/functions';
import { CryptoError } from '@matrixai/quic/dist/native';
import { utils as quicUtils } from '@matrixai/quic';
import * as networkErrors from './errors';
import * as keysUtils from '../keys/utils';
import { utils as quicUtils } from '@matrixai/quic'

/**
* Validates that a provided host address is a valid IPv4 or IPv6 address.
Expand Down
83 changes: 45 additions & 38 deletions src/nodes/NodeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type { ContextTimedInput } from '@matrixai/contexts/dist/types';
import type { X509Certificate } from '@peculiar/x509';
import Logger from '@matrixai/logger';
import { CreateDestroy } from '@matrixai/async-init/dist/CreateDestroy';
import { status } from "@matrixai/async-init";
import { status } from '@matrixai/async-init';
import { timedCancellable, context } from '@matrixai/contexts/dist/decorators';
import { AbstractEvent, EventAll } from "@matrixai/events";
import { AbstractEvent, EventAll } from '@matrixai/events';
import { QUICClient, events as quicEvents } from '@matrixai/quic';
import * as nodesErrors from './errors';
import * as nodesEvents from './events';
Expand Down Expand Up @@ -65,70 +65,81 @@ class NodeConnection<M extends ClientManifest> {
* error event. Will trigger destruction of the `NodeConnection` via the
* `EventNodeConnectionError` -> `EventNodeConnectionClose` event path.
*/
protected handleEventNodeConnectionError = (evt: nodesEvents.EventNodeConnectionError): void => {
protected handleEventNodeConnectionError = (
evt: nodesEvents.EventNodeConnectionError,
): void => {
this.logger.warn(`NodeConnection error caused by ${evt.detail.message}`);
this.dispatchEvent(new nodesEvents.EventNodeConnectionClose())
}
this.dispatchEvent(new nodesEvents.EventNodeConnectionClose());
};

/**
* Triggers the destruction of the `NodeConnection`. Since this is only in
* response to an underlying problem or close it will force destroy.
* Dispatched by the `EventNodeConnectionError` event as the
* `EventNodeConnectionError` -> `EventNodeConnectionClose` event path.
*/
protected handleEventNodeConnectionClose = async (_evt: nodesEvents.EventNodeConnectionClose): Promise<void> => {
this.logger.warn(`close event triggering NodeConnection.destroy`)
protected handleEventNodeConnectionClose = async (
_evt: nodesEvents.EventNodeConnectionClose,
): Promise<void> => {
this.logger.warn(`close event triggering NodeConnection.destroy`);
// This will trigger the destruction of this NodeConnection.
if (this[status] !== 'destroying') {
await this.destroy({force: true});
await this.destroy({ force: true });
}
}
};

/**
* redispatches a `QUICStream` from a `EventQUICConnectionStream` event with
* Redispatches a `QUICStream` from a `EventQUICConnectionStream` event with
* a `EventNodeConnectionStream` event. Should bubble upwards through the
* `NodeConnectionManager`.
*/
protected handleEventQUICConnectionStream = (evt: quicEvents.EventQUICConnectionStream): void => {
// re-dispatches the stream under a `EventNodeConnectionStream` event
protected handleEventQUICConnectionStream = (
evt: quicEvents.EventQUICConnectionStream,
): void => {
// Re-dispatches the stream under a `EventNodeConnectionStream` event
const quicStream = evt.detail;
this.dispatchEvent(
new nodesEvents.EventNodeConnectionStream({ detail: quicStream }),
);
}
};

/**
* redispatches `QUICConnection` or `QUICClient` error events as `NodeConnection` error events.
* Redispatches `QUICConnection` or `QUICClient` error events as `NodeConnection` error events.
* This should trigger the destruction of the `NodeConnection` through the
* `EventNodeConnectionError` -> `EventNodeConnectionClose` event path.
*/
protected handleEventQUICError = (evt: quicEvents.EventQUICConnectionError): void => {
const err = new nodesErrors.ErrorNodeConnectionInternalError(
undefined,
{ cause: evt.detail },
);
protected handleEventQUICError = (
evt: quicEvents.EventQUICConnectionError,
): void => {
const err = new nodesErrors.ErrorNodeConnectionInternalError(undefined, {
cause: evt.detail,
});
this.dispatchEvent(
new nodesEvents.EventNodeConnectionError({ detail: err }),
);
}
};

protected handleEventQUICClientDestroyed = (_evt: quicEvents.EventQUICClientDestroyed) => {
protected handleEventQUICClientDestroyed = (
_evt: quicEvents.EventQUICClientDestroyed,
) => {
const err = new nodesErrors.ErrorNodeConnectionInternalError(
'QUICClient destroyed unexpectedly',
);
this.dispatchEvent(
new nodesEvents.EventNodeConnectionError({ detail: err }),
);
}
};

protected handleEventQUICConnectionStopped = (_evt: quicEvents.EventQUICConnectionStopped) => {
protected handleEventQUICConnectionStopped = (
_evt: quicEvents.EventQUICConnectionStopped,
) => {
const err = new nodesErrors.ErrorNodeConnectionInternalError(
'QUICClient stopped unexpectedly',
);
this.dispatchEvent(
new nodesEvents.EventNodeConnectionError({ detail: err }),
);
}
};

/**
* Propagates all events from the `QUICClient` or `QUICConnection` upwards.
Expand All @@ -138,12 +149,12 @@ class NodeConnection<M extends ClientManifest> {
*/
protected handleEventAll = (evt: EventAll): void => {
// This just propagates events upwards
const event = evt.detail
const event = evt.detail;
if (event instanceof AbstractEvent) {
// clone and dispatch upwards
// Clone and dispatch upwards
this.dispatchEvent(event.clone());
}
}
};

static createNodeConnection<M extends ClientManifest>(
{
Expand Down Expand Up @@ -268,7 +279,9 @@ class NodeConnection<M extends ClientManifest> {
// This may de different from the NodeId we validated it as if it renewed at some point.
const connection = quicClient.connection;
// Remote certificate information should always be available here due to custom verification
const { nodeId, certChain } = nodesUtils.parseRemoteCertsChain(connection.getRemoteCertsChain());
const { nodeId, certChain } = nodesUtils.parseRemoteCertsChain(
connection.getRemoteCertsChain(),
);

const newLogger = logger.getParent() ?? new Logger(this.name);
const nodeConnection = new this<M>({
Expand Down Expand Up @@ -300,7 +313,7 @@ class NodeConnection<M extends ClientManifest> {
nodeConnection.addEventListener(
nodesEvents.EventNodeConnectionError.name,
nodeConnection.handleEventNodeConnectionError,
);
);
nodeConnection.addEventListener(
nodesEvents.EventNodeConnectionClose.name,
nodeConnection.handleEventNodeConnectionClose,
Expand All @@ -317,10 +330,7 @@ class NodeConnection<M extends ClientManifest> {
quicEvents.EventQUICClientDestroyed.name,
nodeConnection.handleEventQUICClientDestroyed,
);
quicClient.addEventListener(
EventAll.name,
nodeConnection.handleEventAll,
);
quicClient.addEventListener(EventAll.name, nodeConnection.handleEventAll);
logger.info(`Created ${this.name}`);
return nodeConnection;
}
Expand Down Expand Up @@ -455,7 +465,7 @@ class NodeConnection<M extends ClientManifest> {
);
await this.rpcClient.destroy();
this.logger.debug(`${this.constructor.name} triggered destroyed event`);
// removing all event listeners
// Removing all event listeners
this.addEventListener(
nodesEvents.EventNodeConnectionError.name,
this.handleEventNodeConnectionError,
Expand Down Expand Up @@ -487,10 +497,7 @@ class NodeConnection<M extends ClientManifest> {
quicEvents.EventQUICClientError.name,
this.handleEventQUICError,
);
quicClientOrConnection.addEventListener(
EventAll.name,
this.handleEventAll,
);
quicClientOrConnection.addEventListener(EventAll.name, this.handleEventAll);
this.dispatchEvent(new nodesEvents.EventNodeConnectionDestroy());
this.logger.info(`Destroyed ${this.constructor.name}`);
}
Expand Down
Loading

0 comments on commit abc177a

Please sign in to comment.