Skip to content

Commit 087dda6

Browse files
author
Alan Shaw
committed
chore: update deps
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 <[email protected]>
1 parent 4eab302 commit 087dda6

File tree

3 files changed

+23
-45
lines changed

3 files changed

+23
-45
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"devDependencies": {
2121
"aegir": "^19.0.5",
2222
"chai": "^4.2.0",
23-
"cids": "~0.5.5",
24-
"go-ipfs-dep": "~0.4.17",
25-
"ipfsd-ctl": "~0.39.2"
23+
"cids": "^0.7.1",
24+
"go-ipfs-dep": "^0.4.21",
25+
"ipfsd-ctl": "^0.43.0"
2626
},
2727
"dependencies": {
28-
"async": "^2.6.1",
29-
"ipfs-api": "^24.0.2",
30-
"multiaddr": "^5.0.0",
31-
"peer-id": "~0.11.0",
32-
"peer-info": "~0.14.1"
28+
"async": "^2.6.2",
29+
"ipfs-http-client": "github:ipfs/js-ipfs-http-client#fix/findpeerprovs-response",
30+
"multiaddr": "^6.1.0",
31+
"peer-id": "^0.12.2",
32+
"peer-info": "^0.15.1"
3333
},
3434
"contributors": [
3535
"David Dias <[email protected]>",

src/index.js

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
const PeerInfo = require('peer-info')
44
const PeerID = require('peer-id')
5-
const dht = require('ipfs-api/src/dht')
6-
const swarm = require('ipfs-api/src/swarm')
7-
const refs = require('ipfs-api/src/refs')
8-
const defaultConfig = require('ipfs-api/src/utils/default-config')
5+
const dht = require('ipfs-http-client/src/dht')
6+
const swarm = require('ipfs-http-client/src/swarm')
7+
const refs = require('ipfs-http-client/src/files-regular/refs')
8+
const defaultConfig = require('ipfs-http-client/src/utils/default-config')
99
const series = require('async/series')
1010
const parallel = require('async/parallel')
1111
const reflect = require('async/reflect')
@@ -79,31 +79,9 @@ class DelegatedContentRouting {
7979

8080
options.maxTimeout = options.maxTimeout || DEFAULT_MAX_TIMEOUT
8181

82-
this.dht.findprovs(key.toBaseEncodedString(), {
82+
this.dht.findProvs(key.toString(), {
8383
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms)
84-
}, (err, results) => {
85-
if (err) {
86-
return callback(err)
87-
}
88-
89-
// cleanup result from ipfs-api
90-
const infos = []
91-
results
92-
.filter((res) => Boolean(res.Responses))
93-
.forEach((res) => {
94-
res.Responses.forEach((raw) => {
95-
const info = new PeerInfo(
96-
PeerID.createFromB58String(raw.ID)
97-
)
98-
if (raw.Addrs) {
99-
raw.Addrs.forEach((addr) => info.multiaddrs.add(addr))
100-
}
101-
infos.push(info)
102-
})
103-
})
104-
105-
callback(null, infos)
106-
})
84+
}, callback)
10785
}
10886

10987
/**
@@ -138,7 +116,7 @@ class DelegatedContentRouting {
138116
cb()
139117
}),
140118
(cb) => {
141-
this.refs(key.toBaseEncodedString(), { recursive: true }, cb)
119+
this.refs(key.toString(), { recursive: true }, cb)
142120
}
143121
], (err) => callback(err))
144122
}

test/index.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const factory = IPFSFactory.create({ type: 'go' })
1111

1212
const DelegatedContentRouting = require('../src')
1313

14-
function spawnNode (boostrap, callback) {
15-
if (typeof boostrap === 'function') {
16-
callback = boostrap
17-
boostrap = []
14+
function spawnNode (bootstrap, callback) {
15+
if (typeof bootstrap === 'function') {
16+
callback = bootstrap
17+
bootstrap = []
1818
}
1919

2020
factory.spawn({
2121
// Lock down the nodes so testing can be deterministic
2222
config: {
23-
Bootstrap: boostrap,
23+
Bootstrap: bootstrap,
2424
Discovery: {
2525
MDNS: {
2626
Enabled: false
@@ -49,7 +49,7 @@ describe('DelegatedContentRouting', function () {
4949

5050
before((done) => {
5151
async.waterfall([
52-
// Spawn a "Boostrap" node that doesnt connect to anything
52+
// Spawn a "bootstrap" node that doesnt connect to anything
5353
(cb) => spawnNode(cb),
5454
(ipfsd, id, cb) => {
5555
bootstrapNode = ipfsd
@@ -188,14 +188,14 @@ describe('DelegatedContentRouting', function () {
188188
host: opts.host
189189
})
190190

191-
selfNode.api.files.add(Buffer.from(`hello-${Math.random()}`), cb)
191+
selfNode.api.add(Buffer.from(`hello-${Math.random()}`), cb)
192192
},
193193
(res, cb) => {
194194
cid = new CID(res[0].hash)
195195
contentRouter.provide(cid, cb)
196196
},
197197
(cb) => {
198-
delegatedNode.api.dht.findprovs(cid.toBaseEncodedString(), cb)
198+
delegatedNode.api.dht.findProvs(cid.toString(), cb)
199199
},
200200
(provs, cb) => {
201201
let providers = []

0 commit comments

Comments
 (0)