Skip to content

Commit

Permalink
fix: fix nodesGetAll Handler and add a jest to test the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 26, 2023
1 parent 07c3037 commit 5c5a467
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/client/handlers/NodesGetAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,18 @@ class NodesGetAll extends ServerHandler<
): AsyncGenerator<ClientRPCResponseResult<NodesGetMessage>> {
if (ctx.signal.aborted) throw ctx.signal.reason;
const { nodeGraph, keyRing } = this.container;
for await (const bucket of nodeGraph.getBuckets()) {
let index;
for (const id of Object.keys(bucket)) {
const encodedId = nodesUtils.encodeNodeId(
IdInternal.fromString<NodeId>(id),
);
for await (const [index, bucket] of nodeGraph.getBuckets()) {
for (const [id, info] of bucket) {
const encodedId = nodesUtils.encodeNodeId(keyRing.getNodeId());
// For every node in every bucket, add it to our message
if (!index) {
index = nodesUtils.bucketIndex(
keyRing.getNodeId(),
IdInternal.fromString<NodeId>(id),
);
if (ctx.signal.aborted) {
throw ctx.signal.reason;
}
if (ctx.signal.aborted) throw ctx.signal.reason;
yield {
bucketIndex: index,
nodeIdEncoded: encodedId,
host: bucket[id].address.host,
port: bucket[id].address.port,
host: info.address.host,
port: info.address.port,
};
}
}
Expand Down

0 comments on commit 5c5a467

Please sign in to comment.