Layrisanalphaversionsoftwarethataimstoimplementatransaction-basedp2pdistributedfilestoragesystem.
EachLayrpeerhastwonodes:aKademlianodethatisresponsibleformanagingcontactinformationbetweennodesaswellasaddressingthelocationsoffilesinthenetwork,andaBatNodewhichisresponsibleforhandlingfiledatatransfer,retrieval,andauditing.
Initscurrentstate,anNATtraversalstrategyinwhichaLayrpeer'sKademlianodebrokersconnectionsbetweentwoLayrnodes'BatNodesusingTCPhole-punchingissomethingwearecurrentlyworkingon.Ourcasestudy(comingsoon)willdetailourapproachtoNATtraversal.
WedefineaLayrnodeasaBatNode-KademliaNodepairrunningonadevice.
ALayrnetworkneedsatleastoneseednoderunningsothatothernodescanjointhenetwork.So,beforeanythingelse,youshouldconstructaseednode.AseednodeisnotaLayrnodebecauseitdoesnotincludeaBatNode:itisanindividualKademlianode.
TogetaLayrnodeupandrunningonaserver,sshintotheserverandforkthisrepo.Youshouldthencdintotherepoandrunyarninstall.Afterrunningyarninstall,cdintotherootdirectoryoftheprojectandrunyarnlink.ThiswillallowyoutousetheCLI.
Tosetupaseednodespecifically,updatetheconstants.jsfiletomatchyourserver'shostinformation.Then,cdintotheseednodedirectoryandrunnodeseed.js.Furthernodesthatwishtojoinyournetworkwillneedthisupdatedversionofconstants.jsinordertojoinyournetwork.
ForLayrnodesthatwillbeparticipatingasdatahostsand/ordataowners,sshintoanewserver,cdintotherootdirectoryoftheproject,andrunyarninstallandthenyarnlink.Afteryoudothat,runnodestart.js.Inasecondterminalwindow,sshintothesameserverandcdintotherepo'srootdirectoryandrunbatchain-hforalistofcommandsyoucanuse.
DataOwnersChancesarethatyouwilluploadfilestothenetwork.Thequestionis:Ifyouwanttouploadthefilefromonemachineandretrieveitfromanother,whatdoyoudo?
Toretrieveafile,youneedthefilename,theidsoftheshardcopiesonthenetwork,andthesecretkeyusedtoencrypt(anddecrypt)thefile'scontents.
Therefore,youcanretrieveyourfilefromanydeviceaslongas:
TheLayrnodeonthatdevicehasthemanifestfilecorrespondingtothefileyouwishtoretrieve.TheLayrnode's.envfilecontainstheprivatekeyyouusedtoencryptthefile'sdataInotherwords,whatdefinesyouastheownerofthedataispossessionofthemanifestfilethatwasgeneratedwhenyouuploadedthefiletothenetworkaswellastheprivatekeyyouusedtoencryptthatfile'sdata.
Ifyousimplyrunnodestart.jswithoutmanuallycreatinga.envfileandwithoutincludingaPRIVATE_KEYinthatfile,thenaprivatekeywillbegeneratedforyouautomatically.
StellarLayrusesthestellarnetworktoallowpeernodestopayforspaceonotherpeernodes'devices.Initscurrentstate,Layrisaproof-of-conceptprojectandthereforeusesStellar'stest-net.TheStellartest-netprovidestest-currencyfortransactions(10,000lumensperaccount).
Whenanodeislaunchedwithnodestart.js,asecret.envfileiscreatedforyou.Thisfilewillcontainyourprivatekeyfordecryptingandencryptingfiledatathatyouuploadtothenetwork,aswellasyourStellaraccountinformation.Ifyoualreadyhaveastellaraccount,youshouldcreatethe.envfilemanuallyandincludeyourstellarpublicidlikeso:STELLAR_ACCOUNT_ID=xxxaswellasyourstellarsecretkey:STELLAR_SECRET=xxx
Botharerequiredfortransactionstoworkproperly.
DemosNote:Fornpm:
Runnpminstall-gbeforerunninganybatchainoptionorcommand,makesuretoNeedtorunnpminstall-gwhenmakingbinchangesIf"chalk"isnotworkingforyou,runnpminstallchalk--savetomakethecommandlinemorecolorfulForyarn:
RunyarnlinktocreateasymboliclinkbetweenprojectdirectoryandexecutablecommandOpenanotherterminalwindow,runbatchainandyoushouldsee:Usage:batchain[options][command]Commands:sampleseethesamplenodesrunninghelp[cmd]displayhelpfor[cmd]Options:-h,--helpoutputusageinformation-l,--listviewyourlistofuploadedfilesinBatChainnetworkLocalCLIdemo2-uploadandauditafileFirststepistomakesometemporarychangestoallowthecodetorunlocally
Uncommenttheseednodeinformationandcommentouttheremoteseednodeinfo.Thefileshouldenduplookinglikethis:
//Fornetworktesting://exports.SEED_NODE=['a678ed17938527be1383388004dbf84246505dbd',{hostname:'167.99.2.1',port:80}];//exports.CLI_SERVER={host:'localhost',port:1800};//exports.BATNODE_SERVER_PORT=1900;//exports.KADNODE_PORT=80;//Forlocaltestingexports.SEED_NODE=['a678ed17938527be1383388004dbf84246505dbd',{hostname:'localhost',port:1338}]exports.BASELINE_REDUNDANCY=3;Next,changethislineofcodeinthewhileloop
getClosestBatNodeToShard(shardId,callback){this.kadenceNode.iterativeFindNode(shardId,(err,res)=>{leti=0lettargetKadNode=res[0];//resisanarrayofthesetuples:[id,{hostname,port}]while(targetKadNode[1].hostname===this.kadenceNode.contact.hostname&&(targetKadNode[1].port===this.kadenceNode.contact.port){tothis.
//while(targetKadNode[1].hostname===this.kadenceNode.contact.hostname&&while(targetKadNode[1].port===this.kadenceNode.contact.port){Nowwecanproceedwiththedemo.
cdinto/auditdirectoryIfyouhaven'talready,runyarnlinktocreateasymboliclinkbetweenprojectdirectoryandexecutablecommand.Thisonlyneedstobedoneonce.Open3additionalterminalwindowsortabsthatarealsointhe/auditdirectoryInthefirstterminal,cdintoserverdirectory.Runrm/dbfirstandthenrunnodenode.jsInthesecondterminal,cdintoserver2directory.Runrm/dbfirstandthenrunnodenode.jsInthethirdterminal,cdintoclientdirectory.Runrm/dbfirstandthenrunnodenode.js.ThisbootsuptheCLIserverwhichwilllistenforCLIcommands.WaitforamessagetologoutsayingtheCLIisreadybeforeissuinganycommands.Inthefourthterminal,cdintoclientaswell.HerewecanissuebatchainCLIcommands.Thereshouldbeaexamplefileinthepersonaldirectory,sorunbatchain-u./personal/example.txt.Waitafewsecondsforthe24orsoshardfilestobewrittentoserverandserver2/hostdirectories.Killtheprocessmanually(Control-C)andrunbatchain-a./manifest/$MANIFESTNAME.batchain.Replace$MANIFESTNAMEwiththemanifestfilenamegeneratedonclient/manifestdirectory.
评论