UNPKG

decentralized-internet

Version:

An NPM library of programs to create decentralized web and distributed computing projects

1 lines 423 B
"use strict";const random=require("random-int"),Endpoint=require("../Endpoint"),hex=require("../hex"),fixFingers=function(e){if(!e)throw new Error("Peer is missing.");return(r,n)=>{const i=random(2,160),s=hex.add(e.self.id,hex.pow2x(i-1));e.remote(e.self).run("find-successor",{id:s},(r,s)=>{if(r)return n.sendStatus(500);e.fingers[i]=new Endpoint({host:s.host,port:s.port}),n.sendStatus(200)})}};module.exports=fixFingers;