From 4e39d2c30cd3be7a75033dead8f9f7df3a719b3b Mon Sep 17 00:00:00 2001 From: Pedro Teixeira Date: Tue, 4 Jul 2017 21:35:15 +0100 Subject: [PATCH] feat: adapted to new ipfs-repo API (#887) * feat: adapted to new ipfs-repo API --- package.json | 12 +++++------ src/core/components/config.js | 39 ++--------------------------------- src/core/components/dht.js | 2 +- src/core/components/start.js | 4 ++-- src/core/components/stop.js | 2 +- src/http-api/index.js | 2 +- 6 files changed, 12 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 91be568b56..88ebf37115 100644 --- a/package.json +++ b/package.json @@ -100,14 +100,14 @@ "hapi-set-header": "^1.0.2", "hoek": "^4.1.1", "ipfs-api": "^14.0.4", - "ipfs-bitswap": "~0.13.1", + "ipfs-bitswap": "~0.14.0", "ipfs-block": "~0.6.0", - "ipfs-block-service": "~0.9.1", + "ipfs-block-service": "~0.10.0", "ipfs-multipart": "~0.1.0", - "ipfs-repo": "~0.13.1", + "ipfs-repo": "~0.15.0", "ipfs-unixfs": "~0.1.12", - "ipfs-unixfs-engine": "~0.20.0", - "ipld-resolver": "~0.11.1", + "ipfs-unixfs-engine": "~0.21.0", + "ipld-resolver": "~0.12.0", "is-ipfs": "^0.3.0", "isstream": "^0.1.2", "joi": "^10.6.0", @@ -125,8 +125,6 @@ "libp2p-websockets": "^0.10.0", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", - "lodash.has": "^4.5.2", - "lodash.set": "^4.3.2", "lodash.sortby": "^4.7.0", "lodash.values": "^4.3.0", "mafmt": "^2.1.8", diff --git a/src/core/components/config.js b/src/core/components/config.js index 4fa5ec1189..1f3afbfc8e 100644 --- a/src/core/components/config.js +++ b/src/core/components/config.js @@ -1,9 +1,6 @@ 'use strict' const promisify = require('promisify-es6') -const _get = require('lodash.get') -const _has = require('lodash.has') -const _set = require('lodash.set') module.exports = function config (self) { return { @@ -13,42 +10,10 @@ module.exports = function config (self) { key = undefined } - if (!key) { - return self._repo.config.get(callback) - } - - if (typeof key !== 'string') { - return callback(new Error('Invalid key type')) - } - - self._repo.config.get((err, config) => { - if (err) { - return callback(err) - } - if (_has(config, key)) { - const value = _get(config, key, undefined) - callback(null, value) - } else { - callback(new Error('Key does not exist in config')) - } - }) + return self._repo.config.get(key, callback) }), set: promisify((key, value, callback) => { - if (!key || typeof key !== 'string') { - return callback(new Error('Invalid key type')) - } - - if (value === undefined || Buffer.isBuffer(value)) { - return callback(new Error('Invalid value type')) - } - - self._repo.config.get((err, config) => { - if (err) { - return callback(err) - } - _set(config, key, value) - self.config.replace(config, callback) - }) + self._repo.config.set(key, value, callback) }), replace: promisify((config, callback) => { self._repo.config.set(config, callback) diff --git a/src/core/components/dht.js b/src/core/components/dht.js index 0a2ce5d8e2..8c85b9e438 100644 --- a/src/core/components/dht.js +++ b/src/core/components/dht.js @@ -116,7 +116,7 @@ module.exports = (self) => { // ensure blocks are actually local every(keys, (key, cb) => { - self._repo.blockstore.has(key, cb) + self._repo.blocks.has(key, cb) }, (err, has) => { if (err) { return callback(err) diff --git a/src/core/components/start.js b/src/core/components/start.js index b41039e36e..54ff3c9833 100644 --- a/src/core/components/start.js +++ b/src/core/components/start.js @@ -43,12 +43,12 @@ module.exports = (self) => { self._bitswap = new Bitswap( self._libp2pNode, - self._repo.blockstore, + self._repo.blocks, self._peerInfoBook ) self._bitswap.start() - self._blockService.goOnline(self._bitswap) + self._blockService.setExchange(self._bitswap) if (self._options.EXPERIMENTAL.pubsub) { self._pubsub = new FloodSub(self._libp2pNode) diff --git a/src/core/components/stop.js b/src/core/components/stop.js index 865c6f2943..e9d508d10b 100644 --- a/src/core/components/stop.js +++ b/src/core/components/stop.js @@ -26,7 +26,7 @@ module.exports = (self) => { } self.state.stop() - self._blockService.goOffline() + self._blockService.unsetExchange() self._bitswap.stop() series([ diff --git a/src/http-api/index.js b/src/http-api/index.js index cdd7d1bc00..5746979b83 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -130,7 +130,7 @@ function HttpApi (repo, config) { console.log('Gateway (readonly) is listening on: %s', gateway.info.ma) // for the CLI to know the where abouts of the API - this.node._repo.setApiAddress(api.info.ma, cb) + this.node._repo.apiAddr.set(api.info.ma, cb) } ], (err) => { this.log('done', err)