Skip to content

Commit b64511e

Browse files
authoredApr 9, 2020
chore: update ipfs-http-client and other deps (#30)
* chore: update ipfs-http-client and other deps Refactors code do work with new ky-less http client * chore: remove timeout from tests * chore: specify minimum http client version
1 parent a5dcd46 commit b64511e

File tree

4 files changed

+57
-36
lines changed

4 files changed

+57
-36
lines changed
 

‎.aegir.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
'use strict'
22

3-
const createServer = require('ipfsd-ctl').createServer
4-
5-
const server = createServer()
3+
const { createServer } = require('ipfsd-ctl')
4+
let server
65

76
module.exports = {
87
hooks: {
98
browser: {
10-
pre: () => server.start(),
9+
pre: async () => {
10+
server = createServer({
11+
host: '127.0.0.1',
12+
port: 57483
13+
}, {
14+
type: 'go',
15+
ipfsHttpModule: require('ipfs-http-client'),
16+
ipfsBin: require('go-ipfs-dep').path(),
17+
test: true
18+
})
19+
20+
await server.start()
21+
},
1122
post: () => server.stop()
1223
}
1324
}

‎package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@
1010
"scripts": {
1111
"lint": "aegir lint",
1212
"build": "aegir build",
13-
"test": "aegir test -f test/**/*.js",
14-
"test:node": "aegir test --target node -f test/**/*.js",
13+
"test": "aegir test",
14+
"test:node": "aegir test --target node",
1515
"release": "aegir release",
1616
"release-minor": "aegir release --type minor",
1717
"release-major": "aegir release --type major",
1818
"coverage": "aegir coverage"
1919
},
2020
"devDependencies": {
21-
"aegir": "^21.0.2",
21+
"aegir": "^21.4.5",
2222
"chai": "^4.2.0",
23-
"cids": "^0.7.1",
24-
"go-ipfs-dep": "^0.4.23",
25-
"ipfsd-ctl": "~0.47.4",
23+
"cids": "^0.8.0",
24+
"go-ipfs-dep": "0.4.23-3",
25+
"ipfs-utils": "^1.2.1",
26+
"ipfsd-ctl": "^3.0.0",
27+
"it-drain": "^1.0.0",
28+
"it-last": "^1.0.1",
2629
"peer-id": "^0.13.7"
2730
},
2831
"dependencies": {
2932
"debug": "^4.1.1",
30-
"ipfs-http-client": "^42.0.0",
33+
"ipfs-http-client": "^43.0.1",
3134
"it-all": "^1.0.0",
3235
"multiaddr": "^7.2.1",
3336
"p-defer": "^3.0.0",

‎src/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DelegatedContentRouting {
6262
* @param {CID} key
6363
* @param {object} options
6464
* @param {number} options.timeout How long the query can take. Defaults to 30 seconds
65+
* @param {number} options.numProviders How many providers to find, defaults to 20
6566
* @returns {AsyncIterable<PeerInfo>}
6667
*/
6768
async * findProviders (key, options = {}) {
@@ -80,12 +81,12 @@ class DelegatedContentRouting {
8081
try {
8182
await onStart.promise
8283

83-
const providers = this.dht.findProvs(key, {
84+
for await (const { id, addrs } of this.dht.findProvs(key, {
8485
numProviders: options.numProviders,
85-
timeout: `${options.timeout}ms` // The api requires specification of the time unit (s/ms)
86-
})
87-
88-
for await (const { id, addrs } of providers) {
86+
searchParams: {
87+
timeout: `${options.timeout}ms` // The api requires specification of the time unit (s/ms)
88+
}
89+
})) {
8990
const peerInfo = new PeerInfo(PeerId.createFromCID(id))
9091
addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
9192
yield peerInfo

‎test/index.spec.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@
22
'use strict'
33

44
const expect = require('chai').expect
5-
const IPFSFactory = require('ipfsd-ctl')
5+
const { createFactory } = require('ipfsd-ctl')
66
const CID = require('cids')
77
const PeerId = require('peer-id')
88
const all = require('it-all')
9-
const factory = IPFSFactory.create({
10-
type: 'go'
9+
const last = require('it-last')
10+
const drain = require('it-drain')
11+
const { isNode } = require('ipfs-utils/src/env')
12+
const factory = createFactory({
13+
type: 'go',
14+
ipfsHttpModule: require('ipfs-http-client'),
15+
ipfsBin: isNode ? require('go-ipfs-dep').path() : undefined,
16+
test: true,
17+
endpoint: 'http://localhost:57483'
1118
})
1219

1320
const DelegatedContentRouting = require('../src')
1421

1522
async function spawnNode (bootstrap = []) {
1623
const node = await factory.spawn({
1724
// Lock down the nodes so testing can be deterministic
18-
config: {
19-
Bootstrap: bootstrap,
20-
Discovery: {
21-
MDNS: {
22-
Enabled: false
25+
ipfsOptions: {
26+
config: {
27+
Bootstrap: bootstrap,
28+
Discovery: {
29+
MDNS: {
30+
Enabled: false
31+
}
2332
}
2433
}
2534
}
@@ -59,11 +68,7 @@ describe('DelegatedContentRouting', function () {
5968
})
6069

6170
after(() => {
62-
return Promise.all([
63-
selfNode.stop(),
64-
delegateNode.stop(),
65-
bootstrapNode.stop()
66-
])
71+
return factory.clean()
6772
})
6873

6974
describe('create', () => {
@@ -109,11 +114,11 @@ describe('DelegatedContentRouting', function () {
109114
const cid = new CID('QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv')
110115

111116
before('register providers', async () => {
112-
await bootstrapNode.api.dht.provide(cid)
113-
await selfNode.api.dht.provide(cid)
117+
await drain(bootstrapNode.api.dht.provide(cid))
118+
await drain(selfNode.api.dht.provide(cid))
114119
})
115120

116-
it('should be able to find providers through the delegate node', async () => {
121+
it('should be able to find providers through the delegate node', async function () {
117122
const opts = delegateNode.apiAddr.toOptions()
118123
const routing = new DelegatedContentRouting(selfId, {
119124
protocol: 'http',
@@ -153,13 +158,14 @@ describe('DelegatedContentRouting', function () {
153158
host: opts.host
154159
})
155160

156-
const res = await selfNode.api.add(Buffer.from(`hello-${Math.random()}`))
157-
const cid = new CID(res[0].hash)
161+
const { cid } = await last(selfNode.api.add(Buffer.from(`hello-${Math.random()}`)))
162+
158163
await contentRouter.provide(cid)
159-
const providers = await delegateNode.api.dht.findProvs(cid.toBaseEncodedString())
164+
165+
const providers = await all(delegateNode.api.dht.findProvs(cid, { numProviders: 2 }))
160166

161167
// We are hosting the file, validate we're the provider
162-
expect(providers.map((p) => p.id.toB58String())).to.include(selfId.toB58String(), 'Did not include self node')
168+
expect(providers.map((p) => p.id)).to.include(selfId.toB58String(), 'Did not include self node')
163169
})
164170
})
165171
})

0 commit comments

Comments
 (0)
Please sign in to comment.