Skip to content

Commit

Permalink
tests: all tests passing
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed Dec 4, 2023
1 parent b0772be commit 6eb23ac
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 437 deletions.
72 changes: 24 additions & 48 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import path from 'path';
import process from 'process';
import Logger from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { MDNS } from '@matrixai/mdns';
import {
CreateDestroyStartStop,
ready,
Expand Down Expand Up @@ -216,7 +215,6 @@ class PolykeyAgent {
let gestaltGraph: GestaltGraph | undefined;
let identitiesManager: IdentitiesManager | undefined;
let nodeGraph: NodeGraph | undefined;
let mdns: MDNS | undefined;
let nodeConnectionManager: NodeConnectionManager | undefined;
let nodeManager: NodeManager | undefined;
let discovery: Discovery | undefined;
Expand Down Expand Up @@ -359,15 +357,6 @@ class PolykeyAgent {
rpcCallTimeoutTime: optionsDefaulted.nodes.rpcCallTimeoutTime,
logger: logger.getChild(NodeConnectionManager.name),
});
mdns = new MDNS({
logger: logger.getChild(MDNS.name),
});
await mdns.start({
id: keyRing.getNodeId().toBuffer().readUint16BE(),
hostname: nodesUtils.encodeNodeId(keyRing.getNodeId()),
groups: optionsDefaulted.mdns.groups,
port: optionsDefaulted.mdns.port,
});
nodeManager = new NodeManager({
db,
sigchain,
Expand All @@ -376,28 +365,12 @@ class PolykeyAgent {
nodeConnectionManager,
taskManager,
gestaltGraph,
mdns,
mdnsOptions: {
groups: optionsDefaulted.mdns.groups,
port: optionsDefaulted.mdns.port,
},
logger: logger.getChild(NodeManager.name),
});
await nodeManager.start();
// Add seed nodes to the nodeGraph
const setNodeProms = new Array<Promise<void>>();
for (const nodeIdEncoded in optionsDefaulted.seedNodes) {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
if (nodeId == null) utils.never();
const setNodeProm = nodeManager.setNode(
nodeId,
optionsDefaulted.seedNodes[nodeIdEncoded],
{
mode: 'direct',
connectedTime: 0,
scopes: ['global'],
},
true,
);
setNodeProms.push(setNodeProm);
}
await Promise.all(setNodeProms);
discovery = await Discovery.createDiscovery({
db,
keyRing,
Expand All @@ -411,7 +384,6 @@ class PolykeyAgent {
await NotificationsManager.createNotificationsManager({
acl,
db,
nodeConnectionManager,
nodeManager,
keyRing,
logger: logger.getChild(NotificationsManager.name),
Expand All @@ -420,7 +392,7 @@ class PolykeyAgent {
vaultManager = await VaultManager.createVaultManager({
vaultsPath,
keyRing,
nodeConnectionManager,
nodeManager,
notificationsManager,
gestaltGraph,
acl,
Expand Down Expand Up @@ -466,7 +438,6 @@ class PolykeyAgent {
await discovery?.stop();
await identitiesManager?.stop();
await gestaltGraph?.stop();
await mdns?.stop();
await acl?.stop();
await sigchain?.stop();
await certManager?.stop();
Expand All @@ -491,7 +462,6 @@ class PolykeyAgent {
acl,
gestaltGraph,
nodeGraph,
mdns,
taskManager,
nodeConnectionManager,
nodeManager,
Expand Down Expand Up @@ -532,7 +502,6 @@ class PolykeyAgent {
public readonly acl: ACL;
public readonly gestaltGraph: GestaltGraph;
public readonly nodeGraph: NodeGraph;
public readonly mdns: MDNS;
public readonly taskManager: TaskManager;
public readonly nodeConnectionManager: NodeConnectionManager;
public readonly nodeManager: NodeManager;
Expand Down Expand Up @@ -579,7 +548,6 @@ class PolykeyAgent {
acl,
gestaltGraph,
nodeGraph,
mdns,
taskManager,
nodeConnectionManager,
nodeManager,
Expand All @@ -603,7 +571,6 @@ class PolykeyAgent {
acl: ACL;
gestaltGraph: GestaltGraph;
nodeGraph: NodeGraph;
mdns: MDNS;
taskManager: TaskManager;
nodeConnectionManager: NodeConnectionManager;
nodeManager: NodeManager;
Expand All @@ -629,7 +596,6 @@ class PolykeyAgent {
this.gestaltGraph = gestaltGraph;
this.discovery = discovery;
this.nodeGraph = nodeGraph;
this.mdns = mdns;
this.taskManager = taskManager;
this.nodeConnectionManager = nodeConnectionManager;
this.nodeManager = nodeManager;
Expand Down Expand Up @@ -779,13 +745,6 @@ class PolykeyAgent {
host: optionsDefaulted.clientServiceHost,
port: optionsDefaulted.clientServicePort,
});
await this.mdns.start({
id: this.keyRing.getNodeId().toBuffer().readUint16BE(),
hostname: nodesUtils.encodeNodeId(this.keyRing.getNodeId()),
groups: optionsDefaulted.mdns.groups,
port: optionsDefaulted.mdns.port,
});
await this.nodeManager.start();
await this.nodeConnectionManager.start({
host: optionsDefaulted.agentServiceHost,
port: optionsDefaulted.agentServicePort,
Expand All @@ -803,6 +762,25 @@ class PolykeyAgent {
vaultManager: this.vaultManager,
}),
});
await this.nodeManager.start();
// Add seed nodes to the nodeGraph
const setNodeProms = new Array<Promise<void>>();
for (const nodeIdEncoded in optionsDefaulted.seedNodes) {
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded);
if (nodeId == null) utils.never();
const setNodeProm = this.nodeManager.setNode(
nodeId,
optionsDefaulted.seedNodes[nodeIdEncoded],
{
mode: 'direct',
connectedTime: 0,
scopes: ['global'],
},
true,
);
setNodeProms.push(setNodeProm);
}
await Promise.all(setNodeProms);
await this.nodeGraph.start({ fresh });
const seedNodeEntries = Object.entries(
optionsDefaulted.seedNodes as SeedNodes,
Expand Down Expand Up @@ -861,7 +839,6 @@ class PolykeyAgent {
await this.vaultManager?.stop();
await this.discovery?.stop();
await this.nodeGraph?.stop();
await this.mdns?.stop();
await this.nodeConnectionManager?.stop();
await this.nodeManager?.stop();
await this.clientService.stop({ force: true });
Expand Down Expand Up @@ -905,7 +882,6 @@ class PolykeyAgent {
await this.clientService.stop({ force: true });
await this.identitiesManager.stop();
await this.gestaltGraph.stop();
await this.mdns.stop();
await this.acl.stop();
await this.sigchain.stop();
await this.certManager.stop();
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ async function bootstrapState({
await NotificationsManager.createNotificationsManager({
acl,
db,
nodeConnectionManager: {} as any, // No connections are attempted
nodeManager,
keyRing,
logger: logger.getChild(NotificationsManager.name),
Expand All @@ -206,7 +205,7 @@ async function bootstrapState({
db,
gestaltGraph,
keyRing,
nodeConnectionManager: {} as any, // No connections are attempted
nodeManager: {} as any, // No connections are attempted
vaultsPath,
notificationsManager,
logger: logger.getChild(VaultManager.name),
Expand Down
12 changes: 6 additions & 6 deletions src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ function toCanonicalHost(host: string): Host {
if (scope != null) {
host_ = host_.replace(/%.+/, '');
}
if (isIPv4MappedIPv6(host)) {
host_ = fromIPv4MappedIPv6(host);
} else if (isIPv4(host)) {
host_ = IPv4.fromString(host).toString();
if (isIPv4MappedIPv6(host_)) {
host_ = fromIPv4MappedIPv6(host_);
} else if (isIPv4(host_)) {
host_ = IPv4.fromString(host_).toString();
// Host_ = (new IPv4(host)).toString();
} else if (isIPv6(host)) {
host_ = IPv6.fromString(host).toString();
} else if (isIPv6(host_)) {
host_ = IPv6.fromString(host_).toString();
// Host_ = (new IPv6(host)).toString();
} else {
throw new TypeError('Invalid IP address');
Expand Down
3 changes: 1 addition & 2 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
TLSConfig,
} from '../network/types';
import type { AgentServerManifest } from './agent/handlers';
import type { NodeId, NodeIdString, SeedNodes } from './types';
import type { NodeId, NodeIdString } from './types';
import {
events as quicEvents,
QUICServer,
Expand Down Expand Up @@ -168,7 +168,6 @@ class NodeConnectionManager {
protected logger: Logger;
protected keyRing: KeyRing;
protected tlsConfig: TLSConfig;
protected seedNodes: SeedNodes;

protected quicSocket: QUICSocket;
protected quicServer: QUICServer;
Expand Down
Loading

0 comments on commit 6eb23ac

Please sign in to comment.