From 6eb23ac7a98391c386986df5b159336acadfe6f7 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 4 Dec 2023 15:55:21 +1100 Subject: [PATCH] tests: all tests passing [ci skip] --- src/PolykeyAgent.ts | 72 ++-- src/bootstrap/utils.ts | 3 +- src/network/utils.ts | 12 +- src/nodes/NodeConnectionManager.ts | 3 +- src/nodes/NodeManager.ts | 142 ++++--- src/notifications/NotificationsManager.ts | 10 +- src/vaults/VaultInternal.ts | 18 +- src/vaults/VaultManager.ts | 22 +- tests/client/handlers/gestalts.test.ts | 29 +- tests/client/handlers/keys.test.ts | 8 +- tests/client/handlers/nodes.test.ts | 101 +++-- tests/client/handlers/notifications.test.ts | 27 +- tests/client/handlers/vaults.test.ts | 31 +- tests/discovery/Discovery.test.ts | 17 +- tests/identities/TestProvider.ts | 4 +- tests/nodes/NodeConnectionManager.test.ts | 2 +- tests/nodes/NodeManager.test.ts | 16 +- .../agent/handlers/notificationsSend.test.ts | 1 - .../NotificationsManager.test.ts | 36 +- tests/tasks/utils.test.ts | 1 - tests/vaults/VaultManager.test.ts | 384 ++++++++++-------- 21 files changed, 502 insertions(+), 437 deletions(-) diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index f844be8888..b8df370e04 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -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, @@ -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; @@ -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, @@ -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>(); - 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, @@ -411,7 +384,6 @@ class PolykeyAgent { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger: logger.getChild(NotificationsManager.name), @@ -420,7 +392,7 @@ class PolykeyAgent { vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing, - nodeConnectionManager, + nodeManager, notificationsManager, gestaltGraph, acl, @@ -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(); @@ -491,7 +462,6 @@ class PolykeyAgent { acl, gestaltGraph, nodeGraph, - mdns, taskManager, nodeConnectionManager, nodeManager, @@ -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; @@ -579,7 +548,6 @@ class PolykeyAgent { acl, gestaltGraph, nodeGraph, - mdns, taskManager, nodeConnectionManager, nodeManager, @@ -603,7 +571,6 @@ class PolykeyAgent { acl: ACL; gestaltGraph: GestaltGraph; nodeGraph: NodeGraph; - mdns: MDNS; taskManager: TaskManager; nodeConnectionManager: NodeConnectionManager; nodeManager: NodeManager; @@ -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; @@ -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, @@ -803,6 +762,25 @@ class PolykeyAgent { vaultManager: this.vaultManager, }), }); + await this.nodeManager.start(); + // Add seed nodes to the nodeGraph + const setNodeProms = new Array>(); + 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, @@ -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 }); @@ -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(); diff --git a/src/bootstrap/utils.ts b/src/bootstrap/utils.ts index 23643dcd50..77d96cf992 100644 --- a/src/bootstrap/utils.ts +++ b/src/bootstrap/utils.ts @@ -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), @@ -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), diff --git a/src/network/utils.ts b/src/network/utils.ts index edaa531aba..4fafebf1c9 100644 --- a/src/network/utils.ts +++ b/src/network/utils.ts @@ -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'); diff --git a/src/nodes/NodeConnectionManager.ts b/src/nodes/NodeConnectionManager.ts index 7268d36528..02669e69f4 100644 --- a/src/nodes/NodeConnectionManager.ts +++ b/src/nodes/NodeConnectionManager.ts @@ -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, @@ -168,7 +168,6 @@ class NodeConnectionManager { protected logger: Logger; protected keyRing: KeyRing; protected tlsConfig: TLSConfig; - protected seedNodes: SeedNodes; protected quicSocket: QUICSocket; protected quicServer: QUICServer; diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 255bfb0091..8d22d18c79 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -6,7 +6,12 @@ import type KeyRing from '../keys/KeyRing'; import type Sigchain from '../sigchain/Sigchain'; import type TaskManager from '../tasks/TaskManager'; import type GestaltGraph from '../gestalts/GestaltGraph'; -import type { TaskHandler, TaskHandlerId, Task } from '../tasks/types'; +import type { + TaskHandler, + TaskHandlerId, + Task, + TaskInfo, +} from '../tasks/types'; import type { SignedTokenEncoded } from '../tokens/types'; import type { Host, Port } from '../network/types'; import type { @@ -32,14 +37,14 @@ import type { } from './types'; import type NodeConnectionManager from './NodeConnectionManager'; import type NodeGraph from './NodeGraph'; -import type { MDNS, ServicePOJO } from '@matrixai/mdns'; +import type { ServicePOJO } from '@matrixai/mdns'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; import { Semaphore, Lock } from '@matrixai/async-locks'; import { IdInternal } from '@matrixai/id'; import { timedCancellable, context } from '@matrixai/contexts/dist/decorators'; import { withF } from '@matrixai/resources'; -import { events as mdnsEvents, utils as mdnsUtils } from '@matrixai/mdns'; +import { MDNS, events as mdnsEvents, utils as mdnsUtils } from '@matrixai/mdns'; import * as nodesUtils from './utils'; import * as nodesEvents from './events'; import * as nodesErrors from './errors'; @@ -92,6 +97,12 @@ class NodeManager { protected taskManager: TaskManager; protected nodeGraph: NodeGraph; protected nodeConnectionManager: NodeConnectionManager; + protected mdnsOptions: + | { + groups: Array; + port: Port; + } + | undefined; protected mdns: MDNS | undefined; protected pendingNodes: Map< @@ -197,9 +208,9 @@ class NodeManager { public readonly checkConnectionsHandlerId: TaskHandlerId = `${this.tasksPath}.${this.checkConnectionsHandler.name}` as TaskHandlerId; - protected syncNodeGraphHandler: TaskHandler = async ( + protected syncNodeGraphHandler = async ( ctx: ContextTimed, - taskInfo, + taskInfo: TaskInfo | undefined, initialNodes: Array<[NodeIdEncoded, [Host, Port]]>, pingTimeoutTime: number | undefined, ) => { @@ -276,7 +287,7 @@ class NodeManager { taskManager, nodeGraph, nodeConnectionManager, - mdns, + mdnsOptions, connectionConnectTimeoutTime = config.defaultsSystem .nodesConnectionConnectTimeoutTime, refreshBucketDelayTime = config.defaultsSystem @@ -292,7 +303,10 @@ class NodeManager { gestaltGraph: GestaltGraph; taskManager: TaskManager; nodeGraph: NodeGraph; - mdns?: MDNS; + mdnsOptions?: { + groups: Array; + port: Port; + }; nodeConnectionManager: NodeConnectionManager; connectionConnectTimeoutTime?: number; refreshBucketDelayTime?: number; @@ -308,7 +322,10 @@ class NodeManager { this.nodeGraph = nodeGraph; this.taskManager = taskManager; this.gestaltGraph = gestaltGraph; - this.mdns = mdns; + this.mdnsOptions = mdnsOptions; + if (mdnsOptions != null) { + this.mdns = new MDNS({ logger: this.logger.getChild(MDNS.name) }); + } this.connectionConnectTimeoutTime = connectionConnectTimeoutTime; this.refreshBucketDelayTime = refreshBucketDelayTime; this.refreshBucketDelayJitter = Math.max(0, refreshBucketDelayJitter); @@ -345,6 +362,13 @@ class NodeManager { } // Starting MDNS if (this.mdns != null) { + const nodeId = this.keyRing.getNodeId(); + await this.mdns.start({ + id: nodeId.toBuffer().readUint16BE(), + hostname: nodesUtils.encodeNodeId(nodeId), + groups: this.mdnsOptions!.groups, + port: this.mdnsOptions!.port, + }); this.mdns.registerService({ name: nodesUtils.encodeNodeId(this.keyRing.getNodeId()), port: this.nodeConnectionManager.port, @@ -367,6 +391,7 @@ class NodeManager { nodesEvents.EventNodeConnectionManagerConnectionReverse.name, this.handleEventNodeConnectionManagerConnectionReverse, ); + await this.mdns?.stop(); // Cancels all NodeManager tasks const taskPs: Array> = []; for await (const task of this.taskManager.getTasks(undefined, false, [ @@ -477,15 +502,15 @@ class NodeManager { } /** - * Will do a Kademlia find node proceedure. + * Will attempt to find a node within the network using a hybrid strategy of + * attempting signalled connections, direct connections and checking MDNS. * * Will attempt to fix regardless of existing connection. * @param nodeId - NodeId of target to find. - * @param pingTimeoutTime - * @param concurrencyLimit - Limit the number of concurrent connections - * @param limit + * @param pingTimeoutTime - timeout time for each individual connection. + * @param concurrencyLimit - Limit the number of concurrent connections. + * @param limit - Limit the number of total connections to be made before giving up. * @param ctx - * @returns true if the node was found. */ public findNode( nodeId: NodeId, @@ -554,11 +579,11 @@ class NodeManager { } /** - * Will try to make a connection to the node using active connections only + * Will try to make a connection to the node using hole punched connections only * - * @param nodeId - * @param nodeConnectionsQueue - * @param pingTimeoutTime + * @param nodeId - NodeId of the target to find. + * @param nodeConnectionsQueue - shared nodeConnectionQueue helper class. + * @param pingTimeoutTime - timeout time for each individual connection. * @param ctx */ public findNodeBySignal( @@ -692,6 +717,14 @@ class NodeManager { ] as [[Host, Port], NodeContactAddressData]; } + /** + * Will try to make a connection to the node using direct connections only + * + * @param nodeId - NodeId of the target to find. + * @param nodeConnectionsQueue - shared nodeConnectionQueue helper class. + * @param pingTimeoutTime - timeout time for each individual connection. + * @param ctx + */ public findNodeByDirect( nodeId: NodeId, nodeConnectionsQueue: NodeConnectionQueue, @@ -764,7 +797,7 @@ class NodeManager { await this.nodeConnectionManager.createConnectionMultiple( [nodeIdTarget], addresses, - newCtx, + { timer: pingTimeoutTime, signal: newCtx.signal }, ); } catch (e) { if (e instanceof nodesErrors.ErrorNodeConnectionTimeout) { @@ -917,6 +950,11 @@ class NodeManager { return addresses; } + /** + * Will query MDNS for local nodes and attempt a connection. + * @param nodeId - NodeId of the target to find. + * @param ctx + */ public findNodeByMDNS( nodeId: NodeId, ctx?: Partial, @@ -962,10 +1000,10 @@ class NodeManager { } /** - * Will ask the target node about closest nodes to the `node` + * Will ask the target node about the closest nodes to the `node` * and add them to the `nodeConnectionsQueue`. * - * @param nodeId - node to find closest nodes to + * @param nodeId - node to find the closest nodes to * @param nodeIdTarget - node to make RPC requests to * @param nodeConnectionsQueue * @param ctx @@ -1090,7 +1128,7 @@ class NodeManager { * For node1 -> node2 claims, the verification process also involves connecting * to node2 to verify the claim (to retrieve its signing public key). * @param targetNodeId Id of the node to connect request the chain data of. - * @param claimId If set then we get the claims newer that this claim Id. + * @param claimId If set then we get the claims newer that this claim ID. * @param ctx */ public requestChainData( @@ -1505,7 +1543,7 @@ class NodeManager { * Adds a node to the node graph. This assumes that you have already authenticated the node * Updates the node if the node already exists * This operation is blocking by default - set `block` 2qto false to make it non-blocking - * @param nodeId - Id of the node we wish to add + * @param nodeId - ID of the node we wish to add * @param nodeAddress - Expected address of the node we want to add * @param nodeContactAddressData * @param block - When true it will wait for any garbage collection to finish before returning. @@ -1537,20 +1575,6 @@ class NodeManager { @context ctx: ContextTimed, tran?: DBTransaction, ): Promise { - // Such a complicated function - // To just set a node into our system - // We have to basically say we have already authenticated - // Because we can have a protected version of set Node - // that just sets the node without doing any authentication - // so what exactly is this function for? - // So doing this literally means we have the address - // To do so is to add a node into graph without connecting to it - // I'm not sure if that makes sense - // we can "prefill" some already well known things - // But I think with the SRV style - // I would not expose such a feature - // It seems more like a debug feature - // We don't want to add our own node if (nodeId.equals(this.keyRing.getNodeId())) { this.logger.debug('Is own NodeId, skipping'); @@ -1584,9 +1608,6 @@ class NodeManager { // To avoid conflict we want to lock on the bucket index await this.nodeGraph.lockBucket(bucketIndex, tran); - // WHY - this checks if it already exists - // What if it doesn't exist? - const nodeContact = await this.nodeGraph.getNodeContact(nodeId, tran); // If this is a new entry, check the bucket limit const count = await this.nodeGraph.getBucketMetaProp( @@ -1595,15 +1616,6 @@ class NodeManager { tran, ); - // Because we have to do this one at a time? - // To avoid a bucket limit problem? - // Setting a node and now figuring out what to do with the old nodes - // To GC them somehow - // Problem is, we have to "force" it - // It should default to forcing it - // But you can keep old connections on automatic systems - // But if it is set, it should default to forcing - if (nodeContact != null || count < this.nodeGraph.nodeBucketLimit) { // Either already exists or has room in the bucket // We want to add or update the node @@ -2104,20 +2116,30 @@ class NodeManager { if (initialNodes.length === 0) { throw Error('TMP IMP Must provide at least 1 initial node'); } - // Create task const initialNodesParameter = initialNodes.map(([nodeId, address]) => { - return [nodesUtils.encodeNodeId(nodeId), address]; + return [nodesUtils.encodeNodeId(nodeId), address] as [ + NodeIdEncoded, + [Host, Port], + ]; }); - const task = this.taskManager.scheduleTask({ - delay: 0, - handlerId: this.syncNodeGraphHandlerId, - lazy: true, - parameters: [initialNodesParameter, pingTimeoutTime], - path: [this.tasksPath, this.syncNodeGraphHandlerId], - priority: 0, - }); - // TODO: cancellation - if (blocking) await task; + if (blocking) { + await this.syncNodeGraphHandler( + ctx, + undefined, + initialNodesParameter, + pingTimeoutTime, + ); + } else { + // Create task + await this.taskManager.scheduleTask({ + delay: 0, + handlerId: this.syncNodeGraphHandlerId, + lazy: true, + parameters: [initialNodesParameter, pingTimeoutTime], + path: [this.tasksPath, this.syncNodeGraphHandlerId], + priority: 0, + }); + } } } diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index 92e1da96a3..d9ea85bea2 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -3,7 +3,6 @@ import type { NotificationId, Notification, NotificationData } from './types'; import type ACL from '../acl/ACL'; import type KeyRing from '../keys/KeyRing'; import type NodeManager from '../nodes/NodeManager'; -import type NodeConnectionManager from '../nodes/NodeConnectionManager'; import type { NodeId } from '../ids/types'; import Logger from '@matrixai/logger'; import { IdInternal } from '@matrixai/id'; @@ -40,7 +39,6 @@ class NotificationsManager { static async createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, messageCap = 10000, @@ -49,7 +47,6 @@ class NotificationsManager { }: { acl: ACL; db: DB; - nodeConnectionManager: NodeConnectionManager; nodeManager: NodeManager; keyRing: KeyRing; messageCap?: number; @@ -63,7 +60,6 @@ class NotificationsManager { keyRing, logger, messageCap, - nodeConnectionManager, nodeManager, }); @@ -77,7 +73,6 @@ class NotificationsManager { protected db: DB; protected keyRing: KeyRing; protected nodeManager: NodeManager; - protected nodeConnectionManager: NodeConnectionManager; protected messageCap: number; /** @@ -101,7 +96,6 @@ class NotificationsManager { constructor({ acl, db, - nodeConnectionManager, nodeManager, keyRing, messageCap, @@ -109,7 +103,6 @@ class NotificationsManager { }: { acl: ACL; db: DB; - nodeConnectionManager: NodeConnectionManager; nodeManager: NodeManager; keyRing: KeyRing; messageCap: number; @@ -120,7 +113,6 @@ class NotificationsManager { this.acl = acl; this.db = db; this.keyRing = keyRing; - this.nodeConnectionManager = nodeConnectionManager; this.nodeManager = nodeManager; } @@ -183,7 +175,7 @@ class NotificationsManager { notification, this.keyRing.keyPair, ); - await this.nodeConnectionManager.withConnF(nodeId, async (connection) => { + await this.nodeManager.withConnF(nodeId, async (connection) => { const client = connection.getClient(); await client.methods.notificationsSend({ signedNotificationEncoded: signedNotification, diff --git a/src/vaults/VaultInternal.ts b/src/vaults/VaultInternal.ts index 51d1d3ac25..38c8304933 100644 --- a/src/vaults/VaultInternal.ts +++ b/src/vaults/VaultInternal.ts @@ -14,7 +14,7 @@ import type { } from './types'; import type KeyRing from '../keys/KeyRing'; import type { NodeId, NodeIdEncoded } from '../ids/types'; -import type NodeConnectionManager from '../nodes/NodeConnectionManager'; +import type NodeManager from '../nodes/NodeManager'; import type { RPCClient } from '@matrixai/rpc'; import type agentClientManifest from '../nodes/agent/callers'; import type { POJO } from '../types'; @@ -113,7 +113,7 @@ class VaultInternal { db, vaultsDbPath, keyRing, - nodeConnectionManager, + nodeManager, efs, logger = new Logger(this.name), tran, @@ -125,7 +125,7 @@ class VaultInternal { vaultsDbPath: LevelPath; efs: EncryptedFS; keyRing: KeyRing; - nodeConnectionManager: NodeConnectionManager; + nodeManager: NodeManager; logger?: Logger; tran?: DBTransaction; }): Promise { @@ -138,7 +138,7 @@ class VaultInternal { db, vaultsDbPath, keyRing, - nodeConnectionManager, + nodeManager, efs, logger, tran, @@ -165,7 +165,7 @@ class VaultInternal { let remoteVaultId: VaultId; let remote: RemoteInfo; try { - [vaultName, remoteVaultId] = await nodeConnectionManager.withConnF( + [vaultName, remoteVaultId] = await nodeManager.withConnF( targetNodeId, async (connection) => { const client = connection.getClient(); @@ -539,12 +539,12 @@ class VaultInternal { @ready(new vaultsErrors.ErrorVaultNotRunning()) public async pullVault({ - nodeConnectionManager, + nodeManager, pullNodeId, pullVaultNameOrId, tran, }: { - nodeConnectionManager: NodeConnectionManager; + nodeManager: NodeManager; pullNodeId?: NodeId; pullVaultNameOrId?: VaultId | VaultName; tran?: DBTransaction; @@ -552,7 +552,7 @@ class VaultInternal { if (tran == null) { return this.db.withTransactionF((tran) => this.pullVault({ - nodeConnectionManager, + nodeManager, pullNodeId, pullVaultNameOrId, tran, @@ -594,7 +594,7 @@ class VaultInternal { ); let remoteVaultId: VaultId; try { - remoteVaultId = await nodeConnectionManager.withConnF( + remoteVaultId = await nodeManager.withConnF( pullNodeId!, async (connection) => { const client = connection.getClient(); diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index 5a3771959e..50f9806649 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -11,7 +11,7 @@ import type { FileSystem } from '../types'; import type { PolykeyWorkerManagerInterface } from '../workers/types'; import type { NodeId } from '../ids/types'; import type KeyRing from '../keys/KeyRing'; -import type NodeConnectionManager from '../nodes/NodeConnectionManager'; +import type NodeManager from '../nodes/NodeManager'; import type GestaltGraph from '../gestalts/GestaltGraph'; import type NotificationsManager from '../notifications/NotificationsManager'; import type ACL from '../acl/ACL'; @@ -74,7 +74,7 @@ class VaultManager { db, acl, keyRing, - nodeConnectionManager, + nodeManager, gestaltGraph, notificationsManager, fs = require('fs'), @@ -85,7 +85,7 @@ class VaultManager { db: DB; acl: ACL; keyRing: KeyRing; - nodeConnectionManager: NodeConnectionManager; + nodeManager: NodeManager; gestaltGraph: GestaltGraph; notificationsManager: NotificationsManager; fs?: FileSystem; @@ -99,7 +99,7 @@ class VaultManager { db, acl, keyRing, - nodeConnectionManager, + nodeManager, gestaltGraph, notificationsManager, fs, @@ -118,7 +118,7 @@ class VaultManager { protected db: DB; protected acl: ACL; protected keyRing: KeyRing; - protected nodeConnectionManager: NodeConnectionManager; + protected nodeManager: NodeManager; protected gestaltGraph: GestaltGraph; protected notificationsManager: NotificationsManager; protected vaultsDbPath: LevelPath = [this.constructor.name]; @@ -136,7 +136,7 @@ class VaultManager { db, acl, keyRing, - nodeConnectionManager, + nodeManager, gestaltGraph, notificationsManager, fs, @@ -146,7 +146,7 @@ class VaultManager { db: DB; acl: ACL; keyRing: KeyRing; - nodeConnectionManager: NodeConnectionManager; + nodeManager: NodeManager; gestaltGraph: GestaltGraph; notificationsManager: NotificationsManager; fs: FileSystem; @@ -158,7 +158,7 @@ class VaultManager { this.db = db; this.acl = acl; this.keyRing = keyRing; - this.nodeConnectionManager = nodeConnectionManager; + this.nodeManager = nodeManager; this.gestaltGraph = gestaltGraph; this.notificationsManager = notificationsManager; this.fs = fs; @@ -706,7 +706,7 @@ class VaultManager { targetVaultNameOrId: vaultNameOrId, vaultId, db: this.db, - nodeConnectionManager: this.nodeConnectionManager, + nodeManager: this.nodeManager, vaultsDbPath: this.vaultsDbPath, keyRing: this.keyRing, efs: this.efs, @@ -786,7 +786,7 @@ class VaultManager { await tran.lock([...this.vaultsDbPath, vaultId].join('')); const vault = await this.getVault(vaultId, tran); await vault.pullVault({ - nodeConnectionManager: this.nodeConnectionManager, + nodeManager: this.nodeManager, pullNodeId, pullVaultNameOrId, tran, @@ -899,7 +899,7 @@ class VaultManager { vaultPermissions: VaultAction[]; }> { // Create a connection to another node - return yield* this.nodeConnectionManager.withConnG( + return yield* this.nodeManager.withConnG( targetNodeId, async function* (connection): AsyncGenerator<{ vaultName: VaultName; diff --git a/tests/client/handlers/gestalts.test.ts b/tests/client/handlers/gestalts.test.ts index 62d828b4ba..151dc5f754 100644 --- a/tests/client/handlers/gestalts.test.ts +++ b/tests/client/handlers/gestalts.test.ts @@ -16,6 +16,7 @@ import type { import type { SignedClaim } from '@/claims/types'; import type { Host } from '@/network/types'; import type { ClaimLinkIdentity } from '@/claims/payloads'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import path from 'path'; import os from 'os'; @@ -463,6 +464,7 @@ describe('gestaltsDiscoveryByIdentity', () => { await nodeManager.start(); await nodeConnectionManager.start({ host: localhost as Host, + agentService: {} as AgentServerManifest, }); discovery = await Discovery.createDiscovery({ db, @@ -639,7 +641,10 @@ describe('gestaltsDiscoveryByNode', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); discovery = await Discovery.createDiscovery({ db, gestaltGraph, @@ -1252,7 +1257,10 @@ describe('gestaltsGestaltTrustByIdentity', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); discovery = await Discovery.createDiscovery({ db, gestaltGraph, @@ -1628,12 +1636,19 @@ describe('gestaltsGestaltTrustByNode', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); - await nodeManager.setNode(nodeIdRemote, { - host: node.agentServiceHost, - port: node.agentServicePort, - scopes: ['global'], + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, }); + await nodeManager.setNode( + nodeIdRemote, + [node.agentServiceHost, node.agentServicePort], + { + mode: 'direct', + connectedTime: 0, + scopes: ['global'], + }, + ); discovery = await Discovery.createDiscovery({ db, gestaltGraph, diff --git a/tests/client/handlers/keys.test.ts b/tests/client/handlers/keys.test.ts index 108488b730..eead4030a0 100644 --- a/tests/client/handlers/keys.test.ts +++ b/tests/client/handlers/keys.test.ts @@ -567,7 +567,7 @@ describe('keysKeyPairRenew', () => { expect(mockedRefreshBuckets).toHaveBeenCalledTimes(0); expect(fwdTLSConfig1).toEqual(expectedTLSConfig1); expect(nodeId1.equals(nodeIdStatus1)).toBe(true); - const certChangeEventProm = testsUtils.promFromEvent( + const certChangeEventP = testsUtils.promFromEvent( pkAgent.certManager, keysEvents.EventCertManagerCertChange, ); @@ -576,7 +576,7 @@ describe('keysKeyPairRenew', () => { password: 'somepassphrase', }); // Awaiting change to propagate - await certChangeEventProm.p; + await certChangeEventP; // Wait some time after event for domains to update await utils.sleep(500); const rootKeyPair2 = pkAgent.keyRing.keyPair; @@ -695,7 +695,7 @@ describe('keysKeyPairReset', () => { expect(mockedRefreshBuckets).not.toHaveBeenCalled(); expect(fwdTLSConfig1).toEqual(expectedTLSConfig1); expect(nodeId1.equals(nodeIdStatus1)).toBe(true); - const certChangeEventProm = testsUtils.promFromEvent( + const certChangeEventP = testsUtils.promFromEvent( pkAgent.certManager, keysEvents.EventCertManagerCertChange, ); @@ -704,7 +704,7 @@ describe('keysKeyPairReset', () => { password: 'somepassphrase', }); // Awaiting change to propagate - await certChangeEventProm.p; + await certChangeEventP; // Wait some time after event for domains to update await utils.sleep(500); const rootKeyPair2 = pkAgent.keyRing.keyPair; diff --git a/tests/client/handlers/nodes.test.ts b/tests/client/handlers/nodes.test.ts index 7b2724392a..3f66336ba0 100644 --- a/tests/client/handlers/nodes.test.ts +++ b/tests/client/handlers/nodes.test.ts @@ -2,7 +2,7 @@ import type GestaltGraph from '@/gestalts/GestaltGraph'; import type { NodeIdEncoded } from '@/ids/types'; import type { TLSConfig, Host, Port } from '@/network/types'; import type { Notification } from '@/notifications/types'; -import type { NodeAddress } from '@/nodes/types'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import path from 'path'; import os from 'os'; @@ -100,7 +100,6 @@ describe('nodesAdd', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -119,7 +118,10 @@ describe('nodesAdd', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); clientService = new ClientService({ tlsConfig, @@ -178,17 +180,17 @@ describe('nodesAdd', () => { ping: false, force: false, }); - const result = await nodeGraph.getNode( + const result = await nodeGraph.getNodeContact( nodesUtils.decodeNodeId( 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0', )!, ); expect(result).toBeDefined(); - expect(result!.address).toEqual({ - host: '127.0.0.1', - port: 11111, - scopes: ['global'], - }); + expect( + result![ + nodesUtils.nodeContactAddress(['127.0.0.1' as Host, 11111 as Port]) + ], + ).toBeDefined(); }); test('cannot add invalid node', async () => { // Invalid host @@ -315,7 +317,6 @@ describe('nodesClaim', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -334,13 +335,15 @@ describe('nodesClaim', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); notificationsManager = await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -434,16 +437,21 @@ describe('nodesFind', () => { let nodeGraph: NodeGraph; let taskManager: TaskManager; let nodeConnectionManager: NodeConnectionManager; + let nodeManager: NodeManager; let sigchain: Sigchain; let mockedFindNode: jest.SpyInstance; beforeEach(async () => { mockedFindNode = jest - .spyOn(NodeConnectionManager.prototype, 'findNode') - .mockResolvedValue({ - host: '127.0.0.1' as Host, - port: 11111 as Port, - scopes: ['local'], - }); + .spyOn(NodeManager.prototype, 'findNode') + // [NodeAddress, NodeContactAddressData] + .mockResolvedValue([ + ['127.0.0.1' as Host, 11111 as Port], + { + mode: 'direct', + connectedTime: 0, + scopes: ['local'], + }, + ]); dataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'polykey-test-'), ); @@ -479,7 +487,6 @@ describe('nodesFind', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -487,7 +494,20 @@ describe('nodesFind', () => { connectionIdleTimeoutTimeScale: 0, logger: logger.getChild('NodeConnectionManager'), }); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); + nodeManager = new NodeManager({ + db, + keyRing, + nodeGraph, + nodeConnectionManager, + taskManager, + gestaltGraph: {} as GestaltGraph, + sigchain: {} as Sigchain, + logger: logger.getChild(NodeManager.name), + }); await taskManager.startProcessing(); clientService = new ClientService({ tlsConfig, @@ -496,7 +516,7 @@ describe('nodesFind', () => { await clientService.start({ manifest: { nodesFind: new NodesFind({ - nodeConnectionManager, + nodeManager, }), }, host: localhost, @@ -540,9 +560,9 @@ describe('nodesFind', () => { nodeIdEncoded: 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, }); - const address = response.addresses.at(0); - expect(address?.host).toBe('127.0.0.1'); - expect(address?.port).toBe(11111); + const [host, port] = response.nodeAddress; + expect(host).toBe('127.0.0.1'); + expect(port).toBe(11111); }); test('cannot find an invalid node', async () => { await testsUtils.expectRemoteError( @@ -613,7 +633,6 @@ describe('nodesPing', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -631,7 +650,10 @@ describe('nodesPing', () => { gestaltGraph: {} as GestaltGraph, logger, }); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); clientService = new ClientService({ tlsConfig, @@ -680,7 +702,7 @@ describe('nodesPing', () => { }); }); test('pings a node (offline)', async () => { - mockedPingNode.mockResolvedValue(false); + mockedPingNode.mockResolvedValue(undefined); const response = await rpcClient.methods.nodesPing({ nodeIdEncoded: 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, @@ -688,7 +710,7 @@ describe('nodesPing', () => { expect(response.success).toBeFalsy(); }); test('pings a node (online)', async () => { - mockedPingNode.mockResolvedValue(true); + mockedPingNode.mockResolvedValue([]); const response = await rpcClient.methods.nodesPing({ nodeIdEncoded: 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, @@ -762,7 +784,6 @@ describe('nodesGetAll', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -781,7 +802,10 @@ describe('nodesGetAll', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); clientService = new ClientService({ tlsConfig, @@ -834,10 +858,12 @@ describe('nodesGetAll', () => { parseNodeId( 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0' as NodeIdEncoded, ), + ['127.0.0.1' as Host, 1111 as Port], { - host: networkUtils.parseHostOrHostname('127.0.0.1'), - port: networkUtils.parsePort(1111), - } as NodeAddress, + mode: 'direct', + connectedTime: 0, + scopes: ['local'], + }, ); const values: Array = []; const response = await rpcClient.methods.nodesGetAll({}); @@ -912,7 +938,6 @@ describe('nodesListConnections', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -931,7 +956,10 @@ describe('nodesListConnections', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); clientService = new ClientService({ tlsConfig, @@ -983,6 +1011,8 @@ describe('nodesListConnections', () => { mockedConnection.mockReturnValue([ { nodeId: testsUtils.generateRandomNodeId(), + connectionId: 'someId', + primary: true, address: { host: '127.0.0.1', port: 11111, @@ -992,6 +1022,7 @@ describe('nodesListConnections', () => { timeout: undefined, }, ]); + const values: Array = []; const responses = await rpcClient.methods.nodesListConnections({}); for await (const response of responses) { diff --git a/tests/client/handlers/notifications.test.ts b/tests/client/handlers/notifications.test.ts index 2ea8866e47..32194b465b 100644 --- a/tests/client/handlers/notifications.test.ts +++ b/tests/client/handlers/notifications.test.ts @@ -3,6 +3,7 @@ import type { Host, TLSConfig } from '@/network/types'; import type { General, Notification, VaultShare } from '@/notifications/types'; import type { VaultIdEncoded, NodeIdEncoded } from '@/ids/types'; import type { VaultName } from '@/vaults/types'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import path from 'path'; import os from 'os'; @@ -103,7 +104,6 @@ describe('notificationsClear', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -122,13 +122,15 @@ describe('notificationsClear', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.startProcessing(); notificationsManager = await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -259,7 +261,6 @@ describe('notificationsRead', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, // TLS not needed for this test tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, @@ -278,13 +279,15 @@ describe('notificationsRead', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.start(); notificationsManager = await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -599,10 +602,7 @@ describe('notificationsSend', () => { let sigchain: Sigchain; let mockedSendNotification: jest.SpyInstance; beforeEach(async () => { - mockedSendNotification = jest.spyOn( - NodeConnectionManager.prototype, - 'withConnF', - ); + mockedSendNotification = jest.spyOn(NodeManager.prototype, 'withConnF'); dataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'polykey-test-'), ); @@ -642,7 +642,6 @@ describe('notificationsSend', () => { }); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, tlsConfig: {} as TLSConfig, connectionConnectTimeoutTime: 2000, connectionIdleTimeoutTimeMin: 2000, @@ -660,13 +659,15 @@ describe('notificationsSend', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.start(); notificationsManager = await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index ab2cb15b42..562e50dfe9 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -1,4 +1,3 @@ -import type NodeConnectionManager from '@/nodes/NodeConnectionManager'; import type { TLSConfig } from '@/network/types'; import type { FileSystem } from '@/types'; import type { VaultId } from '@/ids'; @@ -106,7 +105,7 @@ describe('vaultsClone', () => { db, acl: {} as ACL, keyRing: {} as KeyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -170,7 +169,7 @@ describe('vaultsCreate and vaultsDelete and vaultsList', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -305,7 +304,7 @@ describe('vaultsLog', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -468,7 +467,6 @@ describe('vaultsPermissionSet and vaultsPermissionUnset and vaultsPermissionGet' await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager: {} as NodeConnectionManager, nodeManager: {} as NodeManager, keyRing, logger, @@ -479,7 +477,7 @@ describe('vaultsPermissionSet and vaultsPermissionUnset and vaultsPermissionGet' db, acl, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph, notificationsManager, logger, @@ -642,7 +640,6 @@ describe('vaultsPull', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager: {} as NodeConnectionManager, nodeManager: {} as NodeManager, keyRing, logger, @@ -653,7 +650,7 @@ describe('vaultsPull', () => { db, acl, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph, notificationsManager, logger, @@ -718,7 +715,7 @@ describe('vaultsRename', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -813,7 +810,7 @@ describe('vaultsScan', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -875,7 +872,7 @@ describe('vaultsSecretsEdit', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -988,7 +985,7 @@ describe('vaultsSecretsMkdir', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -1096,7 +1093,7 @@ describe('vaultsSecretsNew and vaultsSecretsDelete, vaultsSecretsGet', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -1231,7 +1228,7 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -1359,7 +1356,7 @@ describe('vaultsSecretsRename', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -1473,7 +1470,7 @@ describe('vaultsSecretsStat', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, @@ -1592,7 +1589,7 @@ describe('vaultsVersion', () => { db, acl: {} as ACL, keyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: {} as NodeManager, gestaltGraph: {} as GestaltGraph, notificationsManager: {} as NotificationsManager, logger, diff --git a/tests/discovery/Discovery.test.ts b/tests/discovery/Discovery.test.ts index 751a34eb18..8cda0b4f2c 100644 --- a/tests/discovery/Discovery.test.ts +++ b/tests/discovery/Discovery.test.ts @@ -4,6 +4,7 @@ import type { Key } from '@/keys/types'; import type { SignedClaim } from '../../src/claims/types'; import type { ClaimLinkIdentity } from '@/claims/payloads'; import type { NodeId } from '../../src/ids'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import path from 'path'; import os from 'os'; @@ -154,7 +155,6 @@ describe('Discovery', () => { const tlsConfig = await createTLSConfig(keyRing.keyPair); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, tlsConfig, connectionConnectTimeoutTime: 2000, connectionIdleTimeoutTimeMin: 2000, @@ -174,6 +174,7 @@ describe('Discovery', () => { await nodeManager.start(); await nodeConnectionManager.start({ host: localhost as Host, + agentService: {} as AgentServerManifest, }); // Set up other gestalt nodeA = await PolykeyAgent.createPolykeyAgent({ @@ -207,11 +208,15 @@ describe('Discovery', () => { nodeIdA = nodeA.keyRing.getNodeId(); nodeIdB = nodeB.keyRing.getNodeId(); await testNodesUtils.nodesConnect(nodeA, nodeB); - await nodeGraph.setNode(nodeA.keyRing.getNodeId(), { - host: nodeA.agentServiceHost, - port: nodeA.agentServicePort, - scopes: ['global'], - }); + await nodeGraph.setNodeContactAddressData( + nodeA.keyRing.getNodeId(), + [nodeA.agentServiceHost, nodeA.agentServicePort], + { + mode: 'direct', + connectedTime: 0, + scopes: ['global'], + }, + ); await nodeB.acl.setNodeAction(nodeA.keyRing.getNodeId(), 'claim'); await nodeA.nodeManager.claimNode(nodeB.keyRing.getNodeId()); nodeA.identitiesManager.registerProvider(testProvider); diff --git a/tests/identities/TestProvider.ts b/tests/identities/TestProvider.ts index 02d8e54f02..6d24d0d7b2 100644 --- a/tests/identities/TestProvider.ts +++ b/tests/identities/TestProvider.ts @@ -89,7 +89,7 @@ class TestProvider extends Provider { `${authIdentityId} has not been authenticated`, ); } - providerToken = await this.checkToken(providerToken, authIdentityId); + await this.checkToken(providerToken, authIdentityId); const user = this.users[identityId]; if (!user) { return; @@ -113,7 +113,7 @@ class TestProvider extends Provider { `${authIdentityId} has not been authenticated`, ); } - providerToken = await this.checkToken(providerToken, authIdentityId); + await this.checkToken(providerToken, authIdentityId); for (const [k, v] of Object.entries(this.users) as Array< [ IdentityId, diff --git a/tests/nodes/NodeConnectionManager.test.ts b/tests/nodes/NodeConnectionManager.test.ts index b3a7bfe6e1..c5e80eb2b9 100644 --- a/tests/nodes/NodeConnectionManager.test.ts +++ b/tests/nodes/NodeConnectionManager.test.ts @@ -15,7 +15,7 @@ import * as nodesTestUtils from './utils'; import * as keysTestUtils from '../keys/utils'; import * as testsUtils from '../utils'; -describe(`NodeConnectionManager`, () => { +describe(`${NodeConnectionManager.name}`, () => { const logger = new Logger( `${NodeConnectionManager.name} test`, LogLevel.WARN, diff --git a/tests/nodes/NodeManager.test.ts b/tests/nodes/NodeManager.test.ts index a4e706a2a8..fd88bc49cb 100644 --- a/tests/nodes/NodeManager.test.ts +++ b/tests/nodes/NodeManager.test.ts @@ -29,16 +29,12 @@ import * as nodesTestUtils from './utils'; import ACL from '../../src/acl/ACL'; import * as testsUtils from '../utils'; -describe(`NodeConnectionManager`, () => { - const logger = new Logger( - `${NodeConnectionManager.name} test`, - LogLevel.WARN, - [ - new StreamHandler( - formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`, - ), - ], - ); +describe(`${NodeManager.name}`, () => { + const logger = new Logger(`${NodeManager.name} test`, LogLevel.WARN, [ + new StreamHandler( + formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`, + ), + ]); const password = 'password'; const localHost = '127.0.0.1' as Host; const timeoutTime = 300; diff --git a/tests/nodes/agent/handlers/notificationsSend.test.ts b/tests/nodes/agent/handlers/notificationsSend.test.ts index 3828e91588..406cccd1e0 100644 --- a/tests/nodes/agent/handlers/notificationsSend.test.ts +++ b/tests/nodes/agent/handlers/notificationsSend.test.ts @@ -148,7 +148,6 @@ describe('notificationsSend', () => { db, keyRing, acl, - nodeConnectionManager, nodeManager, logger, }); diff --git a/tests/notifications/NotificationsManager.test.ts b/tests/notifications/NotificationsManager.test.ts index 57981c73d0..3a39cd9d61 100644 --- a/tests/notifications/NotificationsManager.test.ts +++ b/tests/notifications/NotificationsManager.test.ts @@ -4,6 +4,7 @@ import type { VaultActions, VaultName } from '@/vaults/types'; import type { Notification, NotificationData } from '@/notifications/types'; import type { Key } from '@/keys/types'; import type GestaltGraph from '@/gestalts/GestaltGraph'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import os from 'os'; import path from 'path'; @@ -112,7 +113,6 @@ describe('NotificationsManager', () => { }); const tlsConfig = await tlsTestsUtils.createTLSConfig(keyRing.keyPair); nodeConnectionManager = new NodeConnectionManager({ - nodeGraph, keyRing, tlsConfig, logger, @@ -128,7 +128,10 @@ describe('NotificationsManager', () => { logger, }); await nodeManager.start(); - await nodeConnectionManager.start({ host: localhost as Host }); + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, + }); await taskManager.start(); // Set up node for receiving notifications receiver = await PolykeyAgent.createPolykeyAgent({ @@ -145,11 +148,15 @@ describe('NotificationsManager', () => { }, logger, }); - await nodeGraph.setNode(receiver.keyRing.getNodeId(), { - host: receiver.agentServiceHost, - port: receiver.agentServicePort, - scopes: ['global'], - }); + await nodeGraph.setNodeContactAddressData( + receiver.keyRing.getNodeId(), + [receiver.agentServiceHost, receiver.agentServicePort], + { + mode: 'direct', + connectedTime: 0, + scopes: ['global'], + }, + ); }, globalThis.defaultTimeout); afterEach(async () => { await taskManager.stopProcessing(); @@ -173,7 +180,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -200,7 +206,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -264,7 +269,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -318,7 +322,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -385,7 +388,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -425,7 +427,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -461,7 +462,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -521,7 +521,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -580,7 +579,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -638,7 +636,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -699,7 +696,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, messageCap: 2, @@ -759,7 +755,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -793,7 +788,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -828,7 +822,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, @@ -886,7 +879,6 @@ describe('NotificationsManager', () => { await NotificationsManager.createNotificationsManager({ acl, db, - nodeConnectionManager, nodeManager, keyRing, logger, diff --git a/tests/tasks/utils.test.ts b/tests/tasks/utils.test.ts index 179cf91f5f..afac0a7795 100644 --- a/tests/tasks/utils.test.ts +++ b/tests/tasks/utils.test.ts @@ -94,5 +94,4 @@ describe('tasks/utils', () => { tasksUtils.decodeTaskId('vvvvvvvvvvvvvvvvvvvvvvvvvvs')?.equals(taskId3), ).toBe(true); }); - test; }); diff --git a/tests/vaults/VaultManager.test.ts b/tests/vaults/VaultManager.test.ts index 7291c7e44f..ff9805a153 100644 --- a/tests/vaults/VaultManager.test.ts +++ b/tests/vaults/VaultManager.test.ts @@ -7,6 +7,8 @@ import type { } from '@/vaults/types'; import type NotificationsManager from '@/notifications/NotificationsManager'; import type { Host } from '@/network/types'; +import type { Sigchain } from '@/sigchain'; +import type { AgentServerManifest } from '@/nodes/agent/handlers'; import fs from 'fs'; import os from 'os'; import path from 'path'; @@ -19,6 +21,7 @@ import { RWLockWriter } from '@matrixai/async-locks'; import TaskManager from '@/tasks/TaskManager'; import ACL from '@/acl/ACL'; import GestaltGraph from '@/gestalts/GestaltGraph'; +import NodeManager from '@/nodes/NodeManager'; import NodeConnectionManager from '@/nodes/NodeConnectionManager'; import KeyRing from '@/keys/KeyRing'; import PolykeyAgent from '@/PolykeyAgent'; @@ -61,6 +64,11 @@ describe('VaultManager', () => { const dummyKeyRing = { getNodeId: () => nodeId, } as KeyRing; + const dummyGestaltGraph = {} as GestaltGraph; + const dummySigchain = {} as Sigchain; + const dummyACL = {} as ACL; + const dummyNodeManager = {} as NodeManager; + const dummyNotificationsManager = {} as NotificationsManager; beforeEach(async () => { dataDir = await fs.promises.mkdtemp( @@ -86,10 +94,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -116,10 +124,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -136,10 +144,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -178,10 +186,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -211,10 +219,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -239,10 +247,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -271,10 +279,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -316,10 +324,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -342,10 +350,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -367,10 +375,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -392,10 +400,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -428,10 +436,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -472,6 +480,7 @@ describe('VaultManager', () => { let keyRing: KeyRing; let nodeGraph: NodeGraph; let nodeConnectionManager: NodeConnectionManager; + let nodeManager: NodeManager; let remoteKeynode1: PolykeyAgent, remoteKeynode2: PolykeyAgent; let localNodeId: NodeId; let taskManager: TaskManager; @@ -514,17 +523,24 @@ describe('VaultManager', () => { remoteKeynode2Id = remoteKeynode2.keyRing.getNodeId(); // Adding details to each agent - await remoteKeynode1.nodeGraph.setNode(remoteKeynode2Id, { - host: remoteKeynode2.agentServiceHost, - port: remoteKeynode2.agentServicePort, - scopes: ['global'], - }); - await remoteKeynode2.nodeGraph.setNode(remoteKeynode1Id, { - host: remoteKeynode1.agentServiceHost, - port: remoteKeynode1.agentServicePort, - scopes: ['global'], - }); - + await remoteKeynode1.nodeGraph.setNodeContactAddressData( + remoteKeynode2Id, + [remoteKeynode2.agentServiceHost, remoteKeynode2.agentServicePort], + { + mode: 'direct', + connectedTime: Date.now(), + scopes: ['global'], + }, + ); + await remoteKeynode2.nodeGraph.setNodeContactAddressData( + remoteKeynode1Id, + [remoteKeynode1.agentServiceHost, remoteKeynode1.agentServicePort], + { + mode: 'direct', + connectedTime: Date.now(), + scopes: ['global'], + }, + ); await remoteKeynode1.gestaltGraph.setNode({ nodeId: remoteKeynode2Id, }); @@ -572,27 +588,49 @@ describe('VaultManager', () => { const tlsConfig = await tlsTestsUtils.createTLSConfig(keyRing.keyPair); nodeConnectionManager = new NodeConnectionManager({ keyRing, - nodeGraph, tlsConfig, logger, }); - await nodeConnectionManager.start({ host: localhost as Host }); - await taskManager.startProcessing(); - await nodeGraph.setNode(remoteKeynode1Id, { - host: remoteKeynode1.agentServiceHost, - port: remoteKeynode1.agentServicePort, - scopes: ['global'], + await nodeConnectionManager.start({ + host: localhost as Host, + agentService: {} as AgentServerManifest, }); - await nodeGraph.setNode(remoteKeynode2Id, { - host: remoteKeynode2.agentServiceHost, - port: remoteKeynode2.agentServicePort, - scopes: ['global'], + nodeManager = new NodeManager({ + db, + keyRing, + nodeConnectionManager, + nodeGraph, + gestaltGraph: dummyGestaltGraph, + sigchain: dummySigchain, + taskManager, + logger, }); + await nodeManager.start(); + await taskManager.startProcessing(); + await nodeGraph.setNodeContactAddressData( + remoteKeynode1Id, + [remoteKeynode1.agentServiceHost, remoteKeynode1.agentServicePort], + { + mode: 'direct', + connectedTime: Date.now(), + scopes: ['global'], + }, + ); + await nodeGraph.setNodeContactAddressData( + remoteKeynode2Id, + [remoteKeynode2.agentServiceHost, remoteKeynode2.agentServicePort], + { + mode: 'direct', + connectedTime: Date.now(), + scopes: ['global'], + }, + ); }); afterEach(async () => { await taskManager.stopProcessing(); await taskManager.stopTasks(); await remoteKeynode1.vaultManager.destroyVault(remoteVaultId); + await nodeManager.stop(); await nodeConnectionManager.stop(); await nodeGraph.stop(); await nodeGraph.destroy(); @@ -605,10 +643,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -667,10 +705,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -706,10 +744,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -749,10 +787,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -812,10 +850,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -836,10 +874,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -878,10 +916,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -966,10 +1004,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1099,10 +1137,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1173,10 +1211,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1230,10 +1268,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1256,10 +1294,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1372,10 +1410,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing, - nodeConnectionManager, + nodeManager, acl: {} as any, gestaltGraph: {} as any, - notificationsManager: {} as NotificationsManager, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1385,11 +1423,15 @@ describe('VaultManager', () => { const nodeId1 = keyRing.getNodeId(); // Letting nodeGraph know where the remote agent is - await nodeGraph.setNode(targetNodeId, { - host: remoteKeynode1.agentServiceHost, - port: remoteKeynode1.agentServicePort, - scopes: ['global'], - }); + await nodeGraph.setNodeContactAddressData( + targetNodeId, + [remoteKeynode1.agentServiceHost, remoteKeynode1.agentServicePort], + { + mode: 'direct', + connectedTime: Date.now(), + scopes: ['global'], + }, + ); await remoteKeynode1.gestaltGraph.setNode({ nodeId: nodeId1, @@ -1474,10 +1516,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - nodeConnectionManager: {} as NodeConnectionManager, + nodeManager: dummyNodeManager, acl, gestaltGraph, - notificationsManager: {} as NotificationsManager, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1539,10 +1581,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1582,10 +1624,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1624,10 +1666,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1663,10 +1705,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1684,10 +1726,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1715,10 +1757,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1743,10 +1785,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1773,10 +1815,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1790,10 +1832,10 @@ describe('VaultManager', () => { vaultManager2 = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1813,10 +1855,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), }); @@ -1836,10 +1878,10 @@ describe('VaultManager', () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyRing: dummyKeyRing, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, + gestaltGraph: dummyGestaltGraph, + nodeManager: dummyNodeManager, + acl: dummyACL, + notificationsManager: dummyNotificationsManager, db, logger: logger.getChild(VaultManager.name), });