peer: better stall detection.

This commit is contained in:
Christopher Jeffrey 2017-02-28 10:08:17 -08:00
parent 56ccfaa980
commit a4201e6bd5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 17 additions and 3 deletions

View File

@ -1322,6 +1322,18 @@ Peer.prototype.maybeTimeout = function maybeTimeout() {
this.destroy();
return;
}
keys = this.requestMap.keys();
for (i = 0; i < keys.length; i++) {
key = keys[i];
entry = this.requestMap.get(key);
if (now > entry + Peer.BLOCK_TIMEOUT) {
this.error('Peer is stalling (block).');
this.destroy();
return;
}
}
}
};

View File

@ -2455,7 +2455,7 @@ Pool.prototype.handleCmpctBlock = co(function* handleCmpctBlock(peer, packet) {
peer.destroy();
return;
}
peer.requestMap.insert(hash);
peer.requestMap.set(hash, util.ms());
assert(!this.requestMap.has(hash));
this.requestMap.insert(hash);
}
@ -3012,6 +3012,7 @@ Pool.prototype.getBlocks = co(function* getBlocks(peer, tip, stop) {
*/
Pool.prototype.getBlock = function getBlock(peer, hashes) {
var now = util.ms();
var items = [];
var i, hash;
@ -3031,7 +3032,7 @@ Pool.prototype.getBlock = function getBlock(peer, hashes) {
continue;
this.requestMap.insert(hash);
peer.requestMap.insert(hash);
peer.requestMap.set(hash, now);
items.push(hash);
}
@ -3055,6 +3056,7 @@ Pool.prototype.getBlock = function getBlock(peer, hashes) {
*/
Pool.prototype.getTX = function getTX(peer, hashes) {
var now = util.ms();
var items = [];
var i, hash;
@ -3074,7 +3076,7 @@ Pool.prototype.getTX = function getTX(peer, hashes) {
continue;
this.requestMap.insert(hash);
peer.requestMap.insert(hash);
peer.requestMap.set(hash, now);
items.push(hash);
}