From 9262768fd194c1d7f662f0a7f0031983c3c02324 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Tue, 10 Apr 2018 09:48:36 -0700 Subject: [PATCH 01/10] feat(bitswap.unwant) expose bitswap.unwant to cli and http api --- src/cli/commands/bitswap/unwant.js | 14 ++++++++++++-- src/core/components/bitswap.js | 2 +- src/http/api/resources/bitswap.js | 13 +++++++++++-- test/cli/bitswap.js | 9 +++++++-- test/core/bitswap.spec.js | 2 +- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/cli/commands/bitswap/unwant.js b/src/cli/commands/bitswap/unwant.js index 840276e9b2..28eb1a7a14 100644 --- a/src/cli/commands/bitswap/unwant.js +++ b/src/cli/commands/bitswap/unwant.js @@ -1,11 +1,21 @@ 'use strict' +const print = require('../../utils').print + module.exports = { command: 'unwant ', - describe: 'Remove a given block from your wantlist.', + describe: 'Removes a given block from your wantlist.', + builder: { + key: { + alias: 'k', + describe: 'Key to remove from your wantlist', + type: 'string' + } + }, handler (argv) { - throw new Error('Not implemented yet') + argv.ipfs.bitswap.unwant(argv.key) + print(`Key ${argv.key} removed from wantlist`) } } diff --git a/src/core/components/bitswap.js b/src/core/components/bitswap.js index e148f8c165..44d2d2d3d9 100644 --- a/src/core/components/bitswap.js +++ b/src/core/components/bitswap.js @@ -45,7 +45,7 @@ module.exports = function bitswap (self) { throw new Error(OFFLINE_ERROR) } - // TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged + self._bitswap.unwant(key) } } } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index da830c6415..e9e78ca09f 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -46,10 +46,19 @@ exports.stat = (request, reply) => { } exports.unwant = { - // uses common parseKey method that returns a `key` + // uses common parseKey method that assigns a `key` to request.pre.args parseArgs: parseKey, + // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { - reply(boom.badRequest(new Error('Not implemented yet'))) + const key = request.pre.args.key + const ipfs = request.server.app.ipfs + try { + ipfs.bitswap.unwant(key) + } catch (err) { + return reply(boom.badRequest(err)) + } + + reply({ Key: key }) } } diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 6652364f9b..9fb042addc 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -23,8 +23,7 @@ describe('bitswap', () => runOn((thing) => { }) }) - // TODO @hacdias fix this with https://github.com/ipfs/js-ipfs/pull/1198 - it.skip('stat', function () { + it('stat', function () { this.timeout(20 * 1000) return ipfs('bitswap stat').then((out) => { @@ -40,4 +39,10 @@ describe('bitswap', () => runOn((thing) => { ].join('\n') + '\n') }) }) + + it('unwant', function () { + return ipfs('bitswap unwant ' + key).then((out) => { + expect(out).to.eql(`Key ${key} removed from wantlist\n`) + }) + }) })) diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index d9c9db978c..55ac6116cf 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -283,7 +283,7 @@ skipOnWindows('bitswap', function () { }) }) - it('throws if offline', () => { + it('.unwant throws if offline', () => { expect(() => node.bitswap.unwant('my key')).to.throw(/online/) }) }) From 2ff6c2cea797925ea90c60cb818d28ea42195e59 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Thu, 26 Apr 2018 10:29:32 -0700 Subject: [PATCH 02/10] feat(tests) move some bitswap tests to interface Will require including the version of interface-ipfs-core that they are moved to --- src/cli/commands/bitswap/unwant.js | 8 ++- src/cli/commands/bitswap/wantlist.js | 4 +- src/cli/commands/block/get.js | 7 ++- src/core/components/bitswap.js | 31 ++++++++---- src/http/api/resources/bitswap.js | 28 +++++------ src/http/api/resources/block.js | 8 ++- test/cli/bitswap.js | 2 +- test/core/bitswap.spec.js | 74 ---------------------------- test/core/interface/bitswap.js | 35 +++++++++++++ test/http-api/index.js | 5 +- test/http-api/interface/bitswap.js | 31 ++++++++++++ 11 files changed, 123 insertions(+), 110 deletions(-) create mode 100644 test/core/interface/bitswap.js create mode 100644 test/http-api/interface/bitswap.js diff --git a/src/cli/commands/bitswap/unwant.js b/src/cli/commands/bitswap/unwant.js index 28eb1a7a14..ea676450fa 100644 --- a/src/cli/commands/bitswap/unwant.js +++ b/src/cli/commands/bitswap/unwant.js @@ -15,7 +15,11 @@ module.exports = { } }, handler (argv) { - argv.ipfs.bitswap.unwant(argv.key) - print(`Key ${argv.key} removed from wantlist`) + argv.ipfs.bitswap.unwant(argv.key, (err) => { + if (err) { + throw err + } + print(`Key ${argv.key} removed from wantlist`) + }) } } diff --git a/src/cli/commands/bitswap/wantlist.js b/src/cli/commands/bitswap/wantlist.js index 63692a993a..8ad26a439a 100644 --- a/src/cli/commands/bitswap/wantlist.js +++ b/src/cli/commands/bitswap/wantlist.js @@ -21,8 +21,8 @@ module.exports = { if (err) { throw err } - res.Keys.forEach((cidStr) => { - print(cidStr) + res.Keys.forEach((cid) => { + print(cid['/']) }) }) } diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index ed753aeadb..dd1e21d7fc 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -1,6 +1,7 @@ 'use strict' const CID = require('cids') +const print = require('../../utils').print module.exports = { command: 'get ', @@ -17,7 +18,11 @@ module.exports = { throw err } - process.stdout.write(block.data) + if (block) { + print(block.data) + } else { + print('Block was unwanted before it could be remotely retrieved') + } }) } } diff --git a/src/core/components/bitswap.js b/src/core/components/bitswap.js index 44d2d2d3d9..9f3c7bfbab 100644 --- a/src/core/components/bitswap.js +++ b/src/core/components/bitswap.js @@ -4,21 +4,23 @@ const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR const promisify = require('promisify-es6') const setImmediate = require('async/setImmediate') const Big = require('big.js') +const CID = require('cids') function formatWantlist (list) { - return Array.from(list).map((e) => e[1]) + return Array.from(list).map((e) => ({ '/': e[1].cid.toBaseEncodedString() })) } module.exports = function bitswap (self) { return { - wantlist: () => { + wantlist: promisify((callback) => { if (!self.isOnline()) { - throw new Error(OFFLINE_ERROR) + return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } - const list = self._bitswap.getWantlist() - return formatWantlist(list) - }, + let list = self._bitswap.getWantlist() + list = formatWantlist(list) + callback(null, { Keys: list }) + }), stat: promisify((callback) => { if (!self.isOnline()) { @@ -40,12 +42,21 @@ module.exports = function bitswap (self) { }) }), - unwant: (key) => { + unwant: promisify((keys, callback) => { if (!self.isOnline()) { - throw new Error(OFFLINE_ERROR) + return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } - self._bitswap.unwant(key) - } + if (!Array.isArray(keys)) { + keys = [keys] + } + keys = keys.map((key) => { + if (CID.isCID(key)) { + return key + } + return new CID(key) + }) + callback(null, self._bitswap.unwant(keys)) + }) } } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index e9e78ca09f..f846d87ba2 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -7,16 +7,11 @@ const parseKey = require('./block').parseKey exports = module.exports exports.wantlist = (request, reply) => { - let list - try { - list = request.server.app.ipfs.bitswap.wantlist() - list = list.map((entry) => entry.cid.toBaseEncodedString()) - } catch (err) { - return reply(boom.badRequest(err)) - } - - reply({ - Keys: list + request.server.app.ipfs.bitswap.wantlist((err, list) => { + if (err) { + return reply(boom.badRequest(err)) + } + reply(list) }) } @@ -53,12 +48,11 @@ exports.unwant = { handler: (request, reply) => { const key = request.pre.args.key const ipfs = request.server.app.ipfs - try { - ipfs.bitswap.unwant(key) - } catch (err) { - return reply(boom.badRequest(err)) - } - - reply({ Key: key }) + ipfs.bitswap.unwant(key, (err) => { + if (err) { + return reply(boom.badRequest(err)) + } + reply({ key: key.toBaseEncodedString() }) + }) } } diff --git a/src/http/api/resources/block.js b/src/http/api/resources/block.js index 77553cbcaf..f536fb2a22 100644 --- a/src/http/api/resources/block.js +++ b/src/http/api/resources/block.js @@ -48,7 +48,13 @@ exports.get = { }).code(500) } - return reply(block.data) + if (block) { + return reply(block.data) + } + return reply({ + Message: 'Block was unwanted before it could be remotely retrieved', + Code: 0 + }).code(404) }) } } diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 9fb042addc..6cdebe61de 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -13,7 +13,7 @@ describe('bitswap', () => runOn((thing) => { ipfs('block get ' + key) .then(() => {}) .catch(() => {}) - setTimeout(done, 800) + setTimeout(done, 250) }) it('wantlist', function () { diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 55ac6116cf..645581f2c1 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -18,9 +18,6 @@ const CID = require('cids') const IPFSFactory = require('ipfsd-ctl') -// This gets replaced by '../utils/create-repo-browser.js' in the browser -const createTempRepo = require('../utils/create-repo-nodejs.js') - const IPFS = require('../../src/core') // TODO bitswap tests on windows is failing, missing proper shutdown of daemon @@ -247,75 +244,4 @@ skipOnWindows('bitswap', function () { }) }) }) - - describe('api', () => { - let node - - before(function (done) { - this.timeout(40 * 1000) - - node = new IPFS({ - repo: createTempRepo(), - start: false, - config: { - Addresses: { - Swarm: [] - }, - Discovery: { - MDNS: { - Enabled: false - } - } - } - }) - node.on('ready', () => done()) - }) - - describe('while offline', () => { - it('.wantlist throws if offline', () => { - expect(() => node.bitswap.wantlist()).to.throw(/online/) - }) - - it('.stat gives error while offline', () => { - node.bitswap.stat((err, stats) => { - expect(err).to.exist() - expect(stats).to.not.exist() - }) - }) - - it('.unwant throws if offline', () => { - expect(() => node.bitswap.unwant('my key')).to.throw(/online/) - }) - }) - - describe('while online', () => { - before(function (done) { - this.timeout(80 * 1000) - - node.start(() => done()) - }) - - it('.wantlist returns an array of wanted blocks', () => { - expect(node.bitswap.wantlist()).to.eql([]) - }) - - it('returns the stats', (done) => { - node.bitswap.stat((err, stats) => { - expect(err).to.not.exist() - expect(stats).to.have.keys([ - 'blocksReceived', - 'blocksSent', - 'dataReceived', - 'dataSent', - 'wantlist', - 'peers', - 'provideBufLen', - 'dupDataReceived', - 'dupBlksReceived' - ]) - done() - }) - }) - }) - }) }) diff --git a/test/core/interface/bitswap.js b/test/core/interface/bitswap.js new file mode 100644 index 0000000000..b7927dd5dd --- /dev/null +++ b/test/core/interface/bitswap.js @@ -0,0 +1,35 @@ +/* eslint-env mocha */ +'use strict' + +const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + +const IPFS = require('../../../src') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ type: 'proc', exec: IPFS }) + +const nodes = [] +const common = { + setup: function (callback) { + callback(null, { + spawnNode: (cb) => { + df.spawn({ + initOptions: { bits: 512 } + }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) + } +} + +test.bitswap(common) diff --git a/test/http-api/index.js b/test/http-api/index.js index 44d48f7f1f..924b2b43d9 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -1,11 +1,12 @@ 'use strict' -require('./interface') -require('./inject') +require('./bitswap') require('./block') require('./bootstrap') require('./config') require('./dns') require('./id') +require('./inject') +require('./interface') require('./object') require('./version') diff --git a/test/http-api/interface/bitswap.js b/test/http-api/interface/bitswap.js new file mode 100644 index 0000000000..231a41cfe2 --- /dev/null +++ b/test/http-api/interface/bitswap.js @@ -0,0 +1,31 @@ +/* eslint-env mocha */ +'use strict' + +const test = require('interface-ipfs-core') +const parallel = require('async/parallel') + +const DaemonFactory = require('ipfsd-ctl') +const df = DaemonFactory.create({ exec: 'src/cli/bin.js' }) + +const nodes = [] +const common = { + setup: function (callback) { + callback(null, { + spawnNode: (cb) => { + df.spawn({ initOptions: { bits: 512 } }, (err, _ipfsd) => { + if (err) { + return cb(err) + } + + nodes.push(_ipfsd) + cb(null, _ipfsd.api) + }) + } + }) + }, + teardown: function (callback) { + parallel(nodes.map((node) => (cb) => node.stop(cb)), callback) + } +} + +test.bitswap(common) From 8ddd541557c1f3768303803d5ed333dc4bc51304 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Thu, 26 Apr 2018 10:29:32 -0700 Subject: [PATCH 03/10] feat(tests) move some bitswap tests to interface Will require including the version of interface-ipfs-core that they are moved to --- src/cli/commands/block/get.js | 4 ++-- src/http/api/resources/bitswap.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index dd1e21d7fc..cb503afef7 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -19,9 +19,9 @@ module.exports = { } if (block) { - print(block.data) + process.stdout.write(block.data) } else { - print('Block was unwanted before it could be remotely retrieved') + process.stderr.write('Block was unwanted before it could be remotely retrieved') } }) } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index f846d87ba2..3da9b1bf6e 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -11,7 +11,10 @@ exports.wantlist = (request, reply) => { if (err) { return reply(boom.badRequest(err)) } - reply(list) + list = list.map((entry) => entry.cid.toBaseEncodedString()) + reply({ + Keys: list + }) }) } From 43c40ec58fe86c825581df2d185f9ed1502e2e08 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Thu, 10 May 2018 13:25:12 -0700 Subject: [PATCH 04/10] feat(bitswap.wantlist) add peer parameter --- src/cli/commands/bitswap/wantlist.js | 3 +- src/core/components/bitswap.js | 27 ++++++++++-- src/http/api/resources/bitswap.js | 65 +++++++++++++++------------- src/http/api/routes/bitswap.js | 4 +- src/http/api/routes/stats.js | 2 +- 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/cli/commands/bitswap/wantlist.js b/src/cli/commands/bitswap/wantlist.js index 8ad26a439a..01170782d7 100644 --- a/src/cli/commands/bitswap/wantlist.js +++ b/src/cli/commands/bitswap/wantlist.js @@ -16,8 +16,7 @@ module.exports = { }, handler (argv) { - // TODO: handle argv.peer - argv.ipfs.bitswap.wantlist((err, res) => { + argv.ipfs.bitswap.wantlist(argv.peer, (err, res) => { if (err) { throw err } diff --git a/src/core/components/bitswap.js b/src/core/components/bitswap.js index 9f3c7bfbab..bd59eb3b16 100644 --- a/src/core/components/bitswap.js +++ b/src/core/components/bitswap.js @@ -5,6 +5,7 @@ const promisify = require('promisify-es6') const setImmediate = require('async/setImmediate') const Big = require('big.js') const CID = require('cids') +const PeerId = require('peer-id') function formatWantlist (list) { return Array.from(list).map((e) => ({ '/': e[1].cid.toBaseEncodedString() })) @@ -12,14 +13,32 @@ function formatWantlist (list) { module.exports = function bitswap (self) { return { - wantlist: promisify((callback) => { + wantlist: promisify((peerId, callback) => { + if (!callback) { + callback = peerId + peerId = undefined + } + if (!self.isOnline()) { return setImmediate(() => callback(new Error(OFFLINE_ERROR))) } - let list = self._bitswap.getWantlist() + let list + if (peerId) { + try { + peerId = PeerId.createFromB58String(peerId) + } catch (e) { + peerId = null + } + if (!peerId) { + return setImmediate(() => callback(new Error('Invalid peerId'))) + } + list = self._bitswap.wantlistForPeer(peerId) + } else { + list = self._bitswap.getWantlist() + } list = formatWantlist(list) - callback(null, { Keys: list }) + return setImmediate(() => callback(null, { Keys: list })) }), stat: promisify((callback) => { @@ -56,7 +75,7 @@ module.exports = function bitswap (self) { } return new CID(key) }) - callback(null, self._bitswap.unwant(keys)) + return setImmediate(() => callback(null, self._bitswap.unwant(keys))) }) } } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index 3da9b1bf6e..1130aeb832 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -6,41 +6,44 @@ const parseKey = require('./block').parseKey exports = module.exports -exports.wantlist = (request, reply) => { - request.server.app.ipfs.bitswap.wantlist((err, list) => { - if (err) { - return reply(boom.badRequest(err)) - } - list = list.map((entry) => entry.cid.toBaseEncodedString()) - reply({ - Keys: list +exports.wantlist = { + handler: (request, reply) => { + const peerId = request.query.arg + let list + request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => { + if (err) { + return reply(boom.badRequest(err)) + } + reply(list) }) - }) + } } -exports.stat = (request, reply) => { - const ipfs = request.server.app.ipfs - - ipfs.bitswap.stat((err, stats) => { - if (err) { - return reply({ - Message: err.toString(), - Code: 0 - }).code(500) - } - - reply({ - ProvideBufLen: stats.provideBufLen, - BlocksReceived: stats.blocksReceived, - Wantlist: stats.wantlist, - Peers: stats.peers, - DupBlksReceived: stats.dupBlksReceived, - DupDataReceived: stats.dupDataReceived, - DataReceived: stats.dataReceived, - BlocksSent: stats.blocksSent, - DataSent: stats.dataSent +exports.stat = { + handler: (request, reply) => { + const ipfs = request.server.app.ipfs + + ipfs.bitswap.stat((err, stats) => { + if (err) { + return reply({ + Message: err.toString(), + Code: 0 + }).code(500) + } + + reply({ + ProvideBufLen: stats.provideBufLen, + BlocksReceived: stats.blocksReceived, + Wantlist: stats.wantlist, + Peers: stats.peers, + DupBlksReceived: stats.dupBlksReceived, + DupDataReceived: stats.dupDataReceived, + DataReceived: stats.dataReceived, + BlocksSent: stats.blocksSent, + DataSent: stats.dataSent + }) }) - }) + } } exports.unwant = { diff --git a/src/http/api/routes/bitswap.js b/src/http/api/routes/bitswap.js index 23c75b9a86..04def2fb91 100644 --- a/src/http/api/routes/bitswap.js +++ b/src/http/api/routes/bitswap.js @@ -9,7 +9,7 @@ module.exports = (server) => { method: '*', path: '/api/v0/bitswap/wantlist', config: { - handler: resources.bitswap.wantlist + handler: resources.bitswap.wantlist.handler } }) @@ -17,7 +17,7 @@ module.exports = (server) => { method: '*', path: '/api/v0/bitswap/stat', config: { - handler: resources.bitswap.stat + handler: resources.bitswap.stat.handler } }) diff --git a/src/http/api/routes/stats.js b/src/http/api/routes/stats.js index 35ec768083..1fe0707c1b 100644 --- a/src/http/api/routes/stats.js +++ b/src/http/api/routes/stats.js @@ -9,7 +9,7 @@ module.exports = (server) => { method: '*', path: '/api/v0/stats/bitswap', config: { - handler: resources.stats.bitswap + handler: resources.stats.bitswap.handler } }) From c99cf1f85ec38e668b06e72eaf0ddc32dc2f79a6 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Mon, 11 Jun 2018 14:28:17 -0700 Subject: [PATCH 05/10] fix(test) fix cli tests for both bitswap.unwant and bitswap.wantlist peerId --- src/cli/commands/bitswap/stat.js | 7 +------ src/cli/commands/bitswap/wantlist.js | 2 +- src/cli/commands/block/get.js | 4 ++-- src/http/api/resources/bitswap.js | 1 - test/cli/bitswap.js | 15 ++++++++++++++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/cli/commands/bitswap/stat.js b/src/cli/commands/bitswap/stat.js index 081dceb595..d7a26680f1 100644 --- a/src/cli/commands/bitswap/stat.js +++ b/src/cli/commands/bitswap/stat.js @@ -1,6 +1,5 @@ 'use strict' -const CID = require('cids') const print = require('../../utils').print module.exports = { @@ -17,11 +16,7 @@ module.exports = { } stats.wantlist = stats.wantlist || [] - stats.wantlist = stats.wantlist.map((entry) => { - const buf = Buffer.from(entry.cid.hash.data) - const cid = new CID(entry.cid.version, entry.cid.codec, buf) - return cid.toBaseEncodedString() - }) + stats.wantlist = stats.wantlist.map(entry => entry['/']) stats.peers = stats.peers || [] print(`bitswap status diff --git a/src/cli/commands/bitswap/wantlist.js b/src/cli/commands/bitswap/wantlist.js index 01170782d7..9397f492ae 100644 --- a/src/cli/commands/bitswap/wantlist.js +++ b/src/cli/commands/bitswap/wantlist.js @@ -3,7 +3,7 @@ const print = require('../../utils').print module.exports = { - command: 'wantlist', + command: 'wantlist [peer]', describe: 'Print out all blocks currently on the bitswap wantlist for the local peer.', diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index cb503afef7..dd1e21d7fc 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -19,9 +19,9 @@ module.exports = { } if (block) { - process.stdout.write(block.data) + print(block.data) } else { - process.stderr.write('Block was unwanted before it could be remotely retrieved') + print('Block was unwanted before it could be remotely retrieved') } }) } diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index 1130aeb832..e54b6f6863 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -9,7 +9,6 @@ exports = module.exports exports.wantlist = { handler: (request, reply) => { const peerId = request.query.arg - let list request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => { if (err) { return reply(boom.badRequest(err)) diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index 6cdebe61de..e2ab91a800 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -3,9 +3,11 @@ const expect = require('chai').expect const runOn = require('../utils/on-and-off').on +const PeerId = require('peer-id') describe('bitswap', () => runOn((thing) => { let ipfs + let peerId const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' before((done) => { @@ -13,7 +15,11 @@ describe('bitswap', () => runOn((thing) => { ipfs('block get ' + key) .then(() => {}) .catch(() => {}) - setTimeout(done, 250) + PeerId.create((err, peer) => { + expect(err).to.not.exist() + peerId = peer.toB58String() + setTimeout(done, 250) + }) }) it('wantlist', function () { @@ -23,6 +29,13 @@ describe('bitswap', () => runOn((thing) => { }) }) + it('wantlist peerid', function () { + this.timeout(20 * 1000) + return ipfs('bitswap wantlist ' + peerId).then((out) => { + expect(out).to.eql('') + }) + }) + it('stat', function () { this.timeout(20 * 1000) From e929da1823bec84626ef17b830c71f75ae6b2c37 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 18 Jun 2018 15:28:31 +0100 Subject: [PATCH 06/10] fix: pick peer property from querystring, fix tests License: MIT Signed-off-by: Alan Shaw --- src/http/api/resources/bitswap.js | 2 +- test/core/interface/interface.spec.js | 1 + test/http-api/index.js | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/api/resources/bitswap.js b/src/http/api/resources/bitswap.js index e54b6f6863..33eccd7bcb 100644 --- a/src/http/api/resources/bitswap.js +++ b/src/http/api/resources/bitswap.js @@ -8,7 +8,7 @@ exports = module.exports exports.wantlist = { handler: (request, reply) => { - const peerId = request.query.arg + const peerId = request.query.peer request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => { if (err) { return reply(boom.badRequest(err)) diff --git a/test/core/interface/interface.spec.js b/test/core/interface/interface.spec.js index 356036adeb..6bc0cdbe67 100644 --- a/test/core/interface/interface.spec.js +++ b/test/core/interface/interface.spec.js @@ -15,6 +15,7 @@ describe('interface-ipfs-core tests', () => { require('./stats') require('./key') if (isNode) { + require('./bitswap') require('./swarm') require('./ping') require('./pubsub') diff --git a/test/http-api/index.js b/test/http-api/index.js index 924b2b43d9..d619014896 100644 --- a/test/http-api/index.js +++ b/test/http-api/index.js @@ -1,6 +1,5 @@ 'use strict' -require('./bitswap') require('./block') require('./bootstrap') require('./config') From d5346cd22fbf58b9d1e632e4bee60bd9e6c4b396 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 18 Jun 2018 17:12:33 +0100 Subject: [PATCH 07/10] chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dba09a090d..e99a440375 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.66.2", + "interface-ipfs-core": "~0.68.1", "ipfsd-ctl": "~0.37.3", "lodash": "^4.17.10", "mocha": "^5.1.1", From 9e09073691f7cc42ce83b35562484d296cdbf122 Mon Sep 17 00:00:00 2001 From: Michael Garvin Date: Tue, 19 Jun 2018 09:52:32 -0700 Subject: [PATCH 08/10] fix: don't add newline to cli block.get output --- src/cli/commands/block/get.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index dd1e21d7fc..9fb61f4434 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -19,7 +19,7 @@ module.exports = { } if (block) { - print(block.data) + print(block.data, false) } else { print('Block was unwanted before it could be remotely retrieved') } From 884d37b33ed7b8935391fcbacbc05a8f46babbaa Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 19 Jun 2018 22:41:12 +0100 Subject: [PATCH 09/10] chore: increase timeout for bitswap cli test setup License: MIT Signed-off-by: Alan Shaw --- test/cli/bitswap.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/cli/bitswap.js b/test/cli/bitswap.js index e2ab91a800..8b6b8eea2a 100644 --- a/test/cli/bitswap.js +++ b/test/cli/bitswap.js @@ -10,7 +10,8 @@ describe('bitswap', () => runOn((thing) => { let peerId const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR' - before((done) => { + before(function (done) { + this.timeout(60 * 1000) ipfs = thing.ipfs ipfs('block get ' + key) .then(() => {}) @@ -18,7 +19,7 @@ describe('bitswap', () => runOn((thing) => { PeerId.create((err, peer) => { expect(err).to.not.exist() peerId = peer.toB58String() - setTimeout(done, 250) + done() }) }) From ec8ee4e703ed177f7ef45f98aa8394ee736d4236 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 19 Jun 2018 22:44:36 +0100 Subject: [PATCH 10/10] chore: update interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e99a440375..cd363adf15 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.68.1", + "interface-ipfs-core": "~0.68.2", "ipfsd-ctl": "~0.37.3", "lodash": "^4.17.10", "mocha": "^5.1.1",