From 01ef4b530da1b602aa6f9ee972ce5bde76dd898e Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 30 Jan 2017 09:55:14 +0000 Subject: [PATCH 01/28] fix: default config file --- src/init-files/default-config-browser.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/init-files/default-config-browser.json b/src/init-files/default-config-browser.json index 93fbbbdd58..fb0220729c 100644 --- a/src/init-files/default-config-browser.json +++ b/src/init-files/default-config-browser.json @@ -4,6 +4,11 @@ "API": "/ip4/127.0.0.1/tcp/5002", "Gateway": "/ip4/127.0.0.1/tcp/9090" }, - "Discovery": {}, + "Discovery": { + "MDNS": { + "Enabled": false, + "Interval": 10 + } + }, "Bootstrap": [] } From 79e8f7b968a16c1939c55bff3b5331d3e76cc6e9 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 30 Jan 2017 15:44:13 +0000 Subject: [PATCH 02/28] chore: update deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 409077524a..be6ec41697 100644 --- a/package.json +++ b/package.json @@ -103,10 +103,10 @@ "ipfs-multipart": "^0.1.0", "ipfs-repo": "^0.11.2", "ipfs-unixfs": "^0.1.9", - "ipfs-unixfs-engine": "^0.15.1", - "ipld-resolver": "^0.4.2", + "ipfs-unixfs-engine": "^0.15.2", + "ipld-resolver": "^0.4.3", "isstream": "^0.1.2", - "libp2p-floodsub": "0.7.1", + "libp2p-floodsub": "0.7.2", "joi": "^10.2.0", "libp2p-ipfs-nodejs": "^0.17.9", "libp2p-ipfs-browser": "^0.17.8", @@ -171,4 +171,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} From 9181f8433dca83fbd143e4faa0646c106d301794 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 30 Jan 2017 15:48:37 +0000 Subject: [PATCH 03/28] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be6ec41697..5e0ce69b10 100644 --- a/package.json +++ b/package.json @@ -171,4 +171,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} +} \ No newline at end of file From 02efd7cd451b2f8efcd3a7381f3971389d05e3f8 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 30 Jan 2017 15:48:37 +0000 Subject: [PATCH 04/28] chore: release version v0.21.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e0ce69b10..0c39ba4056 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs", - "version": "0.21.6", + "version": "0.21.7", "description": "JavaScript implementation of the IPFS specification", "bin": { "jsipfs": "src/cli/bin.js" From d3dc3d376e7ff92108a6034fab64b1f8f8938b0a Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 31 Jan 2017 13:03:08 +0000 Subject: [PATCH 05/28] test: another add recursive test (#743) * test: another add recursive test * chore: update deps --- package.json | 4 ++-- test/cli/test-files.js | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0c39ba4056..2ec5e18ec6 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "ipfs-multipart": "^0.1.0", "ipfs-repo": "^0.11.2", "ipfs-unixfs": "^0.1.9", - "ipfs-unixfs-engine": "^0.15.2", + "ipfs-unixfs-engine": "^0.15.4", "ipld-resolver": "^0.4.3", "isstream": "^0.1.2", "libp2p-floodsub": "0.7.2", @@ -171,4 +171,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/test/cli/test-files.js b/test/cli/test-files.js index 2f5510c026..3a5d649d70 100644 --- a/test/cli/test-files.js +++ b/test/cli/test-files.js @@ -72,7 +72,7 @@ describe('files', () => { }) }) - it('add recursively', () => { + it('add recursively test 1', () => { return ipfs('files add -r src/init-files/init-docs').then((out) => { expect(out).to.be.eql([ 'added QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs init-docs/tour/0.0-intro', @@ -89,5 +89,27 @@ describe('files', () => { ].join('\n')) }) }) + + it('add recursively test 2', () => { + return ipfs('files add -r test').then((out) => { + const nLines = out.split('\n').length + expect(nLines).to.be.above(10) + /* + expect(out).to.be.eql([ + 'added QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs init-docs/tour/0.0-intro', + 'added QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te init-docs/tour', + 'added QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ init-docs/security-notes', + 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB init-docs/readme', + 'added QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha init-docs/quick-start', + 'added QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 init-docs/help', + 'added QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT init-docs/docs/index', + 'added QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC init-docs/docs', + 'added QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y init-docs/contact', + 'added QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V init-docs/about', + 'added QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU init-docs' + ].join('\n')) + */ + }) + }) }) }) From a6c522f209fdb86e2a8cdb4517e42e7c29b0c5b5 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 31 Jan 2017 19:44:06 +0000 Subject: [PATCH 06/28] feat: add CLI support for different hash func and type (#748) --- src/cli/commands/block/get.js | 16 ++++------ src/cli/commands/block/put.js | 52 ++++++++++++++++++++++++--------- src/cli/commands/block/stat.js | 12 ++++---- test/cli/test-block.js | 38 +++++++++++++----------- test/test-data/eth-block | Bin 0 -> 534 bytes 5 files changed, 69 insertions(+), 49 deletions(-) create mode 100644 test/test-data/eth-block diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index f042eb0632..e8a653be0f 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -1,7 +1,7 @@ 'use strict' const utils = require('../../utils') -const mh = require('multihashes') +const CID = require('cids') const debug = require('debug') const log = debug('cli:block') log.error = debug('cli:block:error') @@ -19,21 +19,15 @@ module.exports = { throw err } - const hash = utils.isDaemonOn() - ? argv.key - : mh.fromB58String(argv.key) + const cid = new CID(argv.key) - ipfs.block.get(hash, (err, block) => { + ipfs.block.get(cid, (err, block) => { if (err) { throw err } - if (block.data) { - console.log(block.data.toString()) - return - } - - console.log(block.toString()) + process.stdout.write(block.data) + process.stdout.write('\n') }) }) } diff --git a/src/cli/commands/block/put.js b/src/cli/commands/block/put.js index cdd47a7776..14895e96d7 100644 --- a/src/cli/commands/block/put.js +++ b/src/cli/commands/block/put.js @@ -1,7 +1,8 @@ 'use strict' const utils = require('../../utils') -const mh = require('multihashes') +const CID = require('cids') +const multihashing = require('multihashing-async') const bl = require('bl') const fs = require('fs') const Block = require('ipfs-block') @@ -10,35 +11,58 @@ const debug = require('debug') const log = debug('cli:block') log.error = debug('cli:block:error') -function addBlock (buf) { +function addBlock (data, opts) { utils.getIPFS((err, ipfs) => { if (err) { throw err } + let cid + waterfall([ - (cb) => ipfs.block.put(new Block(buf), cb), - (block, cb) => block.key(cb) - ], (err, key) => { - if (err) { - throw err - } + (cb) => multihashing(data, opts.mhtype || 'sha2-256', cb), + (multihash, cb) => { + if (!opts.version || opts.version !== 0) { + cid = new CID(1, opts.format || 'dag-pb', multihash) + } else { + cid = new CID(0, 'dag-pb', multihash) + } + cb(null, cid) + }, + (cid, cb) => ipfs.block.put(new Block(data), cid, cb) + ], (err) => { + if (err) { throw err } - console.log(mh.toB58String(key)) + // console.log(cid) + console.log(cid.toBaseEncodedString()) }) }) } module.exports = { - command: 'put [data]', + command: 'put [block]', describe: 'Stores input as an IPFS block', - builder: {}, + builder: { + format: { + alias: 'f', + describe: 'cid format for blocks to be created with.', + default: 'dag-pb' + }, + mhtype: { + describe: 'multihash hash function', + default: 'sha2-256' + }, + mhlen: { + describe: 'multihash hash length', + default: undefined + } + }, handler (argv) { - if (argv.data) { - return addBlock(fs.readFileSync(argv.data)) + if (argv.block) { + return addBlock(fs.readFileSync(argv.block), argv) } process.stdin.pipe(bl((err, input) => { @@ -46,7 +70,7 @@ module.exports = { throw err } - addBlock(input) + addBlock(input, argv) })) } } diff --git a/src/cli/commands/block/stat.js b/src/cli/commands/block/stat.js index ab7887c75b..73c82aff9e 100644 --- a/src/cli/commands/block/stat.js +++ b/src/cli/commands/block/stat.js @@ -2,6 +2,7 @@ const utils = require('../../utils') const debug = require('debug') +const CID = require('cids') const log = debug('cli:block') log.error = debug('cli:block:error') @@ -14,14 +15,11 @@ module.exports = { handler (argv) { utils.getIPFS((err, ipfs) => { - if (err) { - throw err - } + if (err) { throw err } + const cid = new CID(argv.key) - ipfs.block.stat(argv.key, (err, stats) => { - if (err) { - throw err - } + ipfs.block.stat(cid, (err, stats) => { + if (err) { throw err } console.log('Key:', stats.key) console.log('Size:', stats.size) diff --git a/test/cli/test-block.js b/test/cli/test-block.js index 6beb8b3076..4e9db386cc 100644 --- a/test/cli/test-block.js +++ b/test/cli/test-block.js @@ -10,33 +10,37 @@ describe('block', () => { describeOnlineAndOffline(repoPath, () => { it('put', () => { return ipfs('block put test/test-data/hello').then((out) => { - expect(out).to.be.eql( - 'QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' - ) + expect(out).to.eql('zdj7Wgpi9yzsvjJerghrdhPFpe1p1jZFyB5GKLyXEzFQyaxVk') }) }) + it('put with flags, format and mhtype', () => { + return ipfs('block put --format eth-block --mhtype keccak-256 test/test-data/eth-block') + .then((out) => expect(out).to.eql('z43AaGF23fmvRnDP56Ub9WcJCfzSfqtmzNCCvmz5eudT8dtdCDS')) + }) + it('get', () => { - return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp').then((out) => { - expect(out).to.be.eql('hello world\n') - }) + return ipfs('block get QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + .then((out) => expect(out).to.eql('hello world\n')) }) it('stat', () => { - return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp').then((out) => { - expect(out).to.be.eql([ - 'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', - 'Size: 12' - ].join('\n')) - }) + return ipfs('block stat QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + .then((out) => { + expect(out).to.eql([ + 'Key: QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp', + 'Size: 12' + ].join('\n')) + }) }) it.skip('rm', () => { - return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp').then((out) => { - expect(out).to.be.eql( - 'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' - ) - }) + return ipfs('block rm QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp') + .then((out) => { + expect(out).to.eql( + 'removed QmZjTnYw2TFhn9Nn7tjmPSoTBoY7YRkwPzwSrSbabY24Kp' + ) + }) }) }) }) diff --git a/test/test-data/eth-block b/test/test-data/eth-block new file mode 100644 index 0000000000000000000000000000000000000000..f2b366dc93835883562d5cf2d82c70956abaffb5 GIT binary patch literal 534 zcmey#B)s6nfrZ7aYhTUY?LA|uuFHpm?)@zoO33eH@lkG$zUU>CA2Ua^S;(b2}$~2@hQGZ}NgyT?W2; z^Jcb37Ow?U|lQGf$LV=|nl~px@ IMl5X30Df$PU;qFB literal 0 HcmV?d00001 From f62d1013f32067b55d83a4ce8e311734e2b25123 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 31 Jan 2017 19:47:33 +0000 Subject: [PATCH 07/28] chore: update contributors --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ec5e18ec6..e2a5aecf4a 100644 --- a/package.json +++ b/package.json @@ -171,4 +171,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} +} \ No newline at end of file From c2057363689bfd2218ca23ae2d2bdc4fe7742136 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 31 Jan 2017 19:47:33 +0000 Subject: [PATCH 08/28] chore: release version v0.21.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2a5aecf4a..beba89cc54 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs", - "version": "0.21.7", + "version": "0.21.8", "description": "JavaScript implementation of the IPFS specification", "bin": { "jsipfs": "src/cli/bin.js" From 69fa802de80e95d6b398056d517fa24c76230584 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 1 Feb 2017 13:15:14 +0000 Subject: [PATCH 09/28] feat(breaking change): experimental config options (#749) * feat(breaking change): experimental config options --- README.md | 7 +- examples/basics/index.js | 7 +- examples/bundle-browserify/src/index.js | 7 +- examples/bundle-webpack/src/components/app.js | 7 +- src/cli/commands/init.js | 13 +- src/cli/utils.js | 9 +- src/core/components/go-offline.js | 11 +- src/core/components/go-online.js | 10 +- src/core/components/index.js | 20 ++++ src/core/index.js | 111 +++++++++--------- src/http-api/index.js | 8 +- test/cli/index.js | 4 +- test/core/bitswap.spec.js | 7 +- test/core/bootstrap.spec.js | 7 +- test/core/init.spec.js | 7 +- test/utils/factory-core/index.js | 8 +- test/utils/factory-http/index.js | 8 +- test/utils/temp-node.js | 7 +- 18 files changed, 173 insertions(+), 85 deletions(-) create mode 100644 src/core/components/index.js diff --git a/README.md b/README.md index 8ee50b9894..df3167cb16 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,12 @@ The HTTP-API exposed by the js-ipfs daemon follows the [`http-api-spec`](https:/ const repo = // Create the IPFS node instance -const node = new IPFS(repo) +const node = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: false + } +}) // We need to init our repo, in this case the repo was empty // We are picking 2048 bits for the RSA key that will be our PeerId diff --git a/examples/basics/index.js b/examples/basics/index.js index a3c9c1c2ee..0c1528ea62 100644 --- a/examples/basics/index.js +++ b/examples/basics/index.js @@ -12,7 +12,12 @@ const IPFS = require('../../src/core') /* * Create a new IPFS instance, using default repo (fs) on default path (~/.ipfs) */ -const node = new IPFS(path.join(os.tmpDir() + '/' + new Date().toString())) +const node = new IPFS({ + repo: path.join(os.tmpDir() + '/' + new Date().toString()), + EXPERIMENTAL: { + pubsub: false + } +}) const fileToAdd = { path: 'hello.txt', diff --git a/examples/bundle-browserify/src/index.js b/examples/bundle-browserify/src/index.js index f4fa15d2ee..bb95e3f48a 100644 --- a/examples/bundle-browserify/src/index.js +++ b/examples/bundle-browserify/src/index.js @@ -7,7 +7,12 @@ var IPFS = require('../../../src/core') // replace this by line below // for simplicity, we create a new repo everytime the node // is created, because you can't init already existing repos const repoPath = String(Math.random()) -const node = new IPFS(repoPath) +const node = new IPFS({ + repo: repoPath, + EXPERIMENTAL: { + pubsub: false + } +}) const concat = require('concat-stream') node.init({ emptyRepo: true, bits: 2048 }, function (err) { diff --git a/examples/bundle-webpack/src/components/app.js b/examples/bundle-webpack/src/components/app.js index 33c145b912..0b84e6404d 100644 --- a/examples/bundle-webpack/src/components/app.js +++ b/examples/bundle-webpack/src/components/app.js @@ -29,7 +29,12 @@ class App extends React.Component { // for simplicity, we create a new repo everytime the node // is created, because you can't init already existing repos const repoPath = String(Math.random()) - node = new IPFS(repoPath) + node = new IPFS({ + repo: repoPath, + EXPERIMENTAL: { + pubsub: false + } + }) node.init({ emptyRepo: true, bits: 2048 }, function (err) { if (err) { diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index dae5dbb61b..c165b53e9f 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,7 +1,7 @@ 'use strict' -const IpfsRepo = require('ipfs-repo') -const Ipfs = require('../../core') +const Repo = require('ipfs-repo') +const IPFS = require('../../core') const Store = require('fs-pull-blob-store') const utils = require('../utils') @@ -35,18 +35,21 @@ module.exports = { const log = utils.createLogger(true) log(`initializing ipfs node at ${path}`) - const repo = new IpfsRepo(path, { + const repo = new Repo(path, { stores: Store }) - const ipfs = new Ipfs(repo) + const ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: {} + }) ipfs.init({ bits: argv.bits, force: argv.force, emptyRepo: argv.emptyRepo, log - }, function (err) { + }, (err) => { if (err) { console.error(err.toString()) process.exit(1) diff --git a/src/cli/utils.js b/src/cli/utils.js index be2695f815..b46731f78d 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -36,10 +36,13 @@ function getAPICtl () { exports.getIPFS = (callback) => { if (!isDaemonOn()) { - const ipfs = new IPFS(exports.getRepoPath()) - ipfs.load(() => { - callback(null, ipfs) + const ipfs = new IPFS({ + repo: exports.getRepoPath(), + EXPERIMENTAL: { + pubsub: true + } }) + ipfs.load(() => callback(null, ipfs)) return } diff --git a/src/core/components/go-offline.js b/src/core/components/go-offline.js index f0786702da..e68f450559 100644 --- a/src/core/components/go-offline.js +++ b/src/core/components/go-offline.js @@ -4,11 +4,18 @@ module.exports = (self) => { return (callback) => { self._blockService.goOffline() self._bitswap.stop() - self._pubsub.stop((err) => { + + if (self._configOpts.EXPERIMENTAL.pubsub) { + self._pubsub.stop(next) + } else { + next() + } + + function next (err) { if (err) { return callback(err) } self.libp2p.stop(callback) - }) + } } } diff --git a/src/core/components/go-online.js b/src/core/components/go-online.js index d710478899..fb9b407b17 100644 --- a/src/core/components/go-online.js +++ b/src/core/components/go-online.js @@ -31,9 +31,13 @@ module.exports = (self) => { self._blockService.goOnline(self._bitswap) cb() }, - (cb) => self._pubsub.start(cb) // , - // For all of the protocols to handshake with each other - // (cb) => setTimeout(cb, 1000) // Still not decided if we want this + (cb) => { + if (self._configOpts.EXPERIMENTAL.pubsub) { + self._pubsub.start(cb) + } else { + cb() + } + } ], callback) }) } diff --git a/src/core/components/index.js b/src/core/components/index.js new file mode 100644 index 0000000000..6d8193c5e4 --- /dev/null +++ b/src/core/components/index.js @@ -0,0 +1,20 @@ +'use strict' + +exports.goOnline = require('./go-online') +exports.goOffline = require('./go-offline') +exports.isOnline = require('./is-online') +exports.load = require('./load') +exports.version = require('./version') +exports.id = require('./id') +exports.repo = require('./repo') +exports.init = require('./init') +exports.bootstrap = require('./bootstrap') +exports.config = require('./config') +exports.block = require('./block') +exports.object = require('./object') +exports.libp2p = require('./libp2p') +exports.swarm = require('./swarm') +exports.ping = require('./ping') +exports.files = require('./files') +exports.bitswap = require('./bitswap') +exports.pubsub = require('./pubsub') diff --git a/src/core/index.js b/src/core/index.js index fa4c2e8ae2..3dc676a019 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -3,71 +3,66 @@ const BlockService = require('ipfs-block-service') const IPLDResolver = require('ipld-resolver') const PeerBook = require('peer-book') +const debug = require('debug') const defaultRepo = require('./default-repo') -const goOnline = require('./components/go-online') -const goOffline = require('./components/go-offline') -const isOnline = require('./components/is-online') -const load = require('./components/load') -const version = require('./components/version') -const id = require('./components/id') -const repo = require('./components/repo') -const init = require('./components/init') -const bootstrap = require('./components/bootstrap') -const config = require('./components/config') -const block = require('./components/block') -const object = require('./components/object') -const libp2p = require('./components/libp2p') -const swarm = require('./components/swarm') -const ping = require('./components/ping') -const files = require('./components/files') -const bitswap = require('./components/bitswap') -const pubsub = require('./components/pubsub') +const components = require('./components') -exports = module.exports = IPFS +class IPFS { + constructor (configOpts) { + let repoInstance + if (typeof configOpts.repo === 'string' || configOpts.repo === undefined) { + repoInstance = defaultRepo(configOpts.repo) + } else { + repoInstance = configOpts.repo + } + delete configOpts.repo -function IPFS (repoInstance) { - if (!(this instanceof IPFS)) { - throw new Error('Must be instantiated with new') - } - - if (typeof repoInstance === 'string' || - repoInstance === undefined) { - repoInstance = defaultRepo(repoInstance) - } + configOpts.EXPERIMENTAL = configOpts.EXPERIMENTAL || {} - // IPFS Core Internals - this._repo = repoInstance - this._peerInfoBook = new PeerBook() - this._peerInfo = null - this._libp2pNode = null - this._bitswap = null - this._blockService = new BlockService(this._repo) - this._ipldResolver = new IPLDResolver(this._blockService) - this._pubsub = null + // IPFS utils + this.types = {} + this.log = debug('jsipfs') + this.log.err = debug('jsipfs:err') - // IPFS Core exposed components + // IPFS Core Internals + this._configOpts = configOpts + this._repo = repoInstance + this._peerInfoBook = new PeerBook() + this._peerInfo = undefined + this._libp2pNode = undefined + this._bitswap = undefined + this._blockService = new BlockService(this._repo) + this._ipldResolver = new IPLDResolver(this._blockService) + this._pubsub = undefined - // for booting up a node - this.goOnline = goOnline(this) - this.goOffline = goOffline(this) - this.isOnline = isOnline(this) - this.load = load(this) - this.init = init(this) + // IPFS Core exposed components + // - for booting up a node + this.goOnline = components.goOnline(this) + this.goOffline = components.goOffline(this) + this.isOnline = components.isOnline(this) + this.load = components.load(this) + this.init = components.init(this) + // - interface-ipfs-core defined API + this.version = components.version(this) + this.id = components.id(this) + this.repo = components.repo(this) + this.bootstrap = components.bootstrap(this) + this.config = components.config(this) + this.block = components.block(this) + this.object = components.object(this) + this.libp2p = components.libp2p(this) + this.swarm = components.swarm(this) + this.files = components.files(this) + this.bitswap = components.bitswap(this) + this.ping = components.ping(this) + this.pubsub = components.pubsub(this) - // interface-ipfs-core defined API - this.version = version(this) - this.id = id(this) - this.repo = repo(this) - this.bootstrap = bootstrap(this) - this.config = config(this) - this.block = block(this) - this.object = object(this) - this.libp2p = libp2p(this) - this.swarm = swarm(this) - this.files = files(this) - this.bitswap = bitswap(this) - this.ping = ping(this) - this.pubsub = pubsub(this) + if (configOpts.EXPERIMENTAL.pubsub) { + this.log('EXPERIMENTAL pubsub is enabled') + } + } } + +module.exports = IPFS diff --git a/src/http-api/index.js b/src/http-api/index.js index 21a6bc5e44..4530d64873 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -25,7 +25,13 @@ exports = module.exports = function HttpApi (repo) { repo = new IPFSRepo(repo, {stores: Store}) } - this.ipfs = new IPFS(repo) + this.ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) + const repoPath = this.ipfs.repo.path() try { diff --git a/test/cli/index.js b/test/cli/index.js index 8682844680..80b128248f 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -20,9 +20,7 @@ describe('cli', () => { }) }) - after(() => { - clean(repoTests) - }) + after(() => clean(repoTests)) describe('--all', () => { const tests = fs.readdirSync(__dirname) diff --git a/test/core/bitswap.spec.js b/test/core/bitswap.spec.js index 83bb63f4e5..57ebd48b4b 100644 --- a/test/core/bitswap.spec.js +++ b/test/core/bitswap.spec.js @@ -32,7 +32,12 @@ describe('bitswap', () => { beforeEach((done) => { const repo = createTempRepo() - inProcNode = new IPFS(repo) + inProcNode = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) series([ (cb) => inProcNode.init({ bits: 2048 }, cb), (cb) => { diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index 729f2ec31e..c5c0bb5f2c 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -18,7 +18,12 @@ describe('bootstrap', () => { before((done) => { const repo = createTempRepo() - ipfs = new IPFS(repo) + ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) series([ (cb) => ipfs.init({ bits: 1024 }, cb), (cb) => ipfs.load(cb) diff --git a/test/core/init.spec.js b/test/core/init.spec.js index 89176bbabe..16b382eba9 100644 --- a/test/core/init.spec.js +++ b/test/core/init.spec.js @@ -18,7 +18,12 @@ describe('init', () => { beforeEach(() => { repo = createTempRepo() - ipfs = new IPFS(repo) + ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) }) afterEach((done) => repo.teardown(done)) diff --git a/test/utils/factory-core/index.js b/test/utils/factory-core/index.js index 56598e9060..2c81ae6489 100644 --- a/test/utils/factory-core/index.js +++ b/test/utils/factory-core/index.js @@ -43,7 +43,13 @@ function Factory () { const repo = createTempRepo(repoPath) // create the IPFS node - const ipfs = new IPFS(repo) + const ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) + ipfs.init({ emptyRepo: true, bits: 1024 }, (err) => { if (err) { return callback(err) diff --git a/test/utils/factory-http/index.js b/test/utils/factory-http/index.js index 1c863adcb4..5ffe839119 100644 --- a/test/utils/factory-http/index.js +++ b/test/utils/factory-http/index.js @@ -51,7 +51,13 @@ function Factory () { } // create the IPFS node - const ipfs = new IPFS(repo) + const ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) + ipfs.init({ emptyRepo: true, bits: 1024 diff --git a/test/utils/temp-node.js b/test/utils/temp-node.js index 85fdbb5ac9..16b2df53c6 100644 --- a/test/utils/temp-node.js +++ b/test/utils/temp-node.js @@ -30,7 +30,12 @@ function setAddresses (repo, num, callback) { function createTempNode (num, callback) { const repo = createTempRepo() - const ipfs = new IPFS(repo) + const ipfs = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } + }) num = leftPad(num, 3, 0) From e5ec0cfa82b4969685e9e0b580fa7b1d1e54055e Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 1 Feb 2017 14:16:07 +0000 Subject: [PATCH 10/28] feat(dag): basics (get, put) (#746) * feat(dag): basics (get and put) --- package.json | 4 ++-- src/core/components/dag.js | 34 +++++++++++++++++++++++++++ src/core/components/index.js | 1 + src/core/index.js | 1 + test/core/interface/dag.js | 20 ++++++++++++++++ test/core/interface/interface.spec.js | 1 + 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/core/components/dag.js create mode 100644 test/core/interface/dag.js diff --git a/package.json b/package.json index beba89cc54..fc9fee0d5d 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "form-data": "^2.1.2", "fs-pull-blob-store": "^0.4.1", "gulp": "^3.9.1", - "interface-ipfs-core": "^0.23.5", + "interface-ipfs-core": "^0.23.8", "ipfsd-ctl": "^0.18.1", "left-pad": "^1.1.3", "lodash": "^4.17.4", @@ -171,4 +171,4 @@ "nginnever ", "npmcdn-to-unpkg-bot " ] -} \ No newline at end of file +} diff --git a/src/core/components/dag.js b/src/core/components/dag.js new file mode 100644 index 0000000000..21a203d67c --- /dev/null +++ b/src/core/components/dag.js @@ -0,0 +1,34 @@ +'use strict' + +const promisify = require('promisify-es6') + +const dagPB = require('ipld-dag-pb') +const dagCBOR = require('ipld-dag-cbor') + +module.exports = function dag (self) { + return { + put: promisify((dagNode, multicodec, hashAlg, callback) => { + switch (multicodec) { + case 'dag-pb': dagPB.util.cid(dagNode, gotCid); break + case 'dag-cbor': dagCBOR.util.cid(dagNode, gotCid); break + default: callback(new Error('IPLD Format not supported')) + } + + function gotCid (err, cid) { + if (err) { + return callback(err) + } + self._ipldResolver.put({ + node: dagNode, + cid: cid + }, callback) + } + }), + get: promisify((cid, callback) => { + self._ipldResolver.get(cid, callback) + }), + resolve: promisify((cid, path, callback) => { + self._ipldResolver.resolve(cid, path, callback) + }) + } +} diff --git a/src/core/components/index.js b/src/core/components/index.js index 6d8193c5e4..28193af597 100644 --- a/src/core/components/index.js +++ b/src/core/components/index.js @@ -12,6 +12,7 @@ exports.bootstrap = require('./bootstrap') exports.config = require('./config') exports.block = require('./block') exports.object = require('./object') +exports.dag = require('./dag') exports.libp2p = require('./libp2p') exports.swarm = require('./swarm') exports.ping = require('./ping') diff --git a/src/core/index.js b/src/core/index.js index 3dc676a019..3c6d3470e3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -52,6 +52,7 @@ class IPFS { this.config = components.config(this) this.block = components.block(this) this.object = components.object(this) + this.dag = components.dag(this) this.libp2p = components.libp2p(this) this.swarm = components.swarm(this) this.files = components.files(this) diff --git a/test/core/interface/dag.js b/test/core/interface/dag.js new file mode 100644 index 0000000000..1a617691c6 --- /dev/null +++ b/test/core/interface/dag.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +'use strict' + +const test = require('interface-ipfs-core') +const IPFSFactory = require('../../utils/factory-core') + +let factory + +const common = { + setup: function (cb) { + factory = new IPFSFactory() + cb(null, factory) + }, + teardown: function (cb) { + factory.dismantle(cb) + } +} + +test.dag(common) diff --git a/test/core/interface/interface.spec.js b/test/core/interface/interface.spec.js index a3cfae8350..bf749464d1 100644 --- a/test/core/interface/interface.spec.js +++ b/test/core/interface/interface.spec.js @@ -10,6 +10,7 @@ describe('interface-ipfs-core tests', () => { require('./files') require('./generic') require('./object') + require('./dag') if (isNode) { require('./swarm') require('./pubsub') From dd21c6df0b0226723e798a96f1fa85393a9c481b Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 1 Feb 2017 14:43:47 +0000 Subject: [PATCH 11/28] test: 'get recursive' test (#741) --- package.json | 6 +- src/cli/commands/files/get.js | 62 +++----- test/cli/test-files.js | 142 +++++++++++++----- ...JOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data | 28 ++++ ...WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data | Bin 0 -> 10765 bytes ...LZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data | 4 + ...774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data | Bin 0 -> 10807 bytes ...XCX5XMZLMGTYVODWPEDIW7JYEG7YXBIA7IUWY.data | 3 + ...5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data | 3 + ...2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data | 3 + ...HSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data | 4 + ...ANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data | Bin 0 -> 10891 bytes ...DDTF32OIR4FWLKT5YLL7MLDVIT7DC3NHOK5VA.data | 23 +++ ...2BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y.data | 2 + ...LOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY.data | 114 ++++++++++++++ ...HTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data | Bin 0 -> 10765 bytes ...VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data | 4 + ...YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data | Bin 0 -> 309 bytes ...LP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data | 3 + ...D6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data | Bin 0 -> 10765 bytes ...LJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data | 24 +++ ...NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data | Bin 0 -> 309 bytes ...TJNUP57QHR4SKHZ74OIITBBGLOMCO3ZOLWLGA.data | 9 ++ ...AJNF2GF5UHUAGGHC6LLAH6VYDEKLQMD4QLILY.data | 8 + ...2FSMG76VV256I4PXBULZZ5ASNLK4FL4EG7XOI.data | Bin 0 -> 10849 bytes ...7E32LQAL6236OUKZTMHPQSFIXPWXNZHQOV7JQ.data | 55 +++++++ ...RTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data | Bin 0 -> 10849 bytes ...EBXFD5QN6MTI5YBYMCVQJDXPKCOVR6RMLHZFQ.data | Bin 0 -> 10807 bytes ...B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data | Bin 0 -> 101 bytes ...57JSEZN64SIJ5OIHSGJG4TJSSJLGI3PBJLQVI.data | 0 ...RYYVBUXHTS3SM5EORZDU63LYPEFUAFE4SBM4I.data | 115 ++++++++++++++ ...NH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data | Bin 0 -> 10765 bytes ...SIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data | 3 + ...33ROGCKOFZLXJJ2MPKYZBTV4H3N7GYHXMAO6A.data | 3 + ...YNRNMP2VDKWBWGAEDDEJDACM3SGG3VIANDDXI.data | Bin 0 -> 10765 bytes test/test-data/recursive-get-dir/config | 1 + .../recursive-get-dir/datastore/000002.ldb | Bin 0 -> 211 bytes .../recursive-get-dir/datastore/000005.ldb | Bin 0 -> 1120 bytes .../recursive-get-dir/datastore/000010.ldb | Bin 0 -> 1143 bytes .../recursive-get-dir/datastore/CURRENT | 1 + .../recursive-get-dir/datastore/LOCK | 0 .../test-data/recursive-get-dir/datastore/LOG | 29 ++++ .../recursive-get-dir/datastore/LOG.old | 10 ++ .../datastore/MANIFEST-000014 | Bin 0 -> 314 bytes .../recursive-get-dir/init-docs/about | 53 +++++++ .../recursive-get-dir/init-docs/contact | 6 + .../recursive-get-dir/init-docs/docs/index | 1 + .../recursive-get-dir/init-docs/help | 7 + .../recursive-get-dir/init-docs/quick-start | 113 ++++++++++++++ .../recursive-get-dir/init-docs/readme | 26 ++++ .../init-docs/security-notes | 21 +++ .../init-docs/tour/0.0-intro | 34 +++++ test/test-data/recursive-get-dir/version | 1 + 53 files changed, 843 insertions(+), 78 deletions(-) create mode 100644 test/test-data/recursive-get-dir/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDVW2EZIJF4NQH7WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQDM/CIQDMKFEUGKSLXMEXO774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQDV/CIQDVKITASFS55MC2TXCX5XMZLMGTYVODWPEDIW7JYEG7YXBIA7IUWY.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQFE/CIQFEAGMNNXXTYKYQSANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQFF/CIQFFRR4O52TS2Z7QLDDTF32OIR4FWLKT5YLL7MLDVIT7DC3NHOK5VA.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQFT/CIQFTFEEHEDF6KLBT32BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQGF/CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQGP/CIQGPALRQ24P6NS4OWHTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQHA/CIQHAKDLTL5GMIFGN5YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQHP/CIQHPUVCWD6JA6AFUVD6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQJ2/CIQJ23BL4UHXA2KTI6NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQJB/CIQJBQD2O6K4CGJVCCTJNUP57QHR4SKHZ74OIITBBGLOMCO3ZOLWLGA.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQJF/CIQJFGRQHQ45VCQLM7AJNF2GF5UHUAGGHC6LLAH6VYDEKLQMD4QLILY.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQJG/CIQJGO2B2N75IUEM372FSMG76VV256I4PXBULZZ5ASNLK4FL4EG7XOI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQKK/CIQKKLBWAIBQZOIS5X7E32LQAL6236OUKZTMHPQSFIXPWXNZHQOV7JQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQLB/CIQLBK52T5EHVHZY5URTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQLB/CIQLBS5HG4PRCRQ7O4EBXFD5QN6MTI5YBYMCVQJDXPKCOVR6RMLHZFQ.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQMB/CIQMB7DLJFKD267QJ2B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQOH/CIQOHMGEIKMPYHAUTL57JSEZN64SIJ5OIHSGJG4TJSSJLGI3PBJLQVI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQOL/CIQOLBQZSZAODJGGH6RYYVBUXHTS3SM5EORZDU63LYPEFUAFE4SBM4I.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQOM/CIQOMBKARLB7PAITVSNH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQON/CIQONICFQZH7QVU6IPSIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQOY/CIQOYW2THIZBRGI7IN33ROGCKOFZLXJJ2MPKYZBTV4H3N7GYHXMAO6A.data create mode 100644 test/test-data/recursive-get-dir/blocks/CIQPD/CIQPDQJBGYDZNMOAGGYNRNMP2VDKWBWGAEDDEJDACM3SGG3VIANDDXI.data create mode 100644 test/test-data/recursive-get-dir/config create mode 100644 test/test-data/recursive-get-dir/datastore/000002.ldb create mode 100644 test/test-data/recursive-get-dir/datastore/000005.ldb create mode 100644 test/test-data/recursive-get-dir/datastore/000010.ldb create mode 100644 test/test-data/recursive-get-dir/datastore/CURRENT create mode 100644 test/test-data/recursive-get-dir/datastore/LOCK create mode 100644 test/test-data/recursive-get-dir/datastore/LOG create mode 100644 test/test-data/recursive-get-dir/datastore/LOG.old create mode 100644 test/test-data/recursive-get-dir/datastore/MANIFEST-000014 create mode 100644 test/test-data/recursive-get-dir/init-docs/about create mode 100644 test/test-data/recursive-get-dir/init-docs/contact create mode 100644 test/test-data/recursive-get-dir/init-docs/docs/index create mode 100644 test/test-data/recursive-get-dir/init-docs/help create mode 100644 test/test-data/recursive-get-dir/init-docs/quick-start create mode 100644 test/test-data/recursive-get-dir/init-docs/readme create mode 100644 test/test-data/recursive-get-dir/init-docs/security-notes create mode 100644 test/test-data/recursive-get-dir/init-docs/tour/0.0-intro create mode 100644 test/test-data/recursive-get-dir/version diff --git a/package.json b/package.json index fc9fee0d5d..652a906960 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "chai": "^3.5.0", "delay": "^1.3.1", "detect-node": "^2.0.3", + "dir-compare": "^1.3.0", "eslint-plugin-react": "^6.9.0", "execa": "^0.6.0", "expose-loader": "^0.7.1", @@ -106,10 +107,10 @@ "ipfs-unixfs-engine": "^0.15.4", "ipld-resolver": "^0.4.3", "isstream": "^0.1.2", - "libp2p-floodsub": "0.7.2", "joi": "^10.2.0", - "libp2p-ipfs-nodejs": "^0.17.9", + "libp2p-floodsub": "0.7.2", "libp2p-ipfs-browser": "^0.17.8", + "libp2p-ipfs-nodejs": "^0.17.9", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.has": "^4.5.2", @@ -117,6 +118,7 @@ "lodash.sortby": "^4.7.0", "lodash.values": "^4.3.0", "mafmt": "^2.1.6", + "mkdirp": "^0.5.1", "multiaddr": "^2.2.0", "multihashes": "^0.3.2", "path-exists": "^3.0.0", diff --git a/src/cli/commands/files/get.js b/src/cli/commands/files/get.js index bc011ff68b..7bbc82f221 100644 --- a/src/cli/commands/files/get.js +++ b/src/cli/commands/files/get.js @@ -6,7 +6,7 @@ const log = debug('cli:files') log.error = debug('cli:files:error') var fs = require('fs') const path = require('path') -const pathExists = require('path-exists') +const mkdirp = require('mkdirp') const pull = require('pull-stream') const toPull = require('stream-to-pull-stream') @@ -23,53 +23,31 @@ function checkArgs (hash, outPath) { return outPath } -function ensureDir (dir, cb) { - pathExists(dir) - .then((exists) => { - if (!exists) { - fs.mkdir(dir, cb) - } else { - cb() - } - }) - .catch(cb) +function ensureDirFor (dir, file, callback) { + const lastSlash = file.path.lastIndexOf('/') + const filePath = file.path.substring(0, lastSlash + 1) + const dirPath = path.join(dir, filePath) + mkdirp(dirPath, callback) } function fileHandler (dir) { - return function onFile (file, cb) { - const lastSlash = file.path.lastIndexOf('/') - // Check to see if the result is in a directory - if (lastSlash === -1) { - const dirPath = path.join(dir, file.path) - // Check to see if the result is a directory - if (file.content) { - file.content.pipe(fs.createWriteStream(dirPath)) - .once('error', cb) - .once('end', cb) + return function onFile (file, callback) { + ensureDirFor(dir, file, (err) => { + if (err) { + callback(err) } else { - ensureDir(dirPath, cb) - } - } else { - const filePath = file.path.substring(0, lastSlash + 1) - const dirPath = path.join(dir, filePath) - - ensureDir(dirPath, (err) => { - if (err) { - return cb(err) - } - + const fullFilePath = path.join(dir, file.path) if (file.content) { - const filename = file.path.substring(lastSlash) - const target = path.join(dirPath, filename) - - file.content.pipe(fs.createWriteStream(target)) - .once('error', cb) - .once('end', cb) - return + file.content + .pipe(fs.createWriteStream(fullFilePath)) + .once('error', callback) + .once('finish', callback) + } else { + // this is a dir + mkdirp(fullFilePath, callback) } - cb() - }) - } + } + }) } } diff --git a/test/cli/test-files.js b/test/cli/test-files.js index 3a5d649d70..328019c01b 100644 --- a/test/cli/test-files.js +++ b/test/cli/test-files.js @@ -5,6 +5,8 @@ const expect = require('chai').expect const repoPath = require('./index').repoPath const fs = require('fs') const path = require('path') +const compareDir = require('dir-compare').compareSync +const rimraf = require('rimraf').sync const describeOnlineAndOffline = require('../utils/on-and-off') const ipfs = require('../utils/ipfs-exec')(repoPath) @@ -35,7 +37,7 @@ describe('files', () => { 'hello world\n' ) - fs.unlinkSync(file) + rimraf(file) }) }) @@ -52,7 +54,7 @@ describe('files', () => { 'hello world\n' ) - fs.unlinkSync(file) + rimraf(file) }) }) @@ -72,43 +74,115 @@ describe('files', () => { }) }) - it('add recursively test 1', () => { - return ipfs('files add -r src/init-files/init-docs').then((out) => { + it('add recursively test', () => { + return ipfs('files add -r test/test-data/recursive-get-dir').then((out) => { expect(out).to.be.eql([ - 'added QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs init-docs/tour/0.0-intro', - 'added QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te init-docs/tour', - 'added QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ init-docs/security-notes', - 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB init-docs/readme', - 'added QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha init-docs/quick-start', - 'added QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 init-docs/help', - 'added QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT init-docs/docs/index', - 'added QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC init-docs/docs', - 'added QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y init-docs/contact', - 'added QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V init-docs/about', - 'added QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU init-docs' + 'added QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV recursive-get-dir/version', + 'added QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs recursive-get-dir/init-docs/tour/0.0-intro', + 'added QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te recursive-get-dir/init-docs/tour', + 'added QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ recursive-get-dir/init-docs/security-notes', + 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB recursive-get-dir/init-docs/readme', + 'added QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha recursive-get-dir/init-docs/quick-start', + 'added QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 recursive-get-dir/init-docs/help', + 'added QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT recursive-get-dir/init-docs/docs/index', + 'added QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC recursive-get-dir/init-docs/docs', + 'added QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y recursive-get-dir/init-docs/contact', + 'added QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V recursive-get-dir/init-docs/about', + 'added QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU recursive-get-dir/init-docs', + 'added QmeiTxVN4xAjxUzHzBqCpK3GaT3GeiLQeJRpYDXDfLeEmR recursive-get-dir/datastore/MANIFEST-000014', + 'added QmQpc75sJGUv59dAwHF7vazBGV9o6C7z587Dp9nv7HYAps recursive-get-dir/datastore/LOG.old', + 'added QmbFNLNr9at9eK5LrNyUdyE5cdLb5yaT9DkjXw7BK68kcM recursive-get-dir/datastore/LOG', + 'added QmfJMCvenrj4SKKRc48DYPxwVdS44qCUCqqtbqhJuSTWXP recursive-get-dir/datastore/LOCK', + 'added QmVJi93Yj5RW3NuqqxonGz3jAXUYHrdQvWrURxg1TiLEuX recursive-get-dir/datastore/CURRENT', + 'added QmcJ6TXPMPm6puSC9vpxuG57PyfGpr8bvTgkKU9SHHU5Uo recursive-get-dir/datastore/000010.ldb', + 'added QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU recursive-get-dir/datastore/000005.ldb', + 'added QmfExFwdFKspsY2q5WnhQjd1QDKnjpTQ4UkiHqqQxV7h67 recursive-get-dir/datastore/000002.ldb', + 'added Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz recursive-get-dir/datastore', + 'added QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN recursive-get-dir/config', + 'added QmbJgQa4XNBFvGQcLbWBNtvWZetbCUKiyAQNfePoTzwf9L recursive-get-dir/blocks/CIQPD/CIQPDQJBGYDZNMOAGGYNRNMP2VDKWBWGAEDDEJDACM3SGG3VIANDDXI.data', + 'added QmSCUPYy4CfFt9nA61J9v2DMfJygQAJjaUcRmygDbVME2D recursive-get-dir/blocks/CIQPD', + 'added QmTU72W5EAnNUAtnVW1qoFzdDD8FyiBjpF5MUzjBAFnHS6 recursive-get-dir/blocks/CIQOY/CIQOYW2THIZBRGI7IN33ROGCKOFZLXJJ2MPKYZBTV4H3N7GYHXMAO6A.data', + 'added QmQ1mNtPTJ6JG3TNNq73m2orvsfKCKrqMKoXyXwRKWM1ma recursive-get-dir/blocks/CIQOY', + 'added QmaTXag3TaaG6hFUXGxybEuMUk7UHSutZobZgDtjr6aXjf recursive-get-dir/blocks/CIQON/CIQONICFQZH7QVU6IPSIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data', + 'added QmNi9kKnfKJGuofhBRKMdKj5R6BQAYHWRtu3vXJHRy69TE recursive-get-dir/blocks/CIQON', + 'added QmTH5Jc2uhu5LqGEFAgrn2HwoDHLpvQd9b6fyoUGi6aeQu recursive-get-dir/blocks/CIQOM/CIQOMBKARLB7PAITVSNH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data', + 'added Qmec4atiyfysPR8HU5gPfjKY1NpQDY2kmSeeadx8wLEBqY recursive-get-dir/blocks/CIQOM', + 'added QmeBypQ2yE4t4Loybhby15DjkeLDXJKCcgMfxTXeFnHa8F recursive-get-dir/blocks/CIQOL/CIQOLBQZSZAODJGGH6RYYVBUXHTS3SM5EORZDU63LYPEFUAFE4SBM4I.data', + 'added Qmd6s8LXAEjW7y9QbGSzeuewrRBYjJHmcazG3Hk7cJ74da recursive-get-dir/blocks/CIQOL', + 'added QmfJMCvenrj4SKKRc48DYPxwVdS44qCUCqqtbqhJuSTWXP recursive-get-dir/blocks/CIQOH/CIQOHMGEIKMPYHAUTL57JSEZN64SIJ5OIHSGJG4TJSSJLGI3PBJLQVI.data', + 'added QmdiJnDhn4Bb1odByw1BA5qpXssjxgttVz42tpEfo7HNUe recursive-get-dir/blocks/CIQOH', + 'added Qmc1nasezDdPyZiXB5VB6Aygzswcr6QkauzzXMeUGouHTN recursive-get-dir/blocks/CIQMB/CIQMB7DLJFKD267QJ2B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data', + 'added QmeqJBkwmzsVR79HBKLW7AYhfAMxMaJs5dGHSgey5ezy7N recursive-get-dir/blocks/CIQMB', + 'added QmaSjzSSRanYzRGPXQY6m5SWfSkkfcnzNkurJEQc4chPJx recursive-get-dir/blocks/CIQLB/CIQLBS5HG4PRCRQ7O4EBXFD5QN6MTI5YBYMCVQJDXPKCOVR6RMLHZFQ.data', + 'added QmQ8ag7ysVyCMzJGFjxrUStwWtniQ69c7G9aezbmsKeNYD recursive-get-dir/blocks/CIQLB/CIQLBK52T5EHVHZY5URTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data', + 'added Qmbqod68qdYiEs7kkTGu7G59adekUbAFAAg7WEyM6iPP5z recursive-get-dir/blocks/CIQLB', + 'added Qmd4FKC6GcKnhJHnEJJwqg9A1eDd7JXKkG5v3iv9XSHtwq recursive-get-dir/blocks/CIQKK/CIQKKLBWAIBQZOIS5X7E32LQAL6236OUKZTMHPQSFIXPWXNZHQOV7JQ.data', + 'added QmUBsjP45UUHzKymAUqwEFJsuCvfC1AcaLvBgMsoGMipoG recursive-get-dir/blocks/CIQKK', + 'added QmWR1EuH5cui4EW5W16ADxzmYEFPjHDs1LcPe3uQL3CmiS recursive-get-dir/blocks/CIQJG/CIQJGO2B2N75IUEM372FSMG76VV256I4PXBULZZ5ASNLK4FL4EG7XOI.data', + 'added QmWrs7zVFkbpsTEbEpe3MyAB8ssUNp8jamE7i4PZ736zWy recursive-get-dir/blocks/CIQJG', + 'added QmWNXfkCTxSAuFBdNQ8gGmyxnZ28XrzRbjjmvCViLoNU5W recursive-get-dir/blocks/CIQJF/CIQJFGRQHQ45VCQLM7AJNF2GF5UHUAGGHC6LLAH6VYDEKLQMD4QLILY.data', + 'added QmWjsRHRK7ENAhMvgwfkze9bkySxjAsNMGXrMGMsFcrDWU recursive-get-dir/blocks/CIQJF', + 'added QmTt3mbtfVGEfqqjec9WZcWaC4SkesErDPAhhr8NRfsWFp recursive-get-dir/blocks/CIQJB/CIQJBQD2O6K4CGJVCCTJNUP57QHR4SKHZ74OIITBBGLOMCO3ZOLWLGA.data', + 'added QmQebEvyaFbez884asHoTrNsbck1JdMLcM8EhUFYCraGHZ recursive-get-dir/blocks/CIQJB', + 'added Qmb7AKKnZwLLFtseMZiHkq4fKNhP5rSggcvN2oGXUBZv8B recursive-get-dir/blocks/CIQJ2/CIQJ23BL4UHXA2KTI6NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data', + 'added QmT1zKYzUpt2kF8AEV2igH9hXwzGu4q8pc4uJ9BLWqjMhT recursive-get-dir/blocks/CIQJ2', + 'added QmazVLpyExfPkwASngrz3MDZD1pdaBUxj7VqAkjAFAWaa9 recursive-get-dir/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data', + 'added QmNM7hxdJfaApCJe1ubCrhAQSA6AWQXUvKZrHcf5RxsNvn recursive-get-dir/blocks/CIQIX', + 'added QmRfQcw4qrW91Vqj3evXiH11MuvRVJb7S7vKSgau7aBzRa recursive-get-dir/blocks/CIQHP/CIQHPUVCWD6JA6AFUVD6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data', + 'added QmRsyLntZoGPWURqtemAmgRdtmuCjbbdZ5xzkCAEUhh4iU recursive-get-dir/blocks/CIQHP', + 'added QmU7mw6KaaAJA6tHi9FdiHu2HtA6rjb6e1aYuWscwTJ9yV recursive-get-dir/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data', + 'added Qma1ytRhbzt3tGcJopMvd7g3ZE38mRKTTuJuRaHmguq8mN recursive-get-dir/blocks/CIQHB', + 'added QmVLdEzvgvM5k7NUWWSgURAZuJmiQBnbuZga3EpRip8xTu recursive-get-dir/blocks/CIQHA/CIQHAKDLTL5GMIFGN5YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data', + 'added QmddXWuKjfCbF6HXR9jStKDoLEAZ7xc8SZgDanQLMiGjpn recursive-get-dir/blocks/CIQHA', + 'added QmZe7irS2FotZtsUx9wpy5QPKJF6YEaAEZLHLUwQy6XgY8 recursive-get-dir/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data', + 'added Qmb5NqTFar7MnxyRwwQtfb81nyS6g5NRG1bdo6AefmvhXU recursive-get-dir/blocks/CIQH7', + 'added QmWGima5TqLfUTzUsCF6h3oXGvwu3QQ1zjZYLDMaGeFRbB recursive-get-dir/blocks/CIQGP/CIQGPALRQ24P6NS4OWHTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data', + 'added QmZMHzPS1qema8HvLk4jRuSLrUjRHZ8Siu6Wc4njAmx8MG recursive-get-dir/blocks/CIQGP', + 'added QmabxyrxY1uUzHcd7mTBCfibFwemGC89vuJFUw4UkebmSn recursive-get-dir/blocks/CIQGF/CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY.data', + 'added QmYLZ3uqYLkViS7Bh3vxcT5yrPscyWMV11iqFVJnqA7JVT recursive-get-dir/blocks/CIQGF', + 'added QmSMYdQtDTqykd7oLKZq3vJtS7KoWZwjL7GA9zj6UsCngE recursive-get-dir/blocks/CIQFT/CIQFTFEEHEDF6KLBT32BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y.data', + 'added QmWjMLA3ppmngQaHs8YEQ3Bru4tKoDeJh2cKv7U7dtLUuf recursive-get-dir/blocks/CIQFT', + 'added QmVdfEEiQmem5GanTjja7HKHNFpfa2LB8196fD9m9b656Q recursive-get-dir/blocks/CIQFF/CIQFFRR4O52TS2Z7QLDDTF32OIR4FWLKT5YLL7MLDVIT7DC3NHOK5VA.data', + 'added QmUcLzGWDuBPA6iVF65n676KiCbQNXV4owecfSR4QFVy3U recursive-get-dir/blocks/CIQFF', + 'added QmNtkNt8oZASY7AYVpswA3RQ43hASjP1NGj8GB1L6vgHUx recursive-get-dir/blocks/CIQFE/CIQFEAGMNNXXTYKYQSANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data', + 'added QmXrrAYhbThjuHRPA23HujCLFbTrnwd3jmvNbZBAnKEddk recursive-get-dir/blocks/CIQFE', + 'added QmcozcFvmaTqVPaFXgZUHPsroSG8YP6tHEYyFaFhnonwSG recursive-get-dir/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data', + 'added QmVU52FEpQQF3ViFGUKLhLeJaRKpCZfqN4AWLuzAXyrzyU recursive-get-dir/blocks/CIQEU', + 'added QmPiJAUg2J3dWWnQvtKXbkr8g1qCxX4RCPkU3wFmxd6x8H recursive-get-dir/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data', + 'added QmboWqKvhjxdBw1AfxQ56sqhqrrtG7ibaGhHb19TPnjr69 recursive-get-dir/blocks/CIQER', + 'added QmPbgB6GzeUEnvXqQgYLTJnrdcm95kGRWH36euTr2eAB2w recursive-get-dir/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data', + 'added QmZCxJdNTR1MHRNGGWgZRZdW66FTpyTLdT8odbUz1CP7J9 recursive-get-dir/blocks/CIQEN', + 'added QmQCYnQWAHqSy1ts7VmHbp18BFEmbVvfX7FASVQF21uo5g recursive-get-dir/blocks/CIQDV/CIQDVKITASFS55MC2TXCX5XMZLMGTYVODWPEDIW7JYEG7YXBIA7IUWY.data', + 'added QmQaTiy1CufRfP3zTCW8fAtNWjvdeWuMkvTi4q6dykNDif recursive-get-dir/blocks/CIQDV', + 'added QmSynZ3cTjBzpMTSPCP5Q6RJSa9WEAA8p178cZRLnKdahz recursive-get-dir/blocks/CIQDM/CIQDMKFEUGKSLXMEXO774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data', + 'added QmNS3zMGDTPRTuR8nbPz4ddQpGN4gtuVyZ5G3mn3ajg4Rb recursive-get-dir/blocks/CIQDM', + 'added QmTpxXKswGwhTYLn1qL4EG9aLGFXS2LSnreceV2FJeArVh recursive-get-dir/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data', + 'added Qmbm7ToWsTta4Y1RipmRudCenKF7qAHRVTCtTPuoVqfY8H recursive-get-dir/blocks/CIQDD/CIQDDVW2EZIJF4NQH7WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data', + 'added QmSCq2peGvGDXZKuX565UczxRpgzsiPPF3PgcJq9zDbByL recursive-get-dir/blocks/CIQDD', + 'added QmdgaiKe1HFfhrZvLwTFCrXmgTojhSWuBvyFXUVc8KzJVc recursive-get-dir/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data', + 'added QmYwUkwNwJN2cevwXKL48DRpbbjbdLWyyLANG3BKTtsTZ8 recursive-get-dir/blocks/CIQBE', + 'added QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 recursive-get-dir/blocks', + 'added QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 recursive-get-dir' ].join('\n')) }) }) - it('add recursively test 2', () => { - return ipfs('files add -r test').then((out) => { - const nLines = out.split('\n').length - expect(nLines).to.be.above(10) - /* - expect(out).to.be.eql([ - 'added QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs init-docs/tour/0.0-intro', - 'added QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te init-docs/tour', - 'added QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ init-docs/security-notes', - 'added QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB init-docs/readme', - 'added QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha init-docs/quick-start', - 'added QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 init-docs/help', - 'added QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT init-docs/docs/index', - 'added QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC init-docs/docs', - 'added QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y init-docs/contact', - 'added QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V init-docs/about', - 'added QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU init-docs' - ].join('\n')) - */ + it('get recursively', () => { + const outDir = path.join(process.cwd(), 'QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') + rimraf(outDir) + return ipfs('files get QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2').then((out) => { + expect(out).to.be.eql( + 'Saving file(s) to QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2' + ) + + const outDir = path.join(process.cwd(), 'QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') + const expectedDir = path.join(process.cwd(), 'test', 'test-data', 'recursive-get-dir') + const compareResult = compareDir(outDir, expectedDir, { + compareContent: true, + compareSize: true + }) + expect(compareResult.differences).to.be.eql(0) + rimraf(outDir) }) }) }) diff --git a/test/test-data/recursive-get-dir/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data b/test/test-data/recursive-get-dir/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data new file mode 100644 index 0000000000..389e111776 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data @@ -0,0 +1,28 @@ + +Hello and Welcome to IPFS! + +██╗██████╗ ███████╗███████╗ +██║██╔══██╗██╔════╝██╔════╝ +██║██████╔╝█████╗ ███████╗ +██║██╔═══╝ ██╔══╝ ╚════██║ +██║██║ ██║ ███████║ +╚═╝╚═╝ ╚═╝ ╚══════╝ + +If you're seeing this, you have successfully installed +IPFS and are now interfacing with the ipfs merkledag! + + ------------------------------------------------------- +| Warning: | +| This is alpha software. Use at your own discretion! | +| Much is missing or lacking polish. There are bugs. | +| Not yet secure. Read the security notes for more. | + ------------------------------------------------------- + +Check out some of the other files in this directory: + + ./about + ./help + ./quick-start <-- usage examples + ./readme <-- this file + ./security-notes + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDVW2EZIJF4NQH7WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data b/test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDVW2EZIJF4NQH7WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data new file mode 100644 index 0000000000000000000000000000000000000000..5ea0edda6f82982c276a4a3813a50c0e35121c68 GIT binary patch literal 10765 zcmeIzF%AJy6a~;Rm3)!Nk3xb(CK9$mt(wFR^jf72s6=9D)srdd6*gc6EI~I4+fbbT zRX6Y66Q?1IqgQpGAHRd{ss22Q^=&*UXYbW{zqlNV{wBXJW712aODXvf?XV11kq9)T zAq{CrLmJYMhBTxh4QWV28q$!4G^8O7X-GpF(vXHUq#+GyNJARZkcKp*;U8!iTA|tK KY}4Vho$h|}9P~&4 literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data b/test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data new file mode 100644 index 0000000000..ecce1053f6 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data @@ -0,0 +1,4 @@ +5 +" ׾F_uؔlzS?|ڲPc@ js-ipfs-repo + + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQDM/CIQDMKFEUGKSLXMEXO774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data b/test/test-data/recursive-get-dir/blocks/CIQDM/CIQDMKFEUGKSLXMEXO774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data new file mode 100644 index 0000000000000000000000000000000000000000..bbe6bda78d0a52f6d87da578f452d43718b9aa9f GIT binary patch literal 10807 zcmeI&tqQ_m6vpvsQC>mhU=TmxWeCpZ4H&eDU=nNw5wR?6Yue0K5w>X*qZns5SS{Xw z-hn1RK)egXzn^qC&+{usEM| recursiveT \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data b/test/test-data/recursive-get-dir/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data new file mode 100644 index 0000000000..2965d1c457 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data @@ -0,0 +1,3 @@ + + hello world + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data b/test/test-data/recursive-get-dir/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data new file mode 100644 index 0000000000..4a26a4ac35 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data @@ -0,0 +1,3 @@ +/ +" !61صF2$`7#u@1directT2 +" Hz8#3u2ED ƥ*QKMQ recursiveT \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data b/test/test-data/recursive-get-dir/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data new file mode 100644 index 0000000000..4145619655 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data @@ -0,0 +1,4 @@ + +ys# js-ipfs-repo +Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript +s \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQFE/CIQFEAGMNNXXTYKYQSANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data b/test/test-data/recursive-get-dir/blocks/CIQFE/CIQFEAGMNNXXTYKYQSANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data new file mode 100644 index 0000000000000000000000000000000000000000..10aa2ae4f1291a62edd84980f1c05b09b95f78ff GIT binary patch literal 10891 zcmWgA;8GG&c)a0=(~LhdBC~#fIWaSTr;7SI$0sSXC;Kd!I#aqLXh*0Jg9L-nsLIh$ z8ciXixns0s7%de?YlP9-aI`iYtqn(O!_nGsv^E^A4M%Ik(b{mdHXN-DM{C2;+HkZs z9IXvUYs1mnaI`iYtqn(O!_nGsv^E^A4M%Ik(b{mdHXN-DM{C2;+HkZs9IXvUYs1mn zaI`iYG__&mlom_2c+JFlUxXS??=;#MbToJ7(P`PK4+MoQKg`(u9q~6w(px+ cb8FMhello + ipfs add hello + + +View it: + + ipfs cat + + +Try a directory: + + mkdir foo + mkdir foo/bar + echo "baz" > foo/baz + echo "baz" > foo/bar/baz + ipfs add -r foo + + +View things: + + ipfs ls + ipfs ls /bar + ipfs cat /baz + ipfs cat /bar/baz + ipfs cat /bar + ipfs ls /baz + + +References: + + ipfs refs + ipfs refs -r + ipfs refs --help + + +Get: + + ipfs get foo2 + diff foo foo2 + + +Objects: + + ipfs object get + ipfs object get /foo2 + ipfs object --help + + +Pin + GC: + + ipfs pin -r + ipfs gc + ipfs ls + ipfs unpin -r + ipfs gc + + +Daemon: + + ipfs daemon (in another terminal) + ipfs id + + +Network: + + (must be online) + ipfs swarm peers + ipfs id + ipfs cat + + +Mount: + + (warning: fuse is finicky!) + ipfs mount + cd /ipfs/< + + +Tool: + + ipfs version + ipfs update + ipfs commands + ipfs config --help + open http://localhost:5001/webui + + +Browse: + + webui: + + http://localhost:5001/webui + + video: + + http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse + + images: + + http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs + + markdown renderer app: + + http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQGP/CIQGPALRQ24P6NS4OWHTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data b/test/test-data/recursive-get-dir/blocks/CIQGP/CIQGPALRQ24P6NS4OWHTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data new file mode 100644 index 0000000000000000000000000000000000000000..a8f98693b7d4797d0a55704b16c15a6aa7d34bd5 GIT binary patch literal 10765 zcmeIzF%AJy6a~Szz&}ww{ J&EYejEr0X~^v?hQ literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data b/test/test-data/recursive-get-dir/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data new file mode 100644 index 0000000000..ee87b9db01 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data @@ -0,0 +1,4 @@ +0 +" ,Qv3k>\IzxEElM/fLICENSE1 +" JZXoRX!Fwd87U;SöWw README.md{ + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQHA/CIQHAKDLTL5GMIFGN5YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data b/test/test-data/recursive-get-dir/blocks/CIQHA/CIQHAKDLTL5GMIFGN5YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data new file mode 100644 index 0000000000000000000000000000000000000000..74de75af616ff437b5c7a3a5272281eac2146b6c GIT binary patch literal 309 zcmWgA<5Ch*SgK>j#LTl(=mjz6J*Z#Z`mUeibke1%>*qt`A@ymo*6O-~wOC)CS z3K@XZPnu<5V|lBKJN>}4>2CTNRSd^0_H1qVw~ozKk4Ii%i@p$ha(-S(VseSZ2}U7Z zkd6rls>-Jxlr$AsHtpiyKm2l@?&p6zQA*^T_KfrP>FKF6gjh0Ca|$F5F$tM~lqa2& z*O|D`YWmh`FN(J=HpxnHW4)f}dn)*>RpfVzsIJ{Y+=Zo?$=SNaC5c5P5({~S^g+6W z__Mw-Uda>Kbm^hob(zph@di$ZR2iSh3b{RB`110NH$rShsfj7MsS@Wngv>!2f{xjg zms)1qHyyK_UR9)g=w{aZf~|kMWdrSdqBHNTyCTF_oSIx(lvz@#o0ngbS}f7b!NtVE F2moEFc%uLS literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data b/test/test-data/recursive-get-dir/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data new file mode 100644 index 0000000000..3a99c365f0 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data @@ -0,0 +1,3 @@ +4 +" Y9_)a˹2RmŖke9 js-ipfs-repo + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQHP/CIQHPUVCWD6JA6AFUVD6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data b/test/test-data/recursive-get-dir/blocks/CIQHP/CIQHPUVCWD6JA6AFUVD6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data new file mode 100644 index 0000000000000000000000000000000000000000..78421c81c29ed8c18921f686ea3292e3e7300668 GIT binary patch literal 10765 zcmeIzAqoOf6a~;x48ym`#~`RM41#V$vuVH`*sVtQAcCXSECW-t8{CI3!R7?FVL1Jz z%e(i)S;%Adsve7DGwPqdpJ%zbPo~%Tdwt$7FNbotEpDrr43g+lN<931^R@s0 literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data b/test/test-data/recursive-get-dir/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data new file mode 100644 index 0000000000..3da92595c2 --- /dev/null +++ b/test/test-data/recursive-get-dir/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data @@ -0,0 +1,24 @@ + +The MIT License (MIT) + +Copyright (c) 2015 IPFS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQJ2/CIQJ23BL4UHXA2KTI6NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data b/test/test-data/recursive-get-dir/blocks/CIQJ2/CIQJ23BL4UHXA2KTI6NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data new file mode 100644 index 0000000000000000000000000000000000000000..b799cf6b2236c91f8224b9fefe43aca16c773490 GIT binary patch literal 309 zcmWgA<5Ch*SgK>j#LTl(=mjz6J*Z#Z`mUeibke1%>*qt`A@ymo*6O-~wOC)CS z3K@XZPnu<5V|lBKJN>}4>2CTNRSd^0_H1qVw~ozKk4Ii%i@p$ha(-S(VseSZ2}U7Z zkd6rls>-Jxlr$AsHtpiyKm2l@?&p6zQA*^T_KfrP>FKF6gjh0Ca|$F5F$tM~ls|2g zoaXRw$uaxIJs~DLpX;8StGsyP<=b&`P8V3!Rm2K~xC=`&le2Y;OA?DpBo6Qj>4S6$ z@n?Nwypkud>C!{F>oTF2;tiY*sWLv16>@vN@a5$jZ-m&2QWH~hQzg!E2$_R41Rb*} zFSX3JZ#rf` +- browsers or extensions can learn to use `ipfs://` directly +- hash-addressed content guarantees authenticity + +IPFS is modular: +- connection layer over any network protocol +- routing layer +- uses a routing layer DHT (kademlia/coral) +- uses a path-based naming service +- uses bittorrent-inspired block exchange + +IPFS uses crypto: +- cryptographic-hash content addressing +- block-level deduplication +- file integrity + versioning +- filesystem-level encryption + signing support + +IPFS is p2p: +- worldwide peer-to-peer file transfers +- completely decentralized architecture +- **no** central point of failure + +IPFS is a cdn: +- add a file to the filesystem locally, and it's now available to the world +- caching-friendly (content-hash naming) +- bittorrent-based bandwidth distribution + +IPFS has a name service: +- IPNS, an SFS inspired name system +- global namespace based on PKI +- serves to build trust chains +- compatible with other NSes +- can map DNS, .onion, .bit, etc to IPNS + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQLB/CIQLBK52T5EHVHZY5URTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data b/test/test-data/recursive-get-dir/blocks/CIQLB/CIQLBK52T5EHVHZY5URTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data new file mode 100644 index 0000000000000000000000000000000000000000..82458cdf713592bffde3af64f85bfa867231d7d1 GIT binary patch literal 10849 zcmWgA;8GG&c)a0=(~LhdBC~#fIWaSTr;7SI$0sSXC;Kd!I#aqLXh*0Jg9L-nsLIh$ z8ciXixns0s7%de?YlP9-aI`iYtqn(O!_nGsv^E^A4M%Ik(b{mdHXN-DM{C2;+HkZs z9IXvUYs1mnaI`iYtqn(O!_nGsv^E^A4M%Ik(b{mdHXN-DM{C2;+HkZs9IXvUYs1mn zaI`iYG__&mlom_2c+JFlUxXS??=;#MbToJ7(P`PK4+MoQKg`(u9pXsYYQnaL-~-$SEZaY-MiqUv4K}orj%_y00+YJV}#XGok z)Gc&_%?H(zbc;FK34aUrCGW}p=j0S(a*4bcz{(GU&M5Dn1~4bcz{(GU&M5Dn1~4bcz{(GU&M5Dn1~ z4bcz{(GU&M5Dn4rZ!}yDE04r@ptViQt$NSPbgyf+T8kZmjdSx~?(hFos3IOo>d{>N G+6cZA+z2}W literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/blocks/CIQMB/CIQMB7DLJFKD267QJ2B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data b/test/test-data/recursive-get-dir/blocks/CIQMB/CIQMB7DLJFKD267QJ2B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data new file mode 100644 index 0000000000000000000000000000000000000000..c9885c45d7e7c10d02b98208d40cfd7b8bfaed21 GIT binary patch literal 101 zcmWgA=TZ_+Kwo-;;PadOz%uNME$6+{JHE$$U!OUW!sO)in> z4G}T|X$WFClbv7rFrua5=1<0)Q}=J#b|1g=hello + ipfs add hello + + +View it: + + ipfs cat + + +Try a directory: + + mkdir foo + mkdir foo/bar + echo "baz" > foo/baz + echo "baz" > foo/bar/baz + ipfs add -r foo + + +View things: + + ipfs ls + ipfs ls /bar + ipfs cat /baz + ipfs cat /bar/baz + ipfs cat /bar + ipfs ls /baz + + +References: + + ipfs refs + ipfs refs -r + ipfs refs --help + + +Get: + + ipfs get -o foo2 + diff foo foo2 + + +Objects: + + ipfs object get + ipfs object get /foo2 + ipfs object --help + + +Pin + GC: + + ipfs pin add + ipfs repo gc + ipfs ls + ipfs pin rm + ipfs repo gc + + +Daemon: + + ipfs daemon (in another terminal) + ipfs id + + +Network: + + (must be online) + ipfs swarm peers + ipfs id + ipfs cat + + +Mount: + + (warning: fuse is finicky!) + ipfs mount + cd /ipfs/ + ls + + +Tool: + + ipfs version + ipfs update + ipfs commands + ipfs config --help + open http://localhost:5001/webui + + +Browse: + + webui: + + http://localhost:5001/webui + + video: + + http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse + + images: + + http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs + + markdown renderer app: + + http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown + \ No newline at end of file diff --git a/test/test-data/recursive-get-dir/blocks/CIQOM/CIQOMBKARLB7PAITVSNH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data b/test/test-data/recursive-get-dir/blocks/CIQOM/CIQOMBKARLB7PAITVSNH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data new file mode 100644 index 0000000000000000000000000000000000000000..b65398976526bbfc4648bcc7e8dc533ce6f4dff5 GIT binary patch literal 10765 zcmeIzF%AJy6a~FJWY200SX~$SEzBZ1I|j^S%f*oZe})FX(9Q%%jt? zQy&NlS$>$Y`#n34QbA^3F(V^P!?OjhZT>&P<~cuU%i;RLe(ysy@1_qD4Q&dq4R$uX zbPxoo11sKKRu>QF9Qd?w0|O_M0pouNU?_u2-8}VndNoG}qZmkp00{rx(5+JHej5PO CoIXSV literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/datastore/000005.ldb b/test/test-data/recursive-get-dir/datastore/000005.ldb new file mode 100644 index 0000000000000000000000000000000000000000..63d9d260b936415ee42b5aeda6c79fb941664398 GIT binary patch literal 1120 zcmZQDSjViNS&&z(FQg!8*qs;0^V3RMWIveo0t|Brg#j3VRkisv@!=|IgJvNC_dNx9y@%e`@arzW`upR#0^RR3Lu1P3 zgny1+s9JOHtH$|N^V2^pIaU+*`j0Vdf^UEA=Y(L*NL7==e45ubJUDbI<}5@1nZ5i@ zU-f@onB_6=BHQa-tVc_VRZiT0AST5ib<){%%1r}PkJe@8+6(<3{`CFeMP?prC*c znwwdgM`+7O$B&?~72w>77RV zf{y0SJUT5q^?{&}<%b!&-?Q^56=dcWGqS)myonCBGLo1n?_9oP$D!cvsdqIm%dJT< zUeCYn&kfrf>=lfOBoQtW6k&$7W$0~c7gOL@IORq4N$7y_CFLmFs-1D4yKkEePa;Yx&V3}9e z6J;wFzbL(7XX!B6*Rdrw=+4dxeU2>!j1QaGe>~sK(>yOETD?v4ss5$s3VXC14~0|~ z@|s=JZrGS)y@`hY)f%XfBnQv@ZgL4too7C-W6;9@lKgp&)Y9xu#YGC zq+Q(oPkf)J&zo^7bJ>~t)Xqs~*IU@HQqP#^{d0FztkiZ*y~k%OjhiRCYiY>$1@7+Z zzc{J2k%`0O*2zuI)9>zn)wWdsh9cXQc|w1;OnM=;)%wQi`6UM;Jtuj8n*Q?qk;X3q zZaf<6!(B7;zLu#kRKLAQM`r(FbFXM+CT2zkqS6H@{24)n$QSJzIOo8pg&P<+nGG2K hLjXe)2VAZvSyQK-gJTMZI7kRT2>;#Cty1cK8vstu!bkuB literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/datastore/000010.ldb b/test/test-data/recursive-get-dir/datastore/000010.ldb new file mode 100644 index 0000000000000000000000000000000000000000..92077582ca4c1094d81e1c35f8703550afefa5f7 GIT binary patch literal 1143 zcmZQDV9?Jj$Sc+tQjj$4&Wq#uX{9W(pHXd=&LNx2cdi6ocRIV%d~TcDw2tFO0@nWL9`h-bL3Yk+%*afr8@TbPk^RJchgVHA9N_5eTxD41QxO=J9Z^{56JZ); z7-4K;T3DFokyM;!W}Z>zXzZ6K)WGC&@4ao?>Nz(8|F>suXs_zIpd7w&-MpLjzTew7 zw;bnNa{uX~ml~7*<|J4d{FVA*zBjGA&O}w!=F`N7tE3H@g#_I96y)_DdRxPzt0SfDVr1iIeMXL&AqQ0=U2^7|FGm(P2B50#;ggx{k5MHf;A&mO%C&EUfb~C z(50BO4E<;J@;iOi|8-%O$GnSduXnK?Eh$zxasPps6ob@BXVWP+4NN^+mzirX^ndu{ z#t*;Sx0dNGNfK9{8ZLg&Y3{=GymywrWge8Ax zb8_8$u}O-_UoIvnSEU^1zHqkmzk}Jo{lB**@XgG7Tp+=qBxht`XsT;yq-$sxVrXh* zVrgY+u4iCoXlQ9}W@#R!!6>CfIN}*~849wANg!O1*k!T*#RNJcTULFAv{=p%R0p5|p&LRGejGWK}qNY!jl|rkT zI2eSMF&Q*5DjD#yacZ@Bw0-AgWMpJzU~XdMX8?+GF*PwVGHml$WiN9uvO;p{6~^*7 zjnC_)?mL!yo-^-fogiH<)#V;6^U8XnY{lXir8n#>9VYuaw!{YA*;%2_v890VVH5k0 z=ev2D=Y>S8w`o4rzw}&TkCx-1kjg?{vrD=>%@*e)9$i}<^>(k?*#eGjDX!_SpO^_A zd~u&uKT_JeV$DC^DKqPN`vna4@g$$Li@X1c@ALF|GfrhLJ5!(9IqB?r3;R{-856yK z?v9F;+ODbh_-v(d^JI4|4f(#n-Cg|`C$%;*ad_N1xygC@-QBO+mg?V7WV_2So6|Ky~%*a4g zWP`$=5k#;l^#s5<2R<#_z`)6D!1x~m7-n+7<=&pJcTULFAv{=p%R0p5|p&LRGe zjGPcN*cn(K5N|UhD@2zb$Y#P0Wn_a{!gQHYLO&-zIWb2+Ei)&zxF|orgpmm%D-4w= M$jmEdWQ2$T0KrCJEdT%j literal 0 HcmV?d00001 diff --git a/test/test-data/recursive-get-dir/init-docs/about b/test/test-data/recursive-get-dir/init-docs/about new file mode 100644 index 0000000000..eaa644b24b --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/about @@ -0,0 +1,53 @@ + + IPFS -- Inter-Planetary File system + +IPFS is a global, versioned, peer-to-peer filesystem. It combines good ideas +from Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bit- +torrent swarm, exchanging git objects. IPFS provides an interface as simple +as the HTTP web, but with permanence built in. You can also mount the world +at /ipfs. + +IPFS is a protocol: +- defines a content-addressed file system +- coordinates content delivery +- combines Kademlia + BitTorrent + Git + +IPFS is a filesystem: +- has directories and files +- mountable filesystem (via FUSE) + +IPFS is a web: +- can be used to view documents like the web +- files accessible via HTTP at `http://ipfs.io/` +- browsers or extensions can learn to use `ipfs://` directly +- hash-addressed content guarantees authenticity + +IPFS is modular: +- connection layer over any network protocol +- routing layer +- uses a routing layer DHT (kademlia/coral) +- uses a path-based naming service +- uses bittorrent-inspired block exchange + +IPFS uses crypto: +- cryptographic-hash content addressing +- block-level deduplication +- file integrity + versioning +- filesystem-level encryption + signing support + +IPFS is p2p: +- worldwide peer-to-peer file transfers +- completely decentralized architecture +- **no** central point of failure + +IPFS is a cdn: +- add a file to the filesystem locally, and it's now available to the world +- caching-friendly (content-hash naming) +- bittorrent-based bandwidth distribution + +IPFS has a name service: +- IPNS, an SFS inspired name system +- global namespace based on PKI +- serves to build trust chains +- compatible with other NSes +- can map DNS, .onion, .bit, etc to IPNS diff --git a/test/test-data/recursive-get-dir/init-docs/contact b/test/test-data/recursive-get-dir/init-docs/contact new file mode 100644 index 0000000000..965de025e2 --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/contact @@ -0,0 +1,6 @@ +Come hang out in our IRC chat room if you have any questions. + +Contact the ipfs dev team: +- Bugs: https://github.com/ipfs/go-ipfs/issues +- Help: irc.freenode.org/#ipfs +- Email: dev@ipfs.io diff --git a/test/test-data/recursive-get-dir/init-docs/docs/index b/test/test-data/recursive-get-dir/init-docs/docs/index new file mode 100644 index 0000000000..c846c91b8c --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/docs/index @@ -0,0 +1 @@ +Index diff --git a/test/test-data/recursive-get-dir/init-docs/help b/test/test-data/recursive-get-dir/init-docs/help new file mode 100644 index 0000000000..d069d6ba76 --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/help @@ -0,0 +1,7 @@ +Some helpful resources for finding your way around ipfs: + +- quick-start: a quick show of various ipfs features. +- ipfs commands: a list of all commands +- ipfs --help: every command describes itself +- https://github.com/ipfs/go-ipfs -- the src repository +- #ipfs on irc.freenode.org -- the community irc channel diff --git a/test/test-data/recursive-get-dir/init-docs/quick-start b/test/test-data/recursive-get-dir/init-docs/quick-start new file mode 100644 index 0000000000..92eca892de --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/quick-start @@ -0,0 +1,113 @@ +# 0.1 - Quick Start + +This is a set of short examples with minimal explanation. It is meant as +a "quick start". Soon, we'll write a longer tour :-) + + +Add a file to ipfs: + + echo "hello world" >hello + ipfs add hello + + +View it: + + ipfs cat + + +Try a directory: + + mkdir foo + mkdir foo/bar + echo "baz" > foo/baz + echo "baz" > foo/bar/baz + ipfs add -r foo + + +View things: + + ipfs ls + ipfs ls /bar + ipfs cat /baz + ipfs cat /bar/baz + ipfs cat /bar + ipfs ls /baz + + +References: + + ipfs refs + ipfs refs -r + ipfs refs --help + + +Get: + + ipfs get -o foo2 + diff foo foo2 + + +Objects: + + ipfs object get + ipfs object get /foo2 + ipfs object --help + + +Pin + GC: + + ipfs pin add + ipfs repo gc + ipfs ls + ipfs pin rm + ipfs repo gc + + +Daemon: + + ipfs daemon (in another terminal) + ipfs id + + +Network: + + (must be online) + ipfs swarm peers + ipfs id + ipfs cat + + +Mount: + + (warning: fuse is finicky!) + ipfs mount + cd /ipfs/ + ls + + +Tool: + + ipfs version + ipfs update + ipfs commands + ipfs config --help + open http://localhost:5001/webui + + +Browse: + + webui: + + http://localhost:5001/webui + + video: + + http://localhost:8080/ipfs/QmVc6zuAneKJzicnJpfrqCH9gSy6bz54JhcypfJYhGUFQu/play#/ipfs/QmTKZgRNwDNZwHtJSjCp6r5FYefzpULfy37JvMt9DwvXse + + images: + + http://localhost:8080/ipfs/QmZpc3HvfjEXvLWGQPWbHk3AjD5j8NEN4gmFN8Jmrd5g83/cs + + markdown renderer app: + + http://localhost:8080/ipfs/QmX7M9CiYXjVeFnkfVGf3y5ixTZ2ACeSGyL1vBJY1HvQPp/mdown diff --git a/test/test-data/recursive-get-dir/init-docs/readme b/test/test-data/recursive-get-dir/init-docs/readme new file mode 100644 index 0000000000..eeade6617b --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/readme @@ -0,0 +1,26 @@ +Hello and Welcome to IPFS! + +██╗██████╗ ███████╗███████╗ +██║██╔══██╗██╔════╝██╔════╝ +██║██████╔╝█████╗ ███████╗ +██║██╔═══╝ ██╔══╝ ╚════██║ +██║██║ ██║ ███████║ +╚═╝╚═╝ ╚═╝ ╚══════╝ + +If you're seeing this, you have successfully installed +IPFS and are now interfacing with the ipfs merkledag! + + ------------------------------------------------------- +| Warning: | +| This is alpha software. Use at your own discretion! | +| Much is missing or lacking polish. There are bugs. | +| Not yet secure. Read the security notes for more. | + ------------------------------------------------------- + +Check out some of the other files in this directory: + + ./about + ./help + ./quick-start <-- usage examples + ./readme <-- this file + ./security-notes diff --git a/test/test-data/recursive-get-dir/init-docs/security-notes b/test/test-data/recursive-get-dir/init-docs/security-notes new file mode 100644 index 0000000000..da55ea71c4 --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/security-notes @@ -0,0 +1,21 @@ + IPFS Alpha Security Notes + +We try hard to ensure our system is safe and robust, but all software +has bugs, especially new software. This distribution is meant to be an +alpha preview, don't use it for anything mission critical. + +Please note the following: + +- This is alpha software and has not been audited. It is our goal + to conduct a proper security audit once we close in on a 1.0 release. + +- ipfs is a networked program, and may have serious undiscovered + vulnerabilities. It is written in Go, and we do not execute any + user provided data. But please point any problems out to us in a + github issue, or email security@ipfs.io privately. + +- ipfs uses encryption for all communication, but it's NOT PROVEN SECURE + YET! It may be totally broken. For now, the code is included to make + sure we benchmark our operations with encryption in mind. In the future, + there will be an "unsafe" mode for high performance intranet apps. + If this is a blocking feature for you, please contact us. diff --git a/test/test-data/recursive-get-dir/init-docs/tour/0.0-intro b/test/test-data/recursive-get-dir/init-docs/tour/0.0-intro new file mode 100644 index 0000000000..36d8da0c6d --- /dev/null +++ b/test/test-data/recursive-get-dir/init-docs/tour/0.0-intro @@ -0,0 +1,34 @@ +WIP + +# 0.0 - Introduction + +Welcome to IPFS! This tour will guide you through a few of the +features of this tool, and the most common commands. Then, it will +immerse you into the world of merkledags and the amazing things +you can do with them. + + +This tour has many parts, and can be taken in different sequences. +Different people learn different ways, so choose your own adventure: + + To start with the concepts, try: + - The Merkle DAG + - Data Structures on the Merkle DAG + - Representing Files with unixfs + - add, cat, ls, refs + ... + + + To start with the examples, try: + - add, cat, ls, refs + - Representing Files with unixfs + - Data Structures on the Merkle DAG + - The Merkle DAG + ... + + + To start with the network, try: + - IPFS Nodes + - Running the daemon + - The Swarm + - The Web diff --git a/test/test-data/recursive-get-dir/version b/test/test-data/recursive-get-dir/version new file mode 100644 index 0000000000..b8626c4cff --- /dev/null +++ b/test/test-data/recursive-get-dir/version @@ -0,0 +1 @@ +4 From 838bfde0316a54f55adfaf7f05848d2e6e68d58e Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 08:05:39 -0800 Subject: [PATCH 12/28] http-api - parseArgs - allow lookup by CID (#703) --- src/http-api/resources/block.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/http-api/resources/block.js b/src/http-api/resources/block.js index 04f3d1fef8..a087630e0d 100644 --- a/src/http-api/resources/block.js +++ b/src/http-api/resources/block.js @@ -1,6 +1,7 @@ 'use strict' const mh = require('multihashes') +const CID = require('cids') const multipart = require('ipfs-multipart') const Block = require('ipfs-block') const waterfall = require('async/waterfall') @@ -18,7 +19,7 @@ exports.parseKey = (request, reply) => { try { return reply({ - key: mh.fromB58String(request.query.arg) + key: new CID(request.query.arg) }) } catch (err) { log.error(err) From c608f5f52e3d64023b2bc451f32db682dd3a0d4d Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Wed, 1 Feb 2017 17:07:14 +0100 Subject: [PATCH 13/28] test(interop): add more sizes (#715) --- test/interop/daemons/js.js | 2 +- test/interop/index.js | 83 ++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/test/interop/daemons/js.js b/test/interop/daemons/js.js index 84da8d66c7..b03e43ace5 100644 --- a/test/interop/daemons/js.js +++ b/test/interop/daemons/js.js @@ -41,7 +41,7 @@ class JsDaemon { this.init = opts.init this.port = opts.port - this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 1000)}` + this.path = opts.path || os.tmpdir() + `/${Math.ceil(Math.random() * 10000)}` if (this.init) { this.ipfs = new IPFS(this.path) } else { diff --git a/test/interop/index.js b/test/interop/index.js index b1262b854a..2f4a30ab97 100644 --- a/test/interop/index.js +++ b/test/interop/index.js @@ -11,6 +11,20 @@ const crypto = require('crypto') const GoDaemon = require('./daemons/go') const JsDaemon = require('./daemons/js') +const sizes = [ + 1024, + 1024 * 62, + // starts failing with spdy + 1024 * 64, + 1024 * 512, + 1024 * 768, + 1024 * 1023, + // starts failing with multiplex + 1024 * 1024, + 1024 * 1024 * 4, + 1024 * 1024 * 8 +] + describe('basic', () => { let goDaemon let jsDaemon @@ -92,43 +106,44 @@ describe('basic', () => { ], done) }) - it('cat file: go -> js', (done) => { - const data = crypto.randomBytes(1024 * 1024) - waterfall([ - (cb) => goDaemon.api.add(data, cb), - (res, cb) => jsDaemon.api.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], (err, file) => { - expect(err).to.not.exist - expect(file).to.be.eql(data) - done() + describe('cat file', () => sizes.forEach((size) => { + it(`go -> js: ${size}bytes`, (done) => { + const data = crypto.randomBytes(size) + waterfall([ + (cb) => goDaemon.api.add(data, cb), + (res, cb) => jsDaemon.api.cat(res[0].hash, cb), + (stream, cb) => stream.pipe(bl(cb)) + ], (err, file) => { + expect(err).to.not.exist + expect(file).to.be.eql(data) + done() + }) }) - }) - it('cat file: js -> go', (done) => { - // This will fail once the size is increased to 64512 = 1024 * 63 - const data = crypto.randomBytes(1024 * 63 - 1) - waterfall([ - (cb) => jsDaemon.api.add(data, cb), - (res, cb) => goDaemon.api.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], (err, file) => { - expect(err).to.not.exist - expect(file).to.be.eql(data) - done() + it(`js -> go: ${size}bytes`, (done) => { + const data = crypto.randomBytes(size) + waterfall([ + (cb) => jsDaemon.api.add(data, cb), + (res, cb) => goDaemon.api.cat(res[0].hash, cb), + (stream, cb) => stream.pipe(bl(cb)) + ], (err, file) => { + expect(err).to.not.exist + expect(file).to.be.eql(data) + done() + }) }) - }) - it('cat file: js -> js', (done) => { - const data = crypto.randomBytes(1024 * 1024) - waterfall([ - (cb) => js2Daemon.api.add(data, cb), - (res, cb) => jsDaemon.api.cat(res[0].hash, cb), - (stream, cb) => stream.pipe(bl(cb)) - ], (err, file) => { - expect(err).to.not.exist - expect(file).to.be.eql(data) - done() + it(`js -> js: ${size}bytes`, (done) => { + const data = crypto.randomBytes(size) + waterfall([ + (cb) => js2Daemon.api.add(data, cb), + (res, cb) => jsDaemon.api.cat(res[0].hash, cb), + (stream, cb) => stream.pipe(bl(cb)) + ], (err, file) => { + expect(err).to.not.exist + expect(file).to.be.eql(data) + done() + }) }) - }) + })) }) From 6e683b4a14621509cb53c2f859b77ae7468f2d89 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 1 Feb 2017 08:09:29 -0800 Subject: [PATCH 14/28] http-api - block - get - return value raw (#704) fix(http:api - block.get): value may be a binary buffer, it should be returned as is instead of coerced into unicode --- src/http-api/resources/block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http-api/resources/block.js b/src/http-api/resources/block.js index a087630e0d..b0ffc7a92c 100644 --- a/src/http-api/resources/block.js +++ b/src/http-api/resources/block.js @@ -47,7 +47,7 @@ exports.get = { }).code(500) } - return reply(block.data.toString()) + return reply(block.data) }) } } From b910c74b3e5e28de99b1ee1fe429fc666248b54d Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 1 Feb 2017 22:00:28 +0000 Subject: [PATCH 15/28] test: the first pass of a big refactor of tests towards using only ipfs-factory to spawn nodes (#750) * test: mega clean up to the tests * fix: but in starting api on port 0 --- gulpfile.js | 64 ++++++-- src/cli/commands/daemon.js | 2 + src/http-api/index.js | 23 ++- test/cli/bitswap.js | 39 +++++ test/cli/block.js | 48 ++++++ test/cli/bootstrap.js | 78 +++++++++ test/cli/commands.js | 23 +++ test/cli/config.js | 86 ++++++++++ test/cli/{test-daemon.js => daemon.js} | 6 +- test/cli/{test-files.js => files.js} | 151 +++++++++--------- test/cli/id.js | 22 +++ test/cli/index.js | 33 +--- test/cli/{test-init.js => init.js} | 18 +-- test/cli/object.js | 106 ++++++++++++ test/cli/{test-pubsub.js => pubsub.js} | 3 +- test/cli/swarm.js | 79 +++++++++ test/cli/test-bitswap.js | 77 --------- test/cli/test-block.js | 46 ------ test/cli/test-bootstrap.js | 76 --------- test/cli/test-commands.js | 28 ---- test/cli/test-config.js | 83 ---------- test/cli/test-id.js | 20 --- test/cli/test-object.js | 104 ------------ test/cli/test-swarm.js | 87 ---------- test/cli/test-version.js | 20 --- test/cli/version.js | 22 +++ test/core/bitswap.spec.js | 10 +- test/core/interface/block.js | 2 +- test/core/interface/config.js | 2 +- test/core/interface/dag.js | 2 +- test/core/interface/files.js | 2 +- test/core/interface/generic.js | 2 +- test/core/interface/object.js | 2 +- test/core/interface/pubsub.js | 2 +- test/core/interface/swarm.js | 2 +- test/http-api/index.js | 30 ++-- .../interface/{test-block.js => block.js} | 2 +- .../interface/{test-config.js => config.js} | 2 +- .../interface/{test-files.js => files.js} | 2 +- .../interface/{test-object.js => object.js} | 2 +- .../interface/{test-pubsub.js => pubsub.js} | 9 +- .../interface/{test-swarm.js => swarm.js} | 2 +- .../over-ipfs-api/{test-block.js => block.js} | 2 +- .../{test-bootstrap.js => bootstrap.js} | 0 .../{test-config.js => config.js} | 0 .../over-ipfs-api/{test-id.js => id.js} | 0 .../{test-object.js => object.js} | 0 test/http-api/over-ipfs-api/test-bitswap.js | 8 - test/http-api/over-ipfs-api/test-repo.js | 9 -- test/http-api/over-ipfs-api/test-swarm.js | 71 -------- .../{test-version.js => version.js} | 0 .../spec/{test-bitswap.js => bitswap.js} | 5 - .../http-api/spec/{test-block.js => block.js} | 0 .../spec/{test-bootstrap.js => bootstrap.js} | 0 .../spec/{test-config.js => config.js} | 2 +- .../http-api/spec/{test-files.js => files.js} | 0 test/http-api/spec/{test-id.js => id.js} | 0 .../spec/{test-object.js => object.js} | 0 .../spec/{test-pubsub.js => pubsub.js} | 5 +- test/http-api/spec/test-repo.js | 10 -- test/http-api/spec/test-swarm.js | 93 ----------- .../spec/{test-version.js => version.js} | 0 test/{ => sharness/lib}/ipfs-test-lib.sh | 0 test/sharness/lib/test-lib.sh | 2 +- ...JOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data | 0 ...WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data | Bin ...LZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data | 0 ...774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data | Bin ...XCX5XMZLMGTYVODWPEDIW7JYEG7YXBIA7IUWY.data | 0 ...5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data | 0 ...2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data | 0 ...HSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data | 0 ...ANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data | Bin ...DDTF32OIR4FWLKT5YLL7MLDVIT7DC3NHOK5VA.data | 0 ...2BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y.data | 0 ...LOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY.data | 0 ...HTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data | Bin ...VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data | 0 ...YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data | Bin ...LP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data | 0 ...D6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data | Bin ...LJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data | 0 ...NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data | Bin ...TJNUP57QHR4SKHZ74OIITBBGLOMCO3ZOLWLGA.data | 0 ...AJNF2GF5UHUAGGHC6LLAH6VYDEKLQMD4QLILY.data | 0 ...2FSMG76VV256I4PXBULZZ5ASNLK4FL4EG7XOI.data | Bin ...7E32LQAL6236OUKZTMHPQSFIXPWXNZHQOV7JQ.data | 0 ...RTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data | Bin ...EBXFD5QN6MTI5YBYMCVQJDXPKCOVR6RMLHZFQ.data | Bin ...B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data | Bin ...57JSEZN64SIJ5OIHSGJG4TJSSJLGI3PBJLQVI.data | 0 ...RYYVBUXHTS3SM5EORZDU63LYPEFUAFE4SBM4I.data | 0 ...NH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data | Bin ...SIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data | 0 ...33ROGCKOFZLXJJ2MPKYZBTV4H3N7GYHXMAO6A.data | 0 ...YNRNMP2VDKWBWGAEDDEJDACM3SGG3VIANDDXI.data | Bin test/{ => test-data}/go-ipfs-repo/config | 0 .../go-ipfs-repo/datastore/000002.ldb | Bin .../go-ipfs-repo/datastore/000005.ldb | Bin .../go-ipfs-repo/datastore/000010.ldb | Bin .../go-ipfs-repo/datastore/CURRENT | 0 .../go-ipfs-repo/datastore/LOCK | 0 .../go-ipfs-repo/datastore/LOG | 0 .../go-ipfs-repo/datastore/LOG.old | 0 .../go-ipfs-repo/datastore/MANIFEST-000014 | Bin test/{ => test-data}/go-ipfs-repo/version | 0 test/utils/factory-http/index.js | 131 --------------- .../default-config.json | 0 test/utils/ipfs-factory-daemon/index.js | 92 +++++++++++ .../default-config.json | 0 .../index.js | 0 test/utils/on-and-off.js | 69 ++++++-- test/utils/temp-node.js | 57 ------- 113 files changed, 845 insertions(+), 1130 deletions(-) create mode 100644 test/cli/bitswap.js create mode 100644 test/cli/block.js create mode 100644 test/cli/bootstrap.js create mode 100644 test/cli/commands.js create mode 100644 test/cli/config.js rename test/cli/{test-daemon.js => daemon.js} (87%) rename test/cli/{test-files.js => files.js} (82%) create mode 100644 test/cli/id.js rename test/cli/{test-init.js => init.js} (74%) create mode 100644 test/cli/object.js rename test/cli/{test-pubsub.js => pubsub.js} (97%) create mode 100644 test/cli/swarm.js delete mode 100644 test/cli/test-bitswap.js delete mode 100644 test/cli/test-block.js delete mode 100644 test/cli/test-bootstrap.js delete mode 100644 test/cli/test-commands.js delete mode 100644 test/cli/test-config.js delete mode 100644 test/cli/test-id.js delete mode 100644 test/cli/test-object.js delete mode 100644 test/cli/test-swarm.js delete mode 100644 test/cli/test-version.js create mode 100644 test/cli/version.js rename test/http-api/interface/{test-block.js => block.js} (80%) rename test/http-api/interface/{test-config.js => config.js} (80%) rename test/http-api/interface/{test-files.js => files.js} (80%) rename test/http-api/interface/{test-object.js => object.js} (80%) rename test/http-api/interface/{test-pubsub.js => pubsub.js} (64%) rename test/http-api/interface/{test-swarm.js => swarm.js} (80%) rename test/http-api/over-ipfs-api/{test-block.js => block.js} (95%) rename test/http-api/over-ipfs-api/{test-bootstrap.js => bootstrap.js} (100%) rename test/http-api/over-ipfs-api/{test-config.js => config.js} (100%) rename test/http-api/over-ipfs-api/{test-id.js => id.js} (100%) rename test/http-api/over-ipfs-api/{test-object.js => object.js} (100%) delete mode 100644 test/http-api/over-ipfs-api/test-bitswap.js delete mode 100644 test/http-api/over-ipfs-api/test-repo.js delete mode 100644 test/http-api/over-ipfs-api/test-swarm.js rename test/http-api/over-ipfs-api/{test-version.js => version.js} (100%) rename test/http-api/spec/{test-bitswap.js => bitswap.js} (85%) rename test/http-api/spec/{test-block.js => block.js} (100%) rename test/http-api/spec/{test-bootstrap.js => bootstrap.js} (100%) rename test/http-api/spec/{test-config.js => config.js} (98%) rename test/http-api/spec/{test-files.js => files.js} (100%) rename test/http-api/spec/{test-id.js => id.js} (100%) rename test/http-api/spec/{test-object.js => object.js} (100%) rename test/http-api/spec/{test-pubsub.js => pubsub.js} (97%) delete mode 100644 test/http-api/spec/test-repo.js delete mode 100644 test/http-api/spec/test-swarm.js rename test/http-api/spec/{test-version.js => version.js} (100%) rename test/{ => sharness/lib}/ipfs-test-lib.sh (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQBE/CIQBED3K6YA5I3QQWLJOCHWXDRK5EXZQILBCKAPEDUJENZ5B5HJ5R3A.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQDD/CIQDDVW2EZIJF4NQH7WJNESD7XHQSXA5EGJVNTPVHD7444C2KLKXHDI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQDD/CIQDDZ5EDQK5AP7LRTLZHQZUR2R3GECRFV3WPKNL7PL2SKFIL2LXC4Y.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQDM/CIQDMKFEUGKSLXMEXO774EZOYCYNHPRVFD53ZSAU7237F67XDSQGCYQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQDV/CIQDVKITASFS55MC2TXCX5XMZLMGTYVODWPEDIW7JYEG7YXBIA7IUWY.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQEN/CIQENVCICS44LLYUDQ5KVN6ALXC6QRHK2X4R6EUFRMBB5OSFO2FUYDQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQER/CIQERMRAAFXUAUOX3V2DCW7R77FRIVHQ3V5OIPPS3XQBX34KRPNOIRQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQEU/CIQEUWUVLBXVFYSYCHHSCRTXCYHGIOBXKWUMKFR3UPAFHQ5WK5362FQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQFE/CIQFEAGMNNXXTYKYQSANT6IBNTFN7WR5RPD5F6GN6MBKUUO25DNOTWQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQFF/CIQFFRR4O52TS2Z7QLDDTF32OIR4FWLKT5YLL7MLDVIT7DC3NHOK5VA.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQFT/CIQFTFEEHEDF6KLBT32BFAGLXEZL4UWFNWM4LFTLMXQBCERZ6CMLX3Y.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQGF/CIQGFTQ7FSI2COUXWWLOQ45VUM2GUZCGAXLWCTOKKPGTUWPXHBNIVOY.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQGP/CIQGPALRQ24P6NS4OWHTQ7R247ZI7KJWP3QWPQYS43LFULQC5ANLQFI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQH7/CIQH7OEYWXL34RWYL7VXLWEU4FWPVGT24VJT7DUZPTNLF25N25IGGQA.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQHA/CIQHAKDLTL5GMIFGN5YVY4BA22FPHUIODJEXS4LCTQDWA275XAJDAPI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQHB/CIQHBGZNZRPWVEFNMTLP4OS5EAVHFMCX2HD7FZUC2B3WUU3D4LGKS5A.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQHP/CIQHPUVCWD6JA6AFUVD6VA64TGWP67KYA3AIMBUMVWGZ5AQN2L2HSWQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQIX/CIQIXBZMUTXFC5QIGMLJNXLLHZOPGSL2PBC65D4UIVWM6TI5F5TAFNI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQJ2/CIQJ23BL4UHXA2KTI6NLTXZM4PW4VEFWQBJ4ACZQAS37BLGL4HUO5XY.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQJB/CIQJBQD2O6K4CGJVCCTJNUP57QHR4SKHZ74OIITBBGLOMCO3ZOLWLGA.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQJF/CIQJFGRQHQ45VCQLM7AJNF2GF5UHUAGGHC6LLAH6VYDEKLQMD4QLILY.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQJG/CIQJGO2B2N75IUEM372FSMG76VV256I4PXBULZZ5ASNLK4FL4EG7XOI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQKK/CIQKKLBWAIBQZOIS5X7E32LQAL6236OUKZTMHPQSFIXPWXNZHQOV7JQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQLB/CIQLBK52T5EHVHZY5URTG5JS3JCUJDQM2DRB5RVF33DCUUOFJNGVDUI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQLB/CIQLBS5HG4PRCRQ7O4EBXFD5QN6MTI5YBYMCVQJDXPKCOVR6RMLHZFQ.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQMB/CIQMB7DLJFKD267QJ2B5FJNHZPTSVA7IB6OHXSQ2XSVEEKMKK6RT75I.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQOH/CIQOHMGEIKMPYHAUTL57JSEZN64SIJ5OIHSGJG4TJSSJLGI3PBJLQVI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQOL/CIQOLBQZSZAODJGGH6RYYVBUXHTS3SM5EORZDU63LYPEFUAFE4SBM4I.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQOM/CIQOMBKARLB7PAITVSNH7VEGIQJRPL6J7FT2XYVKAXT4MQPXXPUYUNY.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQON/CIQONICFQZH7QVU6IPSIM3AK7AD554D3BWZPAGEAQYQOWMFZQDUUAEI.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQOY/CIQOYW2THIZBRGI7IN33ROGCKOFZLXJJ2MPKYZBTV4H3N7GYHXMAO6A.data (100%) rename test/{ => test-data}/go-ipfs-repo/blocks/CIQPD/CIQPDQJBGYDZNMOAGGYNRNMP2VDKWBWGAEDDEJDACM3SGG3VIANDDXI.data (100%) rename test/{ => test-data}/go-ipfs-repo/config (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/000002.ldb (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/000005.ldb (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/000010.ldb (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/CURRENT (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/LOCK (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/LOG (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/LOG.old (100%) rename test/{ => test-data}/go-ipfs-repo/datastore/MANIFEST-000014 (100%) rename test/{ => test-data}/go-ipfs-repo/version (100%) delete mode 100644 test/utils/factory-http/index.js rename test/utils/{factory-core => ipfs-factory-daemon}/default-config.json (100%) create mode 100644 test/utils/ipfs-factory-daemon/index.js rename test/utils/{factory-http => ipfs-factory-instance}/default-config.json (100%) rename test/utils/{factory-core => ipfs-factory-instance}/index.js (100%) delete mode 100644 test/utils/temp-node.js diff --git a/gulpfile.js b/gulpfile.js index 23d8130c4a..0138ab4be7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,36 +3,70 @@ const gulp = require('gulp') const parallel = require('async/parallel') const series = require('async/series') -const createTempNode = require('./test/utils/temp-node') -const API = require('./src/http-api') +const createTempRepo = require('./test/utils/create-repo-node.js') +const IPFS = require('./src/core') +const HTTPAPI = require('./src/http-api') +const leftPad = require('left-pad') let nodes = [] -function startNode (num, done) { - createTempNode(num, (err, node) => { - if (err) { - return done(err) - } +/* + * spawns a daemon with ports numbers starting in 10 and ending in `num` + */ +function spawnDaemon (num, callback) { + num = leftPad(num, 3, 0) + + const repo = createTempRepo() - const api = new API(node.repo.path()) - nodes.push(api) - api.start(done) + const node = new IPFS({ + repo: repo, + EXPERIMENTAL: { + pubsub: true + } }) + + series([ + (cb) => node.init({ emptyRepo: true, bits: 1024 }, cb), + (cb) => { + repo.config.get((err, config) => { + if (err) { return callback(err) } + + config.Addresses = { + Swarm: [ + `/ip4/127.0.0.1/tcp/10${num}`, + `/ip4/127.0.0.1/tcp/20${num}/ws` + ], + API: `/ip4/127.0.0.1/tcp/31${num}`, + Gateway: `/ip4/127.0.0.1/tcp/32${num}` + } + + config.Discovery.MDNS.Enabled = false + + repo.config.set(config, cb) + }) + }, + (cb) => node.load(cb), + (cb) => { + const daemon = new HTTPAPI(node.repo.path()) + nodes.push(daemon) + daemon.start(cb) + } + ], callback) } gulp.task('libnode:start', (done) => { nodes = [] parallel([ - (cb) => startNode(7, cb), - (cb) => startNode(8, cb), - (cb) => startNode(12, cb), - (cb) => startNode(13, cb) + (cb) => spawnDaemon(7, cb), + (cb) => spawnDaemon(8, cb), + (cb) => spawnDaemon(12, cb), + (cb) => spawnDaemon(13, cb) ], done) }) gulp.task('libnode:stop', (done) => { series(nodes.map((node) => (cb) => { - setTimeout(() => node.stop(cb), 500) + setTimeout(() => node.stop(cb), 200) }), done) }) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index fb7d8c2614..e2a7d6aa67 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -14,7 +14,9 @@ module.exports = { handler () { console.log('Initializing daemon...') + httpAPI = new HttpAPI(process.env.IPFS_PATH) + httpAPI.start((err) => { if (err && err.code === 'ENOENT') { console.log('Error: no ipfs repo found in ' + process.env.IPFS_PATH) diff --git a/src/http-api/index.js b/src/http-api/index.js index 4530d64873..21c6e1ed8b 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -16,6 +16,11 @@ log.error = debug('api:error') const IPFS = require('../core') const errorHandler = require('./error-handler') +function uriToMultiaddr (uri) { + const ipPort = uri.split('/')[2].split(':') + return `/ip4/${ipPort[0]}/tcp/${ipPort[1]}` +} + exports = module.exports = function HttpApi (repo) { this.ipfs = null this.server = null @@ -49,9 +54,7 @@ exports = module.exports = function HttpApi (repo) { fs.statSync(apiPath) console.log('This repo is currently being used by another daemon') process.exit(1) - } catch (err) { - fs.writeFileSync(apiPath, 'api is on by js-ipfs', {flag: 'w+'}) - } + } catch (err) {} this.ipfs.config.get((err, config) => { if (err) { @@ -71,9 +74,6 @@ exports = module.exports = function HttpApi (repo) { const api = config.Addresses.API.split('/') const gateway = config.Addresses.Gateway.split('/') - // for the CLI to know the where abouts of the API - fs.writeFileSync(apiPath, config.Addresses.API) - // select which connection with server.select(