diff --git a/SPEC/BITSWAP.md b/SPEC/BITSWAP.md index 205d1bc63a..4f54e01c83 100644 --- a/SPEC/BITSWAP.md +++ b/SPEC/BITSWAP.md @@ -4,7 +4,7 @@ * [bitswap.unwant](#bitswapunwant) * [bitswap.stat](#bitswapstat) -#### `unwant` +#### `bitswap.unwant` > Removes a given block from your wantlist @@ -21,11 +21,20 @@ ### `bitswap.wantlist` -(not spec'ed yet) +> Returns the wantlist, optionally limited by peerID -#### `bitswap.unwant` +#### `Go` **WIP** + +#### `JavaScript` - ipfs.bitswap.wantlist([peerId]) + +```JavaScript +ipfs.bitswap.wantlist((err, list) => console.log(list)) + +//[ { Wantlist object }, ... ] + +ipfs.bitswap.wantlist(peerId, (err, list) => console.log(list)) -(not spec'ed yet) +//[ { Wantlist object }, ... ] #### `bitswap.stat` diff --git a/js/src/bitswap.js b/js/src/bitswap.js index 44cae902ec..4b0707f9ae 100644 --- a/js/src/bitswap.js +++ b/js/src/bitswap.js @@ -14,6 +14,7 @@ module.exports = (common) => { let ipfsA let ipfsB let withGo + let ipfsBId const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' before(function (done) { @@ -29,18 +30,18 @@ module.exports = (common) => { ipfsA = node withGo = node.peerId.agentVersion.startsWith('go-ipfs') cb() - //ipfsA.block.get(key) - //.then(() => {}) - //.catch(() => {}) - //cb() }), (cb) => spawn.spawnNodeWithId(factory, (err, node) => { expect(err).to.not.exist() ipfsB = node + ipfsBId = node.peerId ipfsB.block.get(new CID(key)) .then(() => {}) .catch(() => {}) - ipfsA.swarm.connect(node.peerId.addresses[0], cb) + ipfsA.swarm.connect(ipfsBId.addresses[0], (err) => { + expect(err).to.not.exist() + setTimeout(cb, 350) + }) }) ], done) }) @@ -49,7 +50,7 @@ module.exports = (common) => { after((done) => common.teardown(done)) it('.stat', (done) => { - ipfsA.bitswap.stat((err, stats) => { + ipfsB.bitswap.stat((err, stats) => { expect(err).to.not.exist() statsTests.expectIsBitswap(err, stats) done() @@ -57,7 +58,7 @@ module.exports = (common) => { }) it('.wantlist', (done) => { - ipfsA.bitswap.wantlist((err, list) => { + ipfsB.bitswap.wantlist((err, list) => { expect(err).to.not.exist() expect(list.Keys).to.have.length(1); expect(list.Keys[0]['/']).to.equal(key) @@ -66,7 +67,7 @@ module.exports = (common) => { }) it('.wantlist peerid', (done) => { - ipfsA.bitswap.wantlist(ipfsBId, (err, list) => { + ipfsA.bitswap.wantlist(ipfsBId.id, (err, list) => { expect(err).to.not.exist() expect(list.Keys[0]['/']).to.equal(key) done() @@ -77,9 +78,9 @@ module.exports = (common) => { if (withGo) { this.skip() } - ipfsA.bitswap.unwant(key, (err) => { + ipfsB.bitswap.unwant(key, (err) => { expect(err).to.not.exist(); - ipfsA.bitswap.wantlist((err, list) => { + ipfsB.bitswap.wantlist((err, list) => { expect(err).to.not.exist(); expect(list.Keys).to.be.empty() done() @@ -115,7 +116,7 @@ module.exports = (common) => { }) }) - it('.stat gives error while offline', () => { + it('.stat gives error while offline', (done) => { ipfs.bitswap.stat((err, stats) => { expect(err).to.exist() //When run against core we get our expected error, when run @@ -124,10 +125,11 @@ module.exports = (common) => { expect(err).to.match(/online mode/) } expect(stats).to.not.exist() + done() }) }) - it('.wantlist gives error if offline', () => { + it('.wantlist gives error if offline', (done) => { ipfs.bitswap.wantlist((err, list) => { expect(err).to.exist() //When run against core we get our expected error, when run @@ -136,18 +138,21 @@ module.exports = (common) => { expect(err).to.match(/online mode/) } expect(list).to.not.exist() + done() }) }) - it('.unwant gives error if offline', () => { - expect(() => ipfs.bitswap.unwant(key, (err) => { + it('.unwant gives error if offline', (done) => { + const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' + ipfs.bitswap.unwant(key, (err) => { expect(err).to.exist() //When run against core we get our expected error, when run //as part of the http tests we get a connection refused if (err.code !== 'ECONNREFUSED') { expect(err).to.match(/online mode/) } - })) + done() + }) }) }) }