Skip to content

Commit

Permalink
fix: general fixes
Browse files Browse the repository at this point in the history
- added getBuckets test for distance and lastUpdated order
- resetting buckets work
- changing utility names
  • Loading branch information
CMCDragonkai authored and tegefaulkes committed Jun 1, 2022
1 parent 170d155 commit c6d01f9
Show file tree
Hide file tree
Showing 51 changed files with 3,258 additions and 1,327 deletions.
220 changes: 67 additions & 153 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"dependencies": {
"@grpc/grpc-js": "1.3.7",
"@matrixai/async-init": "^1.6.0",
"@matrixai/db": "^1.1.5",
"@matrixai/db": "^1.2.1",
"@matrixai/id": "^3.3.2",
"@matrixai/logger": "^2.1.0",
"@matrixai/workers": "^1.2.5",
Expand Down Expand Up @@ -109,6 +109,7 @@
"@types/cross-spawn": "^6.0.2",
"@types/google-protobuf": "^3.7.4",
"@types/jest": "^26.0.20",
"@types/level": "^6.0.0",
"@types/nexpect": "^0.4.31",
"@types/node": "^14.14.35",
"@types/node-forge": "^0.9.7",
Expand Down
8 changes: 6 additions & 2 deletions src/bin/nodes/CommandGetAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ class CommandGetAll extends CommandPolykey {
let output: any = {};
for (const [bucketIndex, bucket] of result.getBucketsMap().entries()) {
output[bucketIndex] = {};
for (const [encodedId, address] of bucket.getNodeTableMap().entries()) {
for (const [encodedId, address] of bucket
.getNodeTableMap()
.entries()) {
output[bucketIndex][encodedId] = {};
output[bucketIndex][encodedId].host = address.getHost();
output[bucketIndex][encodedId].port = address.getPort();
}
}
if (options.format === 'human') output = [result.getBucketsMap().getEntryList()];
if (options.format === 'human') {
output = [result.getBucketsMap().getEntryList()];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
Expand Down
18 changes: 11 additions & 7 deletions src/client/service/nodesGetAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { Authenticate } from '../types';
import type { NodeGraph } from '../../nodes';
import type { KeyManager } from '../../keys';
import type { NodeId } from '../../nodes/types';
import type * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';
import { IdInternal } from '@matrixai/id';
import { utils as nodesUtils } from '../../nodes';
import { utils as grpcUtils } from '../../grpc';
import * as nodesPB from '../../proto/js/polykey/v1/nodes/nodes_pb';
import * as utilsPB from '../../proto/js/polykey/v1/utils/utils_pb';

/**
* Retrieves all nodes from all buckets in the NodeGraph.
Expand All @@ -29,24 +29,28 @@ function nodesGetAll({
const response = new nodesPB.NodeBuckets();
const metadata = await authenticate(call.metadata);
call.sendMetadata(metadata);
const buckets = await nodeGraph.getAllBuckets();
// FIXME:
// const buckets = await nodeGraph.getAllBuckets();
const buckets: any = [];
for (const b of buckets) {
let index;
for (const id of Object.keys(b)) {
const encodedId = nodesUtils.encodeNodeId(IdInternal.fromString<NodeId>(id));
const encodedId = nodesUtils.encodeNodeId(
IdInternal.fromString<NodeId>(id),
);
const address = new nodesPB.Address()
.setHost(b[id].address.host)
.setPort(b[id].address.port);
// For every node in every bucket, add it to our message
if (!index) {
index = nodesUtils.calculateBucketIndex(
index = nodesUtils.bucketIndex(
keyManager.getNodeId(),
IdInternal.fromString<NodeId>(id)
IdInternal.fromString<NodeId>(id),
);
}
// Need to either add node to an existing bucket, or create a new
// Need to either add node to an existing bucket, or create a new
// bucket (if doesn't exist)
let bucket = response.getBucketsMap().get(index);
const bucket = response.getBucketsMap().get(index);
if (bucket) {
bucket.getNodeTableMap().set(encodedId, address);
} else {
Expand Down
Loading

0 comments on commit c6d01f9

Please sign in to comment.