wip
This commit is contained in:
parent
facea3bd13
commit
d0fb0c12ee
@ -7,9 +7,6 @@ var index = require('../../');
|
||||
var log = index.log;
|
||||
var BaseService = require('../../service');
|
||||
var assert = require('assert');
|
||||
var utils = require('../utils');
|
||||
var async = require('async');
|
||||
var bcoin = require('bcoin');
|
||||
|
||||
var P2P = function(options) {
|
||||
|
||||
@ -29,20 +26,6 @@ util.inherits(P2P, BaseService);
|
||||
|
||||
P2P.dependencies = [];
|
||||
|
||||
P2P.prototype._initRemoteNode = function(callback) {
|
||||
// if no connect params exist for p2p, then spawn bcoin as a fallback
|
||||
if (!this.options.connect) {
|
||||
return this._spawnBcoin(callback);
|
||||
}
|
||||
// remote p2p nodes may not be ready just yet.
|
||||
async.retry({ times: 10, interval: 1000 }, utils.tryTcpConnection, callback);
|
||||
};
|
||||
|
||||
P2P.prototype._spawnBcoin = function(callback) {
|
||||
bcoin.set(this.node.getNetworkName());
|
||||
l
|
||||
};
|
||||
|
||||
P2P.prototype._initP2P = function() {
|
||||
this._maxPeers = this.options.maxPeers || 60;
|
||||
this._minPeers = this.options.minPeers || 1;
|
||||
@ -64,18 +47,10 @@ P2P.prototype._initPubSub = function() {
|
||||
P2P.prototype.start = function(callback) {
|
||||
|
||||
var self = this;
|
||||
self._initRemoteNode(function(err) {
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
self._initCache();
|
||||
self._initPool();
|
||||
this._setupListeners();
|
||||
callback();
|
||||
|
||||
});
|
||||
self._initCache();
|
||||
self._initPool();
|
||||
this._setupListeners();
|
||||
callback();
|
||||
|
||||
};
|
||||
|
||||
|
||||
33
test/services/p2p/index.js
Normal file
33
test/services/p2p/index.js
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var expect = require('chai').expect;
|
||||
var sinon = require('sinon');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var P2PService = require('../../../lib/services/p2p');
|
||||
|
||||
describe('P2P Service', function() {
|
||||
var p2p;
|
||||
var testEmitter;
|
||||
|
||||
before(function(done) {
|
||||
p2p = new P2PService({
|
||||
node: {
|
||||
name: 'p2p',
|
||||
on: sinon.stub()
|
||||
}
|
||||
});
|
||||
sinon.stub(p2p, '_initPool');
|
||||
p2p._pool = new EventEmitter();
|
||||
p2p.start(done);
|
||||
});
|
||||
|
||||
it('should get the mempool from the network', function() {
|
||||
var sendMessage = sinon.stub();
|
||||
var peer = { sendMessage: sendMessage };
|
||||
var getPeer = sinon.stub(p2p, '_getPeer').returns(peer);
|
||||
p2p.getMempool();
|
||||
expect(getPeer.calledOnce).to.be.true;
|
||||
expect(sendMessage.calledOnce).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user