allow hardcoded peers.

This commit is contained in:
Christopher Jeffrey 2014-11-11 13:27:36 -08:00
parent c1dc858c28
commit f83be008f3
1 changed files with 38 additions and 0 deletions

View File

@ -51,6 +51,8 @@ function Bitcoin(options) {
this.config = this.options.datadir + '/bitcoin.conf';
this.network = Bitcoin[this.options.testnet ? 'testnet' : 'livenet'];
if (!fs.existsSync(this.options.datadir)) {
mkdirp.sync(this.options.datadir);
}
@ -66,6 +68,28 @@ function Bitcoin(options) {
);
}
// Add hardcoded peers
var data = fs.readFileSync(this.config, 'utf8');
if (this.network.peers.length) {
var peers = this.network.peers.reduce(function(out, peer) {
if (!~data.indexOf('addnode=' + peer)) {
return out + 'addnode=' + peer + '\n';
}
return out;
}, '\n');
fs.writeFileSync(data + peers);
}
// Copy config into testnet dir
if (this.network.name === 'testnet') {
if (!fs.existsSync(this.datadir + '/testnet3')) {
fs.mkdirSync(this.datadir + '/testnet3');
}
fs.writeFileSync(
this.datadir + '/testnet3/bitcoin.conf',
fs.readFileSync(this.config));
}
Object.keys(exports).forEach(function(key) {
self[key] = exports[key];
});
@ -79,6 +103,20 @@ function Bitcoin(options) {
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
Bitcoin.livenet = {
name: 'livenet',
peers: [
// hardcoded peers
]
};
Bitcoin.testnet = {
name: 'testnet',
peers: [
// hardcoded peers
]
};
// Make sure signal handlers are not overwritten
Bitcoin._signalQueue = [];
Bitcoin._processOn = process.on;