Skip to content

Commit

Permalink
chore: remove peer-info from api (#34)
Browse files Browse the repository at this point in the history
* chore: remove peer-info from api

BREAKING CHANGE: findProviders returns id and addrs properties instead of peer-info instance

* chore: address review
  • Loading branch information
vasco-santos authored Apr 23, 2020
1 parent 437c05e commit 2c97221
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const routing = new DelegatedContentRouing(peerId, {
})
const cid = new CID('QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv')

for await (const peerInfo of routing.findProviders(cid)) {
console.log('found peer', peerInfo)
for await (const { id, multiaddrs } of routing.findProviders(cid)) {
console.log('found peer', id, multiaddrs)
}

await routing.provide(cid)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"it-all": "^1.0.0",
"multiaddr": "^7.4.3",
"p-defer": "^3.0.0",
"p-queue": "^6.3.0",
"peer-info": "^0.17.5"
"p-queue": "^6.2.1"
},
"contributors": [
"Jacob Heun <[email protected]>",
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const debug = require('debug')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const createFindProvs = require('ipfs-http-client/src/dht/find-provs')
const createRefs = require('ipfs-http-client/src/refs')

Expand Down Expand Up @@ -63,7 +62,7 @@ class DelegatedContentRouting {
* @param {object} options
* @param {number} options.timeout How long the query can take. Defaults to 30 seconds
* @param {number} options.numProviders How many providers to find, defaults to 20
* @returns {AsyncIterable<PeerInfo>}
* @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>}
*/
async * findProviders (key, options = {}) {
const keyString = `${key}`
Expand All @@ -85,9 +84,10 @@ class DelegatedContentRouting {
numProviders: options.numProviders,
timeout: options.timeout
})) {
const peerInfo = new PeerInfo(PeerId.createFromCID(id))
addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
yield peerInfo
yield {
id: PeerId.createFromCID(id),
multiaddrs: addrs
}
}
} catch (err) {
log.error('findProviders errored:', err)
Expand Down

0 comments on commit 2c97221

Please sign in to comment.