diff --git a/package.json b/package.json index 1818427..1fe0951 100644 --- a/package.json +++ b/package.json @@ -20,16 +20,16 @@ "devDependencies": { "aegir": "^19.0.5", "chai": "^4.2.0", - "cids": "~0.5.5", - "go-ipfs-dep": "~0.4.17", - "ipfsd-ctl": "~0.39.2" + "cids": "^0.7.1", + "go-ipfs-dep": "^0.4.21", + "ipfsd-ctl": "^0.43.0" }, "dependencies": { - "async": "^2.6.1", - "ipfs-api": "^24.0.2", - "multiaddr": "^5.0.0", - "peer-id": "~0.11.0", - "peer-info": "~0.14.1" + "async": "^2.6.2", + "ipfs-http-client": "github:ipfs/js-ipfs-http-client#fix/findpeerprovs-response", + "multiaddr": "^6.1.0", + "peer-id": "^0.12.2", + "peer-info": "^0.15.1" }, "contributors": [ "David Dias ", diff --git a/src/index.js b/src/index.js index 7e3fb20..caffbfc 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,10 @@ const PeerInfo = require('peer-info') const PeerID = require('peer-id') -const dht = require('ipfs-api/src/dht') -const swarm = require('ipfs-api/src/swarm') -const refs = require('ipfs-api/src/refs') -const defaultConfig = require('ipfs-api/src/utils/default-config') +const dht = require('ipfs-http-client/src/dht') +const swarm = require('ipfs-http-client/src/swarm') +const refs = require('ipfs-http-client/src/files-regular/refs') +const defaultConfig = require('ipfs-http-client/src/utils/default-config') const series = require('async/series') const parallel = require('async/parallel') const reflect = require('async/reflect') @@ -79,31 +79,9 @@ class DelegatedContentRouting { options.maxTimeout = options.maxTimeout || DEFAULT_MAX_TIMEOUT - this.dht.findprovs(key.toBaseEncodedString(), { + this.dht.findProvs(key.toString(), { timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms) - }, (err, results) => { - if (err) { - return callback(err) - } - - // cleanup result from ipfs-api - const infos = [] - results - .filter((res) => Boolean(res.Responses)) - .forEach((res) => { - res.Responses.forEach((raw) => { - const info = new PeerInfo( - PeerID.createFromB58String(raw.ID) - ) - if (raw.Addrs) { - raw.Addrs.forEach((addr) => info.multiaddrs.add(addr)) - } - infos.push(info) - }) - }) - - callback(null, infos) - }) + }, callback) } /** @@ -138,7 +116,7 @@ class DelegatedContentRouting { cb() }), (cb) => { - this.refs(key.toBaseEncodedString(), { recursive: true }, cb) + this.refs(key.toString(), { recursive: true }, cb) } ], (err) => callback(err)) } diff --git a/test/index.spec.js b/test/index.spec.js index e4a70dd..9b6baa9 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -11,16 +11,16 @@ const factory = IPFSFactory.create({ type: 'go' }) const DelegatedContentRouting = require('../src') -function spawnNode (boostrap, callback) { - if (typeof boostrap === 'function') { - callback = boostrap - boostrap = [] +function spawnNode (bootstrap, callback) { + if (typeof bootstrap === 'function') { + callback = bootstrap + bootstrap = [] } factory.spawn({ // Lock down the nodes so testing can be deterministic config: { - Bootstrap: boostrap, + Bootstrap: bootstrap, Discovery: { MDNS: { Enabled: false @@ -49,7 +49,7 @@ describe('DelegatedContentRouting', function () { before((done) => { async.waterfall([ - // Spawn a "Boostrap" node that doesnt connect to anything + // Spawn a "bootstrap" node that doesnt connect to anything (cb) => spawnNode(cb), (ipfsd, id, cb) => { bootstrapNode = ipfsd @@ -188,14 +188,14 @@ describe('DelegatedContentRouting', function () { host: opts.host }) - selfNode.api.files.add(Buffer.from(`hello-${Math.random()}`), cb) + selfNode.api.add(Buffer.from(`hello-${Math.random()}`), cb) }, (res, cb) => { cid = new CID(res[0].hash) contentRouter.provide(cid, cb) }, (cb) => { - delegatedNode.api.dht.findprovs(cid.toBaseEncodedString(), cb) + delegatedNode.api.dht.findProvs(cid.toString(), cb) }, (provs, cb) => { let providers = []