Watch 268

Watch 268 Star 2,518

Star 2,518 Fork 390 LiskHQ / lisk Code Issues 78 Pull requests 4 Projects 4 Insights Permalink Browse files add parameter to sync with specified nodes Provide option to sync with specified nodes and choose only them as peers. closes #296 Loading branch information ... Jan 13, 2017 MaciejBaj committed 1 parent a092812 commit ec174d4485e261cfe271592c31ac328101f9ca9e Unified Split Showing 5 changed files with 101 additions and 48 deletions. +17 −10 app.js +3 −0 config.json +16 −0 helpers/parametersReader.js +62 −38 modules/loader.js +3 −0 test/config.json Show comments View 27 app.js @@ -2,6 +2,7 @@ var async = require ( ' async ' ); var checkIpInList = require ( ' ./helpers/checkIpInList.js ' ); var parametersReader = require ( ' ./helpers/parametersReader.js ' ); var extend = require ( ' extend ' ); var fs = require ( ' fs ' ); var genesisblock = require ( ' ./genesisBlock.json ' ); @@ -29,7 +30,8 @@ program . option ( ' -c, --config <path> ' , ' config file path ' ) . option ( ' -p, --port <port> ' , ' listening port number ' ) . option ( ' -a, --address <ip> ' , ' listening host name or ip ' ) . option ( ' -x, --peers [peers...] ' , ' peers list ' ) . option ( ' -x, --peers [peers...] ' , ' peers list to seed from ' ) . option ( ' -y, --sync [peers...] ' , ' peers list to sync with ' ) . option ( ' -l, --log <level> ' , ' log level ' ) . option ( ' -s, --snapshot <round> ' , ' verify snapshot ' ) . parse ( process . argv ); @@ -45,17 +47,22 @@ if (program.address) { } if ( program . peers ) { if ( typeof program . peers === ' string ' ) { appConfig . peers . list = program . peers . split ( ' , ' ). map ( function ( peer ) { peer = peer . split ( ' : ' ); appConfig . peers . list = parametersReader . convertToAddressList ( program . peers , appConfig . port ); } if ( program . sync ) { appConfig . syncPeers = { list : parametersReader . convertToAddressList ( program . sync , appConfig . port ). map ( function ( syncPeer ) { return { ip : peer . shift (), port : peer . shift () || appConfig . port ip : syncPeer . ip , port : syncPeer . port , version : appConfig . version , state : 2 , broadhash : appConfig . nethash , height : 1 }; }); } else { appConfig . peers . list = []; } }) }; } if ( program . log ) { Show comments View 3 config.json @@ -88,6 +88,9 @@ " timeout " : 5000 } }, " syncPeers " : { " list " : [] }, " broadcasts " : { " broadcastInterval " : 5000 , " broadcastLimit " : 20 , Show comments View 16 helpers/parametersReader.js @@ -0,0 +1,16 @@ ' use strict ' ; var parametersReader = {}; parametersReader . convertToAddressList = function ( addresses , optPort ) { return typeof addresses !== ' string ' ? [] : addresses . split ( ' , ' ). map ( function ( address ) { address = address . split ( ' : ' ); return { ip : address . shift (), port : address . shift () || optPort }; }); }; module . exports = parametersReader; Show comments View 100 modules/loader.js @@ -622,49 +622,73 @@ Loader.prototype.getNetwork = function (cb) { if ( __private . network . height > 0 && Math . abs ( __private . network . height - modules . blocks . getLastBlock (). height ) === 1 ) { return setImmediate (cb, null , __private . network ); } async . waterfall ([ function ( waterCb ) { modules . transport . getFromRandomPeer ({ api : ' /list ' , method : ' GET ' }, function ( err , res ) { if (err) { return setImmediate (waterCb, err); } else { return setImmediate (waterCb, null , res); } }); }, function ( res , waterCb ) { library . schema . validate ( res . body , schema .