node: make hostlist persistence optional.
This commit is contained in:
parent
a986a4c6b8
commit
7d6ebd0201
2
bin/node
2
bin/node
@ -16,6 +16,7 @@ node = new bcoin.fullnode({
|
|||||||
logConsole: true,
|
logConsole: true,
|
||||||
logLevel: 'debug',
|
logLevel: 'debug',
|
||||||
db: 'leveldb',
|
db: 'leveldb',
|
||||||
|
persistent: true,
|
||||||
listen: true,
|
listen: true,
|
||||||
loader: require
|
loader: require
|
||||||
});
|
});
|
||||||
@ -25,6 +26,7 @@ node.on('error', function(err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
co.spawn(function *() {
|
co.spawn(function *() {
|
||||||
|
yield node.ensure();
|
||||||
yield node.open();
|
yield node.open();
|
||||||
yield node.connect();
|
yield node.connect();
|
||||||
node.startSync();
|
node.startSync();
|
||||||
|
|||||||
@ -18,6 +18,7 @@ node = bcoin.spvnode({
|
|||||||
logConsole: true,
|
logConsole: true,
|
||||||
logLevel: 'debug',
|
logLevel: 'debug',
|
||||||
db: 'leveldb',
|
db: 'leveldb',
|
||||||
|
persistent: true,
|
||||||
listen: true,
|
listen: true,
|
||||||
loader: require
|
loader: require
|
||||||
});
|
});
|
||||||
@ -27,6 +28,7 @@ node.on('error', function(err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
co.spawn(function *() {
|
co.spawn(function *() {
|
||||||
|
yield node.ensure();
|
||||||
yield node.open();
|
yield node.open();
|
||||||
yield node.connect();
|
yield node.connect();
|
||||||
|
|
||||||
|
|||||||
@ -196,7 +196,10 @@ HostList.prototype.close = co(function* close() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.start = function start() {
|
HostList.prototype.start = function start() {
|
||||||
if (!this.options.location)
|
if (!this.options.persistent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this.options.filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.timer == null);
|
assert(this.timer == null);
|
||||||
@ -208,7 +211,10 @@ HostList.prototype.start = function start() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.stop = function stop() {
|
HostList.prototype.stop = function stop() {
|
||||||
if (!this.options.location)
|
if (!this.options.persistent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this.options.filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(this.timer != null);
|
assert(this.timer != null);
|
||||||
@ -250,12 +256,15 @@ HostList.prototype.injectSeeds = function injectSeeds() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.loadFile = co(function* loadFile() {
|
HostList.prototype.loadFile = co(function* loadFile() {
|
||||||
var filename = this.options.location;
|
var filename = this.options.filename;
|
||||||
var data, json;
|
var data, json;
|
||||||
|
|
||||||
if (fs.unsupported)
|
if (fs.unsupported)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!this.options.persistent)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -279,12 +288,15 @@ HostList.prototype.loadFile = co(function* loadFile() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
HostList.prototype.flush = co(function* flush() {
|
HostList.prototype.flush = co(function* flush() {
|
||||||
var filename = this.options.location;
|
var filename = this.options.filename;
|
||||||
var json, data;
|
var json, data;
|
||||||
|
|
||||||
if (fs.unsupported)
|
if (fs.unsupported)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!this.options.persistent)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1487,7 +1499,8 @@ function HostListOptions(options) {
|
|||||||
this.maxEntries = 50;
|
this.maxEntries = 50;
|
||||||
|
|
||||||
this.prefix = null;
|
this.prefix = null;
|
||||||
this.location = null;
|
this.filename = null;
|
||||||
|
this.persistent = false;
|
||||||
this.flushInterval = 120000;
|
this.flushInterval = 120000;
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
@ -1583,15 +1596,20 @@ HostListOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.maxEntries = options.maxEntries;
|
this.maxEntries = options.maxEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.persistent != null) {
|
||||||
|
assert(typeof options.persistent === 'boolean');
|
||||||
|
this.persistent = options.persistent;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.prefix != null) {
|
if (options.prefix != null) {
|
||||||
assert(typeof options.prefix === 'string');
|
assert(typeof options.prefix === 'string');
|
||||||
this.prefix = options.prefix;
|
this.prefix = options.prefix;
|
||||||
this.location = this.prefix + '/hosts.json';
|
this.filename = this.prefix + '/hosts.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.location != null) {
|
if (options.filename != null) {
|
||||||
assert(typeof options.location === 'string');
|
assert(typeof options.filename === 'string');
|
||||||
this.location = options.location;
|
this.filename = options.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.flushInterval != null) {
|
if (options.flushInterval != null) {
|
||||||
|
|||||||
@ -3760,6 +3760,7 @@ function PoolOptions(options) {
|
|||||||
this.blockMode = 0;
|
this.blockMode = 0;
|
||||||
this.services = common.LOCAL_SERVICES;
|
this.services = common.LOCAL_SERVICES;
|
||||||
this.requiredServices = common.REQUIRED_SERVICES;
|
this.requiredServices = common.REQUIRED_SERVICES;
|
||||||
|
this.persistent = false;
|
||||||
|
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
}
|
}
|
||||||
@ -3985,6 +3986,11 @@ PoolOptions.prototype.fromOptions = function fromOptions(options) {
|
|||||||
this.blockMode = options.blockMode;
|
this.blockMode = options.blockMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.persistent != null) {
|
||||||
|
assert(typeof options.persistent === 'boolean');
|
||||||
|
this.persistent = options.persistent;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.spv) {
|
if (this.spv) {
|
||||||
this.requiredServices |= common.services.BLOOM;
|
this.requiredServices |= common.services.BLOOM;
|
||||||
this.services &= ~common.services.NETWORK;
|
this.services &= ~common.services.NETWORK;
|
||||||
|
|||||||
@ -537,6 +537,15 @@ Config.prototype.getFile = function getFile(file) {
|
|||||||
return this.prefix + '/' + file;
|
return this.prefix + '/' + file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure prefix.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Config.prototype.ensure = function ensure() {
|
||||||
|
return fs.mkdirp(this.prefix);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file path using `prefix`.
|
* Create a file path using `prefix`.
|
||||||
* @param {String} file
|
* @param {String} file
|
||||||
|
|||||||
@ -110,7 +110,8 @@ function FullNode(options) {
|
|||||||
publicPort: this.config.num('public-port'),
|
publicPort: this.config.num('public-port'),
|
||||||
host: this.config.str('host'),
|
host: this.config.str('host'),
|
||||||
port: this.config.num('port'),
|
port: this.config.num('port'),
|
||||||
listen: this.config.bool('listen')
|
listen: this.config.bool('listen'),
|
||||||
|
persistent: this.config.bool('persistent')
|
||||||
});
|
});
|
||||||
|
|
||||||
// Miner needs access to the chain and mempool.
|
// Miner needs access to the chain and mempool.
|
||||||
|
|||||||
@ -16,7 +16,6 @@ var Logger = require('./logger');
|
|||||||
var workerPool = require('../workers/workerpool').pool;
|
var workerPool = require('../workers/workerpool').pool;
|
||||||
var ec = require('../crypto/ec');
|
var ec = require('../crypto/ec');
|
||||||
var native = require('../utils/native');
|
var native = require('../utils/native');
|
||||||
var fs = require('../utils/fs');
|
|
||||||
var Config = require('./config');
|
var Config = require('./config');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,6 +113,15 @@ Node.prototype.init = function init() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure prefix directory.
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Node.prototype.ensure = function ensure() {
|
||||||
|
return this.config.ensure();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open node. Bind all events.
|
* Open node. Bind all events.
|
||||||
* @private
|
* @private
|
||||||
@ -122,8 +130,6 @@ Node.prototype.init = function init() {
|
|||||||
Node.prototype.handlePreopen = co(function* handlePreopen() {
|
Node.prototype.handlePreopen = co(function* handlePreopen() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
yield fs.mkdirp(this.config.prefix);
|
|
||||||
|
|
||||||
yield this.logger.open();
|
yield this.logger.open();
|
||||||
|
|
||||||
this.bind(this.network.time, 'offset', function(offset) {
|
this.bind(this.network.time, 'offset', function(offset) {
|
||||||
|
|||||||
@ -71,6 +71,7 @@ function SPVNode(options) {
|
|||||||
bip150: this.config.bool('bip150'),
|
bip150: this.config.bool('bip150'),
|
||||||
identityKey: this.config.buf('identity-key'),
|
identityKey: this.config.buf('identity-key'),
|
||||||
maxOutbound: this.config.num('max-outbound'),
|
maxOutbound: this.config.num('max-outbound'),
|
||||||
|
persistent: this.config.bool('persistent'),
|
||||||
selfish: true,
|
selfish: true,
|
||||||
listen: false
|
listen: false
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user