Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: adapted to new ipfs-repo API (#887)
Browse files Browse the repository at this point in the history
* feat: adapted to new ipfs-repo API
  • Loading branch information
pgte authored and dryajov committed Aug 31, 2017
1 parent 954d8d1 commit f6569ae
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 49 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
39 changes: 2 additions & 37 deletions src/core/components/config.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = (self) => {
}

self.state.stop()
self._blockService.goOffline()
self._blockService.unsetExchange()
self._bitswap.stop()

series([
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f6569ae

Please sign in to comment.