From 476a52e49bc560e44a19488882000a08516a3033 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 2 Jul 2019 14:23:35 +0100 Subject: [PATCH 1/2] fix: wait for one key to be the required key not all Also, every returns true if there's no items in the list so this was returning a false positive. --- src/bitswap/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitswap/utils.js b/src/bitswap/utils.js index 5a2c9c35..624c2e09 100644 --- a/src/bitswap/utils.js +++ b/src/bitswap/utils.js @@ -16,7 +16,7 @@ function waitForWantlistKey (ipfs, key, opts, cb) { setTimeout(() => { timedOut = true }, opts.timeout) - const test = () => timedOut ? true : list.Keys.every(k => k['/'] === key) + const test = () => timedOut ? true : list.Keys.some(k => k['/'] === key) const iteratee = (cb) => ipfs.bitswap.wantlist(opts.peerId, cb) until(test, iteratee, (err) => { From 55228e1c1f90db6d69fdc701e92e8e65fd42b705 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 2 Jul 2019 14:33:35 +0100 Subject: [PATCH 2/2] fix: iteratee not updating list --- src/bitswap/utils.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bitswap/utils.js b/src/bitswap/utils.js index 624c2e09..c5f2de34 100644 --- a/src/bitswap/utils.js +++ b/src/bitswap/utils.js @@ -17,7 +17,13 @@ function waitForWantlistKey (ipfs, key, opts, cb) { setTimeout(() => { timedOut = true }, opts.timeout) const test = () => timedOut ? true : list.Keys.some(k => k['/'] === key) - const iteratee = (cb) => ipfs.bitswap.wantlist(opts.peerId, cb) + const iteratee = (cb) => { + ipfs.bitswap.wantlist(opts.peerId, (err, nextList) => { + if (err) return cb(err) + list = nextList + cb() + }) + } until(test, iteratee, (err) => { if (err) return cb(err)