diff --git a/package.json b/package.json index 50ba4b51fa..0eb03fc744 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,9 @@ "ncp": "^2.0.0", "nexpect": "^0.5.0", "pre-commit": "^1.2.2", + "pretty-bytes": "^4.0.2", "qs": "^6.3.0", + "random-fs": "^1.0.3", "rimraf": "^2.5.4", "stream-to-promise": "^2.2.0", "transform-loader": "^0.2.3" @@ -100,7 +102,7 @@ "hoek": "^4.1.0", "idb-pull-blob-store": "~0.5.1", "ipfs-api": "^12.1.7", - "ipfs-bitswap": "~0.9.3", + "ipfs-bitswap": "~0.9.4", "ipfs-block": "~0.5.5", "ipfs-block-service": "~0.8.3", "ipfs-multipart": "~0.1.0", @@ -175,4 +177,4 @@ "npmcdn-to-unpkg-bot ", "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ " ] -} \ No newline at end of file +} diff --git a/src/core/components/go-online.js b/src/core/components/go-online.js index fb9b407b17..c6456d96c0 100644 --- a/src/core/components/go-online.js +++ b/src/core/components/go-online.js @@ -17,11 +17,14 @@ module.exports = (self) => { self._bitswap = new Bitswap( self._libp2pNode, self._repo.blockstore, - self._libp2pNode.peerBook + self._peerInfoBook ) - self._pubsub = new FloodSub(self._libp2pNode) + const pubsub = self._configOpts.EXPERIMENTAL.pubsub + if (pubsub) { + self._pubsub = new FloodSub(self._libp2pNode) + } series([ (cb) => { self._bitswap.start() @@ -32,7 +35,7 @@ module.exports = (self) => { cb() }, (cb) => { - if (self._configOpts.EXPERIMENTAL.pubsub) { + if (pubsub) { self._pubsub.start(cb) } else { cb() diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index ccfcddda7e..4956a58b1b 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -19,7 +19,7 @@ module.exports = function libp2p (self) { bootstrap: config.Bootstrap } - self._libp2pNode = new Node(self._peerInfo, undefined, options) + self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options) self._libp2pNode.start((err) => { if (err) { @@ -31,11 +31,11 @@ module.exports = function libp2p (self) { }) self._libp2pNode.discovery.on('peer', (peerInfo) => { - self._libp2pNode.peerBook.put(peerInfo) + self._peerInfoBook.put(peerInfo) self._libp2pNode.dialByPeerInfo(peerInfo, () => {}) }) self._libp2pNode.swarm.on('peer-mux-established', (peerInfo) => { - self._libp2pNode.peerBook.put(peerInfo) + self._peerInfoBook.put(peerInfo) }) callback() diff --git a/src/core/components/swarm.js b/src/core/components/swarm.js index 45313a79ce..57157678ea 100644 --- a/src/core/components/swarm.js +++ b/src/core/components/swarm.js @@ -23,7 +23,7 @@ module.exports = function swarm (self) { // TODO: return latency and streams when verbose is set // we currently don't have this information - const peers = self._libp2pNode.peerBook.getAll() + const peers = self._peerInfoBook.getAll() const keys = Object.keys(peers) const peerList = flatMap(keys, (id) => { @@ -52,7 +52,7 @@ module.exports = function swarm (self) { return callback(OFFLINE_ERROR) } - const peers = values(self._libp2pNode.peerBook.getAll()) + const peers = values(self._peerInfoBook.getAll()) callback(null, peers) }), diff --git a/test/interop/daemons/go.js b/test/interop/daemons/go.js index e8a8b214af..e1719b7024 100644 --- a/test/interop/daemons/go.js +++ b/test/interop/daemons/go.js @@ -3,6 +3,8 @@ const ctl = require('ipfsd-ctl') const waterfall = require('async/waterfall') +const flags = ['--enable-mplex-experiment'] + class GoDaemon { constructor (opts) { opts = opts || { @@ -37,7 +39,7 @@ class GoDaemon { this.node = node this.node.setConfig('Bootstrap', '[]', cb) }, - (res, cb) => this.node.startDaemon(cb), + (res, cb) => this.node.startDaemon(flags, cb), (api, cb) => { this.api = api diff --git a/test/interop/daemons/js.js b/test/interop/daemons/js.js index 234099aa8c..fffeef714c 100644 --- a/test/interop/daemons/js.js +++ b/test/interop/daemons/js.js @@ -1,10 +1,10 @@ 'use strict' -const os = require('os') const IPFSAPI = require('ipfs-api') const series = require('async/series') const rimraf = require('rimraf') const IPFSRepo = require('ipfs-repo') +const tmpDir = require('../util').tmpDir const IPFS = require('../../../src/core') const HTTPAPI = require('../../../src/http-api') @@ -23,7 +23,10 @@ function setPorts (ipfs, port, callback) { ), (cb) => ipfs.config.set( 'Addresses.Swarm', - ['/ip4/0.0.0.0/tcp/' + (4002 + port)], + [ + '/ip4/0.0.0.0/tcp/' + (4003 + port), + '/ip4/0.0.0.0/tcp/' + (4004 + port) + '/ws' + ], cb ) ], callback) @@ -41,7 +44,7 @@ class JsDaemon { this.init = opts.init this.port = opts.port - this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 10000)}` + this.path = opts.path || tmpDir() if (this.init) { this.ipfs = new IPFS({ repo: this.path @@ -49,7 +52,10 @@ class JsDaemon { } else { const repo = new IPFSRepo(this.path, {stores: require('fs-pull-blob-store')}) this.ipfs = new IPFS({ - repo: repo + repo: repo, + EXPERIMENTAL: { + pubsub: true + } }) } this.node = null diff --git a/test/interop/index.js b/test/interop/index.js index 2f4a30ab97..dea2ae4b10 100644 --- a/test/interop/index.js +++ b/test/interop/index.js @@ -7,6 +7,14 @@ const parallel = require('async/parallel') const waterfall = require('async/waterfall') const bl = require('bl') const crypto = require('crypto') +const pretty = require('pretty-bytes') +const randomFs = require('random-fs') +const promisify = require('promisify-es6') +const rimraf = require('rimraf') + +const rmDir = promisify(rimraf) + +const tmpDir = require('./util').tmpDir const GoDaemon = require('./daemons/go') const JsDaemon = require('./daemons/js') @@ -19,12 +27,18 @@ const sizes = [ 1024 * 512, 1024 * 768, 1024 * 1023, - // starts failing with multiplex 1024 * 1024, 1024 * 1024 * 4, 1024 * 1024 * 8 ] +const dirs = [ + 5, + 10, + 50, + 100 +] + describe('basic', () => { let goDaemon let jsDaemon @@ -107,7 +121,7 @@ describe('basic', () => { }) describe('cat file', () => sizes.forEach((size) => { - it(`go -> js: ${size}bytes`, (done) => { + it(`go -> js: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => goDaemon.api.add(data, cb), @@ -120,7 +134,7 @@ describe('basic', () => { }) }) - it(`js -> go: ${size}bytes`, (done) => { + it(`js -> go: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => jsDaemon.api.add(data, cb), @@ -133,7 +147,7 @@ describe('basic', () => { }) }) - it(`js -> js: ${size}bytes`, (done) => { + it(`js -> js: ${pretty(size)}`, (done) => { const data = crypto.randomBytes(size) waterfall([ (cb) => js2Daemon.api.add(data, cb), @@ -146,4 +160,57 @@ describe('basic', () => { }) }) })) + + describe('get directory', () => dirs.forEach((num) => { + it(`go -> js: depth: 5, num: ${num}`, () => { + const dir = tmpDir() + return randomFs({ + path: dir, + depth: 5, + number: num + }).then(() => { + return goDaemon.api.util.addFromFs(dir, {recursive: true}) + }).then((res) => { + const hash = res[res.length - 1].hash + return jsDaemon.api.object.get(hash) + }).then((res) => { + expect(res).to.exist + return rmDir(dir) + }) + }) + + it(`js -> go: depth: 5, num: ${num}`, () => { + const dir = tmpDir() + return randomFs({ + path: dir, + depth: 5, + number: num + }).then(() => { + return jsDaemon.api.util.addFromFs(dir, {recursive: true}) + }).then((res) => { + const hash = res[res.length - 1].hash + return goDaemon.api.object.get(hash) + }).then((res) => { + expect(res).to.exist + return rmDir(dir) + }) + }) + + it(`js -> js: depth: 5, num: ${num}`, () => { + const dir = tmpDir() + return randomFs({ + path: dir, + depth: 5, + number: num + }).then(() => { + return js2Daemon.api.util.addFromFs(dir, {recursive: true}) + }).then((res) => { + const hash = res[res.length - 1].hash + return jsDaemon.api.object.get(hash) + }).then((res) => { + expect(res).to.exist + return rmDir(dir) + }) + }) + })) }) diff --git a/test/interop/util.js b/test/interop/util.js new file mode 100644 index 0000000000..256f857f0c --- /dev/null +++ b/test/interop/util.js @@ -0,0 +1,13 @@ +'use strict' + +const os = require('os') +const crypto = require('libp2p-crypto') +const path = require('path') + +exports.tmpDir = (prefix) => { + return path.join( + os.tmpdir(), + prefix || 'tmp', + crypto.randomBytes(32).toString('hex') + ) +} diff --git a/test/node.js b/test/node.js index 7c50c663cb..22872e6d02 100644 --- a/test/node.js +++ b/test/node.js @@ -6,19 +6,20 @@ let testCLI = true if (process.env.TEST) { switch (process.env.TEST) { - case 'core': { + case 'core': testHTTP = false testCLI = false - } break - case 'http': { + break + case 'http': testCore = false testCLI = false - } break - case 'cli': { + break + case 'cli': testCore = false testHTTP = false - } break - default: break + break + default: + break } }