Skip to content

Commit

Permalink
chore: update deps
Browse files Browse the repository at this point in the history
Needed for next js-ipfs release. Had to port some changes from #7

Depends on:

* [ ] ipfs-inactive/js-ipfs-http-client#1039

cc @achingbrain

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw committed Jul 10, 2019
1 parent 4eab302 commit 087dda6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 45 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <daviddias.p@gmail.com>",
Expand Down
36 changes: 7 additions & 29 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -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))
}
Expand Down
16 changes: 8 additions & 8 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 087dda6

Please sign in to comment.