diff --git a/.travis.yml b/.travis.yml index 55a73ae20b..76c6d8ccc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ stages: node_js: - 'lts/*' - # cannot support node 14 until hapi > 19.1.1 is released + # blocked by https://github.com/hapijs/hapi/issues/4149 # - 'node' os: @@ -132,7 +132,7 @@ jobs: name: examples script: - npx json -I -f ./lerna.json -e "this.packages.push('examples/*')" - - npx json -I -f ./lerna.json -e "this.command.bootstrap.nohoist.push('ipfs-css', 'tachyons')" + - npx json -I -f ./lerna.json -e "this.command.bootstrap.nohoist = ['ipfs-css', 'tachyons']" - npm run reset - npm install - npm run build -- --scope={ipfs,ipfs-http-client} diff --git a/examples/browser-add-readable-stream/package.json b/examples/browser-add-readable-stream/package.json index e2451f6950..5120083114 100644 --- a/examples/browser-add-readable-stream/package.json +++ b/examples/browser-add-readable-stream/package.json @@ -12,7 +12,7 @@ "keywords": [], "license": "MIT", "devDependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "test-ipfs-example": "^2.0.3" } } diff --git a/examples/browser-browserify/package.json b/examples/browser-browserify/package.json index ffccc57144..f886f49d3c 100644 --- a/examples/browser-browserify/package.json +++ b/examples/browser-browserify/package.json @@ -18,7 +18,7 @@ "concat-stream": "^2.0.0", "execa": "^4.0.0", "http-server": "^0.11.1", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "test-ipfs-example": "^2.0.3" }, "browser": { diff --git a/examples/browser-create-react-app/package.json b/examples/browser-create-react-app/package.json index d7018e9dab..8e7475819f 100644 --- a/examples/browser-create-react-app/package.json +++ b/examples/browser-create-react-app/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "dot-prop": "^5.0.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfs-css": "^0.13.1", "react": "^16.8.6", "react-dom": "^16.8.6", diff --git a/examples/browser-exchange-files/package.json b/examples/browser-exchange-files/package.json index a6f4ac6ea7..506ea0323c 100644 --- a/examples/browser-exchange-files/package.json +++ b/examples/browser-exchange-files/package.json @@ -14,11 +14,11 @@ "browserify": "^16.2.3", "execa": "^4.0.0", "http-server": "^0.11.1", - "ipfs-http-client": "^46.0.0", + "ipfs-http-client": "^46.0.1", "uint8arrays": "^1.1.0" }, "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "it-all": "^1.0.1", "test-ipfs-example": "^2.0.3" }, diff --git a/examples/browser-http-client-upload-file/package.json b/examples/browser-http-client-upload-file/package.json index 02f79500de..34e2c4b0a7 100644 --- a/examples/browser-http-client-upload-file/package.json +++ b/examples/browser-http-client-upload-file/package.json @@ -14,10 +14,10 @@ ], "license": "MIT", "dependencies": { - "ipfs-http-client": "^46.0.0" + "ipfs-http-client": "^46.0.1" }, "devDependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "parcel-bundler": "^1.12.4", "react": "^16.8.6", "react-dom": "^16.8.6", diff --git a/examples/browser-mfs/package.json b/examples/browser-mfs/package.json index a57456a742..2435bf829b 100644 --- a/examples/browser-mfs/package.json +++ b/examples/browser-mfs/package.json @@ -21,7 +21,7 @@ "webpack-cli": "^3.3.11" }, "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "mime-sniffer": "~0.0.3" } } diff --git a/examples/browser-parceljs/package.json b/examples/browser-parceljs/package.json index 1df28b1e36..730b6a13a0 100644 --- a/examples/browser-parceljs/package.json +++ b/examples/browser-parceljs/package.json @@ -18,7 +18,7 @@ "author": "", "license": "ISC", "dependencies": { - "ipfs": "^0.49.0" + "ipfs": "^0.49.1" }, "devDependencies": { "@babel/cli": "^7.1.5", diff --git a/examples/browser-readablestream/package.json b/examples/browser-readablestream/package.json index d353959fe3..6568cc4f23 100644 --- a/examples/browser-readablestream/package.json +++ b/examples/browser-readablestream/package.json @@ -20,7 +20,7 @@ "webpack": "^4.43.0" }, "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "it-to-stream": "^0.1.1", "videostream": "^3.2.0" } diff --git a/examples/browser-script-tag/package.json b/examples/browser-script-tag/package.json index c80410e87b..28b65626c5 100644 --- a/examples/browser-script-tag/package.json +++ b/examples/browser-script-tag/package.json @@ -16,6 +16,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.49.0" + "ipfs": "^0.49.1" } } diff --git a/examples/browser-sharing-node-across-tabs/package.json b/examples/browser-sharing-node-across-tabs/package.json index 666197ffff..b8a8a6fc86 100644 --- a/examples/browser-sharing-node-across-tabs/package.json +++ b/examples/browser-sharing-node-across-tabs/package.json @@ -23,7 +23,7 @@ "worker-plugin": "4.0.3" }, "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfs-message-port-client": "^0.1.0", "ipfs-message-port-server": "^0.1.0" }, diff --git a/examples/browser-video-streaming/package.json b/examples/browser-video-streaming/package.json index 1831a60372..dd9e675d15 100644 --- a/examples/browser-video-streaming/package.json +++ b/examples/browser-video-streaming/package.json @@ -16,6 +16,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.49.0" + "ipfs": "^0.49.1" } } diff --git a/examples/browser-vue/package.json b/examples/browser-vue/package.json index e08545bbde..ee68792927 100644 --- a/examples/browser-vue/package.json +++ b/examples/browser-vue/package.json @@ -11,7 +11,7 @@ }, "dependencies": { "core-js": "^3.6.4", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "vue": "^2.6.11" }, "devDependencies": { diff --git a/examples/browser-webpack/package.json b/examples/browser-webpack/package.json index 5bf336dcb7..41bad083b4 100644 --- a/examples/browser-webpack/package.json +++ b/examples/browser-webpack/package.json @@ -26,7 +26,7 @@ "webpack-dev-server": "^3.11.0" }, "dependencies": { - "ipfs": "^0.49.0" + "ipfs": "^0.49.1" }, "browserslist": [ ">1%", diff --git a/examples/circuit-relaying/package.json b/examples/circuit-relaying/package.json index 79d4780f99..45ec0e9c9b 100644 --- a/examples/circuit-relaying/package.json +++ b/examples/circuit-relaying/package.json @@ -15,14 +15,14 @@ "license": "MIT", "dependencies": { "delay": "^4.3.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfs-pubsub-room": "^2.0.1", "uint8arrays": "^1.1.0" }, "devDependencies": { "execa": "^4.0.0", "ipfs-css": "^0.13.1", - "ipfs-http-client": "^46.0.0", + "ipfs-http-client": "^46.0.1", "parcel-bundler": "^1.12.4", "tachyons": "^4.11.1", "test-ipfs-example": "^2.0.3" diff --git a/examples/custom-ipfs-repo/package.json b/examples/custom-ipfs-repo/package.json index 645b9e3d6b..6a67e06f06 100644 --- a/examples/custom-ipfs-repo/package.json +++ b/examples/custom-ipfs-repo/package.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "datastore-fs": "^2.0.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfs-repo": "^6.0.3", "it-all": "^1.0.1" }, diff --git a/examples/custom-libp2p/package.json b/examples/custom-libp2p/package.json index 85a3a4f7c5..168839ee78 100644 --- a/examples/custom-libp2p/package.json +++ b/examples/custom-libp2p/package.json @@ -10,7 +10,7 @@ }, "license": "MIT", "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "libp2p": "libp2p/js-libp2p#0.29.x", "libp2p-bootstrap": "^0.12.0", "libp2p-kad-dht": "^0.20.0", diff --git a/examples/explore-ethereum-blockchain/package.json b/examples/explore-ethereum-blockchain/package.json index f199c02d4e..2fb29d232d 100644 --- a/examples/explore-ethereum-blockchain/package.json +++ b/examples/explore-ethereum-blockchain/package.json @@ -10,8 +10,8 @@ "keywords": [], "license": "MIT", "devDependencies": { - "ipfs": "^0.49.0", - "ipfs-http-client": "^46.0.0", + "ipfs": "^0.49.1", + "ipfs-http-client": "^46.0.1", "ipfsd-ctl": "^7.0.0", "test-ipfs-example": "^2.0.3" } diff --git a/examples/http-client-browser-pubsub/package.json b/examples/http-client-browser-pubsub/package.json index c7e31e96d3..12d0d05e5a 100644 --- a/examples/http-client-browser-pubsub/package.json +++ b/examples/http-client-browser-pubsub/package.json @@ -12,7 +12,7 @@ "author": "Alan Shaw", "license": "MIT", "dependencies": { - "ipfs-http-client": "^46.0.0" + "ipfs-http-client": "^46.0.1" }, "browserslist": [ "last 2 versions and not dead and > 2%" @@ -20,7 +20,7 @@ "devDependencies": { "execa": "^4.0.0", "go-ipfs": "^0.6.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfsd-ctl": "^7.0.0", "parcel-bundler": "^1.12.4", "test-ipfs-example": "^2.0.3" diff --git a/examples/http-client-bundle-webpack/package.json b/examples/http-client-bundle-webpack/package.json index 8ad0b68cdf..acf0d1e2bd 100644 --- a/examples/http-client-bundle-webpack/package.json +++ b/examples/http-client-bundle-webpack/package.json @@ -12,7 +12,7 @@ "license": "MIT", "keywords": [], "dependencies": { - "ipfs-http-client": "^46.0.0", + "ipfs-http-client": "^46.0.1", "react": "^16.8.6", "react-dom": "^16.8.6" }, @@ -23,7 +23,7 @@ "babel-loader": "^8.0.5", "copy-webpack-plugin": "^5.0.4", "execa": "^4.0.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipfsd-ctl": "^7.0.0", "react-hot-loader": "^4.12.21", "test-ipfs-example": "^2.0.3", diff --git a/examples/http-client-name-api/package.json b/examples/http-client-name-api/package.json index 76200a5491..c0baf96d46 100644 --- a/examples/http-client-name-api/package.json +++ b/examples/http-client-name-api/package.json @@ -12,7 +12,7 @@ "author": "Tara Vancil ", "license": "MIT", "dependencies": { - "ipfs-http-client": "^46.0.0" + "ipfs-http-client": "^46.0.1" }, "devDependencies": { "execa": "^4.0.0", diff --git a/examples/ipfs-101/package.json b/examples/ipfs-101/package.json index 34612e0262..87f7ce7a56 100644 --- a/examples/ipfs-101/package.json +++ b/examples/ipfs-101/package.json @@ -10,7 +10,7 @@ "author": "David Dias ", "license": "MIT", "dependencies": { - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "it-all": "^1.0.1", "uint8arrays": "^1.1.0" }, diff --git a/examples/run-in-electron/package.json b/examples/run-in-electron/package.json index d0ec883534..dc6450fcee 100644 --- a/examples/run-in-electron/package.json +++ b/examples/run-in-electron/package.json @@ -18,7 +18,7 @@ "devDependencies": { "electron": "^6.0.0", "electron-rebuild": "^1.8.4", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "test-ipfs-example": "^2.0.3" }, "greenkeeper": { diff --git a/examples/running-multiple-nodes/package.json b/examples/running-multiple-nodes/package.json index 687bd7c221..91bd4b5a08 100644 --- a/examples/running-multiple-nodes/package.json +++ b/examples/running-multiple-nodes/package.json @@ -13,6 +13,6 @@ "test-ipfs-example": "^2.0.3" }, "dependencies": { - "ipfs": "^0.49.0" + "ipfs": "^0.49.1" } } diff --git a/examples/test-ipfs-example/package.json b/examples/test-ipfs-example/package.json index db84f66784..1f5e6491c5 100644 --- a/examples/test-ipfs-example/package.json +++ b/examples/test-ipfs-example/package.json @@ -7,10 +7,10 @@ }, "license": "MIT", "dependencies": { - "chromedriver": "^83.0.0", + "chromedriver": "^84.0.1", "execa": "^4.0.0", - "fs-extra": "^8.1.0", - "http-server": "^0.11.1", + "fs-extra": "^9.0.1", + "http-server": "^0.12.3", "nightwatch": "^1.2.4", "which": "^2.0.1", "uint8arrays": "^1.1.0" diff --git a/examples/test-ipfs-example/utils.js b/examples/test-ipfs-example/utils.js index a4f32a00f1..5835daaf5d 100644 --- a/examples/test-ipfs-example/utils.js +++ b/examples/test-ipfs-example/utils.js @@ -10,25 +10,18 @@ async function startServer (dir) { async function serveFrom (appDir) { return new Promise((resolve, reject) => { let output = '' + const port = ephemeralPort() - const proc = execa.command(`${path.resolve(__dirname, 'node_modules/.bin/http-server')} ${appDir} -a 127.0.0.1`, { + const proc = execa.command(`${path.resolve(__dirname, 'node_modules/.bin/http-server')} ${appDir} -a 127.0.0.1 -p ${port}`, { cwd: __dirname, all: true }) proc.all.on('data', (data) => { process.stdout.write(data) - const line = uint8ArrayToString(data) - output += line + output += uint8ArrayToString(data) if (output.includes('Hit CTRL-C to stop the server')) { - // find the port - const port = output.match(/http:\/\/127.0.0.1:(\d+)/)[1] - - if (!port) { - throw new Error(`Could not find port in ${output}`) - } - resolve({ stop: () => { console.info('Stopping server') diff --git a/examples/traverse-ipld-graphs/package.json b/examples/traverse-ipld-graphs/package.json index 9e25877cb3..6be1110c76 100644 --- a/examples/traverse-ipld-graphs/package.json +++ b/examples/traverse-ipld-graphs/package.json @@ -14,7 +14,7 @@ }, "dependencies": { "cids": "^1.0.0", - "ipfs": "^0.49.0", + "ipfs": "^0.49.1", "ipld-block": "^0.10.0", "ipld-dag-pb": "^0.20.0", "multihashing-async": "^2.0.1" diff --git a/lerna.json b/lerna.json index 60756e2343..eaac4e1e8d 100644 --- a/lerna.json +++ b/lerna.json @@ -6,11 +6,7 @@ "version": "independent", "command": { "bootstrap": { - "hoist": true, - "nohoist": [ - "libp2p-delegated-content-routing", - "libp2p-delegated-peer-routing" - ] + "hoist": true }, "run": { "stream": true diff --git a/packages/interface-ipfs-core/src/files/chmod.js b/packages/interface-ipfs-core/src/files/chmod.js index 0705d41731..a3a1e9d811 100644 --- a/packages/interface-ipfs-core/src/files/chmod.js +++ b/packages/interface-ipfs-core/src/files/chmod.js @@ -12,7 +12,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.chmod', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/cp.js b/packages/interface-ipfs-core/src/files/cp.js index 347006b52e..044f8915cb 100644 --- a/packages/interface-ipfs-core/src/files/cp.js +++ b/packages/interface-ipfs-core/src/files/cp.js @@ -25,7 +25,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.cp', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/flush.js b/packages/interface-ipfs-core/src/files/flush.js index 1487aaee2a..b8dd57cb77 100644 --- a/packages/interface-ipfs-core/src/files/flush.js +++ b/packages/interface-ipfs-core/src/files/flush.js @@ -15,7 +15,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.flush', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/ls.js b/packages/interface-ipfs-core/src/files/ls.js index 031075f2af..1f91310855 100644 --- a/packages/interface-ipfs-core/src/files/ls.js +++ b/packages/interface-ipfs-core/src/files/ls.js @@ -27,7 +27,7 @@ module.exports = (common, options) => { const largeFile = randomBytes(490668) describe('.files.ls', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/mkdir.js b/packages/interface-ipfs-core/src/files/mkdir.js index 92f4318025..0453142e05 100644 --- a/packages/interface-ipfs-core/src/files/mkdir.js +++ b/packages/interface-ipfs-core/src/files/mkdir.js @@ -19,7 +19,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.mkdir', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/mv.js b/packages/interface-ipfs-core/src/files/mv.js index eb4d13735a..0142e9bcf1 100644 --- a/packages/interface-ipfs-core/src/files/mv.js +++ b/packages/interface-ipfs-core/src/files/mv.js @@ -20,7 +20,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.mv', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/read.js b/packages/interface-ipfs-core/src/files/read.js index 038d89351a..ed4bb93264 100644 --- a/packages/interface-ipfs-core/src/files/read.js +++ b/packages/interface-ipfs-core/src/files/read.js @@ -21,7 +21,7 @@ module.exports = (common, options) => { const smallFile = randomBytes(13) describe('.files.read', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/rm.js b/packages/interface-ipfs-core/src/files/rm.js index 6f149485e5..557eb7b6cb 100644 --- a/packages/interface-ipfs-core/src/files/rm.js +++ b/packages/interface-ipfs-core/src/files/rm.js @@ -19,7 +19,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.rm', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs @@ -171,8 +171,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when removing a file', async function () { - this.timeout(60000) - const { nextFile, dirWithAllFiles, @@ -193,8 +191,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when removing a subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithAllFiles, @@ -215,8 +211,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when removing a file from a subshard of a subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithAllFiles, @@ -237,8 +231,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when removing a subshard of a subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithAllFiles, diff --git a/packages/interface-ipfs-core/src/files/stat.js b/packages/interface-ipfs-core/src/files/stat.js index 46e4b0e6ae..629963d8a6 100644 --- a/packages/interface-ipfs-core/src/files/stat.js +++ b/packages/interface-ipfs-core/src/files/stat.js @@ -25,7 +25,7 @@ module.exports = (common, options) => { const largeFile = randomBytes(490668) describe('.files.stat', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/touch.js b/packages/interface-ipfs-core/src/files/touch.js index 062d7ad1e0..1149be459c 100644 --- a/packages/interface-ipfs-core/src/files/touch.js +++ b/packages/interface-ipfs-core/src/files/touch.js @@ -14,7 +14,7 @@ module.exports = (common, options) => { const it = getIt(options) describe('.files.touch', function () { - this.timeout(10 * 1000) + this.timeout(120 * 1000) let ipfs diff --git a/packages/interface-ipfs-core/src/files/write.js b/packages/interface-ipfs-core/src/files/write.js index c30f152355..0340b97188 100644 --- a/packages/interface-ipfs-core/src/files/write.js +++ b/packages/interface-ipfs-core/src/files/write.js @@ -58,7 +58,7 @@ module.exports = (common, options) => { } describe('.files.write', function () { - this.timeout(40 * 1000) + this.timeout(120 * 1000) let ipfs @@ -734,8 +734,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when adding a new file', async function () { - this.timeout(60000) - const { nextFile, dirWithSomeFiles, @@ -757,8 +755,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when creating a new subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithSomeFiles, @@ -778,8 +774,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when adding a file to a subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithSomeFiles, @@ -801,8 +795,6 @@ module.exports = (common, options) => { }) it('results in the same hash as a sharded directory created by the importer when adding a file to a subshard of a subshard', async function () { - this.timeout(60000) - const { nextFile, dirWithSomeFiles, diff --git a/packages/interface-ipfs-core/src/utils/create-sharded-directory.js b/packages/interface-ipfs-core/src/utils/create-sharded-directory.js index 6009a0e3a9..3d85daf630 100644 --- a/packages/interface-ipfs-core/src/utils/create-sharded-directory.js +++ b/packages/interface-ipfs-core/src/utils/create-sharded-directory.js @@ -7,14 +7,17 @@ const last = require('it-last') module.exports = async (ipfs, files = 1001) => { const dirPath = `/sharded-dir-${Math.random()}` - const result = await last(ipfs.addAll(function * () { + const result = await last(ipfs.addAll((function * () { for (let i = 0; i < files; i++) { yield { path: `${dirPath}/file-${i}`, content: Uint8Array.from([0, 1, 2, 3, 4, 5, i]) } } - }())) + }()), { + preload: false, + pin: false + })) await ipfs.files.cp(`/ipfs/${result.cid}`, dirPath) diff --git a/packages/interface-ipfs-core/src/utils/create-two-shards.js b/packages/interface-ipfs-core/src/utils/create-two-shards.js index cbacf2b4da..62bbf95307 100644 --- a/packages/interface-ipfs-core/src/utils/create-two-shards.js +++ b/packages/interface-ipfs-core/src/utils/create-two-shards.js @@ -22,11 +22,15 @@ const createTwoShards = async (ipfs, fileCount) => { const { cid: dirWithAllFiles } = await last(ipfs.addAll(allFiles, { // for js-ipfs - go-ipfs shards everything when sharding is turned on - shardSplitThreshold: files.length - 1 + shardSplitThreshold: files.length - 1, + preload: false, + pin: false })) const { cid: dirWithSomeFiles } = await last(ipfs.addAll(someFiles, { // for js-ipfs - go-ipfs shards everything when sharding is turned on - shardSplitThreshold: files.length - 1 + shardSplitThreshold: files.length - 1, + preload: false, + pin: false })) await expect(isShardAtPath(`/ipfs/${dirWithAllFiles}`, ipfs)).to.eventually.be.true() diff --git a/packages/ipfs-http-client/src/pubsub/subscribe.js b/packages/ipfs-http-client/src/pubsub/subscribe.js index c62fc8c8cf..ab5ee3c2db 100644 --- a/packages/ipfs-http-client/src/pubsub/subscribe.js +++ b/packages/ipfs-http-client/src/pubsub/subscribe.js @@ -9,27 +9,25 @@ const toUrlSearchParams = require('../lib/to-url-search-params') module.exports = configure((api, options) => { const subsTracker = SubscriptionTracker.singleton() - const publish = require('./publish')(options) - return async (topic, handler, options = {}) => { + return async (topic, handler, options = {}) => { // eslint-disable-line require-await options.signal = subsTracker.subscribe(topic, handler, options.signal) - let res + let done + let fail + + const result = new Promise((resolve, reject) => { + done = resolve + fail = reject + }) // In Firefox, the initial call to fetch does not resolve until some data - // is received. If this doesn't happen within 1 second send an empty message - // to kickstart the process. - const ffWorkaround = setTimeout(async () => { - log(`Publishing empty message to "${topic}" to resolve subscription request`) - try { - await publish(topic, new Uint8Array(0), options) - } catch (err) { - log('Failed to publish empty message', err) - } - }, 1000) + // is received. If this doesn't happen within 1 second assume success + const ffWorkaround = setTimeout(() => done(), 1000) - try { - res = await api.post('pubsub/sub', { + // Do this async to not block Firefox + setTimeout(() => { + api.post('pubsub/sub', { timeout: options.timeout, signal: options.signal, searchParams: toUrlSearchParams({ @@ -38,18 +36,31 @@ module.exports = configure((api, options) => { }), headers: options.headers }) - } catch (err) { // Initial subscribe fail, ensure we clean up - subsTracker.unsubscribe(topic, handler) - throw err - } + .catch((err) => { + // Initial subscribe fail, ensure we clean up + subsTracker.unsubscribe(topic, handler) - clearTimeout(ffWorkaround) + fail(err) + }) + .then((response) => { + clearTimeout(ffWorkaround) - readMessages(res.ndjson(), { - onMessage: handler, - onEnd: () => subsTracker.unsubscribe(topic, handler), - onError: options.onError - }) + if (!response) { + // if there was no response, the subscribe failed + return + } + + readMessages(response.ndjson(), { + onMessage: handler, + onEnd: () => subsTracker.unsubscribe(topic, handler), + onError: options.onError + }) + + done() + }) + }, 0) + + return result } }) diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 1f6fd2156d..230233067e 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -40,7 +40,7 @@ "test:node": "aegir test -t node", "test:browser": "aegir test -t browser", "test:browser:http": "aegir test -t browser -f test/http-api/index.js", - "test:webworker": "aegir test -t webworker", + "test:webworker": "aegir test -t webworker -- --timeout 10000", "test:electron": "aegir test -t electron-main -t electron-renderer", "test:electron-main": "aegir test -t electron-main", "test:electron-renderer": "aegir test -t electron-renderer", @@ -93,7 +93,7 @@ "ipfs-bitswap": "^3.0.0", "ipfs-block-service": "^0.18.0", "ipfs-core-utils": "^0.3.1", - "ipfs-http-client": "^46.0.0", + "ipfs-http-client": "^46.0.1", "ipfs-http-response": "^0.6.0", "ipfs-repo": "^6.0.3", "ipfs-unixfs": "^2.0.2", @@ -131,8 +131,8 @@ "libp2p": "^0.29.0-rc.0", "libp2p-bootstrap": "^0.12.0", "libp2p-crypto": "^0.18.0", - "libp2p-delegated-content-routing": "^0.6.0", - "libp2p-delegated-peer-routing": "^0.6.0", + "libp2p-delegated-content-routing": "^0.7.0", + "libp2p-delegated-peer-routing": "^0.7.0", "libp2p-floodsub": "^0.23.0", "libp2p-gossipsub": "^0.6.0", "libp2p-kad-dht": "^0.20.0", diff --git a/packages/ipfs/src/cli/daemon.js b/packages/ipfs/src/cli/daemon.js index 8dc21a7f3a..ea9d868200 100644 --- a/packages/ipfs/src/cli/daemon.js +++ b/packages/ipfs/src/cli/daemon.js @@ -7,6 +7,7 @@ const Multiaddr = require('multiaddr') const WebRTCStar = require('libp2p-webrtc-star') const DelegatedPeerRouter = require('libp2p-delegated-peer-routing') const DelegatedContentRouter = require('libp2p-delegated-content-routing') +const ipfsHttpClient = require('ipfs-http-client') const IPFS = require('../core') const HttpApi = require('../http') const createRepo = require('../core/runtime/repo-nodejs') @@ -90,18 +91,20 @@ function getLibp2p ({ libp2pOptions, options, config, peerId }) { // Pick a random delegate host const delegateString = delegateHosts[Math.floor(Math.random() * delegateHosts.length)] const delegateAddr = Multiaddr(delegateString).toOptions() - const delegatedApiOptions = { + const delegateApiOptions = { host: delegateAddr.host, // port is a string atm, so we need to convert for the check protocol: parseInt(delegateAddr.port) === 443 ? 'https' : 'http', port: delegateAddr.port } + const delegateHttpClient = ipfsHttpClient(delegateApiOptions) + libp2pOptions.modules.contentRouting = libp2pOptions.modules.contentRouting || [] - libp2pOptions.modules.contentRouting.push(new DelegatedContentRouter(peerId, delegatedApiOptions)) + libp2pOptions.modules.contentRouting.push(new DelegatedContentRouter(peerId, delegateHttpClient)) libp2pOptions.modules.peerRouting = libp2pOptions.modules.peerRouting || [] - libp2pOptions.modules.peerRouting.push(new DelegatedPeerRouter(delegatedApiOptions)) + libp2pOptions.modules.peerRouting.push(new DelegatedPeerRouter(delegateHttpClient)) } const Libp2p = require('libp2p') diff --git a/packages/ipfs/src/core/components/init.js b/packages/ipfs/src/core/components/init.js index 70f589143e..c5cd008fbb 100644 --- a/packages/ipfs/src/core/components/init.js +++ b/packages/ipfs/src/core/components/init.js @@ -301,6 +301,7 @@ function applyProfiles (profiles, config) { function createApi ({ add, + addAll, apiManager, constructorOptions, block, @@ -328,6 +329,7 @@ function createApi ({ const api = { add, + addAll, bitswap: { stat: notStarted, unwant: notStarted, diff --git a/packages/ipfs/test/http-api/inject/files.js b/packages/ipfs/test/http-api/inject/files.js index d963ba8410..e87c8e0e13 100644 --- a/packages/ipfs/test/http-api/inject/files.js +++ b/packages/ipfs/test/http-api/inject/files.js @@ -107,6 +107,17 @@ describe('/files', () => { '------------287032381131322--' ].join('\r\n')) + ipfs.addAll.withArgs(matchIterable(), defaultOptions).returns([{ + path: cid.toString(), + cid, + size: 1024 * 1024 * 2, + mode: 0o420, + mtime: { + secs: 100, + nsecs: 0 + } + }]) + const res = await http({ method: 'POST', url: '/api/v0/add',