Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Oct 26, 2021
1 parent ee44d06 commit f74ed59
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FileSystem, PolykeyWorkerManagerInterface } from './types';
import type { FileSystem } from './types';
import type { PolykeyWorkerManagerInterface } from './workers/types';
import type { Host, Port } from './network/types';

import path from 'path';
Expand Down
3 changes: 2 additions & 1 deletion src/keys/KeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type {
CertificatePem,
CertificatePemChain,
} from './types';
import type { FileSystem, PolykeyWorkerManagerInterface } from '../types';
import type { FileSystem } from '../types';
import type { NodeId } from '../nodes/types';
import type { PolykeyWorkerManagerInterface } from '../workers/types';

import path from 'path';
import Logger from '@matrixai/logger';
Expand Down
2 changes: 0 additions & 2 deletions src/notifications/NotificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { DB, DBLevel } from '@matrixai/db';
import type { KeyManager } from '../keys';
import type { NodeManager } from '../nodes';
import type { NodeId } from '../nodes/types';
import type { PolykeyWorkerManagerInterface } from '../types';

import Logger from '@matrixai/logger';
import { Mutex } from 'async-mutex';
Expand All @@ -34,7 +33,6 @@ class NotificationsManager {
protected db: DB;
protected keyManager: KeyManager;
protected nodeManager: NodeManager;
protected workerManager?: PolykeyWorkerManagerInterface;

protected messageCap: number;

Expand Down
7 changes: 0 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type fs from 'fs';
import type { WorkerManagerInterface } from '@matrixai/workers';
import type { PolykeyWorkerModule } from './workers';

/**
* Plain data dictionary
Expand Down Expand Up @@ -76,9 +74,6 @@ type LockConfig = {
clientPort?: number | undefined;
} & POJO;

type PolykeyWorkerManagerInterface =
WorkerManagerInterface<PolykeyWorkerModule>;

export {
POJO,
Opaque,
Expand All @@ -90,6 +85,4 @@ export {
Timer,
FileSystem,
LockConfig,
PolykeyWorkerManagerInterface,
PolykeyWorkerModule,
};
3 changes: 2 additions & 1 deletion src/vaults/VaultManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import type {
VaultList,
Vault,
} from './types';
import type { FileSystem, PolykeyWorkerManagerInterface } from '../types';
import type { FileSystem } from '../types';
import type { NodeId } from '../nodes/types';
import type { PolykeyWorkerManagerInterface } from '../workers/types';

import path from 'path';
import Logger from '@matrixai/logger';
Expand Down
4 changes: 3 additions & 1 deletion src/workers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as polykeyWorker } from './polykeyWorkerModule';
export type { PolykeyWorkerModule } from './polykeyWorkerModule';
export * as utils from './utils';

export type { PolykeyWorkerModule } from './polykeyWorkerModule';
export type { PolykeyWorkerManagerInterface } from './types';
7 changes: 7 additions & 0 deletions src/workers/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { WorkerManagerInterface } from '@matrixai/workers';
import type { PolykeyWorkerModule } from './polykeyWorkerModule';

type PolykeyWorkerManagerInterface =
WorkerManagerInterface<PolykeyWorkerModule>;

export type { PolykeyWorkerManagerInterface };
14 changes: 8 additions & 6 deletions src/workers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import type { PolykeyWorkerModule } from './polykeyWorkerModule';
import type { PolykeyWorkerManagerInterface } from './types';

import { WorkerManager } from '@matrixai/workers';
import { PolykeyWorkerModule } from './polykeyWorkerModule';
import { spawn, Worker } from 'threads';
import Logger from '@matrixai/logger';
import { spawn, Worker } from 'threads';

function createWorkerManager({
async function createWorkerManager({
cores,
logger,
}: {
cores?: number;
logger?: Logger;
}) {
return WorkerManager.createWorkerManager<PolykeyWorkerModule>({
workerFactory: () => spawn(new Worker('../../src/workers/polykeyWorker')),
}): Promise<PolykeyWorkerManagerInterface> {
return await WorkerManager.createWorkerManager<PolykeyWorkerModule>({
workerFactory: () => spawn(new Worker('./polykeyWorker')),
cores,
logger,
});
Expand Down
4 changes: 1 addition & 3 deletions tests/workers/polykeyWorker.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PolykeyWorkerManagerInterface } from '@/types';
import type { PolykeyWorkerManagerInterface } from '@/workers/types';

import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { createWorkerManager } from '@/workers/utils';
Expand All @@ -8,7 +8,6 @@ describe('Polykey worker', () => {
new StreamHandler(),
]);
let workerManager: PolykeyWorkerManagerInterface;

beforeAll(async () => {
workerManager = await createWorkerManager({
cores: 1,
Expand All @@ -18,7 +17,6 @@ describe('Polykey worker', () => {
afterAll(async () => {
await workerManager.destroy();
});

test('generateKeyPairAsn1', async () => {
await workerManager.call(async (w) => {
await w.generateKeyPairAsn1(4096);
Expand Down

0 comments on commit f74ed59

Please sign in to comment.