Skip to content

Commit 1f6a96c

Browse files
committed
fix: cleaning up TODOs
1 parent 78b6ce5 commit 1f6a96c

8 files changed

Lines changed: 24 additions & 50 deletions

File tree

src/client/service/nodesGetAll.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type * as grpc from '@grpc/grpc-js';
22
import type { Authenticate } from '../types';
3-
import type { KeyManager } from '../../keys';
3+
import type KeyManager from '../../keys/KeyManager';
44
import type { NodeId } from '../../nodes/types';
55
import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';
6+
import type NodeGraph from '../../nodes/NodeGraph';
67
import { IdInternal } from '@matrixai/id';
78
import { utils as nodesUtils } from '../../nodes';
89
import { utils as grpcUtils } from '../../grpc';
@@ -12,11 +13,11 @@ import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb';
1213
* Retrieves all nodes from all buckets in the NodeGraph.
1314
*/
1415
function nodesGetAll({
15-
// NodeGraph,
16+
nodeGraph,
1617
keyManager,
1718
authenticate,
1819
}: {
19-
// NodeGraph: NodeGraph;
20+
nodeGraph: NodeGraph;
2021
keyManager: KeyManager;
2122
authenticate: Authenticate;
2223
}) {
@@ -28,10 +29,8 @@ function nodesGetAll({
2829
const response = new nodesPB.NodeBuckets();
2930
const metadata = await authenticate(call.metadata);
3031
call.sendMetadata(metadata);
31-
// FIXME:
32-
// const buckets = await nodeGraph.getAllBuckets();
33-
const buckets: any = [];
34-
for (const b of buckets) {
32+
const buckets = nodeGraph.getBuckets();
33+
for await (const b of buckets) {
3534
let index;
3635
for (const id of Object.keys(b)) {
3736
const encodedId = nodesUtils.encodeNodeId(
@@ -48,7 +47,7 @@ function nodesGetAll({
4847
);
4948
}
5049
// Need to either add node to an existing bucket, or create a new
51-
// bucket (if doesn't exist)
50+
// bucket (if it doesn't exist)
5251
const bucket = response.getBucketsMap().get(index);
5352
if (bucket) {
5453
bucket.getNodeTableMap().set(encodedId, address);

src/nodes/NodeConnectionManager.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class NodeConnectionManager {
112112
this.nodeManager = nodeManager;
113113
for (const nodeIdEncoded in this.seedNodes) {
114114
const nodeId = nodesUtils.decodeNodeId(nodeIdEncoded)!;
115-
await this.nodeGraph.setNode(nodeId, this.seedNodes[nodeIdEncoded]); // FIXME: also fine implicit transactions
115+
await this.nodeGraph.setNode(nodeId, this.seedNodes[nodeIdEncoded]);
116116
}
117117
this.logger.info(`Started ${this.constructor.name}`);
118118
}
@@ -264,7 +264,6 @@ class NodeConnectionManager {
264264
)}`,
265265
);
266266
// Creating the connection and set in map
267-
// FIXME: this is fine, just use the implicit tran. fix this when adding optional transactions
268267
const targetAddress = await this.findNode(targetNodeId);
269268
if (targetAddress == null) {
270269
throw new nodesErrors.ErrorNodeGraphNodeIdNotFound();
@@ -411,7 +410,6 @@ class NodeConnectionManager {
411410
return address;
412411
}
413412

414-
// FIXME: getClosestNodes was moved to NodeGraph? that needs to be updated.
415413
/**
416414
* Attempts to locate a target node in the network (using Kademlia).
417415
* Adds all discovered, active nodes to the current node's database (up to k
@@ -438,7 +436,6 @@ class NodeConnectionManager {
438436
// Let foundTarget: boolean = false;
439437
let foundAddress: NodeAddress | undefined = undefined;
440438
// Get the closest alpha nodes to the target node (set as shortlist)
441-
// FIXME: no tran
442439
const shortlist = await this.nodeGraph.getClosestNodes(
443440
targetNodeId,
444441
this.initialClosestNodes,
@@ -473,7 +470,6 @@ class NodeConnectionManager {
473470
try {
474471
// Add the node to the database so that we can find its address in
475472
// call to getConnectionToNode
476-
// FIXME: no tran
477473
await this.nodeGraph.setNode(nextNodeId, nextNodeAddress.address);
478474
await this.getConnection(nextNodeId, timer);
479475
} catch (e) {
@@ -496,7 +492,6 @@ class NodeConnectionManager {
496492
continue;
497493
}
498494
if (nodeId.equals(targetNodeId)) {
499-
// FIXME: no tran
500495
await this.nodeGraph.setNode(nodeId, nodeData.address);
501496
foundAddress = nodeData.address;
502497
// We have found the target node, so we can stop trying to look for it

src/nodes/NodeGraph.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,6 @@ class NodeGraph {
679679
* current node has less than k nodes in all of its buckets, in which case it
680680
* returns all nodes it has knowledge of)
681681
*/
682-
// FIXME: this is still operating on assumptions from old code.
683-
// I can't get the gt/lt to work on the iterator.
684682
@ready(new nodesErrors.ErrorNodeGraphNotRunning())
685683
public async getClosestNodes(
686684
nodeId: NodeId,

src/nodes/NodeManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
} from '../nodes/types';
1515
import type { ClaimEncoded } from '../claims/types';
1616
import type { Timer } from '../types';
17-
import type { PromiseType } from '../utils/utils';
17+
import type { PromiseDeconstructed } from '../utils/utils';
1818
import type { AbortSignal } from 'node-abort-controller';
1919
import Logger from '@matrixai/logger';
2020
import { StartStop, ready } from '@matrixai/async-init/dist/StartStop';
@@ -47,8 +47,8 @@ class NodeManager {
4747
protected refreshBucketQueue: Set<NodeBucketIndex> = new Set();
4848
protected refreshBucketQueueRunning: boolean = false;
4949
protected refreshBucketQueueRunner: Promise<void>;
50-
protected refreshBucketQueuePlug_: PromiseType<void> = promise();
51-
protected refreshBucketQueueDrained_: PromiseType<void> = promise();
50+
protected refreshBucketQueuePlug_: PromiseDeconstructed<void> = promise();
51+
protected refreshBucketQueueDrained_: PromiseDeconstructed<void> = promise();
5252
protected refreshBucketQueueAbortController: AbortController;
5353

5454
constructor({

src/nodes/Queue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PromiseType } from '../utils';
1+
import type { PromiseDeconstructed } from '../utils';
22
import Logger from '@matrixai/logger';
33
import { StartStop, ready } from '@matrixai/async-init/dist/StartStop';
44
import * as nodesErrors from './errors';
@@ -11,8 +11,8 @@ class Queue {
1111
protected end: boolean = false;
1212
protected queue: Array<() => Promise<void>> = [];
1313
protected runner: Promise<void>;
14-
protected plug_: PromiseType<void> = promise();
15-
protected drained_: PromiseType<void> = promise();
14+
protected plug_: PromiseDeconstructed<void> = promise();
15+
protected drained_: PromiseDeconstructed<void> = promise();
1616

1717
constructor({ logger }: { logger?: Logger }) {
1818
this.logger = logger ?? new Logger(this.constructor.name);

src/nodes/types.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ type NodeBucketMeta = {
3333
count: number;
3434
};
3535

36-
// Type NodeBucketMetaProps = NonFunctionProperties<NodeBucketMeta>;
37-
3836
// Just make the bucket entries also
3937
// bucketIndex anot as a key
4038
// but as the domain
@@ -45,20 +43,8 @@ type NodeData = {
4543
lastUpdated: number;
4644
};
4745

48-
// Type NodeBucketEntry = {
49-
// address: NodeAddress;
50-
// lastUpdated: Date;
51-
// };
52-
5346
type SeedNodes = Record<NodeIdEncoded, NodeAddress>;
5447

55-
// FIXME: should have a proper name
56-
type NodeEntry = {
57-
id: NodeId;
58-
address: NodeAddress;
59-
distance: BigInt;
60-
};
61-
6248
/**
6349
* A claim made on a node. That is, can be either:
6450
* - a claim from a node -> node
@@ -106,9 +92,6 @@ export type {
10692
NodeBucketMeta,
10793
NodeBucket,
10894
NodeData,
109-
NodeEntry,
110-
// NodeBucketEntry,
111-
11295
NodeGraphOp,
11396
NodeGraphSpace,
11497
};

src/nodes/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import type {
66
} from './types';
77
import { IdInternal } from '@matrixai/id';
88
import lexi from 'lexicographic-integer';
9+
import { utils as dbUtils } from '@matrixai/db';
910
import { bytes2BigInt } from '../utils';
1011
import * as keysUtils from '../keys/utils';
1112

12-
// FIXME:
13-
const prefixBuffer = Buffer.from([33]);
14-
// Const prefixBuffer = Buffer.from(dbUtils.prefix);
13+
const sepBuffer = dbUtils.sep;
1514

1615
/**
1716
* Encodes the NodeId as a `base32hex` string
@@ -94,9 +93,9 @@ function bucketKey(bucketIndex: NodeBucketIndex): string {
9493
*/
9594
function bucketsDbKey(bucketIndex: NodeBucketIndex, nodeId: NodeId): Buffer {
9695
return Buffer.concat([
97-
prefixBuffer,
96+
sepBuffer,
9897
Buffer.from(bucketKey(bucketIndex)),
99-
prefixBuffer,
98+
sepBuffer,
10099
bucketDbKey(nodeId),
101100
]);
102101
}
@@ -117,9 +116,9 @@ function lastUpdatedBucketsDbKey(
117116
nodeId: NodeId,
118117
): Buffer {
119118
return Buffer.concat([
120-
prefixBuffer,
119+
sepBuffer,
121120
Buffer.from(bucketKey(bucketIndex)),
122-
prefixBuffer,
121+
sepBuffer,
123122
lastUpdatedBucketDbKey(lastUpdated, nodeId),
124123
]);
125124
}
@@ -313,7 +312,7 @@ function generateRandomNodeIdForBucket(
313312
}
314313

315314
export {
316-
prefixBuffer,
315+
sepBuffer,
317316
encodeNodeId,
318317
decodeNodeId,
319318
bucketIndex,

src/utils/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function promisify<
170170
};
171171
}
172172

173-
type PromiseType<T> = {
173+
type PromiseDeconstructed<T> = {
174174
p: Promise<T>;
175175
resolveP: (value: T | PromiseLike<T>) => void;
176176
rejectP: (reason?: any) => void;
@@ -179,7 +179,7 @@ type PromiseType<T> = {
179179
/**
180180
* Deconstructed promise
181181
*/
182-
function promise<T = void>(): PromiseType<T> {
182+
function promise<T = void>(): PromiseDeconstructed<T> {
183183
let resolveP, rejectP;
184184
const p = new Promise<T>((resolve, reject) => {
185185
resolveP = resolve;
@@ -310,7 +310,7 @@ function debounce<P extends any[]>(
310310
};
311311
}
312312

313-
export type { PromiseType };
313+
export type { PromiseDeconstructed };
314314
export {
315315
getDefaultNodePath,
316316
never,

0 commit comments

Comments
 (0)