From 649b755c94456a356786397b4577ec659120ccbc Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Sun, 29 Jul 2018 09:45:05 +0100 Subject: [PATCH] feat: preload on content fetch requests (#1475) When JS IPFS requests content not stored locally it needs to ask the peers it knows about to provide it if they have it. The peers are not relays so if they don't have it, they won't find it and provide it to JS IPFS. However, if we issue a preload request prior to these requests we prompt the preload nodes to fetch the content using their DHT and they can then provide it to JS IPFS. License: MIT Signed-off-by: Alan Shaw * chore: update dependencies (#1473) * chore: update libp2p and is-ipfs dependencies License: MIT Signed-off-by: Alan Shaw * chore: update all the deps * fix: rm non used boostrappers from tests * test: increase mfs preload timeout * test: pin-set timeout increase * test: add preload tests for content retrieval License: MIT Signed-off-by: Alan Shaw * fix: GET request not HEAD License: MIT Signed-off-by: Alan Shaw --- package.json | 24 ++++---- src/core/components/block.js | 25 ++++++++- src/core/components/dag.js | 19 ++++++- src/core/components/files.js | 58 ++++++++++++++++--- src/core/components/mfs.js | 16 ++++++ src/core/components/object.js | 10 +++- src/core/components/pin-set.js | 6 +- src/core/components/pin.js | 2 +- src/core/runtime/preload-browser.js | 2 +- test/cli/bootstrap.js | 4 -- test/core/bootstrap.spec.js | 4 -- test/core/mfs-preload.spec.js | 6 +- test/core/pin-set.js | 4 +- test/core/preload.spec.js | 86 +++++++++++++++++++++++++++++ test/fixtures/go-ipfs-repo/config | 2 - 15 files changed, 223 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index e98cd5a278..36460d3a92 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ }, "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { - "aegir": "^15.0.0", + "aegir": "^15.1.0", "buffer-loader": "~0.0.1", "chai": "^4.1.2", "delay": "^3.0.0", @@ -70,8 +70,8 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.72.0", - "ipfsd-ctl": "~0.37.5", + "interface-ipfs-core": "~0.72.1", + "ipfsd-ctl": "~0.38.0", "mocha": "^5.2.0", "ncp": "^2.0.0", "nexpect": "~0.5.0", @@ -93,7 +93,7 @@ "byteman": "^1.3.5", "cids": "~0.5.3", "debug": "^3.1.0", - "file-type": "^8.0.0", + "file-type": "^8.1.0", "filesize": "^3.6.1", "fnv1a": "^1.0.1", "fsm-event": "^2.1.0", @@ -104,30 +104,30 @@ "hoek": "^5.0.3", "human-to-milliseconds": "^1.0.0", "interface-datastore": "~0.4.2", - "ipfs-api": "^22.2.1", - "ipfs-bitswap": "~0.20.2", + "ipfs-api": "^22.2.4", + "ipfs-bitswap": "~0.20.3", "ipfs-block": "~0.7.1", "ipfs-block-service": "~0.14.0", "ipfs-http-response": "~0.1.2", - "ipfs-mfs": "~0.2.2", + "ipfs-mfs": "~0.2.3", "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.22.1", "ipfs-unixfs": "~0.1.15", "ipfs-unixfs-engine": "~0.31.3", "ipld": "~0.17.3", "ipld-dag-cbor": "~0.12.1", - "ipld-dag-pb": "~0.14.5", - "is-ipfs": "~0.3.2", + "ipld-dag-pb": "~0.14.6", + "is-ipfs": "~0.4.2", "is-pull-stream": "~0.0.0", "is-stream": "^1.1.0", "joi": "^13.4.0", "joi-browser": "^13.4.0", "joi-multiaddr": "^2.0.0", - "libp2p": "~0.22.0", + "libp2p": "~0.23.0", "libp2p-bootstrap": "~0.9.3", "libp2p-circuit": "~0.2.0", "libp2p-floodsub": "~0.15.0", - "libp2p-kad-dht": "~0.10.0", + "libp2p-kad-dht": "~0.10.1", "libp2p-keychain": "~0.3.1", "libp2p-mdns": "~0.12.0", "libp2p-mplex": "~0.8.0", @@ -138,7 +138,7 @@ "libp2p-websockets": "~0.12.0", "lodash": "^4.17.10", "mafmt": "^6.0.0", - "mime-types": "^2.1.18", + "mime-types": "^2.1.19", "mkdirp": "~0.5.1", "multiaddr": "^5.0.0", "multiaddr-to-uri": "^4.0.0", diff --git a/src/core/components/block.js b/src/core/components/block.js index b68140af36..babb0e0752 100644 --- a/src/core/components/block.js +++ b/src/core/components/block.js @@ -9,8 +9,20 @@ const promisify = require('promisify-es6') module.exports = function block (self) { return { - get: promisify((cid, callback) => { + get: promisify((cid, options, callback) => { + if (typeof options === 'function') { + callback = options + options = {} + } + + options = options || {} + cid = cleanCid(cid) + + if (options.preload !== false) { + self._preload(cid) + } + self._blockService.get(cid, callback) }), put: promisify((block, options, callback) => { @@ -65,9 +77,18 @@ module.exports = function block (self) { cid = cleanCid(cid) self._blockService.delete(cid, callback) }), - stat: promisify((cid, callback) => { + stat: promisify((cid, options, callback) => { + if (typeof options === 'function') { + callback = options + options = {} + } + cid = cleanCid(cid) + if (options.preload !== false) { + self._preload(cid) + } + self._blockService.get(cid, (err, block) => { if (err) { return callback(err) diff --git a/src/core/components/dag.js b/src/core/components/dag.js index 3aa67d1e88..e8cecdb7a4 100644 --- a/src/core/components/dag.js +++ b/src/core/components/dag.js @@ -66,6 +66,10 @@ module.exports = function dag (self) { } } + if (options.preload !== false) { + self._preload(cid) + } + self._ipld.get(cid, path, options, callback) }), @@ -100,6 +104,10 @@ module.exports = function dag (self) { } } + if (options.preload !== false) { + self._preload(cid) + } + pull( self._ipld.treeStream(cid, path, options), pull.collect(callback) @@ -107,10 +115,17 @@ module.exports = function dag (self) { }), // TODO - use IPLD selectors once they are implemented - _getRecursive: promisify((multihash, callback) => { + _getRecursive: promisify((multihash, options, callback) => { // gets flat array of all DAGNodes in tree given by multihash - self.dag.get(new CID(multihash), (err, res) => { + if (typeof options === 'function') { + callback = options + options = {} + } + + options = options || {} + + self.dag.get(new CID(multihash), '', options, (err, res) => { if (err) { return callback(err) } mapAsync(res.value.links, (link, cb) => { diff --git a/src/core/components/files.js b/src/core/components/files.js index 12a1fcdce0..8877e19b77 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -182,11 +182,17 @@ module.exports = function files (self) { throw new Error('You must supply an ipfsPath') } + options = options || {} + ipfsPath = normalizePath(ipfsPath) const pathComponents = ipfsPath.split('/') const restPath = normalizePath(pathComponents.slice(1).join('/')) const filterFile = (file) => (restPath && file.path === restPath) || (file.path === ipfsPath) + if (options.preload !== false) { + self._preload(pathComponents[0]) + } + const d = deferred.source() pull( @@ -213,16 +219,21 @@ module.exports = function files (self) { } function _lsPullStreamImmutable (ipfsPath, options) { + options = options || {} + const path = normalizePath(ipfsPath) - const recursive = options && options.recursive - const pathDepth = path.split('/').length + const recursive = options.recursive + const pathComponents = path.split('/') + const pathDepth = pathComponents.length const maxDepth = recursive ? global.Infinity : pathDepth - const opts = Object.assign({}, { - maxDepth: maxDepth - }, options) + options.maxDepth = options.maxDepth || maxDepth + + if (options.preload !== false) { + self._preload(pathComponents[0]) + } return pull( - exporter(ipfsPath, self._ipld, opts), + exporter(ipfsPath, self._ipld, options), pull.filter(node => recursive ? node.depth >= pathDepth : node.depth === pathDepth ), @@ -334,8 +345,11 @@ module.exports = function files (self) { options = {} } - if (typeof callback !== 'function') { - throw new Error('Please supply a callback to ipfs.files.get') + options = options || {} + + if (options.preload !== false) { + const pathComponents = normalizePath(ipfsPath).split('/') + self._preload(pathComponents[0]) } pull( @@ -359,6 +373,13 @@ module.exports = function files (self) { }), getReadableStream: (ipfsPath, options) => { + options = options || {} + + if (options.preload !== false) { + const pathComponents = normalizePath(ipfsPath).split('/') + self._preload(pathComponents[0]) + } + return toStream.source( pull( exporter(ipfsPath, self._ipld, options), @@ -375,6 +396,13 @@ module.exports = function files (self) { }, getPullStream: (ipfsPath, options) => { + options = options || {} + + if (options.preload !== false) { + const pathComponents = normalizePath(ipfsPath).split('/') + self._preload(pathComponents[0]) + } + return exporter(ipfsPath, self._ipld, options) }, @@ -384,6 +412,13 @@ module.exports = function files (self) { options = {} } + options = options || {} + + if (options.preload !== false) { + const pathComponents = normalizePath(ipfsPath).split('/') + self._preload(pathComponents[0]) + } + pull( _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { @@ -397,6 +432,13 @@ module.exports = function files (self) { }), lsReadableStreamImmutable: (ipfsPath, options) => { + options = options || {} + + if (options.preload !== false) { + const pathComponents = normalizePath(ipfsPath).split('/') + self._preload(pathComponents[0]) + } + return toStream.source(_lsPullStreamImmutable(ipfsPath, options)) }, diff --git a/src/core/components/mfs.js b/src/core/components/mfs.js index 9f033545b4..2fd44d2979 100644 --- a/src/core/components/mfs.js +++ b/src/core/components/mfs.js @@ -7,7 +7,23 @@ module.exports = self => { const mfsSelf = Object.assign({}, self) // A patched dag API to ensure preload doesn't happen for MFS operations + // (MFS is preloaded periodically) mfsSelf.dag = Object.assign({}, self.dag, { + get: promisify((cid, path, opts, cb) => { + if (typeof path === 'function') { + cb = path + path = undefined + } + + if (typeof opts === 'function') { + cb = opts + opts = {} + } + + opts = Object.assign({}, opts, { preload: false }) + + return self.dag.get(cid, path, opts, cb) + }), put: promisify((node, opts, cb) => { if (typeof opts === 'function') { cb = opts diff --git a/src/core/components/object.js b/src/core/components/object.js index e7ca331056..3b6012ed35 100644 --- a/src/core/components/object.js +++ b/src/core/components/object.js @@ -1,6 +1,7 @@ 'use strict' const waterfall = require('async/waterfall') +const setImmediate = require('async/setImmediate') const promisify = require('promisify-es6') const dagPB = require('ipld-dag-pb') const DAGNode = dagPB.DAGNode @@ -8,7 +9,6 @@ const DAGLink = dagPB.DAGLink const CID = require('cids') const mh = require('multihashes') const Unixfs = require('ipfs-unixfs') -const assert = require('assert') function normalizeMultihash (multihash, enc) { if (typeof multihash === 'string') { @@ -116,7 +116,9 @@ module.exports = function object (self) { let data if (template) { - assert(template === 'unixfs-dir', 'unkown template') + if (template !== 'unixfs-dir') { + return setImmediate(() => callback(new Error('unknown template'))) + } data = (new Unixfs('directory')).marshal() } else { data = Buffer.alloc(0) @@ -221,6 +223,10 @@ module.exports = function object (self) { cid = cid.toV1() } + if (options.preload !== false) { + self._preload(cid) + } + self._ipld.get(cid, (err, result) => { if (err) { return callback(err) diff --git a/src/core/components/pin-set.js b/src/core/components/pin-set.js index 806df5f05f..1c816d993c 100644 --- a/src/core/components/pin-set.js +++ b/src/core/components/pin-set.js @@ -74,7 +74,7 @@ exports = module.exports = function (dag) { seen[bs58Link] = true - dag.get(multihash, (err, res) => { + dag.get(multihash, '', { preload: false }, (err, res) => { if (err) { return someCb(err) } searchChildren(res.value, someCb) }) @@ -184,7 +184,7 @@ exports = module.exports = function (dag) { return callback(new Error('No link found with name ' + name)) } - dag.get(link.multihash, (err, res) => { + dag.get(link.multihash, '', { preload: false }, (err, res) => { if (err) { return callback(err) } const keys = [] const step = link => keys.push(link.multihash) @@ -211,7 +211,7 @@ exports = module.exports = function (dag) { if (!emptyKey.equals(linkHash)) { // walk the links of this fanout bin - return dag.get(linkHash, (err, res) => { + return dag.get(linkHash, '', { preload: false }, (err, res) => { if (err) { return eachCb(err) } pinSet.walkItems(res.value, step, eachCb) }) diff --git a/src/core/components/pin.js b/src/core/components/pin.js index ce0cd72d84..d1d7456fb6 100644 --- a/src/core/components/pin.js +++ b/src/core/components/pin.js @@ -360,7 +360,7 @@ module.exports = (self) => { (_, cb) => repo.datastore.has(pinDataStoreKey, cb), (has, cb) => has ? cb() : cb(new Error('No pins to load')), (cb) => repo.datastore.get(pinDataStoreKey, cb), - (mh, cb) => dag.get(new CID(mh), cb) + (mh, cb) => dag.get(new CID(mh), '', { preload: false }, cb) ], (err, pinRoot) => { if (err) { if (err.message === 'No pins to load') { diff --git a/src/core/runtime/preload-browser.js b/src/core/runtime/preload-browser.js index 8d123a12be..583b0a2128 100644 --- a/src/core/runtime/preload-browser.js +++ b/src/core/runtime/preload-browser.js @@ -11,7 +11,7 @@ module.exports = function preload (url, callback) { const req = new self.XMLHttpRequest() - req.open('HEAD', url) + req.open('GET', url) req.onreadystatechange = function () { if (this.readyState !== this.DONE) { diff --git a/test/cli/bootstrap.js b/test/cli/bootstrap.js index a301bca3f2..f71fee2d84 100644 --- a/test/cli/bootstrap.js +++ b/test/cli/bootstrap.js @@ -30,8 +30,6 @@ describe('bootstrap', () => runOnAndOff((thing) => { '/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx', - '/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', - '/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6' ] @@ -54,8 +52,6 @@ describe('bootstrap', () => runOnAndOff((thing) => { '/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx', - '/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', - '/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/ip4/111.111.111.111/tcp/1001/ipfs/QmcyFFKfLDGJKwufn2GeitxvhricsBQyNKTkrD14psikoD' diff --git a/test/core/bootstrap.spec.js b/test/core/bootstrap.spec.js index d95d622f18..72cae70840 100644 --- a/test/core/bootstrap.spec.js +++ b/test/core/bootstrap.spec.js @@ -58,8 +58,6 @@ describe('bootstrap', () => { '/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx', - '/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', - '/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6' ] @@ -82,8 +80,6 @@ describe('bootstrap', () => { '/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', '/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3', '/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx', - '/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', - '/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic', '/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6', '/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb' diff --git a/test/core/mfs-preload.spec.js b/test/core/mfs-preload.spec.js index 98d1fb70ed..d35bffd628 100644 --- a/test/core/mfs-preload.spec.js +++ b/test/core/mfs-preload.spec.js @@ -23,7 +23,9 @@ const createMockPreload = () => { } describe('MFS preload', () => { - it('should preload MFS root periodically', (done) => { + it('should preload MFS root periodically', function (done) { + this.timeout(80 * 1000) + // CIDs returned from our mock files.stat function const statCids = ['QmInitial', 'QmSame', 'QmSame', 'QmUpdated'] // The CIDs we expect to have been preloaded @@ -48,7 +50,7 @@ describe('MFS preload', () => { ).to.deep.equal(expectedPreloadCids) done() }) - }, statCids.length * (interval + 5)) + }, statCids.length * (interval * 2)) }) }) }) diff --git a/test/core/pin-set.js b/test/core/pin-set.js index 78f30b9c65..33b50ad144 100644 --- a/test/core/pin-set.js +++ b/test/core/pin-set.js @@ -53,7 +53,7 @@ describe('pinSet', function () { let repo before(function (done) { - this.timeout(20 * 1000) + this.timeout(80 * 1000) repo = createTempRepo() ipfs = new IPFS({ repo }) ipfs.on('ready', () => { @@ -63,7 +63,7 @@ describe('pinSet', function () { }) after(function (done) { - this.timeout(20 * 1000) + this.timeout(80 * 1000) ipfs.stop(done) }) diff --git a/test/core/preload.spec.js b/test/core/preload.spec.js index 38db0f3412..dc8527c552 100644 --- a/test/core/preload.spec.js +++ b/test/core/preload.spec.js @@ -97,6 +97,49 @@ describe('preload', () => { }) }) + it('should preload content retrieved with files.cat', (done) => { + ipfs.files.add(Buffer.from(hat()), { preload: false }, (err, res) => { + expect(err).to.not.exist() + ipfs.files.cat(res[0].hash, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(res[0].hash, done) + }) + }) + }) + + it('should preload content retrieved with files.get', (done) => { + ipfs.files.add(Buffer.from(hat()), { preload: false }, (err, res) => { + expect(err).to.not.exist() + ipfs.files.get(res[0].hash, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(res[0].hash, done) + }) + }) + }) + + it('should preload content retrieved with ls', (done) => { + ipfs.files.add([{ + path: 'dir0/dir1/file0', + content: Buffer.from(hat()) + }, { + path: 'dir0/dir1/file1', + content: Buffer.from(hat()) + }, { + path: 'dir0/file2', + content: Buffer.from(hat()) + }], { wrapWithDirectory: true }, (err, res) => { + expect(err).to.not.exist() + + const wrappingDir = res.find(file => file.path === '') + expect(wrappingDir).to.exist() + + ipfs.ls(wrappingDir.hash, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(wrappingDir.hash, done) + }) + }) + }) + it('should preload content added with object.new', (done) => { ipfs.object.new((err, node) => { expect(err).to.not.exist() @@ -186,6 +229,17 @@ describe('preload', () => { }) }) + it('should preload content retrieved with object.get', (done) => { + ipfs.object.new(null, { preload: false }, (err, node) => { + expect(err).to.not.exist() + ipfs.object.get(node.multihash, (err) => { + expect(err).to.not.exist() + const cid = new CID(node.multihash) + MockPreloadNode.waitForCids(cid.toBaseEncodedString(), done) + }) + }) + }) + it('should preload content added with block.put', (done) => { ipfs.block.put(Buffer.from(hat()), (err, block) => { expect(err).to.not.exist() @@ -193,6 +247,26 @@ describe('preload', () => { }) }) + it('should preload content retrieved with block.get', (done) => { + ipfs.block.put(Buffer.from(hat()), { preload: false }, (err, block) => { + expect(err).to.not.exist() + ipfs.block.get(block.cid, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(block.cid.toBaseEncodedString(), done) + }) + }) + }) + + it('should preload content retrieved with block.stat', (done) => { + ipfs.block.put(Buffer.from(hat()), { preload: false }, (err, block) => { + expect(err).to.not.exist() + ipfs.block.stat(block.cid, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(block.cid.toBaseEncodedString(), done) + }) + }) + }) + it('should preload content added with dag.put', (done) => { const obj = { test: hat() } ipfs.dag.put(obj, { format: 'dag-cbor', hashAlg: 'sha2-256' }, (err, cid) => { @@ -200,4 +274,16 @@ describe('preload', () => { MockPreloadNode.waitForCids(cid.toBaseEncodedString(), done) }) }) + + it('should preload content retrieved with dag.get', (done) => { + const obj = { test: hat() } + const opts = { format: 'dag-cbor', hashAlg: 'sha2-256', preload: false } + ipfs.dag.put(obj, opts, (err, cid) => { + expect(err).to.not.exist() + ipfs.dag.get(cid, (err) => { + expect(err).to.not.exist() + MockPreloadNode.waitForCids(cid.toBaseEncodedString(), done) + }) + }) + }) }) diff --git a/test/fixtures/go-ipfs-repo/config b/test/fixtures/go-ipfs-repo/config index 9843d866a8..162598cdfc 100644 --- a/test/fixtures/go-ipfs-repo/config +++ b/test/fixtures/go-ipfs-repo/config @@ -64,8 +64,6 @@ "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", "/ip6/2a03:b0c0:1:d0::e7:1/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", "/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx", - "/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic", - "/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6", "/dns4/node0.preload.ipfs.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic", "/dns4/node1.preload.ipfs.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6" ],