decentralized-internet
Version:
An NPM library of programs to create decentralized web and distributed computing projects
1 lines • 437 B
JavaScript
;const join=function(s){if(!s)throw new Error("Peer is missing.");return(t,e)=>{const o=t.body.host,r=t.body.port;return o&&r?o===s.self.host&&r===s.self.port?e.sendStatus(200):"lonely"!==s.status()?e.sendStatus(200):void s.remote({host:o,port:r}).run("find-successor",{id:s.self.id},(t,o)=>{if(t)return e.sendStatus(500);s.setPredecessor(void 0),s.setSuccessor(o),e.sendStatus(200)}):e.sendStatus(400)}};module.exports=join;