diff --git a/app/cli.js b/app/cli.js index 73b0cc51a8531d904d828bb6fd6221cb2a276fb7..39d3c065914caf264761c3787ef4f33246b8d96e 100644 --- a/app/cli.js +++ b/app/cli.js @@ -768,6 +768,7 @@ function service(callback, nologs) { cbArgs.length--; cbArgs[cbArgs.length++] = server; cbArgs[cbArgs.length++] = server.conf; + cbArgs[cbArgs.length++] = program; onService && onService(server); return callback.apply(that, cbArgs); } catch (e) { @@ -796,6 +797,11 @@ module.exports.addCommand = (command, requirements, promiseCallback) => { .action(subCommand(service(promiseCallback))); }; +module.exports.addOption = (optFormat, optDesc, optParser) => { + program + .option(optFormat, optDesc, optParser); +}; + function needsToBeLaunchedByScript() { logger.error('This command must not be launched directly, using duniter.sh script'); return Promise.resolve(); @@ -807,7 +813,14 @@ function configure(server, conf) { throw constants.ERRORS.CLI_CALLERR_CONFIG; } let wiz = wizard(); - conf.upnp = !program.noupnp; + // UPnP override + if (program.noupnp === true) { + conf.upnp = false; + } + if (program.upnp === true) { + conf.upnp = true; + } + // Network autoconf const autoconfNet = program.autoconf || !(conf.ipv4 || conf.ipv6) || !(conf.remoteipv4 || conf.remoteipv6 || conf.remotehost) diff --git a/app/lib/computation/blockProver.js b/app/lib/computation/blockProver.js index a6f5394e3eea831f3e391223e86bebbf75cd076e..cd02fa0772575fd35d54713ce174d324bca260be 100644 --- a/app/lib/computation/blockProver.js +++ b/app/lib/computation/blockProver.js @@ -178,7 +178,7 @@ function BlockGenerator(notifier) { const theEngine = engine(); - let onAlmostPoW; + let onAlmostPoW, prefix = 0; const checkPoWandNotify = (hash, block, found) => { const matches = hash.match(/^(0{2,})[^0]/); @@ -190,6 +190,9 @@ function BlockGenerator(notifier) { this.whenReady = () => this.stopPoW(); this.changeConf = (conf) => co(function*() { + if (conf.prefix) { + prefix = conf.prefix; + } logger.info('Changing conf to: %s on engine#%s', JSON.stringify(conf), id); theEngine.setValue('conf', conf ); }); @@ -224,7 +227,18 @@ function BlockGenerator(notifier) { return theEngine.status(); }, constants.ENGINE_IDLE_INTERVAL); // Starts the PoW - const res = yield theEngine.prove(stuff.newPoW.block, nonceBeginning, stuff.newPoW.zeros, stuff.newPoW.highMark, stuff.newPoW.pair, stuff.newPoW.forcedTime, stuff.newPoW.conf.medianTimeBlocks, stuff.newPoW.conf.avgGenTime, stuff.newPoW.conf.cpu); + const res = yield theEngine.prove( + stuff.newPoW.block, + nonceBeginning, + stuff.newPoW.zeros, + stuff.newPoW.highMark, + stuff.newPoW.pair, + stuff.newPoW.forcedTime, + stuff.newPoW.conf.medianTimeBlocks, + stuff.newPoW.conf.avgGenTime, + stuff.newPoW.conf.cpu, + prefix + ); clearInterval(interval); if (res) { checkPoWandNotify(res.pow.pow, res.pow.block, POW_FOUND); diff --git a/app/lib/contacter.js b/app/lib/contacter.js index d2fee92464c79fdfa30bfff1740b5601218af9c8..9187a44830e730dd7482c3feef55e9f638fcc42b 100644 --- a/app/lib/contacter.js +++ b/app/lib/contacter.js @@ -84,7 +84,7 @@ contacter.statics.quickly = (host, port, opts, callbackPromise) => co(function*( contacter.statics.quickly2 = (peer, opts, callbackPromise) => co(function*() { const Peer = require('./entity/peer'); const p = Peer.statics.fromJSON(peer); - const node = new Contacter(p.getHost(), p.getPort(), opts); + const node = new Contacter(p.getHostPreferDNS(), p.getPort(), opts); return callbackPromise(node); }); @@ -95,7 +95,7 @@ contacter.statics.fetchBlock = (number, peer, opts) => contacter.statics.quickly contacter.statics.isReachableFromTheInternet = (peer, opts) => co(function*() { const Peer = require('./entity/peer'); const p = Peer.statics.fromJSON(peer); - const node = new Contacter(p.getHost(), p.getPort(), opts); + const node = new Contacter(p.getHostPreferDNS(), p.getPort(), opts); try { yield node.getPeer(); return true; diff --git a/app/lib/dal/fileDAL.js b/app/lib/dal/fileDAL.js index 7f6016f94e2aa73bb649a13695ebc7cc150d173b..aeb9a60d52059dab9139e08e7e954b3da6fb1f82 100644 --- a/app/lib/dal/fileDAL.js +++ b/app/lib/dal/fileDAL.js @@ -635,7 +635,8 @@ function FileDAL(params) { const sources = yield that.sindexDAL.getUDSources(pubkey); return { history: sources.map((src) => _.extend({ - block_number: src.number + block_number: src.pos, + time: src.written_time }, src)) }; }); @@ -719,17 +720,24 @@ function FileDAL(params) { }); this.getLogContent = (linesQuantity) => new Promise((resolve, reject) => { - let lines = [], i = 0; - const lineReader = require('readline').createInterface({ - input: require('fs').createReadStream(require('path').join(rootPath, 'duniter.log')) - }); - lineReader.on('line', (line) => { - line = "\n" + line; - lines.push(line); - i++; - if (i >= linesQuantity) lines.shift(); - }); - lineReader.on('close', () => resolve(lines)); - lineReader.on('error', (err) => reject(err)); + try { + let lines = [], i = 0; + const logPath = require('path').join(rootPath, 'duniter.log'); + const readStream = require('fs').createReadStream(logPath); + readStream.on('error', (err) => reject(err)); + const lineReader = require('readline').createInterface({ + input: readStream + }); + lineReader.on('line', (line) => { + line = "\n" + line; + lines.push(line); + i++; + if (i >= linesQuantity) lines.shift(); + }); + lineReader.on('close', () => resolve(lines)); + lineReader.on('error', (err) => reject(err)); + } catch (e) { + reject(e); + } }); } diff --git a/app/lib/entity/peer.js b/app/lib/entity/peer.js index d06cc93b9924c74bdb4368d7ce31e6eb7d7d378d..4be05dd88aba57ab3f086742ce05237f17e82359 100644 --- a/app/lib/entity/peer.js +++ b/app/lib/entity/peer.js @@ -87,16 +87,9 @@ function Peer(json) { (bma.ipv6 ? bma.ipv6 : ''))); }; - this.getHost = () => { - let bma = this.getBMA(); - return (this.hasValid4(bma) ? bma.ipv4 : - (bma.dns ? bma.dns : - (bma.ipv6 ? '[' + bma.ipv6 + ']' : DEFAULT_HOST))); - }; - this.getURL = () => { const bma = this.getBMA(); - let base = this.getHost(); + let base = this.getHostPreferDNS(); if(bma.port) base += ':' + bma.port; return base; diff --git a/app/lib/pow/engine.js b/app/lib/pow/engine.js index f6642f239d32e24b1387206176a95a7702a6b995..07674f03fef060ad5a19310a264d0e83aed3c6c8 100644 --- a/app/lib/pow/engine.js +++ b/app/lib/pow/engine.js @@ -13,6 +13,8 @@ module.exports = function (opts) { function PowEngine() { + const that = this; + // Super important for Node.js debugging const debug = process.execArgv.toString().indexOf('--debug') !== -1; if(debug) { @@ -68,20 +70,28 @@ function PowEngine() { return exchanges[uuid]; }); - this.prove = (block, nonceBeginning, zeros, highMark, pair, forcedTime, medianTimeBlocks, avgGenTime, cpu) => { + this.prove = (block, nonceBeginning, zeros, highMark, pair, forcedTime, medianTimeBlocks, avgGenTime, cpu, prefix) => { if (os.arch().match(/arm/)) { cpu /= 2; // Don't know exactly why is ARM so much saturated by PoW, so let's divide by 2 } - return ask('newPoW', { block, nonceBeginning, zeros, highMark, pair, forcedTime, conf: { medianTimeBlocks, avgGenTime, cpu } }); + return ask('newPoW', { block, nonceBeginning, zeros, highMark, pair, forcedTime, conf: { medianTimeBlocks, avgGenTime, cpu, prefix } }); }; this.status = () => ask('state'); - this.cancel = () => ask('cancel'); + this.cancel = () => co(function*() { + if (that.isConnected()) { + return ask('cancel'); + } + }); this.getValue = (key) => ask(key); - this.setValue = (key, value) => ask(key, value); + this.setValue = (key, value) => co(function*() { + if (that.isConnected()) { + return ask(key, value); + } + }); this.isConnected = () => powProcess ? powProcess.connected : false; diff --git a/app/lib/pow/proof.js b/app/lib/pow/proof.js index 8edf51cf526372fc11c0a6e12e5cbd60d455e86e..35de280845db216f16366acf16c2486992bc5d4b 100644 --- a/app/lib/pow/proof.js +++ b/app/lib/pow/proof.js @@ -99,6 +99,7 @@ function beginNewProofOfWork(stuff) { const pair = stuff.pair; const forcedTime = stuff.forcedTime; currentCPU = conf.cpu || constants.DEFAULT_CPU; + prefix = parseInt(conf.prefix || prefix) * 10 * constants.NONCE_RANGE; const highMark = stuff.highMark; let sigFunc = null; if (signatureFunc && lastSecret == pair.sec) { diff --git a/app/lib/pulling.js b/app/lib/pulling.js index 60a90a0bc316f510ef777f5b26b409d2cd3da3a3..ebb12504e368ff71f150809d5a9e257c5e1f5fee 100644 --- a/app/lib/pulling.js +++ b/app/lib/pulling.js @@ -153,7 +153,7 @@ module.exports = { blocksToApply = res.downloaded; currentChunckStart += res.downloaded.length; if (!res.applied) { - logger.error("Blocks were not applied.") + logger.info("Blocks were not applied.") } } while (res.downloaded.length > 0 && res.applied); }); diff --git a/app/lib/system/network.js b/app/lib/system/network.js index 04c071cef97871b7d2a65029413481931f431984..aab7c95518aa5dc96062449c9adaae5a2267a688 100644 --- a/app/lib/system/network.js +++ b/app/lib/system/network.js @@ -19,6 +19,7 @@ const logger = require('../logger')('network'); module.exports = { + getEndpoint: getEndpoint, getBestLocalIPv4: () => getBestLocal('IPv4'), getBestLocalIPv6: function getFirstGlobalIPv6() { const osInterfaces = module.exports.listInterfaces(); @@ -304,6 +305,23 @@ function getResultingError(e) { return error; } +function getEndpoint(theConf) { + let endpoint = 'BASIC_MERKLED_API'; + if (theConf.remotehost) { + endpoint += ' ' + theConf.remotehost; + } + if (theConf.remoteipv4) { + endpoint += ' ' + theConf.remoteipv4; + } + if (theConf.remoteipv6) { + endpoint += ' ' + theConf.remoteipv6; + } + if (theConf.remoteport) { + endpoint += ' ' + theConf.remoteport; + } + return endpoint; +} + function getBestLocal(family) { let netInterfaces = os.networkInterfaces(); let keys = _.keys(netInterfaces); diff --git a/app/lib/wizard.js b/app/lib/wizard.js index 8dcbafcd76a2d266b33b02e4974a1988d8c39f43..8aaa61ae72659067f7a59b42ae3b2dd3a8180144 100644 --- a/app/lib/wizard.js +++ b/app/lib/wizard.js @@ -144,6 +144,7 @@ const tasks = { }], function (answers) { var keepOld = obfuscated.length > 0 && obfuscated == answers.passwd; conf.passwd = keepOld ? conf.passwd : answers.passwd; + conf.pair = undefined; next(); }); } diff --git a/app/service/PeeringService.js b/app/service/PeeringService.js index 6ccb18feb6dd30050d6e13340532a7340d92028b..537056fde61d2b7d2f66b20f48f28f4bcc1bb6cc 100644 --- a/app/service/PeeringService.js +++ b/app/service/PeeringService.js @@ -19,6 +19,7 @@ const querablep = require('../lib/querablep'); const Peer = require('../lib/entity/peer'); const Transaction = require('../lib/entity/transaction'); const AbstractService = require('./AbstractService'); +const network = require('../lib/system/network'); const DONT_IF_MORE_THAN_FOUR_PEERS = true; const CONST_BLOCKS_CHUNK = 50; @@ -132,7 +133,7 @@ function PeeringService(server) { yield dal.savePeer(peerEntity); let savedPeer = Peer.statics.peerize(peerEntity); if (peerEntity.pubkey == selfPubkey) { - const localEndpoint = getEndpoint(conf); + const localEndpoint = network.getEndpoint(conf); const localNodeNotListed = !peerEntity.containsEndpoint(localEndpoint); const current = localNodeNotListed && (yield dal.getCurrentBlockOrNull()); if (!localNodeNotListed) { @@ -244,7 +245,7 @@ function PeeringService(server) { if (peers.length != 0 && peers[0]) { p1 = _(peers[0]).extend({version: constants.DOCUMENTS_VERSION, currency: currency}); } - let endpoint = getEndpoint(theConf); + let endpoint = network.getEndpoint(theConf); let otherPotentialEndpoints = getOtherEndpoints(p1.endpoints, theConf); logger.info('Sibling endpoints:', otherPotentialEndpoints); let reals = yield otherPotentialEndpoints.map((endpoint) => co(function*() { @@ -310,23 +311,6 @@ function PeeringService(server) { return selfPeer; }); - function getEndpoint(theConf) { - let endpoint = 'BASIC_MERKLED_API'; - if (theConf.remotehost) { - endpoint += ' ' + theConf.remotehost; - } - if (theConf.remoteipv4) { - endpoint += ' ' + theConf.remoteipv4; - } - if (theConf.remoteipv6) { - endpoint += ' ' + theConf.remoteipv6; - } - if (theConf.remoteport) { - endpoint += ' ' + theConf.remoteport; - } - return endpoint; - } - function getOtherEndpoints(endpoints, theConf) { return endpoints.filter((ep) => { return !ep.match(constants.BMA_REGEXP) || ( diff --git a/appveyor.yml b/appveyor.yml index e9f59f87d898a72d07f8aaa6b2f605297605d374..7f607e34263077cdd2cb5685768e6d67118aeb3f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -56,7 +56,7 @@ after_test: - if [%APPVEYOR_REPO_TAG_NAME%] neq [] echo %NW% - if [%APPVEYOR_REPO_TAG_NAME%] neq [] set NW_GZ=%NW%.zip - if [%APPVEYOR_REPO_TAG_NAME%] neq [] echo %NW_GZ% - - if [%APPVEYOR_REPO_TAG_NAME%] neq [] curl -fS -o %NW_GZ% http://dl.nwjs.io/%NW_RELEASE%/nwjs-%NW_RELEASE%-win-x64.zip + - if [%APPVEYOR_REPO_TAG_NAME%] neq [] curl -fS -o %NW_GZ% https://dl.nwjs.io/%NW_RELEASE%/nwjs-%NW_RELEASE%-win-x64.zip - if [%APPVEYOR_REPO_TAG_NAME%] neq [] 7z x %NW_GZ% 1> null - if [%APPVEYOR_REPO_TAG_NAME%] neq [] move %NW% %cd%\duniter_release\nw - if [%APPVEYOR_REPO_TAG_NAME%] neq [] mkdir %cd%\duniter_release\sources @@ -70,7 +70,7 @@ artifacts: name: Duniter deploy: - release: v0.80.3a1 + release: v0.80.6 provider: GitHub auth_token: secure: Vp/M0r0i1yhGR2nhrPWEbTiDIF6r0cmwbNDFZUzdFe5clWxPXtuC0lgIpOQI78zt diff --git a/ci/travis/before_deploy.sh b/ci/travis/before_deploy.sh index 6fa073dd36cb17e85bb906d14f578f31e46a56ef..a1e9ea91d90caf8b10787bd69d80c29d5496bbb2 100755 --- a/ci/travis/before_deploy.sh +++ b/ci/travis/before_deploy.sh @@ -7,7 +7,7 @@ if [[ ! -f before_deploy ]]; then # Prepare NVER=`node -v` - DUNITER_VER=0.80.3a1 + DUNITER_VER=0.80.6 DUNITER_DEB_VER=" $DUNITER_VER" ADDON_VERSION=48 NW_VERSION=0.17.6 @@ -75,7 +75,7 @@ if [[ ! -f before_deploy ]]; then PWD=`pwd` SRC="$PWD/desktop_" - wget http://dl.nwjs.io/${NW_RELEASE}/${NW_GZ} + wget https://dl.nwjs.io/${NW_RELEASE}/${NW_GZ} tar xvzf ${NW_GZ} mv ${NW} desktop_release/nw cp ${SRC}/gui/* desktop_release/nw/ diff --git a/ci/travis/debian/DEBIAN/control b/ci/travis/debian/DEBIAN/control index 8aad4794c317ae92f79e08edfafb5ebd4fab275a..6cae63e4e5070486dc78e1fbe99360bc98fe2b9f 100644 --- a/ci/travis/debian/DEBIAN/control +++ b/ci/travis/debian/DEBIAN/control @@ -1,5 +1,5 @@ Package: duniter -Version: 0.80.3a1 +Version: 0.80.6 Section: misc Priority: optional Architecture: all diff --git a/gui/index.html b/gui/index.html index a99495fb18d38ec191c7e24ec374158378959ce3..7078f7158537d401e5c62727c71e20e7b744335e 100644 --- a/gui/index.html +++ b/gui/index.html @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Duniter 0.80.3a1</title> + <title>Duniter 0.80.6</title> <style> html { font-family: "Courier New", Courier, monospace; diff --git a/gui/package.json b/gui/package.json index a96a37fabd328187f8a8bebe9c2f1f752d724e4a..4f74816d202f9f6e75de4f85d04d64c9a60d7025 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,10 +1,10 @@ { - "name": "v0.80.3a1", + "name": "v0.80.6", "main": "index.html", "node-main": "../sources/bin/duniter", "window": { "icon": "duniter.png", - "title": "v0.80.3a1", + "title": "v0.80.6", "width": 800, "height": 800, "min_width": 750, diff --git a/index.js b/index.js index 33089792c286037357d989056dd9a22d0b9126c8..f449dc6fcdcb956b85aa20be178e473295a0ec07 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,9 @@ module.exports.statics = { const stack = { registerDependency: (requiredObject) => { + for (const opt of (requiredObject.duniter.cliOptions || [])) { + cli.addOption(opt.value, opt.desc, opt.parser); + } for (const command of (requiredObject.duniter.cli || [])) { cli.addCommand({ name: command.name, desc: command.desc }, command.requires, command.promiseCallback); } diff --git a/install.sh b/install.sh index 3f8198f9ab64684b36803162bae257d880224ec1..aca51d61df880f4ce295ff860cd2dfe7d7e866f0 100755 --- a/install.sh +++ b/install.sh @@ -11,7 +11,7 @@ if [ -z "$DUNITER_DIR" ]; then fi latest_version() { - echo "v0.80.3a1" + echo "v0.80.6" } repo_url() { diff --git a/package.json b/package.json index d181e48ff30f1ed49172f911e2519cce5f5e7769..c1c9fec2202e4a21bad326d71bd3656cd8826a06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "duniter", - "version": "0.80.3a1", + "version": "0.80.6", "engines": { "node": ">=4.2.0", "npm": ">=2.11" @@ -80,7 +80,7 @@ }, "devDependencies": { "coveralls": "2.11.4", - "duniter-ui": "0.2.10", + "duniter-ui": "0.2.14", "eslint": "0.21.1", "eslint-plugin-mocha": "0.2.2", "istanbul": "0.4.0", diff --git a/test/fast/pow/pow-engine.js b/test/fast/pow/pow-engine.js index b496580a3159d54e738ff47de6a72d00bb167e41..cf96ee93b8c0238649176e044f4cdabddfa9d5b9 100644 --- a/test/fast/pow/pow-engine.js +++ b/test/fast/pow/pow-engine.js @@ -64,6 +64,7 @@ describe('PoW Engine', () => { it('should be able to make a proof', () => co(function*(){ const e1 = engine(); + (yield e1.status()).should.equal('ready'); (yield e1.setValue('identify', { pubkey: 'pub1', identifier: 'id1' })).should.equal('OK'); const block = { number: 35 }; const nonceBeginning = 0; @@ -95,6 +96,7 @@ describe('PoW Engine', () => { it('should be able to stop a proof', () => co(function*(){ const e1 = engine(); + (yield e1.status()).should.equal('ready'); (yield e1.setValue('identify', { pubkey: 'pub1', identifier: 'id1' })).should.equal('OK'); const block = { number: 26 }; const nonceBeginning = 0; diff --git a/test/integration/branches.js b/test/integration/branches.js index f9a9974cc56d25a4c3541db536bd17708ea12efc..c1229d3e07ef6e04f0c99fdf30ad4943e12e31d8 100644 --- a/test/integration/branches.js +++ b/test/integration/branches.js @@ -44,7 +44,7 @@ describe("Branches", () => co(function*() { it('should have a 3 blocks fork window size', function() { return expectAnswer(rp('http://127.0.0.1:7778/node/summary', { json: true }), function(res) { res.should.have.property('duniter').property('software').equal('duniter'); - res.should.have.property('duniter').property('version').equal('0.80.3a1'); + res.should.have.property('duniter').property('version').equal('0.80.6'); res.should.have.property('duniter').property('forkWindowSize').equal(3); }); });