diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index 248bff3a55..60a93cdf26 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -175,7 +175,7 @@ class PolykeyAgent { mdns: { groups: config.defaultsSystem.mdnsGroups, port: config.defaultsSystem.mdnsPort, - } + }, }); // This can only happen if the caller didn't specify the node path and the // automatic detection failed @@ -327,14 +327,14 @@ class PolykeyAgent { logger: logger.getChild(NodeGraph.name), }); mdns = new MDNS({ - logger: logger.getChild(MDNS.name) + 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, - }) + }); // Remove your own node ID if provided as a seed node const nodeIdOwnEncoded = nodesUtils.encodeNodeId(keyRing.getNodeId()); delete optionsDefaulted.seedNodes[nodeIdOwnEncoded]; @@ -670,7 +670,7 @@ class PolykeyAgent { mdns: { groups: config.defaultsSystem.mdnsGroups, port: config.defaultsSystem.mdnsPort, - } + }, }); // Register event handlers this.certManager.addEventListener( @@ -745,7 +745,7 @@ class PolykeyAgent { 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, diff --git a/src/client/handlers/NodesAdd.ts b/src/client/handlers/NodesAdd.ts index 7f53cdec2b..9518fd8ed6 100644 --- a/src/client/handlers/NodesAdd.ts +++ b/src/client/handlers/NodesAdd.ts @@ -53,7 +53,9 @@ class NodesAdd extends UnaryHandler< // Pinging to authenticate the node if ( (input.ping ?? false) && - !(await nodeManager.pingNode(nodeId, [{ host, port, scopes: ['external'] }])) + !(await nodeManager.pingNode(nodeId, [ + { host, port, scopes: ['external'] }, + ])) ) { throw new nodeErrors.ErrorNodePingFailed( 'Failed to authenticate target node', diff --git a/src/client/handlers/NodesFind.ts b/src/client/handlers/NodesFind.ts index b62e2e0030..a3bb98abe8 100644 --- a/src/client/handlers/NodesFind.ts +++ b/src/client/handlers/NodesFind.ts @@ -40,7 +40,9 @@ class NodesFind extends UnaryHandler< }, ); const addresses = await nodeConnectionManager.findNodeAll(nodeId); - if (addresses.length === 0) throw new nodesErrors.ErrorNodeGraphNodeIdNotFound(); + if (addresses.length === 0) { + throw new nodesErrors.ErrorNodeGraphNodeIdNotFound(); + } return { addresses }; }; diff --git a/src/client/types.ts b/src/client/types.ts index 63bed25ae2..d154d36d8a 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -113,7 +113,7 @@ type NodesFindMessage = { addresses: Array; }; -type NodesGetMessage = NodeAddressMessage & { bucketIndex: number }; +type NodesGetMessage = NodeAddressMessage & { bucketIndex: number }; type NodesAddMessage = NodeAddressMessage & { force?: boolean; diff --git a/src/config.ts b/src/config.ts index dcec0f666d..cdde0a308e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -13,12 +13,12 @@ const testnet: Record = { v7v9ptvcdbdf8p4upok3prpmu3938ns8v4g45dib7sm5hqvvehv70: { host: 'testnet.polykey.com' as Host, port: 1314 as Port, - scopes: ['external'] + scopes: ['external'], }, v270ktdd3cs3mp1r3q3dkmick92bn927mii9or4sgroeogd1peqb0: { host: 'testnet.polykey.com' as Host, port: 1314 as Port, - scopes: ['external'] + scopes: ['external'], }, }; diff --git a/src/network/utils.ts b/src/network/utils.ts index 34f1bc0597..3254ad5699 100644 --- a/src/network/utils.ts +++ b/src/network/utils.ts @@ -448,17 +448,29 @@ async function resolveHostnames( addresses: Array, existingAddresses: Set = new Set(), ): Promise }>> { - const final: Array<{ host: Host; port: Port; scopes: Array }> = []; + const final: Array<{ + host: Host; + port: Port; + scopes: Array; + }> = []; for (const address of addresses) { if (isHost(address.host)) { if (existingAddresses.has(`${address.host}|${address.port}`)) continue; - final.push({ host: address.host, port: address.port, scopes: address.scopes }); + final.push({ + host: address.host, + port: address.port, + scopes: address.scopes, + }); existingAddresses.add(`${address.host}|${address.port}`); continue; } const resolvedAddresses = await resolveHostname(address.host); for (const resolvedHost of resolvedAddresses) { - const newAddress = { host: resolvedHost, port: address.port, scopes: address.scopes }; + const newAddress = { + host: resolvedHost, + port: address.port, + scopes: address.scopes, + }; if (!Validator.isValidIPv4String(resolvedHost)[0]) continue; if (existingAddresses.has(`${resolvedHost}|${address.port}`)) continue; final.push(newAddress); diff --git a/src/nodes/NodeConnectionManager.ts b/src/nodes/NodeConnectionManager.ts index b003ad154e..0ba14f54f2 100644 --- a/src/nodes/NodeConnectionManager.ts +++ b/src/nodes/NodeConnectionManager.ts @@ -21,6 +21,7 @@ import type { TLSConfig, } from '../network/types'; import type { ServerManifest } from '@matrixai/rpc'; +import type { MDNS, ServicePOJO } from '@matrixai/mdns'; import Logger from '@matrixai/logger'; import { withF } from '@matrixai/resources'; import { ready, StartStop } from '@matrixai/async-init/dist/StartStop'; @@ -38,7 +39,7 @@ import { } from '@matrixai/quic'; import { running, status } from '@matrixai/async-init'; import { RPCServer, middleware as rpcUtilsMiddleware } from '@matrixai/rpc'; -import { MDNS, ServicePOJO, events as mdnsEvents, utils as mdnsUtils } from '@matrixai/mdns'; +import { events as mdnsEvents, utils as mdnsUtils } from '@matrixai/mdns'; import NodeConnection from './NodeConnection'; import * as nodesUtils from './utils'; import * as nodesErrors from './errors'; @@ -711,7 +712,9 @@ class NodeConnectionManager { if (addresses == null || addresses.length === 0) { // Find the node addresses = await this.findNodeAll(targetNodeId, undefined, ctx); - if (addresses.length === 0) throw new nodesErrors.ErrorNodeGraphNodeIdNotFound(); + if (addresses.length === 0) { + throw new nodesErrors.ErrorNodeGraphNodeIdNotFound(); + } } // Then we just get the connection, it should already exist. return this.getConnectionWithAddresses(targetNodeId, addresses, ctx); @@ -772,9 +775,12 @@ class NodeConnectionManager { if (existingConnection != null) return existingConnection; const targetNodeIdEncoded = nodesUtils.encodeNodeId(targetNodeId); let timeoutDivisions = 0; - const addressGroups: { local: Array, external: Array } = { local: [], external: [] }; + const addressGroups: { + local: Array; + external: Array; + } = { local: [], external: [] }; for (const address of addresses) { - let scope = address.scopes.includes('local') ? 'local' : 'external'; + const scope = address.scopes.includes('local') ? 'local' : 'external'; // If this is the first time an addressGroup has had an address added, the timeout divisions must be incremented. if (addressGroups[scope].length === 0) { timeoutDivisions++; @@ -794,7 +800,7 @@ class NodeConnectionManager { addressGroups.local, { signal: ctx.signal, - timer: timeout + timer: timeout, }, ); } @@ -805,7 +811,7 @@ class NodeConnectionManager { addressGroups.external, { signal: ctx.signal, - timer: timeout + timer: timeout, }, ); } @@ -950,7 +956,7 @@ class NodeConnectionManager { address: { host: Host; port: Port; - scopes: Array + scopes: Array; }, connectionsResults: Map, ctx: ContextTimed, @@ -961,7 +967,9 @@ class NodeConnectionManager { this.logger.debug( `establishing single connection for address ${address.host}:${address.port}`, ); - const iceProm = !address.scopes?.includes('local') ? this.initiateHolePunch(nodeIds, ctx) : undefined; + const iceProm = !address.scopes?.includes('local') + ? this.initiateHolePunch(nodeIds, ctx) + : undefined; const connection = await NodeConnection.createNodeConnection( { @@ -1280,45 +1288,53 @@ class NodeConnectionManager { @context ctx: ContextTimed, ): Promise> { const encodedNodeId = nodesUtils.encodeNodeId(targetNodeId); - this.logger.debug( - `Finding local addresses for ${encodedNodeId}`, - ); - let addresses: Array = []; + this.logger.debug(`Finding local addresses for ${encodedNodeId}`); + const addresses: Array = []; if (this.mdns == null) { return addresses; } // First check if we already have an existing MDNS Service - const mdnsOptions = { type: "polykey", protocol: "udp" } as const; - let service = this.mdns.networkServices.get(mdnsUtils.toFqdn({ name: encodedNodeId, ...mdnsOptions })); + const mdnsOptions = { type: 'polykey', protocol: 'udp' } as const; + let service = this.mdns.networkServices.get( + mdnsUtils.toFqdn({ name: encodedNodeId, ...mdnsOptions }), + ); if (service == null) { - // setup promises + // Setup promises ctx.signal.throwIfAborted(); const { p: abortP, rejectP: rejectAbortP } = utils.promise(); const abortHandler = () => { rejectAbortP(ctx.signal.reason); }; ctx.signal.addEventListener('abort', abortHandler, { once: true }); - const { p: serviceP, resolveP: resolveServiceP } = utils.promise(); + const { p: serviceP, resolveP: resolveServiceP } = + utils.promise(); const handleEventMDNSService = (evt: mdnsEvents.EventMDNSService) => { if (evt.detail.name === encodedNodeId) { resolveServiceP(evt.detail); } }; - this.mdns.addEventListener(mdnsEvents.EventMDNSService.name, handleEventMDNSService, { once: true }); - // abort and restart query in case already running + this.mdns.addEventListener( + mdnsEvents.EventMDNSService.name, + handleEventMDNSService, + { once: true }, + ); + // Abort and restart query in case already running this.mdns.stopQuery(mdnsOptions); this.mdns.startQuery(mdnsOptions); - // race promises to find node or timeout + // Race promises to find node or timeout try { service = await Promise.race([serviceP, abortP]); } catch { - this.mdns.removeEventListener(mdnsEvents.EventMDNSService.name, handleEventMDNSService); + this.mdns.removeEventListener( + mdnsEvents.EventMDNSService.name, + handleEventMDNSService, + ); } finally { this.mdns.stopQuery(mdnsOptions); ctx.signal.removeEventListener('abort', abortHandler); } } - // if the service is not found, just return no addresses + // If the service is not found, just return no addresses if (service == null) { return addresses; } @@ -1326,9 +1342,13 @@ class NodeConnectionManager { let host: string; switch (this.quicSocket.type) { case 'ipv4': - if (quicUtils.isIPv4(host_)) host = host_; - else if (quicUtils.isIPv4MappedIPv6(host_)) host = quicUtils.fromIPv4MappedIPv6(host_); - else continue; + if (quicUtils.isIPv4(host_)) { + host = host_; + } else if (quicUtils.isIPv4MappedIPv6(host_)) { + host = quicUtils.fromIPv4MappedIPv6(host_); + } else { + continue; + } break; case 'ipv6': if (quicUtils.isIPv6(host_)) host = host_; @@ -1343,12 +1363,12 @@ class NodeConnectionManager { addresses.push({ host: host as Host, port: service.port as Port, - scopes: ['local'] + scopes: ['local'], }); this.logger.debug( - `found address for ${nodesUtils.encodeNodeId(targetNodeId)} at ${ - host - }:${service.port}`, + `found address for ${nodesUtils.encodeNodeId( + targetNodeId, + )} at ${host}:${service.port}`, ); } return addresses; @@ -1367,15 +1387,26 @@ class NodeConnectionManager { ctx?: Partial, ): PromiseCancellable>; @ready(new nodesErrors.ErrorNodeConnectionManagerNotRunning()) - @timedCancellable(true, (nodeConnectionManager: NodeConnectionManager) => nodeConnectionManager.connectionConnectTimeoutTime) + @timedCancellable( + true, + (nodeConnectionManager: NodeConnectionManager) => + nodeConnectionManager.connectionConnectTimeoutTime, + ) public async findNodeAll( targetNodeId: NodeId, pingTimeoutTime: number | undefined, @context ctx: ContextTimed, ): Promise> { - const [localAddresses, kademliaAddress] = await Promise.allSettled([this.findNodeLocal(targetNodeId, ctx), this.findNode(targetNodeId, pingTimeoutTime, ctx)]) - const addresses = localAddresses.status === 'fulfilled' ? localAddresses.value : []; - if (kademliaAddress.status === 'fulfilled' && kademliaAddress.value != null) { + const [localAddresses, kademliaAddress] = await Promise.allSettled([ + this.findNodeLocal(targetNodeId, ctx), + this.findNode(targetNodeId, pingTimeoutTime, ctx), + ]); + const addresses = + localAddresses.status === 'fulfilled' ? localAddresses.value : []; + if ( + kademliaAddress.status === 'fulfilled' && + kademliaAddress.value != null + ) { addresses.push(kademliaAddress.value); } return addresses; @@ -1450,11 +1481,13 @@ class NodeConnectionManager { if ( !(await this.pingNode( nextNodeId, - [{ - host: nextNodeAddress.address.host, - port: nextNodeAddress.address.port, - scopes: ['external'] - }], + [ + { + host: nextNodeAddress.address.host, + port: nextNodeAddress.address.port, + scopes: ['external'], + }, + ], { signal: ctx.signal, timer: pingTimeoutTime ?? this.connectionConnectTimeoutTime, @@ -1489,11 +1522,13 @@ class NodeConnectionManager { nodeId.equals(targetNodeId) && (await this.pingNode( nodeId, - [{ - host: nextNodeAddress.address.host, - port: nextNodeAddress.address.port, - scopes: ['external'] - }], + [ + { + host: nextNodeAddress.address.host, + port: nextNodeAddress.address.port, + scopes: ['external'], + }, + ], { signal: ctx.signal, timer: pingTimeoutTime ?? this.connectionConnectTimeoutTime, @@ -1573,7 +1608,7 @@ class NodeConnectionManager { address: { host: result.host as Host | Hostname, port: result.port as Port, - scopes: ['external'] + scopes: ['external'], }, // Not really needed // But if it's needed then we need to add the information to the proto definition @@ -1790,11 +1825,7 @@ class NodeConnectionManager { @context ctx: ContextTimed, ): Promise { try { - await this.getConnectionWithAddresses( - nodeId, - addresses, - ctx, - ); + await this.getConnectionWithAddresses(nodeId, addresses, ctx); return true; } catch { return false; diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 69d54e98af..292c027845 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -141,8 +141,19 @@ class NodeManager { ); never(); } - if (await this.pingNode(nodeId, [{ host, port, scopes: ['external'] }], { signal: ctx.signal })) { - await this.setNode(nodeId, { host, port, scopes: ['external'] }, false, false, 2000, ctx); + if ( + await this.pingNode(nodeId, [{ host, port, scopes: ['external'] }], { + signal: ctx.signal, + }) + ) { + await this.setNode( + nodeId, + { host, port, scopes: ['external'] }, + false, + false, + 2000, + ctx, + ); } }; public readonly pingAndSetNodeHandlerId: TaskHandlerId = @@ -210,7 +221,7 @@ class NodeManager { { host: e.detail.remoteHost, port: e.detail.remotePort, - scopes: ['external'] + scopes: ['external'], }, false, false, diff --git a/src/nodes/agent/handlers/NodesConnectionSignalInitial.ts b/src/nodes/agent/handlers/NodesConnectionSignalInitial.ts index c6ff3ed793..f4a5cc2fa5 100644 --- a/src/nodes/agent/handlers/NodesConnectionSignalInitial.ts +++ b/src/nodes/agent/handlers/NodesConnectionSignalInitial.ts @@ -52,7 +52,7 @@ class NodesConnectionSignalInitial extends UnaryHandler< const address: NodeAddress = { host: remoteHost as Host, port: remotePort as Port, - scopes: ['external'] + scopes: ['external'], }; nodeConnectionManager.handleNodesConnectionSignalInitial( requestingNodeId, diff --git a/src/nodes/errors.ts b/src/nodes/errors.ts index dcb236b578..7397c504e9 100644 --- a/src/nodes/errors.ts +++ b/src/nodes/errors.ts @@ -72,7 +72,8 @@ class ErrorNodeConnectionHostWildcard extends ErrorNodeConnection { } class ErrorNodeConnectionHostLinkLocal extends ErrorNodeConnection { - static description = 'A link-local IPv6 address was provided for the target host, attempts to connect will fail due to being unsupported'; + static description = + 'A link-local IPv6 address was provided for the target host, attempts to connect will fail due to being unsupported'; exitCode = sysexits.USAGE; } diff --git a/tests/client/handlers/gestalts.test.ts b/tests/client/handlers/gestalts.test.ts index a0d6fc3bb7..e9eb820105 100644 --- a/tests/client/handlers/gestalts.test.ts +++ b/tests/client/handlers/gestalts.test.ts @@ -1628,7 +1628,7 @@ describe('gestaltsGestaltTrustByNode', () => { await nodeManager.setNode(nodeIdRemote, { host: node.agentServiceHost, port: node.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); discovery = await Discovery.createDiscovery({ db, diff --git a/tests/client/handlers/nodes.test.ts b/tests/client/handlers/nodes.test.ts index 3c5ffcea2c..16630870d7 100644 --- a/tests/client/handlers/nodes.test.ts +++ b/tests/client/handlers/nodes.test.ts @@ -420,7 +420,7 @@ describe('nodesFind', () => { .mockResolvedValue({ host: '127.0.0.1' as Host, port: 11111 as Port, - scopes: ['local'] + scopes: ['local'], }); dataDir = await fs.promises.mkdtemp( path.join(os.tmpdir(), 'polykey-test-'), diff --git a/tests/discovery/Discovery.test.ts b/tests/discovery/Discovery.test.ts index e60a02a51e..839b8a6566 100644 --- a/tests/discovery/Discovery.test.ts +++ b/tests/discovery/Discovery.test.ts @@ -209,7 +209,7 @@ describe('Discovery', () => { await nodeGraph.setNode(nodeA.keyRing.getNodeId(), { host: nodeA.agentServiceHost, port: nodeA.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); await nodeB.acl.setNodeAction(nodeA.keyRing.getNodeId(), 'claim'); await nodeA.nodeManager.claimNode(nodeB.keyRing.getNodeId()); diff --git a/tests/network/utils.test.ts b/tests/network/utils.test.ts index 80c379a4b8..e23ea43985 100644 --- a/tests/network/utils.test.ts +++ b/tests/network/utils.test.ts @@ -12,8 +12,12 @@ describe('utils', () => { expect(networkUtils.isHost('::1234:5678')).toBeTrue(); expect(networkUtils.isHost('2001:db8::1234:5678')).toBeTrue(); expect(networkUtils.isHost('2001:db8:1::ab9:C0A8:102')).toBeTrue(); - expect(networkUtils.isHost('2001:db8:3333:4444:5555:6666:7777:8888')).toBeTrue(); - expect(networkUtils.isHost('2001:0db8:0001:0000:0000:0ab9:C0A8:0102')).toBeTrue(); + expect( + networkUtils.isHost('2001:db8:3333:4444:5555:6666:7777:8888'), + ).toBeTrue(); + expect( + networkUtils.isHost('2001:0db8:0001:0000:0000:0ab9:C0A8:0102'), + ).toBeTrue(); // Link-Local expect(networkUtils.isHost('fe80::210:5aff:feaa:20a2%eth0')).toBeTrue(); }); diff --git a/tests/nodes/NodeConnectionManager.general.test.ts b/tests/nodes/NodeConnectionManager.general.test.ts index a645d9e911..df267c6632 100644 --- a/tests/nodes/NodeConnectionManager.general.test.ts +++ b/tests/nodes/NodeConnectionManager.general.test.ts @@ -127,7 +127,7 @@ describe(`${NodeConnectionManager.name} general test`, () => { serverAddressA = { host: remotePolykeyAgentA.agentServiceHost as Host, port: remotePolykeyAgentA.agentServicePort as Port, - scopes: ['external'] + scopes: ['external'], }; remotePolykeyAgentB = await PolykeyAgent.createPolykeyAgent({ password, @@ -417,11 +417,13 @@ describe(`${NodeConnectionManager.name} general test`, () => { expect( await remotePolykeyAgentA.nodeConnectionManager.pingNode( remotePolykeyAgentB.keyRing.getNodeId(), - [{ - host: remotePolykeyAgentB.agentServiceHost, - port: remotePolykeyAgentB.agentServicePort, - scopes: ['external'] - }] + [ + { + host: remotePolykeyAgentB.agentServiceHost, + port: remotePolykeyAgentB.agentServicePort, + scopes: ['external'], + }, + ], ), ).toBeTrue(); @@ -449,7 +451,7 @@ describe(`${NodeConnectionManager.name} general test`, () => { const serverAddress: NodeAddress = { host: remotePolykeyAgentA.agentServiceHost as Host, port: remotePolykeyAgentA.agentServicePort as Port, - scopes: ['external'] + scopes: ['external'], }; await nodeGraph.setNode(serverNodeId, serverAddress); @@ -503,18 +505,20 @@ describe(`${NodeConnectionManager.name} general test`, () => { const serverAddress: NodeAddress = { host: remotePolykeyAgentA.agentServiceHost, port: remotePolykeyAgentA.agentServicePort, - scopes: ['external'] + scopes: ['external'], }; await nodeGraph.setNode(serverNodeId, serverAddress); // Establish connection between remote A and B expect( await remotePolykeyAgentA.nodeConnectionManager.pingNode( remotePolykeyAgentB.keyRing.getNodeId(), - [{ - host: remotePolykeyAgentB.agentServiceHost, - port: remotePolykeyAgentB.agentServicePort, - scopes: ['external'] - }] + [ + { + host: remotePolykeyAgentB.agentServiceHost, + port: remotePolykeyAgentB.agentServicePort, + scopes: ['external'], + }, + ], ), ).toBeTrue(); @@ -634,11 +638,13 @@ describe(`${NodeConnectionManager.name} general test`, () => { expect( await nodeConnectionManager.pingNode( remotePolykeyAgentB.keyRing.getNodeId(), - [{ - host: remotePolykeyAgentB.agentServiceHost, - port: remotePolykeyAgentB.agentServicePort, - scopes: ['external'] - }] + [ + { + host: remotePolykeyAgentB.agentServiceHost, + port: remotePolykeyAgentB.agentServicePort, + scopes: ['external'], + }, + ], ), ).toBeTrue(); const keyPair = keysUtils.generateKeyPair(); @@ -654,7 +660,7 @@ describe(`${NodeConnectionManager.name} general test`, () => { { host: '127.0.0.1' as Host, port: 55555 as Port, - scopes: ['external'] + scopes: ['external'], }, signature.toString('base64url'), ); diff --git a/tests/nodes/NodeConnectionManager.lifecycle.test.ts b/tests/nodes/NodeConnectionManager.lifecycle.test.ts index aee4c4fff7..7c9f5dfdef 100644 --- a/tests/nodes/NodeConnectionManager.lifecycle.test.ts +++ b/tests/nodes/NodeConnectionManager.lifecycle.test.ts @@ -424,14 +424,13 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { await nodeConnectionManager.start({ host: localHost, }); - const result = await nodeConnectionManager.pingNode( - serverNodeId1, - [{ + const result = await nodeConnectionManager.pingNode(serverNodeId1, [ + { host: localHost as Host, port: nodeConnectionManagerPeer1.port, - scopes: ['local'] - }], - ); + scopes: ['local'], + }, + ]); expect(result).toBeTrue(); expect(nodeConnectionManager.hasConnection(serverNodeId1)).toBeTrue(); @@ -450,11 +449,13 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { }); const result = await nodeConnectionManager.pingNode( serverNodeId1, - [{ - host: localHost as Host, - port: 12345 as Port, - scopes: ['local'] - }], + [ + { + host: localHost as Host, + port: 12345 as Port, + scopes: ['local'], + }, + ], { timer: 100 }, ); expect(result).toBeFalse(); @@ -473,14 +474,13 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { await nodeConnectionManager.start({ host: localHost, }); - const result = await nodeConnectionManager.pingNode( - clientNodeId, - [{ + const result = await nodeConnectionManager.pingNode(clientNodeId, [ + { host: localHost as Host, port: nodeConnectionManagerPeer1.port, - scopes: ['local'] - }], - ); + scopes: ['local'], + }, + ]); expect(result).toBeFalse(); expect(nodeConnectionManager.hasConnection(clientNodeId)).toBeFalse(); @@ -503,9 +503,21 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { const connectedNodes = await nodeConnectionManager.getMultiConnection( [serverNodeId1], [ - { host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.2' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.3' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.2' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.3' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, ], { timer: 200 }, ); @@ -533,12 +545,36 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { const connectedNodes = await nodeConnectionManager.getMultiConnection( [serverNodeId1, serverNodeId2], [ - { host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.2' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.3' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, - { host: '127.0.0.2' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, - { host: '127.0.0.3' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.2' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.3' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, + { + host: '127.0.0.2' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, + { + host: '127.0.0.3' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, ], { timer: 200 }, ); @@ -567,7 +603,13 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { const connectedNodes = await nodeConnectionManager.getMultiConnection( [serverNodeId1, serverNodeId2], - [{ host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }], + [ + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + ], { timer: 200 }, ); expect(connectedNodes.length).toBe(1); @@ -597,12 +639,36 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { const connectedNodesProm = nodeConnectionManager.getMultiConnection( [serverNodeId1, serverNodeId2], [ - { host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.2' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.3' as Host, port: nodeConnectionManagerPeer1.port, scopes: ['external'] }, - { host: '127.0.0.1' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, - { host: '127.0.0.2' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, - { host: '127.0.0.3' as Host, port: nodeConnectionManagerPeer2.port, scopes: ['external'] }, + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.2' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.3' as Host, + port: nodeConnectionManagerPeer1.port, + scopes: ['external'], + }, + { + host: '127.0.0.1' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, + { + host: '127.0.0.2' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, + { + host: '127.0.0.3' as Host, + port: nodeConnectionManagerPeer2.port, + scopes: ['external'], + }, ], { timer: 2000 }, ); diff --git a/tests/nodes/NodeConnectionManager.mdns.test.ts b/tests/nodes/NodeConnectionManager.mdns.test.ts index 7af7d9e4b8..53e47adb24 100644 --- a/tests/nodes/NodeConnectionManager.mdns.test.ts +++ b/tests/nodes/NodeConnectionManager.mdns.test.ts @@ -4,7 +4,7 @@ import path from 'path'; import fs from 'fs'; import os from 'os'; import { DB } from '@matrixai/db'; -import { MDNS, events as mdnsEvents } from '@matrixai/mdns'; +import { MDNS } from '@matrixai/mdns'; import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger'; import KeyRing from '@/keys/KeyRing'; import NodeGraph from '@/nodes/NodeGraph'; @@ -12,8 +12,7 @@ import NodeConnection from '@/nodes/NodeConnection'; import NodeConnectionManager from '@/nodes/NodeConnectionManager'; import * as nodesUtils from '@/nodes/utils'; import * as keysUtils from '@/keys/utils'; -import { promise } from '@/utils'; -import config from '@/config'; +import config from '@/config'; import * as tlsUtils from '../utils/tls'; describe(`${NodeConnectionManager.name} MDNS test`, () => { @@ -73,15 +72,15 @@ describe(`${NodeConnectionManager.name} MDNS test`, () => { id: serverNodeId.at(0), hostname: serverNodeIdEncoded, groups: config.defaultsSystem.mdnsGroups, - port: config.defaultsSystem.mdnsPort - }) + port: config.defaultsSystem.mdnsPort, + }); nodeConnectionManagerPeer = new NodeConnectionManager({ keyRing: keyRingPeer, logger: logger.getChild(`${NodeConnectionManager.name}Peer`), nodeGraph: {} as NodeGraph, tlsConfig: serverTlsConfig, seedNodes: undefined, - mdns: mdnsPeer + mdns: mdnsPeer, }); await nodeConnectionManagerPeer.start({ host: localHost, @@ -114,8 +113,8 @@ describe(`${NodeConnectionManager.name} MDNS test`, () => { id: clientNodeId.at(0), hostname: clientNodeIdEncoded, groups: config.defaultsSystem.mdnsGroups, - port: config.defaultsSystem.mdnsPort - }) + port: config.defaultsSystem.mdnsPort, + }); }); afterEach(async () => { @@ -145,10 +144,13 @@ describe(`${NodeConnectionManager.name} MDNS test`, () => { }); // Expect no error thrown - const foundAddresses = await nodeConnectionManager.findNodeLocal(serverNodeId); + const foundAddresses = + await nodeConnectionManager.findNodeLocal(serverNodeId); expect(foundAddresses).toBeArray(); - expect(foundAddresses).toIncludeAllPartialMembers([{ port: nodeConnectionManagerPeer.port, scopes: ['local'] }]) + expect(foundAddresses).toIncludeAllPartialMembers([ + { port: nodeConnectionManagerPeer.port, scopes: ['local'] }, + ]); await nodeConnectionManager.stop(); }); @@ -167,8 +169,7 @@ describe(`${NodeConnectionManager.name} MDNS test`, () => { host: localHost, }); - const acquire = - await nodeConnectionManager.acquireConnection(serverNodeId); + const acquire = await nodeConnectionManager.acquireConnection(serverNodeId); const [release] = await acquire(); expect(nodeConnectionManager.hasConnection(serverNodeId)).toBeTrue(); await release(); diff --git a/tests/nodes/NodeConnectionManager.seednodes.test.ts b/tests/nodes/NodeConnectionManager.seednodes.test.ts index f809a92e81..670f5b1efe 100644 --- a/tests/nodes/NodeConnectionManager.seednodes.test.ts +++ b/tests/nodes/NodeConnectionManager.seednodes.test.ts @@ -238,7 +238,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => { [nodesUtils.encodeNodeId(localNodeId)]: { host: '127.0.0.1' as Host, port: 55123 as Port, - scopes: ['external'] + scopes: ['external'], }, }; nodeConnectionManager = new NodeConnectionManager({ @@ -292,7 +292,7 @@ describe(`${NodeConnectionManager.name} seednodes test`, () => { [nodesUtils.encodeNodeId(remoteNodeId2)]: { host: '127.0.0.1' as Host, port: 55124 as Port, - scopes: ['external'] + scopes: ['external'], }, }; nodeConnectionManager = new NodeConnectionManager({ diff --git a/tests/nodes/NodeManager.test.ts b/tests/nodes/NodeManager.test.ts index e1a566857d..81db945e80 100644 --- a/tests/nodes/NodeManager.test.ts +++ b/tests/nodes/NodeManager.test.ts @@ -168,7 +168,7 @@ describe(`${NodeManager.name} test`, () => { await nodeManager.setNode(nodeId, { host: '' as Host, port: 11111 as Port, - scopes: ['external'] + scopes: ['external'], }); const nodeData = (await nodeGraph.getNode(nodeId))!; @@ -179,7 +179,7 @@ describe(`${NodeManager.name} test`, () => { await nodeManager.setNode(nodeId, { host: '' as Host, port: 22222 as Port, - scopes: ['external'] + scopes: ['external'], }); const newNodeData = (await nodeGraph.getNode(nodeId))!; @@ -400,7 +400,11 @@ describe(`${NodeManager.name} test`, () => { await nodeManager.start(); const nodeId = keyRing.getNodeId(); - const address: NodeAddress = { host: localHost as Host, port: port as Port, scopes: ['external'] }; + const address: NodeAddress = { + host: localHost as Host, + port: port as Port, + scopes: ['external'], + }; // Let's fill a bucket for (let i = 0; i < nodeGraph.nodeBucketLimit; i++) { const newNode = nodesTestUtils.generateNodeIdForBucket(nodeId, 100, i); @@ -435,7 +439,11 @@ describe(`${NodeManager.name} test`, () => { await nodeManager.start(); const nodeId = keyRing.getNodeId(); - const address: NodeAddress = { host: localHost as Host, port: port as Port, scopes: ['external'] }; + const address: NodeAddress = { + host: localHost as Host, + port: port as Port, + scopes: ['external'], + }; // Let's fill a bucket for (let i = 0; i < nodeGraph.nodeBucketLimit; i++) { const newNode = nodesTestUtils.generateNodeIdForBucket(nodeId, 100, i); @@ -477,7 +485,11 @@ describe(`${NodeManager.name} test`, () => { await nodeManager.start(); const nodeId = keyRing.getNodeId(); - const address: NodeAddress = { host: localHost as Host, port: port as Port, scopes: ['external'] }; + const address: NodeAddress = { + host: localHost as Host, + port: port as Port, + scopes: ['external'], + }; // Let's fill a bucket for (let i = 0; i < nodeGraph.nodeBucketLimit; i++) { const newNode = testNodesUtils.generateNodeIdForBucket(nodeId, 100, i); diff --git a/tests/nodes/agent/handlers/nodesClosestLocalNode.test.ts b/tests/nodes/agent/handlers/nodesClosestLocalNode.test.ts index afda8efd8f..174c1afe9d 100644 --- a/tests/nodes/agent/handlers/nodesClosestLocalNode.test.ts +++ b/tests/nodes/agent/handlers/nodesClosestLocalNode.test.ts @@ -176,7 +176,7 @@ describe('nodesClosestLocalNode', () => { await nodeGraph.setNode(nodeId, { host: 'localhost' as Host, port: 55555 as Port, - scopes: ['local'] + scopes: ['local'], }); nodes.push(nodesUtils.encodeNodeId(nodeId)); } diff --git a/tests/nodes/utils.ts b/tests/nodes/utils.ts index 7fb12c5fd2..dd3bc97e8b 100644 --- a/tests/nodes/utils.ts +++ b/tests/nodes/utils.ts @@ -73,13 +73,13 @@ async function nodesConnect(localNode: PolykeyAgent, remoteNode: PolykeyAgent) { await localNode.nodeManager.setNode(remoteNode.keyRing.getNodeId(), { host: remoteNode.agentServiceHost, port: remoteNode.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); // Add local node's details to remote node await remoteNode.nodeManager.setNode(localNode.keyRing.getNodeId(), { host: localNode.agentServiceHost, port: localNode.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); } diff --git a/tests/notifications/NotificationsManager.test.ts b/tests/notifications/NotificationsManager.test.ts index 9594df1fdf..7e7bb51727 100644 --- a/tests/notifications/NotificationsManager.test.ts +++ b/tests/notifications/NotificationsManager.test.ts @@ -148,7 +148,7 @@ describe('NotificationsManager', () => { await nodeGraph.setNode(receiver.keyRing.getNodeId(), { host: receiver.agentServiceHost, port: receiver.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); }, globalThis.defaultTimeout); afterEach(async () => { diff --git a/tests/vaults/VaultManager.test.ts b/tests/vaults/VaultManager.test.ts index 1265901e8c..e1db788188 100644 --- a/tests/vaults/VaultManager.test.ts +++ b/tests/vaults/VaultManager.test.ts @@ -517,12 +517,12 @@ describe('VaultManager', () => { await remoteKeynode1.nodeGraph.setNode(remoteKeynode2Id, { host: remoteKeynode2.agentServiceHost, port: remoteKeynode2.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); await remoteKeynode2.nodeGraph.setNode(remoteKeynode1Id, { host: remoteKeynode1.agentServiceHost, port: remoteKeynode1.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); await remoteKeynode1.gestaltGraph.setNode({ @@ -581,12 +581,12 @@ describe('VaultManager', () => { await nodeGraph.setNode(remoteKeynode1Id, { host: remoteKeynode1.agentServiceHost, port: remoteKeynode1.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); await nodeGraph.setNode(remoteKeynode2Id, { host: remoteKeynode2.agentServiceHost, port: remoteKeynode2.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); }); afterEach(async () => { @@ -1388,7 +1388,7 @@ describe('VaultManager', () => { await nodeGraph.setNode(targetNodeId, { host: remoteKeynode1.agentServiceHost, port: remoteKeynode1.agentServicePort, - scopes: ['external'] + scopes: ['external'], }); await remoteKeynode1.gestaltGraph.setNode({