From 74c5707872421fc00b09acdb4039fbfd671849f4 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Mon, 22 Oct 2018 19:36:51 +0200 Subject: [PATCH] feat: pass on IPLD options It is now possible to pass in options for IPLD. This makes it possible to pass in the formats that IPFS should support. With version 0.19.0 of js-ipld the default formats are *only* [dag-cbor] and [dag-pb]. BREAKING CHANGE: js-ipfs supports dag-cbor and dag-pb by default only If you use js-ipfs as a library, only [dag-cbor] and [dag-pb] are bundled by default. If you want to use additional formats, you need to pass them into the constructor. This example code shows how to get the same behaviour as before: ```js const ipldBitcoin = require('ipld-bitcoin') const ipldDagCbor = require('ipld-dag-cbor') const ipldDagPb = require('ipld-dag-pb') const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot const ipldEthBlock = require('ipld-ethereum').ethBlock const ipldEthBlockList = require('ipld-ethereum').ethBlockList const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie const ipldEthTrie = require('ipld-ethereum').ethTxTrie const ipldEthTx = require('ipld-ethereum').ethTx const ipldGit = require('ipld-git') const ipldRaw = require('ipld-raw') const ipldZcash = require('ipld-zcash') const node = new IPFS({ ipld: { formats: [ ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot, ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie, ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash ] } }) ``` There is no change on the js-ipfs command line tool, it still supports all those formats. [dag-cbor]: https://github.com/ipld/js-ipld-dag-cbor [dag-pb]: https://github.com/ipld/js-ipld-dag-pp --- README.md | 8 +++++++ .../get-path-accross-formats.js | 2 +- package.json | 9 ++++++-- src/cli/utils.js | 22 +++++++++++++++++++ src/core/index.js | 13 ++++++++++- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ccdc231082..a7c14721d3 100644 --- a/README.md +++ b/README.md @@ -295,6 +295,14 @@ Configure remote preload nodes. The remote will preload content added on this no - `enabled` (boolean): Enable content preloading (Default: `true`) - `addresses` (array): Multiaddr API addresses of nodes that should preload content. **NOTE:** nodes specified here should also be added to your node's bootstrap address list at [`config.Boostrap`](#optionsconfig). +##### `options.ipld` + +| Type | Default | +|------|---------| +| object | `{ blockService: ...}` | + +Pass options into [IPLD](https://github.com/ipld/js-ipld). It can be used to pass in [IPLD formats](https://github.com/ipld/interface-ipld-format) that are not the default ones [`dag-cbor`](https://github.com/ipld/js-ipld-dag-cbor) and [`dag-pb`](https://github.com/ipld/js-ipld-dag-pb). For more information see the [js-ipld readmel](https://github.com/ipld/js-ipld#readme). + ##### `options.EXPERIMENTAL` | Type | Default | diff --git a/examples/traverse-ipld-graphs/get-path-accross-formats.js b/examples/traverse-ipld-graphs/get-path-accross-formats.js index 004c93171b..984e9f234d 100644 --- a/examples/traverse-ipld-graphs/get-path-accross-formats.js +++ b/examples/traverse-ipld-graphs/get-path-accross-formats.js @@ -36,7 +36,7 @@ createNode((err, ipfs) => { const myData = { name: 'David', likes: ['js-ipfs', 'icecream', 'steak'], - hobbies: [{ '/': cidPBNode.toBaseEncodedString() }] + hobbies: [cidPBNode] } ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha3-512' }, (err, cid) => { diff --git a/package.json b/package.json index 0cf550cf4c..1eba04bfbd 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.78.0", + "interface-ipfs-core": "~0.79.0", "ipfsd-ctl": "~0.39.3", "mocha": "^5.2.0", "ncp": "^2.0.0", @@ -117,9 +117,14 @@ "ipfs-repo": "~0.24.0", "ipfs-unixfs": "~0.1.15", "ipfs-unixfs-engine": "~0.32.3", - "ipld": "~0.17.3", + "ipld": "~0.19.0", + "ipld-bitcoin": "~0.1.8", "ipld-dag-cbor": "~0.12.1", "ipld-dag-pb": "~0.14.6", + "ipld-ethereum": "^2.0.1", + "ipld-git": "~0.2.2", + "ipld-raw": "^2.0.1", + "ipld-zcash": "~0.1.6", "ipns": "~0.2.0", "is-ipfs": "~0.4.2", "is-pull-stream": "~0.0.0", diff --git a/src/cli/utils.js b/src/cli/utils.js index 02f830f6c6..6a29507263 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -11,6 +11,21 @@ const Progress = require('progress') const byteman = require('byteman') const promisify = require('promisify-es6') +// All known IPLD formats +const ipldBitcoin = require('ipld-bitcoin') +const ipldDagCbor = require('ipld-dag-cbor') +const ipldDagPb = require('ipld-dag-pb') +const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot +const ipldEthBlock = require('ipld-ethereum').ethBlock +const ipldEthBlockList = require('ipld-ethereum').ethBlockList +const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie +const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie +const ipldEthTrie = require('ipld-ethereum').ethTxTrie +const ipldEthTx = require('ipld-ethereum').ethTx +const ipldGit = require('ipld-git') +const ipldRaw = require('ipld-raw') +const ipldZcash = require('ipld-zcash') + exports = module.exports exports.isDaemonOn = isDaemonOn @@ -53,6 +68,13 @@ exports.getIPFS = (argv, callback) => { pass: argv.pass, EXPERIMENTAL: { pubsub: true + }, + ipld: { + formats: [ + ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot, + ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie, + ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash + ] } }) diff --git a/src/core/index.js b/src/core/index.js index 0f49423f78..f90391ce72 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -86,7 +86,18 @@ class IPFS extends EventEmitter { this._libp2pNode = undefined this._bitswap = undefined this._blockService = new BlockService(this._repo) - this._ipld = new Ipld(this._blockService) + + // Make sure IPLD has the correct BlockService + const ipldDefaults = { + blockService: this._blockService + } + if (this._options.ipld === undefined) { + this._options.ipld = ipldDefaults + } else if (this._options.ipld.blockService === undefined) { + this._options.ipld.blockService = ipldDefaults.blockService + } + this._ipld = new Ipld(this._options.ipld) + this._preload = preload(this) this._mfsPreload = mfsPreload(this) this._ipns = new IPNS(null, this)