peer: less aggresive stall behavior.
This commit is contained in:
parent
cfeafb6273
commit
592191c44c
@ -91,7 +91,6 @@ function Peer(options) {
|
|||||||
this.ts = 0;
|
this.ts = 0;
|
||||||
this.lastSend = 0;
|
this.lastSend = 0;
|
||||||
this.lastRecv = 0;
|
this.lastRecv = 0;
|
||||||
this.drainStart = 0;
|
|
||||||
this.drainSize = 0;
|
this.drainSize = 0;
|
||||||
this.drainQueue = [];
|
this.drainQueue = [];
|
||||||
this.banScore = 0;
|
this.banScore = 0;
|
||||||
@ -152,15 +151,6 @@ util.inherits(Peer, EventEmitter);
|
|||||||
|
|
||||||
Peer.DRAIN_MAX = 10 << 20;
|
Peer.DRAIN_MAX = 10 << 20;
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeout for peer to read from
|
|
||||||
* their end of the socket.
|
|
||||||
* @const {Number}
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
|
|
||||||
Peer.DRAIN_TIMEOUT = 10000;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval to check for drainage
|
* Interval to check for drainage
|
||||||
* and required responses from peer.
|
* and required responses from peer.
|
||||||
@ -394,9 +384,6 @@ Peer.prototype.bind = function bind(socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on('data', function(chunk) {
|
this.socket.on('data', function(chunk) {
|
||||||
if (self.maybeStall())
|
|
||||||
return;
|
|
||||||
|
|
||||||
self.lastRecv = util.ms();
|
self.lastRecv = util.ms();
|
||||||
self.feedParser(chunk);
|
self.feedParser(chunk);
|
||||||
});
|
});
|
||||||
@ -556,7 +543,6 @@ Peer.prototype.initStall = function initStall() {
|
|||||||
assert(!this.stallTimer);
|
assert(!this.stallTimer);
|
||||||
assert(!this.destroyed);
|
assert(!this.destroyed);
|
||||||
this.stallTimer = setInterval(function() {
|
this.stallTimer = setInterval(function() {
|
||||||
self.maybeStall();
|
|
||||||
self.maybeTimeout();
|
self.maybeTimeout();
|
||||||
}, Peer.STALL_INTERVAL);
|
}, Peer.STALL_INTERVAL);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@ -1208,13 +1194,6 @@ Peer.prototype.handleDrain = function handleDrain() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.needsDrain = function needsDrain(size) {
|
Peer.prototype.needsDrain = function needsDrain(size) {
|
||||||
if (this.maybeStall()) {
|
|
||||||
this.error('Peer stalled (drain).');
|
|
||||||
this.destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drainStart = util.ms();
|
|
||||||
this.drainSize += size;
|
this.drainSize += size;
|
||||||
|
|
||||||
if (this.drainSize >= Peer.DRAIN_MAX) {
|
if (this.drainSize >= Peer.DRAIN_MAX) {
|
||||||
@ -1227,26 +1206,6 @@ Peer.prototype.needsDrain = function needsDrain(size) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Potentially timeout peer if it hasn't read.
|
|
||||||
* @private
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Peer.prototype.maybeStall = function maybeStall() {
|
|
||||||
if (this.drainSize === 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (util.ms() < this.drainStart + Peer.DRAIN_TIMEOUT)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this.drainSize = 0;
|
|
||||||
this.error('Peer stalled (write).');
|
|
||||||
this.destroy();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Potentially add response timeout.
|
* Potentially add response timeout.
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user