From cdcdb7bd528ce1936f97f82379e9fa4a25aaff1a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 20 Jan 2017 17:09:00 -0800 Subject: [PATCH] pool: add forceInv for getdata. --- lib/net/peer.js | 12 ++++++++++++ lib/net/pool.js | 10 ++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/net/peer.js b/lib/net/peer.js index 9da62fca..dd289cc0 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -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 diff --git a/lib/net/pool.js b/lib/net/pool.js index 0396d438..d3b2d272 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -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();