work
This commit is contained in:
parent
41516b4866
commit
e8cb2102a3
@ -82,6 +82,10 @@ function Peer(pool, createConnection, options) {
|
|||||||
interval: this.options.pingInterval || 30000
|
interval: this.options.pingInterval || 30000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Peer.uid.iaddn(1);
|
||||||
|
|
||||||
|
this.id = Peer.uid.toString(10);
|
||||||
|
|
||||||
this.setMaxListeners(10000);
|
this.setMaxListeners(10000);
|
||||||
|
|
||||||
if (this.socket)
|
if (this.socket)
|
||||||
@ -92,6 +96,8 @@ function Peer(pool, createConnection, options) {
|
|||||||
|
|
||||||
inherits(Peer, EventEmitter);
|
inherits(Peer, EventEmitter);
|
||||||
|
|
||||||
|
Peer.uid = new bn(0);
|
||||||
|
|
||||||
Peer.prototype._init = function init() {
|
Peer.prototype._init = function init() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|||||||
@ -1378,7 +1378,7 @@ Pool.prototype._scheduleRequests = function _scheduleRequests() {
|
|||||||
Pool.prototype._doRequests = function _doRequests() {
|
Pool.prototype._doRequests = function _doRequests() {
|
||||||
var queue, above, items, below;
|
var queue, above, items, below;
|
||||||
var red, count, split, i, off, req, j;
|
var red, count, split, i, off, req, j;
|
||||||
var mapReq, peerItems, peers;
|
var mapReq, peerItems, peers, uniq;
|
||||||
|
|
||||||
if (this.request.active >= this.parallel)
|
if (this.request.active >= this.parallel)
|
||||||
return;
|
return;
|
||||||
@ -1409,8 +1409,13 @@ Pool.prototype._doRequests = function _doRequests() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (peerItems.length > 0) {
|
if (peerItems.length > 0) {
|
||||||
peers = utils.uniq(peerItems.map(function(item) {
|
uniq = {};
|
||||||
return item.targetPeer;
|
peers = [];
|
||||||
|
peerItems.forEach(function(item) {
|
||||||
|
if (uniq[item.targetPeer.id])
|
||||||
|
return;
|
||||||
|
uniq[item.targetPeer.id] = true;
|
||||||
|
peers.push(item.targetPeer);
|
||||||
}));
|
}));
|
||||||
peers.forEach(function(peer) {
|
peers.forEach(function(peer) {
|
||||||
var items = peerItems.filter(function(item) {
|
var items = peerItems.filter(function(item) {
|
||||||
@ -1881,10 +1886,10 @@ LoadRequest.prototype.start = function start(peer) {
|
|||||||
this.active = true;
|
this.active = true;
|
||||||
this.pool.request.active++;
|
this.pool.request.active++;
|
||||||
|
|
||||||
// this.timer = setTimeout(function() {
|
this.timer = setTimeout(function() {
|
||||||
// self.timer = null;
|
self.timer = null;
|
||||||
// self.retry();
|
self.retry();
|
||||||
// }, this.pool.requestTimeout);
|
}, this.pool.requestTimeout);
|
||||||
|
|
||||||
this.peer = peer || this.targetPeer;
|
this.peer = peer || this.targetPeer;
|
||||||
this.peer.once('close', this.onclose);
|
this.peer.once('close', this.onclose);
|
||||||
@ -1900,6 +1905,7 @@ LoadRequest.compare = function compare(a, b) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
LoadRequest.prototype.add = function add(noQueue) {
|
LoadRequest.prototype.add = function add(noQueue) {
|
||||||
|
assert(!this.pool.request.map[this.hash]);
|
||||||
this.pool.request.map[this.hash] = this;
|
this.pool.request.map[this.hash] = this;
|
||||||
if (!noQueue)
|
if (!noQueue)
|
||||||
this.pool.request.queue.push(this);
|
this.pool.request.queue.push(this);
|
||||||
@ -1938,6 +1944,8 @@ LoadRequest.prototype.finish = function finish(entity) {
|
|||||||
|
|
||||||
if (this.active) {
|
if (this.active) {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
index = this.pool.request.queue.indexOf(this);
|
||||||
|
assert(index !== -1 || this.noQueue);
|
||||||
} else {
|
} else {
|
||||||
// It could be that request was never sent to the node, remove it from
|
// It could be that request was never sent to the node, remove it from
|
||||||
// queue and forget about it
|
// queue and forget about it
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user