decentralized-internet
Version:
An NPM library of programs to create decentralized web and distributed computing projects
1 lines • 1.26 kB
JavaScript
;const knock=require("knockat"),getDockWorker=require("./getDockWorker"),getId=require("../../lib/getId"),remote=require("../../lib/remote"),Application=function(t){this.containerName=void 0,this.id=void 0,this.port=t.port,this.serviceInterval=t.serviceInterval};Application.prototype.start=function(t){getDockWorker((o,e)=>{if(o)return t(o);const r="thenativeweb-p2p-test-"+this.port;e.startContainer({image:"thenativeweb/p2p-test",name:r,env:{HOST:e.options.host,PORT:this.port,SERVICE_INTERVAL:this.serviceInterval},ports:[{container:this.port,host:this.port}]},o=>{if(o)return t(o);this.containerName=r,this.id=getId(e.options.host+":"+this.port),knock.at(e.options.host,this.port,t)})})},Application.prototype.join=function(t,o){getDockWorker((e,r)=>{if(e)return o(e);remote(r.options.host,t.port).run("self",(t,e)=>{if(t)return o(t);remote(r.options.host,this.port).run("join",e,o)})})},Application.prototype.stop=function(t){getDockWorker((o,e)=>{if(o)return t(o);e.stopContainer(this.containerName,o=>{if(o)return t(o);t(null)})})},["self","successor","predecessor","status"].forEach(t=>{Application.prototype[t]=function(o){getDockWorker((e,r)=>{if(e)return o(e);remote(r.options.host,this.port).run(t,o)})}}),module.exports=Application;