UNPKG

decentralized-internet

Version:

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

1 lines 847 B
"use strict";const _=require("lodash"),async=require("async"),flaschenpost=require("flaschenpost"),logger=flaschenpost.getLogger(),isRing=function(e,s){const r=[],n=function(e){return e?_.findIndex(r,function(s){return s.self.host===e.host&&s.self.port===e.port}):-1};logger.info("Verifying ring..."),async.eachSeries(e,(e,s)=>{async.series({self:s=>{e.self(s)},successor:s=>{e.successor(s)},predecessor:s=>{e.predecessor(s)}},(e,n)=>{if(e)return s(e);r.push(n),s(null)})},o=>{if(o)return s(o);r.forEach(e=>{e.successor=n(e.successor),e.predecessor=n(e.predecessor)});const c=_.uniq(_.pluck(r,"predecessor").sort(),!0),t=_.uniq(_.pluck(r,"successor").sort(),!0);return 0!==c[0]||c.length!==e.length?s(new Error("Predecessors are broken.")):0!==t[0]||t.length!==e.length?s(new Error("Successors are broken.")):void s(null)})};module.exports=isRing;