Skip to content

Commit

Permalink
WIP
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 Mar 28, 2022
1 parent 32f5c3e commit c94a166
Show file tree
Hide file tree
Showing 50 changed files with 3,230 additions and 1,319 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
6 changes: 4 additions & 2 deletions src/client/service/nodesGetAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ 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)) {
Expand All @@ -39,7 +41,7 @@ function nodesGetAll({
.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)
);
Expand Down
9 changes: 5 additions & 4 deletions src/discovery/Discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Discovery {
reverse: true,
});
for await (const o of keyStream) {
latestId = IdInternal.fromBuffer<DiscoveryQueueId>(o);
latestId = IdInternal.fromBuffer<DiscoveryQueueId>(o as Buffer);
}
this.discoveryQueueIdGenerator =
discoveryUtils.createDiscoveryQueueIdGenerator(latestId);
Expand Down Expand Up @@ -208,8 +208,9 @@ class Discovery {
while (true) {
if (!(await this.queueIsEmpty())) {
for await (const o of this.discoveryQueueDb.createReadStream()) {
const vertexId = IdInternal.fromBuffer(o.key) as DiscoveryQueueId;
const data = o.value as Buffer;
const kv = (o as any)
const vertexId = IdInternal.fromBuffer(kv.key) as DiscoveryQueueId;
const data = kv.value as Buffer;
const vertex = await this.db.deserializeDecrypt<GestaltKey>(
data,
false,
Expand Down Expand Up @@ -438,7 +439,7 @@ class Discovery {
limit: 1,
});
for await (const o of keyStream) {
nextDiscoveryQueueId = IdInternal.fromBuffer<DiscoveryQueueId>(o);
nextDiscoveryQueueId = IdInternal.fromBuffer<DiscoveryQueueId>(o as Buffer);
}
if (nextDiscoveryQueueId == null) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ function isHostname(hostname: any): hostname is Hostname {

/**
* Ports must be numbers between 0 and 65535 inclusive
* If connect is true, then port must be a number between 1 and 65535 inclusive
*/
function isPort(port: any): port is Port {
function isPort(port: any, connect: boolean = false): port is Port {
if (typeof port !== 'number') return false;
if (port < 0 || port > 65535) return false;
if (connect && port === 0) return false;
return true;
}

Expand Down
Loading

0 comments on commit c94a166

Please sign in to comment.