diff --git a/README.md b/README.md index 24e03be5..640af1f4 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,16 @@ For the documentation see [API.md](API.md). ### API -#### `new Bitswap(id, libp2p, datastore)` +#### `new Bitswap(libp2p, blockstore)` -- `id: PeerId`, the id of the local instance. - `libp2p: Libp2p`, instance of the local network stack. -- `blockstore: Datastore`, instance of the local database (`IpfsRepo.blockstore`) +- `blockstore: Blockstore`, instance of the local database (`IpfsRepo.blockstore`) Create a new instance. -#### `getStream(key)` +#### `getStream(cid)` -- `key: Multihash|Array` +- `cid: CID|Array` Returns a source `pull-stream`. Values emitted are the received blocks. @@ -83,7 +82,7 @@ Example: ```js // Single block pull( - bitswap.getStream(key), + bitswap.getStream(cid), pull.collect((err, blocks) => { // blocks === [block] }) @@ -91,7 +90,7 @@ pull( // Many blocks pull( - bitswap.getStream([key1, key2, key3]), + bitswap.getStream([cid1, cid2, cid3]), pull.collect((err, blocks) => { // blocks === [block1, block2, block3] }) @@ -101,17 +100,17 @@ pull( > Note: This is safe guarded so that the network is not asked > for blocks that are in the local `datastore`. -#### `unwant(keys)` +#### `unwant(cids)` -- `keys: Mutlihash|[]Multihash` +- `cids: CID|[]CID` Cancel previously requested keys, forcefully. That means they are removed from the wantlist independent of how many other resources requested these keys. Callbacks attached to `getBlock` are errored with `Error('manual unwant: key')`. -#### `cancelWants(keys)` +#### `cancelWants(cids)` -- `keys: Multihash|[]Multihash` +- `cid: CID|[]CID` Cancel previously requested keys. @@ -120,10 +119,10 @@ Cancel previously requested keys. Returns a duplex `pull-stream` that emits an object `{key: Multihash}` for every written block when it was stored. Objects passed into here should be of the form `{data: Buffer, key: Multihash}` -#### `put(blockAndKey, cb)` +#### `put(blockAndCid, callback)` -- `blockAndKey: {data: Buffer, key: Multihash}` -- `cb: Function` +- `blockAndKey: {data: Buffer, cid: CID}` +- `callback: Function` Announce that the current node now has the block containing `data`. This will store it in the local database and attempt to serve it to all peers that are known diff --git a/src/index.js b/src/index.js index 203f23c1..3023bb17 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,15 @@ 'use strict' const series = require('async/series') -const retry = require('async/retry') const debug = require('debug') const log = debug('bitswap') log.error = debug('bitswap:error') const EventEmitter = require('events').EventEmitter -const mh = require('multihashes') const pull = require('pull-stream') const paramap = require('pull-paramap') const defer = require('pull-defer/source') -const Block = require('ipfs-block') +const CID = require('cids') const CONSTANTS = require('./constants') const WantManager = require('./components/want-manager') @@ -19,10 +17,7 @@ const Network = require('./components/network') const DecisionEngine = require('./components/decision-engine') class Bitswap { - constructor (id, libp2p, blockstore, peerBook) { - // the ID of the peer to act on behalf of - this.self = id - + constructor (libp2p, blockstore, peerBook) { // the network delivers messages this.network = new Network(libp2p, peerBook, this) @@ -51,95 +46,88 @@ class Bitswap { log('failed to receive message', incoming) } - const iblocks = Array.from(incoming.blocks.values()) + const cidsAndBlocks = Array + .from(incoming.blocks.entries()) + .map((entry) => { + return { cid: new CID(entry[0]), block: entry[1] } + }) - if (iblocks.length === 0) { + if (cidsAndBlocks.length === 0) { return cb() } // quickly send out cancels, reduces chances of duplicate block receives pull( - pull.values(iblocks), - pull.asyncMap((block, cb) => block.key(cb)), - pull.filter((key) => this.wm.wl.contains(key)), - pull.collect((err, keys) => { + pull.values(cidsAndBlocks), + pull.filter((cidAndBlock) => this.wm.wantlist.contains(cidAndBlock.cid)), + pull.collect((err, cidsAndBlocks) => { if (err) { return log.error(err) } - this.wm.cancelWants(keys) + const cids = cidsAndBlocks.map((entry) => entry.cid) + + this.wm.cancelWants(cids) }) ) pull( - pull.values(iblocks), + pull.values(cidsAndBlocks), paramap(this._handleReceivedBlock.bind(this, peerId), 10), pull.onEnd(cb) ) }) } - _handleReceivedBlock (peerId, block, cb) { + _handleReceivedBlock (peerId, cidAndBlock, callback) { series([ - (cb) => this._updateReceiveCounters(block, (err) => { + (cb) => this._updateReceiveCounters(cidAndBlock.block, (err) => { if (err) { // ignore, as these have been handled // in _updateReceiveCounters return cb() } - log('got block from %s', peerId.toB58String(), block.data.length) + log('got block from %s', peerId.toB58String(), cidAndBlock.block.data.length) cb() }), - (cb) => block.key((err, key) => { - if (err) { - return cb(err) - } - this.put({data: block.data, key: key}, (err) => { + (cb) => { + this.put({ + data: cidAndBlock.block.data, + cid: cidAndBlock.cid + }, (err) => { if (err) { log.error('receiveMessage put error: %s', err.message) } cb() }) - }) - ], cb) + } + ], callback) } - _updateReceiveCounters (block, cb) { + _updateReceiveCounters (block, callback) { this.blocksRecvd ++ block.key((err, key) => { if (err) { - return cb(err) + return callback(err) } this.blockstore.has(key, (err, has) => { if (err) { log('blockstore.has error: %s', err.message) - return cb(err) + return callback(err) } if (has) { this.dupBlocksRecvd ++ this.dupDataRecvd += block.data.length - return cb(new Error('Already have block')) + return callback(new Error('Already have block')) } - cb() + callback() }) }) } - _tryPutBlock (block, times, cb) { - log('trying to put block %s', block.data.toString()) - retry({times, interval: 400}, (done) => { - pull( - pull.values([block]), - pull.asyncMap(blockToStore), - this.blockstore.putStream(), - pull.onEnd(done) - ) - }, cb) - } - // handle errors on the receiving channel _receiveError (err) { log.error('ReceiveError: %s', err.message) @@ -161,16 +149,16 @@ class Bitswap { return this.engine.wantlistForPeer(peerId) } - getStream (keys) { - if (!Array.isArray(keys)) { - return this._getStreamSingle(keys) + getStream (cids) { + if (!Array.isArray(cids)) { + return this._getStreamSingle(cids) } return pull( - pull.values(keys), - paramap((key, cb) => { + pull.values(cids), + paramap((cid, cb) => { pull( - this._getStreamSingle(key), + this._getStreamSingle(cid), pull.collect(cb) ) }), @@ -178,110 +166,107 @@ class Bitswap { ) } - _getStreamSingle (key) { + _getStreamSingle (cid) { const unwantListeners = {} const blockListeners = {} - const unwantEvent = (key) => `unwant:${key}` - const blockEvent = (key) => `block:${key}` + const unwantEvent = (cidStr) => `unwant:${cidStr}` + const blockEvent = (cidStr) => `block:${cidStr}` const d = defer() - const cleanupListener = (key) => { - const keyS = mh.toB58String(key) + const cleanupListener = (cid) => { + const cidStr = cid.toBaseEncodedString() - if (unwantListeners[keyS]) { - this.notifications.removeListener(unwantEvent(keyS), unwantListeners[keyS]) - delete unwantListeners[keyS] + if (unwantListeners[cidStr]) { + this.notifications.removeListener(unwantEvent(cidStr), unwantListeners[cidStr]) + delete unwantListeners[cidStr] } - if (blockListeners[keyS]) { - this.notifications.removeListener(blockEvent(keyS), blockListeners[keyS]) - delete blockListeners[keyS] + if (blockListeners[cidStr]) { + this.notifications.removeListener(blockEvent(cidStr), blockListeners[cidStr]) + delete blockListeners[cidStr] } } - const addListener = (key) => { - const keyS = mh.toB58String(key) - unwantListeners[keyS] = () => { - log(`manual unwant: ${keyS}`) - cleanupListener(key) - this.wm.cancelWants([key]) + const addListener = (cid) => { + const cidStr = cid.toBaseEncodedString() + unwantListeners[cidStr] = () => { + log(`manual unwant: ${cidStr}`) + cleanupListener(cid) + this.wm.cancelWants([cid]) d.resolve(pull.empty()) } - blockListeners[keyS] = (block) => { - this.wm.cancelWants([key]) - cleanupListener(key) + blockListeners[cidStr] = (block) => { + this.wm.cancelWants([cid]) + cleanupListener(cid) d.resolve(pull.values([block])) } - this.notifications.once(unwantEvent(keyS), unwantListeners[keyS]) - this.notifications.once(blockEvent(keyS), blockListeners[keyS]) + this.notifications.once(unwantEvent(cidStr), unwantListeners[cidStr]) + this.notifications.once(blockEvent(cidStr), blockListeners[cidStr]) } - this.blockstore.has(key, (err, exists) => { + this.blockstore.has(cid.multihash, (err, exists) => { if (err) { return d.resolve(pull.error(err)) } if (exists) { - log('already have block', mh.toB58String(key)) - return d.resolve(this.blockstore.getStream(key)) + log('already have block', cid.toBaseEncodedString()) + return d.resolve(this.blockstore.getStream(cid.multihash)) } - addListener(key) - this.wm.wantBlocks([key]) + addListener(cid) + this.wm.wantBlocks([cid]) }) return d } - // removes the given keys from the want list independent of any ref counts - unwant (keys) { - if (!Array.isArray(keys)) { - keys = [keys] + // removes the given cids from the wantlist independent of any ref counts + unwant (cids) { + if (!Array.isArray(cids)) { + cids = [cids] } - this.wm.unwantBlocks(keys) - keys.forEach((key) => { - this.notifications.emit(`unwant:${mh.toB58String(key)}`) + this.wm.unwantBlocks(cids) + cids.forEach((cid) => { + this.notifications.emit(`unwant:${cid.toBaseEncodedString()}`) }) } // removes the given keys from the want list - cancelWants (keys) { - if (!Array.isArray(keys)) { - keys = [keys] + cancelWants (cids) { + if (!Array.isArray(cids)) { + cids = [cids] } - this.wm.cancelWants(keys) + this.wm.cancelWants(cids) } putStream () { return pull( - pull.asyncMap((blockAndKey, cb) => { - this.blockstore.has(blockAndKey.key, (err, exists) => { + pull.asyncMap((blockAndCid, cb) => { + this.blockstore.has(blockAndCid.cid.multihash, (err, exists) => { if (err) { return cb(err) } - cb(null, [new Block(blockAndKey.data), exists]) + cb(null, [blockAndCid.block, exists]) }) }), pull.filter((val) => !val[1]), pull.map((val) => { const block = val[0] + const cid = val[1] log('putting block') return pull( - pull.values([block]), - pull.asyncMap(blockToStore), + pull.values([ + { block: block, key: cid.multihash } + ]), this.blockstore.putStream(), pull.asyncMap((meta, cb) => { - block.key((err, key) => { - if (err) { - return cb(err) - } - log('put block: %s', mh.toB58String(key)) - this.notifications.emit(`block:${mh.toB58String(key)}`, block) - this.engine.receivedBlock(key) - cb(null, meta) - }) + log('put block: %s', cid.toBaseEncodedString()) + this.notifications.emit(`block:${cid.toBaseEncodedString()}`, block) + this.engine.receivedBlock(cid) + cb(null, meta) }) ) }), @@ -290,16 +275,16 @@ class Bitswap { } // announces the existance of a block to this service - put (blockAndKey, cb) { + put (blockAndCid, callback) { pull( - pull.values([blockAndKey]), + pull.values([blockAndCid]), this.putStream(), - pull.onEnd(cb) + pull.onEnd(callback) ) } getWantlist () { - return this.wm.wl.entries() + return this.wm.wantlist.entries() } stat () { @@ -326,17 +311,4 @@ class Bitswap { } } -// Helper method, to add a cid to a block before storing it in the ipfs-repo/blockstore -function blockToStore (b, callback) { - b.key((err, key) => { - if (err) { - return callback(err) - } - callback(null, { - data: b.data, - key: key - }) - }) -} - module.exports = Bitswap diff --git a/test/components/network/gen-bitswap-network.node.js b/test/components/network/gen-bitswap-network.node.js index 05aa6169..b74c550f 100644 --- a/test/components/network/gen-bitswap-network.node.js +++ b/test/components/network/gen-bitswap-network.node.js @@ -47,7 +47,7 @@ describe.skip('gen Bitswap network', function () { } cb(null, { - data: block.data, + block: block, cid: new CID(key) }) }) @@ -57,6 +57,7 @@ describe.skip('gen Bitswap network', function () { ) }, (cb) => { + console.log('do I get here?') each(_.range(100), (i, cb) => { map(blocks, (block, cb) => block.key(cb), (err, keys) => { const cids = keys.map((key) => new CID(key)) diff --git a/test/index-test.js b/test/index-test.js index 72017a2c..1a81df82 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -12,9 +12,9 @@ const _ = require('lodash') const expect = require('chai').expect const PeerId = require('peer-id') const Block = require('ipfs-block') -const mh = require('multihashes') const PeerBook = require('peer-book') const pull = require('pull-stream') +const CID = require('cids') const Message = require('../src/types/message') const Bitswap = require('../src') @@ -33,9 +33,10 @@ module.exports = (repo) => { } } - describe.skip('bitswap', () => { + describe('bitswap', () => { let store let blocks + let cids let ids before((done) => { @@ -52,7 +53,13 @@ module.exports = (repo) => { blocks = results[1] ids = results[2] - done() + map(blocks, (b, cb) => b.key(cb), (err, keys) => { + if (err) { + return done(err) + } + cids = keys.map((key) => new CID(key)) + done() + }) }) }) @@ -61,83 +68,84 @@ module.exports = (repo) => { }) describe('receive message', () => { - it('simple block message', (done) => { - const me = ids[0] + it.skip('simple block message', (done) => { const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) bs.start() const other = ids[1] + const b1 = blocks[0] const b2 = blocks[1] + const cid1 = cids[0] + const cid2 = cids[1] + const msg = new Message(false) - each([b1, b2], (b, cb) => msg.addBlock(b, cb), (err) => { - expect(err).to.not.exist + msg.addBlock(cid1, b1) + msg.addBlock(cid2, b2) - bs._receiveMessage(other, msg, (err) => { - if (err) { - throw err - } + bs._receiveMessage(other, msg, (err) => { + if (err) { + throw err + } - expect(bs.blocksRecvd).to.be.eql(2) - expect(bs.dupBlocksRecvd).to.be.eql(0) + expect(bs.blocksRecvd).to.equal(2) + expect(bs.dupBlocksRecvd).to.equal(0) - pull( - pull.values([b1, b2]), - pull.asyncMap((b, cb) => b.key(cb)), - pull.map((key) => store.getStream(key)), - pull.flatten(), - pull.collect((err, blocks) => { - if (err) return done(err) - - expect(blocks[0].data).to.be.eql(b1.data) - expect(blocks[1].data).to.be.eql(b2.data) - done() - }) - ) - }) + pull( + pull.values([cid1, cid2]), + pull.map((cid) => store.getStream(cid)), + pull.flatten(), + pull.collect((err, blocks) => { + if (err) { + return done(err) + } + + expect(blocks[0].data).to.eql(b1.data) + expect(blocks[1].data).to.eql(b2.data) + done() + }) + ) }) }) it('simple want message', (done) => { - const me = ids[0] const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) bs.start() const other = ids[1] - const b1 = blocks[2] - const b2 = blocks[3] + const cid1 = cids[0] + const cid2 = cids[1] + const msg = new Message(false) - parallel([ - (cb) => b1.key(cb), - (cb) => b2.key(cb) - ], (err, keys) => { - expect(err).to.not.exist - msg.addEntry(keys[0], 1, false) - msg.addEntry(keys[1], 1, false) + msg.addEntry(cid1, 1, false) + msg.addEntry(cid2, 1, false) - bs._receiveMessage(other, msg, (err) => { - expect(err).to.not.exist + bs._receiveMessage(other, msg, (err) => { + expect(err).to.not.exist - expect(bs.blocksRecvd).to.be.eql(0) - expect(bs.dupBlocksRecvd).to.be.eql(0) + expect(bs.blocksRecvd).to.be.eql(0) + expect(bs.dupBlocksRecvd).to.be.eql(0) - const wl = bs.wantlistForPeer(other) + const wl = bs.wantlistForPeer(other) - expect(wl.has(mh.toB58String(keys[0]))).to.be.eql(true) - expect(wl.has(mh.toB58String(keys[1]))).to.be.eql(true) + expect(wl.has(cid1.toBaseEncodedString())).to.eql(true) + expect(wl.has(cid2.toBaseEncodedString())).to.eql(true) - done() - }) + done() }) }) it('multi peer', (done) => { - const me = ids[0] const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) + + let others + let blocks + let cids + bs.start() parallel([ @@ -148,21 +156,32 @@ module.exports = (repo) => { return done(err) } - const others = results[0] - const blocks = results[1] + others = results[0] + blocks = results[1] + + map(blocks, (b, cb) => b.key(cb), (err, keys) => { + if (err) { + return done(err) + } + cids = keys.map((key) => new CID(key)) + test() + }) + }) + function test () { map(_.range(5), (i, cb) => { - const m = new Message(false) - each( - [blocks[i], blocks[5 + i]], - (b, cb) => m.addBlock(b, cb), - (err) => { - if (err) { - return cb(err) - } - cb(null, m) - } - ) + const msg = new Message(false) + + each([ + { block: blocks[i], cid: cids[i] }, + { block: blocks[5 + i], cid: cids[5 + i] } + ], (blockAndCid, cb) => { + msg.addBlock(blockAndCid.cid, blockAndCid.block) + cb() + }, (err) => { + expect(err).to.not.exist + cb(null, msg) + }) }, (err, messages) => { expect(err).to.not.exist let i = 0 @@ -170,22 +189,24 @@ module.exports = (repo) => { const msg = messages[i] i++ bs._receiveMessage(other, msg, (err) => { - if (err) return cb(err) + expect(err).to.not.exist hasBlocks(msg, store, cb) }) }, done) }) - }) + } }) }) describe('getStream', () => { it('block exists locally', (done) => { - const me = ids[0] const block = blocks[4] + const cid = cids[4] + pull( - pull.values([block]), - pull.asyncMap(blockToStore), + pull.values([ + { data: block.data, key: cid.multihash } + ]), store.putStream(), pull.onEnd((err) => { if (err) { @@ -193,19 +214,16 @@ module.exports = (repo) => { } const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) pull( - pull.values([block]), - pull.asyncMap((b, cb) => b.key(cb)), - pull.map((key) => bs.getStream(key)), - pull.flatten(), + bs.getStream(cid), pull.collect((err, res) => { if (err) { return done(err) } - expect(res[0].data).to.be.eql(block.data) + expect(res[0].data).to.eql(block.data) done() }) ) @@ -214,85 +232,47 @@ module.exports = (repo) => { }) it('blocks exist locally', (done) => { - const me = ids[0] const b1 = blocks[5] const b2 = blocks[6] const b3 = blocks[7] + const cid1 = cids[5] + const cid2 = cids[6] + const cid3 = cids[7] pull( - pull.values([b1, b2, b3]), - pull.asyncMap(blockToStore), + pull.values([ + { data: b1.data, key: cid1.multihash }, + { data: b2.data, key: cid2.multihash }, + { data: b3.data, key: cid3.multihash } + ]), store.putStream(), pull.onEnd((err) => { expect(err).to.not.exist const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) pull( - pull.values([b1, b2, b3]), - pull.asyncMap((b, cb) => b.key(cb)), - pull.collect((err, keys) => { + bs.getStream([cid1, cid2, cid3]), + pull.collect((err, res) => { expect(err).to.not.exist - pull( - bs.getStream(keys), - pull.collect((err, res) => { - expect(err).to.not.exist - - expect(res[0].data).to.be.eql(b1.data) - expect(res[1].data).to.be.eql(b2.data) - expect(res[2].data).to.be.eql(b3.data) - done() - }) - ) + + expect(res[0].data).to.eql(b1.data) + expect(res[1].data).to.eql(b2.data) + expect(res[2].data).to.eql(b3.data) + done() }) ) }) ) }) - // Not sure if I understand what is going on here - // test fails because now the network is not properly mocked - // what are these net.stores and mockNet.bitswaps? - it.skip('block is retrived from peer', (done) => { - const block = blocks[8] - - let mockNet - waterfall([ - (cb) => utils.createMockNet(repo, 2, cb), - (net, cb) => { - mockNet = net - net.stores[1].put(block, cb) - }, - (val, cb) => { - mockNet.bitswaps[0]._onPeerConnected(mockNet.ids[1]) - mockNet.bitswaps[1]._onPeerConnected(mockNet.ids[0]) - pull( - pull.values([block]), - pull.asyncMap((b, cb) => b.key(cb)), - pull.map((key) => mockNet.bitswaps[0].getStream(key)), - pull.flatten(), - pull.collect((err, res) => { - if (err) { - return cb(err) - } - cb(null, res[0]) - }) - ) - }, - (res, cb) => { - expect(res).to.be.eql(block) - cb() - } - ], done) - }) - - it('block is added locally afterwards', (done) => { - const me = ids[0] + it.skip('block is added locally afterwards', (done) => { const block = blocks[9] const book = new PeerBook() - const bs = new Bitswap(me, libp2pMock, store, book) + const bs = new Bitswap(libp2pMock, store, book) const net = utils.mockNetwork() + bs.network = net bs.wm.network = net bs.engine.network = net @@ -318,7 +298,7 @@ module.exports = (repo) => { }) }) - it('block is sent after local add', (done) => { + it.skip('block is sent after local add', (done) => { const me = ids[0] const other = ids[1] const block = blocks[10] @@ -361,7 +341,7 @@ module.exports = (repo) => { start () {}, stop () {} } - bs1 = new Bitswap(me, libp2pMock, store, new PeerBook()) + bs1 = new Bitswap(libp2pMock, store, new PeerBook()) utils.applyNetwork(bs1, n1) bs1.start() @@ -371,7 +351,7 @@ module.exports = (repo) => { (cb) => repo.create('world', cb), (repo, cb) => { store2 = repo.blockstore - bs2 = new Bitswap(other, libp2pMock, store2, new PeerBook()) + bs2 = new Bitswap(libp2pMock, store2, new PeerBook()) utils.applyNetwork(bs2, n2) bs2.start() bs1._onPeerConnected(other) @@ -405,8 +385,7 @@ module.exports = (repo) => { describe('stat', () => { it('has initial stats', () => { - const me = ids[0] - const bs = new Bitswap(me, libp2pMock, {}, new PeerBook()) + const bs = new Bitswap(libp2pMock, {}, new PeerBook()) const stats = bs.stat() expect(stats).to.have.property('wantlist') @@ -419,8 +398,7 @@ module.exports = (repo) => { describe('unwant', () => { it('removes blocks that are wanted multiple times', (done) => { - const me = ids[0] - const bs = new Bitswap(me, libp2pMock, store, new PeerBook()) + const bs = new Bitswap(libp2pMock, store, new PeerBook()) bs.start() const b = blocks[11] @@ -434,7 +412,7 @@ module.exports = (repo) => { b.key((err, key) => { expect(err).to.not.exist pull( - bs.getStream(key), + bs.getStream(new CID(key)), pull.collect((err, res) => { expect(err).to.not.exist expect(res).to.be.empty @@ -442,7 +420,7 @@ module.exports = (repo) => { }) ) pull( - bs.getStream(key), + bs.getStream(new CID(key)), pull.collect((err, res) => { expect(err).to.not.exist expect(res).to.be.empty @@ -450,7 +428,7 @@ module.exports = (repo) => { }) ) - setTimeout(() => bs.unwant(key), 10) + setTimeout(() => bs.unwant(new CID(key)), 10) }) }) }) @@ -471,13 +449,3 @@ function hasBlocks (msg, store, cb) { }) }, cb) } - -function blockToStore (b, cb) { - b.key((err, key) => { - if (err) { - return cb(err) - } - - cb(null, {data: b.data, key: key}) - }) -} diff --git a/test/types/message.spec.js b/test/types/message.spec.js index 6e9de5d4..27578f9c 100644 --- a/test/types/message.spec.js +++ b/test/types/message.spec.js @@ -1,4 +1,5 @@ /* eslint-env mocha */ +/* eslint max-nested-callbacks: ["error", 8] */ 'use strict' const expect = require('chai').expect diff --git a/test/utils.js b/test/utils.js index f8156962..e1ca88f2 100644 --- a/test/utils.js +++ b/test/utils.js @@ -59,7 +59,7 @@ exports.createMockNet = (repo, count, cb) => { const ids = results[1] const hexIds = ids.map((id) => id.toHexString()) - const bitswaps = _.range(count).map((i) => new Bitswap(ids[i], {}, stores[i])) + const bitswaps = _.range(count).map((i) => new Bitswap({}, stores[i])) const networks = _.range(count).map((i) => { return { connectTo (id, cb) { @@ -153,7 +153,7 @@ exports.genBitswapNetwork = (n, callback) => { // create every BitSwap function createBitswaps () { netArray.forEach((net) => { - net.bitswap = new Bitswap(net.peerInfo, net.libp2p, net.repo.blockstore, net.peerBook) + net.bitswap = new Bitswap(net.libp2p, net.repo.blockstore, net.peerBook) }) establishLinks() }