diff --git a/modules/ethereumNode.js b/modules/ethereumNode.js index b59fae8e1..196d7421b 100644 --- a/modules/ethereumNode.js +++ b/modules/ethereumNode.js @@ -41,8 +41,6 @@ class EthereumNode extends EventEmitter { this._type = null; this._network = null; - getNodePath(); - this._socket = Sockets.get('node-ipc', Settings.rpcMode); this.on('data', _.bind(this._logNodeData, this)); @@ -329,13 +327,15 @@ class EthereumNode extends EventEmitter { this._network = network; this._type = nodeType; - const binPath = getNodePath(nodeType); - - log.debug(`Start node using ${binPath}`); - return new Q((resolve, reject) => { - this.__startProcess(nodeType, network, binPath) - .then(resolve, reject); + getNodePath.probe() + .then(() => { + const binPath = getNodePath.query(nodeType); + log.debug(`Start node using ${binPath}`); + + this.__startProcess(nodeType, network, binPath) + .then(resolve, reject); + }); }); } diff --git a/modules/getNodePath.js b/modules/getNodePath.js index e8d422294..f89909354 100644 --- a/modules/getNodePath.js +++ b/modules/getNodePath.js @@ -6,10 +6,10 @@ Gets the right Node path @module getNodePath */ -const path = require('path'); const fs = require('fs'); -const exec = require('child_process').exec; +const path = require('path'); const Q = require('bluebird'); +const exec = require('child_process').exec; const cmpVer = require('semver-compare'); const binaryPath = path.resolve(__dirname + '/../nodes'); const log = require('./utils/logger').create('getNodePath'); @@ -73,71 +73,84 @@ function compareNodes() { } -/** - * Get paths of all nodes, returns system or bundled path depending on the latest version - * - * @param {String} type the type of node (i.e. 'geth', 'eth') - */ -module.exports = function(type) { - if (resolvedPaths[type]) - return resolvedPaths[type]; - - return new Q((resolve, reject) => { - if(Settings.inProductionMode) { - var binPath = binaryPath.replace('nodes','node').replace('app.asar/','').replace('app.asar\\',''); - - if(process.platform === 'darwin') { - binPath = path.resolve(binPath.replace('/node', '/../Frameworks/node')); - } +module.exports = { + /** + * Returns path of node + * linux and mac only: returns system or bundled path depending on the latest version + * + * @param {String} type the type of node (i.e. 'geth', 'eth') + */ + query: (type) => { + return resolvedPaths[type]; + }, + /** + * Evaluates node paths + * - Enumerates bundled nodes + * linux and mac only: + * - probes for system installation of nodes + * - compares the versions of bundled and system nodes (preferes latest version) + */ + probe: () => { + return new Q((resolve, reject) => { + if(Settings.inProductionMode) { + var binPath = binaryPath.replace('nodes','node').replace('app.asar/','').replace('app.asar\\',''); + + if(process.platform === 'darwin') { + binPath = path.resolve(binPath.replace('/node', '/../Frameworks/node')); + } - fs.readdirSync(binPath).forEach((type) => { - var nodePath = binPath + '/' + type + '/' + type; + fs.readdirSync(binPath).forEach((type) => { + var nodePath = binPath + '/' + type + '/' + type; - if(process.platform === 'win32') { - nodePath = nodePath.replace(/\/+/,'\\'); - nodePath += '.exe'; - } + if(process.platform === 'win32') { + nodePath = nodePath.replace(/\/+/,'\\'); + nodePath += '.exe'; + } - paths[type] = {}; - paths[type][nodePath] = null; - }); - } else { - fs.readdirSync('nodes/').forEach((type) => { - if (fs.statSync('nodes/' + type).isDirectory()) { - var nodePath = path.resolve('nodes/' + type + '/' + process.platform +'-'+ process.arch + '/' + type); paths[type] = {}; paths[type][nodePath] = null; - } - }); - } - - if (process.platform === 'linux' || process.platform === 'darwin') { - var getPathProms = [], - getVersionProms = []; - - for (let type in paths) { - getPathProms.push(getSystemPath(type) - .then((data) => { - paths[type][data.match(/(\/\w+)+/)[0]] = null; - })); + }); + } else { + fs.readdirSync('nodes/').forEach((type) => { + if (fs.statSync('nodes/' + type).isDirectory()) { + var nodePath = path.resolve('nodes/' + type + '/' + process.platform +'-'+ process.arch + '/' + type); + paths[type] = {}; + paths[type][nodePath] = null; + } + }); } + + if (process.platform === 'linux' || process.platform === 'darwin') { + var getPathProms = [], + getVersionProms = []; - Q.all(getPathProms).then(() => { for (let type in paths) { - for (let path in paths[type]) { - getVersionProms.push(getVersion(type, path) - .then((data)=>{ - var version = data.match(/[\d.]+/)[0]; - paths[type][path] = version; - })); - } + getPathProms.push(getSystemPath(type) + .then((data) => { + paths[type][data.match(/(\/\w+)+/)[0]] = null; + })); } - }).then(() => { - Q.all(getVersionProms).then(() => { - compareNodes(); - log.debug('Available backends: %j', paths); + + Q.all(getPathProms).then(() => { + for (let type in paths) { + for (let path in paths[type]) { + getVersionProms.push(getVersion(type, path) + .then((data)=>{ + var version = data.match(/[\d.]+/)[0]; + paths[type][path] = version; + })); + } + } + }).then(() => { + Q.all(getVersionProms).then(() => { + compareNodes(); + log.debug('Available backends: %j', paths); + }) + .then(resolve, reject); }) - }); - } - }); + } else { + resolve(); + } + }); + } }