This commit is contained in:
Christopher Jeffrey 2016-01-29 17:38:31 -08:00
parent 41516b4866
commit e8cb2102a3
2 changed files with 21 additions and 7 deletions

View File

@ -82,6 +82,10 @@ function Peer(pool, createConnection, options) {
interval: this.options.pingInterval || 30000
};
Peer.uid.iaddn(1);
this.id = Peer.uid.toString(10);
this.setMaxListeners(10000);
if (this.socket)
@ -92,6 +96,8 @@ function Peer(pool, createConnection, options) {
inherits(Peer, EventEmitter);
Peer.uid = new bn(0);
Peer.prototype._init = function init() {
var self = this;

View File

@ -1378,7 +1378,7 @@ Pool.prototype._scheduleRequests = function _scheduleRequests() {
Pool.prototype._doRequests = function _doRequests() {
var queue, above, items, below;
var red, count, split, i, off, req, j;
var mapReq, peerItems, peers;
var mapReq, peerItems, peers, uniq;
if (this.request.active >= this.parallel)
return;
@ -1409,8 +1409,13 @@ Pool.prototype._doRequests = function _doRequests() {
});
if (peerItems.length > 0) {
peers = utils.uniq(peerItems.map(function(item) {
return item.targetPeer;
uniq = {};
peers = [];
peerItems.forEach(function(item) {
if (uniq[item.targetPeer.id])
return;
uniq[item.targetPeer.id] = true;
peers.push(item.targetPeer);
}));
peers.forEach(function(peer) {
var items = peerItems.filter(function(item) {
@ -1881,10 +1886,10 @@ LoadRequest.prototype.start = function start(peer) {
this.active = true;
this.pool.request.active++;
// this.timer = setTimeout(function() {
// self.timer = null;
// self.retry();
// }, this.pool.requestTimeout);
this.timer = setTimeout(function() {
self.timer = null;
self.retry();
}, this.pool.requestTimeout);
this.peer = peer || this.targetPeer;
this.peer.once('close', this.onclose);
@ -1900,6 +1905,7 @@ LoadRequest.compare = function compare(a, b) {
};
LoadRequest.prototype.add = function add(noQueue) {
assert(!this.pool.request.map[this.hash]);
this.pool.request.map[this.hash] = this;
if (!noQueue)
this.pool.request.queue.push(this);
@ -1938,6 +1944,8 @@ LoadRequest.prototype.finish = function finish(entity) {
if (this.active) {
this.clear();
index = this.pool.request.queue.indexOf(this);
assert(index !== -1 || this.noQueue);
} else {
// It could be that request was never sent to the node, remove it from
// queue and forget about it