diff --git a/lib/crypto/ec-elliptic.js b/lib/crypto/ec-elliptic.js index 757bedb2..9d96c45a 100644 --- a/lib/crypto/ec-elliptic.js +++ b/lib/crypto/ec-elliptic.js @@ -20,6 +20,13 @@ var BN = require('bn.js'); var ec = exports; +/** + * Whether we're using native bindings. + * @const {Boolean} + */ + +ec.binding = false; + /** * Generate a private key. * @returns {Buffer} Private key. diff --git a/lib/crypto/ec-secp256k1.js b/lib/crypto/ec-secp256k1.js index afa68913..fc73e150 100644 --- a/lib/crypto/ec-secp256k1.js +++ b/lib/crypto/ec-secp256k1.js @@ -31,6 +31,13 @@ var HALF_ORDER = new Buffer( var ec = exports; +/** + * Whether we're using native bindings. + * @const {Boolean} + */ + +ec.binding = true; + /** * Generate a private key. * @returns {Buffer} Private key. diff --git a/lib/node/node.js b/lib/node/node.js index 36f34ab9..f0856d2d 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -15,6 +15,8 @@ var Network = require('../protocol/network'); var Logger = require('./logger'); var NodeClient = require('./nodeclient'); var workerPool = require('../workers/workerpool').pool; +var ec = require('../crypto/ec'); +var native = require('../utils/native'); /** * Base class from which every other @@ -116,15 +118,14 @@ Node.prototype.init = function init(options) { this.client = new NodeClient(this); this.on('preopen', function() { - self.handleOpen(); + self.handlePreopen(); }); this.on('open', function() { - self.startTime = util.now(); + self.handleOpen(); }); this.on('close', function() { - self.startTime = -1; self.handleClose(); }); }; @@ -134,7 +135,7 @@ Node.prototype.init = function init(options) { * @private */ -Node.prototype.handleOpen = function handleOpen() { +Node.prototype.handlePreopen = function handlePreopen() { var self = this; this.logger.open(); @@ -171,6 +172,30 @@ Node.prototype.handleOpen = function handleOpen() { }); }; +/** + * Open node. + * @private + */ + +Node.prototype.handleOpen = function handleOpen() { + this.startTime = util.now(); + + if (!ec.binding) { + this.logger.warning('Warning: secp256k1-node was not built.'); + this.logger.warning('Verification will be slow.'); + } + + if (!native.binding) { + this.logger.warning('Warning: bcoin-native was not built.'); + this.logger.warning('Hashing will be slow.'); + } + + if (!workerPool.enabled) { + this.logger.warning('Warning: worker pool is disabled.'); + this.logger.warning('Verification will be slow.'); + } +}; + /** * Close node. Unbind all events. * @private @@ -179,6 +204,8 @@ Node.prototype.handleOpen = function handleOpen() { Node.prototype.handleClose = function handleClose() { var i, bound; + this.startTime = -1; + this.logger.close(); for (i = 0; i < this.bound.length; i++) { diff --git a/lib/workers/workerpool.js b/lib/workers/workerpool.js index 65722e76..c4d08ecb 100644 --- a/lib/workers/workerpool.js +++ b/lib/workers/workerpool.js @@ -870,7 +870,7 @@ function getCores() { */ exports.pool = new WorkerPool(); -exports.pool.enabled = false; +exports.pool.enabled = true; exports.set = function set(options) { this.pool.set({ @@ -881,7 +881,7 @@ exports.set = function set(options) { }; exports.set({ - useWorkers: +process.env.BCOIN_USE_WORKERS === 1, + useWorkers: +process.env.BCOIN_USE_WORKERS !== 0, maxWorkers: +process.env.BCOIN_MAX_WORKERS, workerTimeout: +process.env.BCOIN_WORKER_TIMEOUT });