diff --git a/src/client/service/nodesGetAll.ts b/src/client/service/nodesGetAll.ts index bc01e84e07..8c021a2482 100644 --- a/src/client/service/nodesGetAll.ts +++ b/src/client/service/nodesGetAll.ts @@ -1,8 +1,9 @@ import type * as grpc from '@grpc/grpc-js'; import type { Authenticate } from '../types'; -import type { KeyManager } from '../../keys'; +import type KeyManager from '../../keys/KeyManager'; import type { NodeId } from '../../nodes/types'; import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb'; +import type NodeGraph from '../../nodes/NodeGraph'; import { IdInternal } from '@matrixai/id'; import { utils as nodesUtils } from '../../nodes'; import { utils as grpcUtils } from '../../grpc'; @@ -12,11 +13,11 @@ import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb'; * Retrieves all nodes from all buckets in the NodeGraph. */ function nodesGetAll({ - // NodeGraph, + nodeGraph, keyManager, authenticate, }: { - // NodeGraph: NodeGraph; + nodeGraph: NodeGraph; keyManager: KeyManager; authenticate: Authenticate; }) { @@ -28,10 +29,8 @@ function nodesGetAll({ const response = new nodesPB.NodeBuckets(); const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - // FIXME: - // const buckets = await nodeGraph.getAllBuckets(); - const buckets: any = []; - for (const b of buckets) { + const buckets = nodeGraph.getBuckets(); + for await (const b of buckets) { let index; for (const id of Object.keys(b)) { const encodedId = nodesUtils.encodeNodeId( @@ -48,7 +47,7 @@ function nodesGetAll({ ); } // Need to either add node to an existing bucket, or create a new - // bucket (if doesn't exist) + // bucket (if it doesn't exist) const bucket = response.getBucketsMap().get(index); if (bucket) { bucket.getNodeTableMap().set(encodedId, address); diff --git a/src/nodes/NodeConnectionManager.ts b/src/nodes/NodeConnectionManager.ts index 484757f81e..8efe369e98 100644 --- a/src/nodes/NodeConnectionManager.ts +++ b/src/nodes/NodeConnectionManager.ts @@ -112,7 +112,7 @@ class NodeConnectionManager { this.nodeManager = nodeManager; for (const nodeIdEncoded in this.seedNodes) { const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded)!; - await this.nodeGraph.setNode(nodeId, this.seedNodes[nodeIdEncoded]); // FIXME: also fine implicit transactions + await this.nodeGraph.setNode(nodeId, this.seedNodes[nodeIdEncoded]); } this.logger.info(`Started ${this.constructor.name}`); } @@ -264,7 +264,6 @@ class NodeConnectionManager { )}`, ); // Creating the connection and set in map - // FIXME: this is fine, just use the implicit tran. fix this when adding optional transactions const targetAddress = await this.findNode(targetNodeId); if (targetAddress == null) { throw new nodesErrors.ErrorNodeGraphNodeIdNotFound(); @@ -411,7 +410,6 @@ class NodeConnectionManager { return address; } - // FIXME: getClosestNodes was moved to NodeGraph? that needs to be updated. /** * Attempts to locate a target node in the network (using Kademlia). * Adds all discovered, active nodes to the current node's database (up to k @@ -438,7 +436,6 @@ class NodeConnectionManager { // Let foundTarget: boolean = false; let foundAddress: NodeAddress | undefined = undefined; // Get the closest alpha nodes to the target node (set as shortlist) - // FIXME: no tran const shortlist = await this.nodeGraph.getClosestNodes( targetNodeId, this.initialClosestNodes, @@ -473,7 +470,6 @@ class NodeConnectionManager { try { // Add the node to the database so that we can find its address in // call to getConnectionToNode - // FIXME: no tran await this.nodeGraph.setNode(nextNodeId, nextNodeAddress.address); await this.getConnection(nextNodeId, timer); } catch (e) { @@ -496,7 +492,6 @@ class NodeConnectionManager { continue; } if (nodeId.equals(targetNodeId)) { - // FIXME: no tran await this.nodeGraph.setNode(nodeId, nodeData.address); foundAddress = nodeData.address; // We have found the target node, so we can stop trying to look for it diff --git a/src/nodes/NodeGraph.ts b/src/nodes/NodeGraph.ts index a5b8da3323..c9ebaf0f3c 100644 --- a/src/nodes/NodeGraph.ts +++ b/src/nodes/NodeGraph.ts @@ -679,8 +679,6 @@ class NodeGraph { * current node has less than k nodes in all of its buckets, in which case it * returns all nodes it has knowledge of) */ - // FIXME: this is still operating on assumptions from old code. - // I can't get the gt/lt to work on the iterator. @ready(new nodesErrors.ErrorNodeGraphNotRunning()) public async getClosestNodes( nodeId: NodeId, diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 23832dbb7f..95251648ca 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -14,7 +14,7 @@ import type { } from '../nodes/types'; import type { ClaimEncoded } from '../claims/types'; import type { Timer } from '../types'; -import type { PromiseType } from '../utils/utils'; +import type { PromiseDeconstructed } from '../utils/utils'; import type { AbortSignal } from 'node-abort-controller'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; @@ -47,8 +47,8 @@ class NodeManager { protected refreshBucketQueue: Set = new Set(); protected refreshBucketQueueRunning: boolean = false; protected refreshBucketQueueRunner: Promise; - protected refreshBucketQueuePlug_: PromiseType = promise(); - protected refreshBucketQueueDrained_: PromiseType = promise(); + protected refreshBucketQueuePlug_: PromiseDeconstructed = promise(); + protected refreshBucketQueueDrained_: PromiseDeconstructed = promise(); protected refreshBucketQueueAbortController: AbortController; constructor({ diff --git a/src/nodes/Queue.ts b/src/nodes/Queue.ts index 0f9c1485e7..602efd5ae7 100644 --- a/src/nodes/Queue.ts +++ b/src/nodes/Queue.ts @@ -1,4 +1,4 @@ -import type { PromiseType } from '../utils'; +import type { PromiseDeconstructed } from '../utils'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; import * as nodesErrors from './errors'; @@ -11,8 +11,8 @@ class Queue { protected end: boolean = false; protected queue: Array<() => Promise> = []; protected runner: Promise; - protected plug_: PromiseType = promise(); - protected drained_: PromiseType = promise(); + protected plug_: PromiseDeconstructed = promise(); + protected drained_: PromiseDeconstructed = promise(); constructor({ logger }: { logger?: Logger }) { this.logger = logger ?? new Logger(this.constructor.name); diff --git a/src/nodes/types.ts b/src/nodes/types.ts index 8e173b4f2c..37775be9d7 100644 --- a/src/nodes/types.ts +++ b/src/nodes/types.ts @@ -33,8 +33,6 @@ type NodeBucketMeta = { count: number; }; -// Type NodeBucketMetaProps = NonFunctionProperties; - // Just make the bucket entries also // bucketIndex anot as a key // but as the domain @@ -45,20 +43,8 @@ type NodeData = { lastUpdated: number; }; -// Type NodeBucketEntry = { -// address: NodeAddress; -// lastUpdated: Date; -// }; - type SeedNodes = Record; -// FIXME: should have a proper name -type NodeEntry = { - id: NodeId; - address: NodeAddress; - distance: BigInt; -}; - /** * A claim made on a node. That is, can be either: * - a claim from a node -> node @@ -106,9 +92,6 @@ export type { NodeBucketMeta, NodeBucket, NodeData, - NodeEntry, - // NodeBucketEntry, - NodeGraphOp, NodeGraphSpace, }; diff --git a/src/nodes/utils.ts b/src/nodes/utils.ts index 449fc407bd..0078ef7849 100644 --- a/src/nodes/utils.ts +++ b/src/nodes/utils.ts @@ -6,12 +6,11 @@ import type { } from './types'; import { IdInternal } from '@matrixai/id'; import lexi from 'lexicographic-integer'; +import { utils as dbUtils } from '@matrixai/db'; import { bytes2BigInt } from '../utils'; import * as keysUtils from '../keys/utils'; -// FIXME: -const prefixBuffer = Buffer.from([33]); -// Const prefixBuffer = Buffer.from(dbUtils.prefix); +const sepBuffer = dbUtils.sep; /** * Encodes the NodeId as a `base32hex` string @@ -94,9 +93,9 @@ function bucketKey(bucketIndex: NodeBucketIndex): string { */ function bucketsDbKey(bucketIndex: NodeBucketIndex, nodeId: NodeId): Buffer { return Buffer.concat([ - prefixBuffer, + sepBuffer, Buffer.from(bucketKey(bucketIndex)), - prefixBuffer, + sepBuffer, bucketDbKey(nodeId), ]); } @@ -117,9 +116,9 @@ function lastUpdatedBucketsDbKey( nodeId: NodeId, ): Buffer { return Buffer.concat([ - prefixBuffer, + sepBuffer, Buffer.from(bucketKey(bucketIndex)), - prefixBuffer, + sepBuffer, lastUpdatedBucketDbKey(lastUpdated, nodeId), ]); } @@ -313,7 +312,7 @@ function generateRandomNodeIdForBucket( } export { - prefixBuffer, + sepBuffer, encodeNodeId, decodeNodeId, bucketIndex, diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 8b8984765b..0a1519d193 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -170,7 +170,7 @@ function promisify< }; } -type PromiseType = { +type PromiseDeconstructed = { p: Promise; resolveP: (value: T | PromiseLike) => void; rejectP: (reason?: any) => void; @@ -179,7 +179,7 @@ type PromiseType = { /** * Deconstructed promise */ -function promise(): PromiseType { +function promise(): PromiseDeconstructed { let resolveP, rejectP; const p = new Promise((resolve, reject) => { resolveP = resolve; @@ -310,7 +310,7 @@ function debounce

( }; } -export type { PromiseType }; +export type { PromiseDeconstructed }; export { getDefaultNodePath, never,