Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25 from WilfredTA/nodeAliveTest
Browse files Browse the repository at this point in the history
getClosestBatNodeToShard filters out nodes w/ same host and port then…
  • Loading branch information
WilfredTA authored Mar 29, 2018
2 parents 0954173 + 4e1e73d commit b236d26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions batnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
})
})
}
Expand Down
1 change: 1 addition & 0 deletions seednode/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ publicIp.v4().then(ip => {


batNode.createServer(1756, ip, nodeConnectionCallback)
console.log(kademliaNode.router)

})
1 change: 1 addition & 0 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})


Expand Down

0 comments on commit b236d26

Please sign in to comment.