peer: less aggresive stall behavior.

This commit is contained in:
Christopher Jeffrey 2017-01-23 20:43:17 -08:00
parent cfeafb6273
commit 592191c44c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -91,7 +91,6 @@ function Peer(options) {
this.ts = 0;
this.lastSend = 0;
this.lastRecv = 0;
this.drainStart = 0;
this.drainSize = 0;
this.drainQueue = [];
this.banScore = 0;
@ -152,15 +151,6 @@ util.inherits(Peer, EventEmitter);
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
* and required responses from peer.
@ -394,9 +384,6 @@ Peer.prototype.bind = function bind(socket) {
});
this.socket.on('data', function(chunk) {
if (self.maybeStall())
return;
self.lastRecv = util.ms();
self.feedParser(chunk);
});
@ -556,7 +543,6 @@ Peer.prototype.initStall = function initStall() {
assert(!this.stallTimer);
assert(!this.destroyed);
this.stallTimer = setInterval(function() {
self.maybeStall();
self.maybeTimeout();
}, Peer.STALL_INTERVAL);
return Promise.resolve();
@ -1208,13 +1194,6 @@ Peer.prototype.handleDrain = function handleDrain() {
*/
Peer.prototype.needsDrain = function needsDrain(size) {
if (this.maybeStall()) {
this.error('Peer stalled (drain).');
this.destroy();
return;
}
this.drainStart = util.ms();
this.drainSize += size;
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.
* @private