匿名用户2021年11月30日
31阅读
所属分类、Web3、区块链
授权协议Readme

作品详情

LayrGettingStartedSeednodeandBatNodeGeneration

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.

DataOwners

Chancesarethatyouwilluploadfilestothenetwork.Thequestionis:Ifyouwanttouploadthefilefromonemachineandretrieveitfromanother,whatdoyoudo?

Toretrieveafile,youneedthefilename,theidsoftheshardcopiesonthenetwork,andthesecretkeyusedtoencrypt(anddecrypt)thefile'scontents.

Therefore,youcanretrieveyourfilefromanydeviceaslongas:

TheLayrnodeonthatdevicehasthemanifestfilecorrespondingtothefileyouwishtoretrieve.TheLayrnode's.envfilecontainstheprivatekeyyouusedtoencryptthefile'sdata

Inotherwords,whatdefinesyouastheownerofthedataispossessionofthemanifestfilethatwasgeneratedwhenyouuploadedthefiletothenetworkaswellastheprivatekeyyouusedtoencryptthatfile'sdata.

Ifyousimplyrunnodestart.jswithoutmanuallycreatinga.envfileandwithoutincludingaPRIVATE_KEYinthatfile,thenaprivatekeywillbegeneratedforyouautomatically.

Stellar

Layrusesthestellarnetworktoallowpeernodestopayforspaceonotherpeernodes'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--savetomakethecommandlinemorecolorful

Foryarn:

RunyarnlinktocreateasymboliclinkbetweenprojectdirectoryandexecutablecommandOpenanotherterminalwindow,runbatchainandyoushouldsee:Usage:batchain[options][command]Commands:sampleseethesamplenodesrunninghelp[cmd]displayhelpfor[cmd]Options:-h,--helpoutputusageinformation-l,--listviewyourlistofuploadedfilesinBatChainnetworkLocalCLIdemo2-uploadandauditafile

Firststepistomakesometemporarychangestoallowthecodetorunlocally

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.
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论