From 4e1e73d7214b72afff84c0e3621e3f1ff0654169 Mon Sep 17 00:00:00 2001 From: Wilfred Tannr Allard Date: Thu, 29 Mar 2018 15:42:37 -0400 Subject: [PATCH] getClosestBatNodeToShard filters out nodes w/ same host and port then checks whether they are alive before contacting --- batnode.js | 13 ++++++++++--- seednode/seed.js | 1 + start.js | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/batnode.js b/batnode.js index 1ca2081..74d13e0 100644 --- a/batnode.js +++ b/batnode.js @@ -106,13 +106,20 @@ class BatNode { this.kadenceNode.iterativeFindNode(shardId, (err, res) => { let i = 0 let targetKadNode = res[0]; // res is an array of these tuples: [id, {hostname, port}] - while (targetKadNode[1].hostname === this.kadenceNode.contact.hostname) { // change to identity and re-test + while (targetKadNode[1].hostname === this.kadenceNode.contact.hostname && + targetKadNode[1].port === this.kadenceNode.contact.port) { // change to identity and re-test i += 1 targetKadNode = res[i] } - this.kadenceNode.getOtherBatNodeContact(targetKadNode, (error, result) => { // res is contact info of batnode {port, host} - callback(result) + this.kadenceNode.ping(targetKadNode, (error) => { // Checks whether target kad node is alive + if (error) { + this.getClosestBatNodeToShard(shardId, callback) // if it's offline, re-calls method. This works because sendign RPCs to disconnected nodes + } else { // will automatically remove the dead node's contact info from sending node's routing table + this.kadenceNode.getOtherBatNodeContact(targetKadNode, (error2, result) => { // res is contact info of batnode {port, host} + callback(result) + }) + } }) }) } diff --git a/seednode/seed.js b/seednode/seed.js index e9607ae..28b7d15 100644 --- a/seednode/seed.js +++ b/seednode/seed.js @@ -67,5 +67,6 @@ publicIp.v4().then(ip => { batNode.createServer(1756, ip, nodeConnectionCallback) + console.log(kademliaNode.router) }) diff --git a/start.js b/start.js index 91c9ec6..944c240 100644 --- a/start.js +++ b/start.js @@ -85,6 +85,7 @@ publicIp.v4().then(ip => { kademliaNode.join(seed, () => { console.log('you have joined the network! Ready to accept commands from the CLI!') + console.log(kademliaNode.router) })