pool: add forceInv for getdata.

This commit is contained in:
Christopher Jeffrey 2017-01-20 17:09:00 -08:00
parent d035eb10eb
commit cdcdb7bd52
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 16 additions and 6 deletions

View File

@ -787,6 +787,18 @@ Peer.prototype.flushInv = function flushInv() {
}
};
/**
* Force send an inv (no filter check).
* @param {InvItem[]} items
*/
Peer.prototype.forceInv = function forceInv(items) {
if (!Array.isArray(items))
items = [items];
this.send(new packets.InvPacket(items));
};
/**
* Send headers to a peer.
* @param {Headers[]} items

View File

@ -1356,7 +1356,7 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) {
}
if (item.hash === peer.hashContinue) {
peer.sendInv([new InvItem(invTypes.BLOCK, this.chain.tip.hash)]);
peer.forceInv([new InvItem(invTypes.BLOCK, this.chain.tip.hash)]);
peer.hashContinue = null;
}
}
@ -1435,10 +1435,8 @@ Pool.prototype.handleGetBlocks = co(function* handleGetBlocks(peer, packet) {
while (hash) {
blocks.push(new InvItem(invTypes.BLOCK, hash));
if (hash === packet.stop) {
peer.hashContinue = hash;
if (hash === packet.stop)
break;
}
if (blocks.length === 500) {
peer.hashContinue = hash;
@ -1490,10 +1488,10 @@ Pool.prototype.handleGetHeaders = co(function* handleGetHeaders(peer, packet) {
while (entry) {
headers.push(entry.toHeaders());
if (headers.length === 2000)
if (entry.hash === packet.stop)
break;
if (entry.hash === packet.stop)
if (headers.length === 2000)
break;
entry = yield entry.getNext();