Skip to content

Commit 22ff40c

Browse files
vasco-santosjacobheun
authored andcommittedNov 29, 2019
chore: rename timeout option (#18)
BREAKING CHANGE: maxTimeout option renamed to timeout
1 parent ac371f1 commit 22ff40c

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed
 

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
"coverage": "aegir coverage"
1919
},
2020
"devDependencies": {
21-
"aegir": "^19.0.5",
21+
"aegir": "^20.4.1",
2222
"async-iterator-all": "^1.0.0",
2323
"chai": "^4.2.0",
2424
"cids": "^0.7.1",
25-
"go-ipfs-dep": "~0.4.17",
26-
"ipfsd-ctl": "~0.44.1",
27-
"peer-id": "~0.13.1"
25+
"go-ipfs-dep": "~0.4.22",
26+
"ipfsd-ctl": "~0.47.4",
27+
"peer-id": "~0.13.5"
2828
},
2929
"dependencies": {
3030
"debug": "^4.1.1",
31-
"ipfs-http-client": "^33.1.0",
32-
"multiaddr": "^6.1.0",
33-
"p-queue": "^6.1.0"
31+
"ipfs-http-client": "^40.0.1",
32+
"multiaddr": "^7.2.1",
33+
"p-queue": "^6.2.1"
3434
},
3535
"contributors": [
3636
"Alan Shaw <alan.shaw@protocol.ai>",

‎src/index.js

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

33
const dht = require('ipfs-http-client/src/dht')
4-
const refs = require('ipfs-http-client/src/files-regular/refs')
5-
const defaultConfig = require('ipfs-http-client/src/utils/default-config')
4+
const refs = require('ipfs-http-client/src/refs')
5+
const getEndpointConfig = require('ipfs-http-client/src/get-endpoint-config')
66
const { default: PQueue } = require('p-queue')
77
const debug = require('debug')
88

99
const log = debug('libp2p-delegated-content-routing')
1010
log.error = debug('libp2p-delegated-content-routing:error')
1111

12-
const DEFAULT_MAX_TIMEOUT = 30e3 // 30 second default
12+
const DEFAULT_TIMEOUT = 30e3 // 30 second default
1313
const DEFAULT_IPFS_API = {
1414
protocol: 'https',
1515
port: 443,
@@ -33,7 +33,7 @@ class DelegatedContentRouting {
3333
throw new Error('missing self peerId')
3434
}
3535

36-
this.api = Object.assign({}, defaultConfig(), DEFAULT_IPFS_API, api)
36+
this.api = Object.assign({}, getEndpointConfig()(), DEFAULT_IPFS_API, api)
3737
this.dht = dht(this.api)
3838
this.refs = refs(this.api)
3939
this.peerId = peerId
@@ -57,16 +57,16 @@ class DelegatedContentRouting {
5757
*
5858
* @param {CID} key
5959
* @param {object} options
60-
* @param {number} options.maxTimeout How long the query can take. Defaults to 30 seconds
60+
* @param {number} options.timeout How long the query can take. Defaults to 30 seconds
6161
* @returns {AsyncIterable<PeerInfo>}
6262
*/
6363
async * findProviders (key, options = {}) {
6464
const keyString = key.toBaseEncodedString()
6565
log('findProviders starts: ' + keyString)
66-
options.maxTimeout = options.maxTimeout || DEFAULT_MAX_TIMEOUT
66+
options.timeout = options.timeout || DEFAULT_TIMEOUT
6767

6868
const results = await this._httpQueue.add(() => this.dht.findProvs(key, {
69-
timeout: `${options.maxTimeout}ms` // The api requires specification of the time unit (s/ms)
69+
timeout: `${options.timeout}ms` // The api requires specification of the time unit (s/ms)
7070
}))
7171

7272
for (let i = 0; i < results.length; i++) {

‎test/index.spec.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('DelegatedContentRouting', function () {
7575
const router = new DelegatedContentRouting(selfId)
7676

7777
expect(router.api).to.include({
78-
'api-path': '/api/v0/',
78+
'api-path': '/api/v0',
7979
protocol: 'https',
8080
port: 443,
8181
host: 'node0.delegate.ipfs.io'
@@ -88,7 +88,7 @@ describe('DelegatedContentRouting', function () {
8888
})
8989

9090
expect(router.api).to.include({
91-
'api-path': '/api/v0/',
91+
'api-path': '/api/v0',
9292
protocol: 'https',
9393
port: 443,
9494
host: 'other.ipfs.io'
@@ -97,7 +97,7 @@ describe('DelegatedContentRouting', function () {
9797

9898
it('should allow for overriding the api', () => {
9999
const api = {
100-
'api-path': '/api/v1/',
100+
'api-path': '/api/v1',
101101
protocol: 'http',
102102
port: 8000,
103103
host: 'localhost'
@@ -132,7 +132,7 @@ describe('DelegatedContentRouting', function () {
132132
expect(providers.map((p) => p.id.toB58String())).to.include(selfId.toB58String(), 'Did not include self node')
133133
})
134134

135-
it('should be able to specify a maxTimeout', async () => {
135+
it('should be able to specify a timeout', async () => {
136136
const opts = delegateNode.apiAddr.toOptions()
137137
const routing = new DelegatedContentRouting(selfId, {
138138
protocol: 'http',
@@ -141,26 +141,23 @@ describe('DelegatedContentRouting', function () {
141141
})
142142

143143
const cid = new CID('QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv')
144-
const providers = await all(routing.findProviders(cid, { maxTimeout: 5e3 }))
144+
const providers = await all(routing.findProviders(cid, { timeout: 5e3 }))
145145

146146
expect(providers.map((p) => p.id.toB58String())).to.include(bootstrapId.id, 'Did not include bootstrap node')
147147
})
148148
})
149149

150150
describe('provide', () => {
151151
it('should be able to register as a content provider to the delegate node', async () => {
152-
let contentRouter
153-
let cid
154-
155152
const opts = delegateNode.apiAddr.toOptions()
156-
contentRouter = new DelegatedContentRouting(selfId, {
153+
const contentRouter = new DelegatedContentRouting(selfId, {
157154
protocol: 'http',
158155
port: opts.port,
159156
host: opts.host
160157
})
161158

162159
const res = await selfNode.api.add(Buffer.from(`hello-${Math.random()}`))
163-
cid = new CID(res[0].hash)
160+
const cid = new CID(res[0].hash)
164161
await contentRouter.provide(cid)
165162
const providers = await delegateNode.api.dht.findProvs(cid.toBaseEncodedString())
166163

0 commit comments

Comments
 (0)