Skip to content

Commit be62fa2

Browse files
committed
chore/remove-peer-info-from-api
BREAKING CHANGE: findPeer returns id and addrs properties instead of peer-info instance
1 parent 3255b6f commit be62fa2

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const DelegatedPeerRouting = require('libp2p-delegated-peer-routing')
1717
const routing = new DelegatedPeerRouing()
1818

1919
try {
20-
const peerInfo = await routing.findPeer('peerid')
20+
const { id, addresses } = await routing.findPeer('peerid')
2121

22-
console.log('found peer details', peerInfo)
22+
console.log('found peer details', id, addresses)
2323
} catch (err) {
2424
console.error(err)
2525
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"debug": "^4.1.1",
3030
"ipfs-http-client": "^44.0.0",
3131
"p-queue": "^6.3.0",
32-
"peer-id": "^0.13.11",
33-
"peer-info": "^0.17.5"
32+
"peer-id": "^0.13.11"
3433
},
3534
"contributors": [
3635
"Jacob Heun <[email protected]>",

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const PeerId = require('peer-id')
4-
const PeerInfo = require('peer-info')
54
const createFindPeer = require('ipfs-http-client/src/dht/find-peer')
65
const { default: PQueue } = require('p-queue')
76
const debug = require('debug')
@@ -36,7 +35,7 @@ class DelegatedPeerRouting {
3635
* @param {PeerID} id
3736
* @param {object} options
3837
* @param {number} options.timeout How long the query can take. Defaults to 30 seconds
39-
* @returns {Promise<PeerInfo>}
38+
* @returns {Promise<{ id: CID, addrs: Multiaddr[] }>}
4039
*/
4140
async findPeer (id, options = {}) {
4241
if (PeerId.isPeerId(id)) {
@@ -52,9 +51,10 @@ class DelegatedPeerRouting {
5251
timeout: options.timeout
5352
})
5453

55-
const peerInfo = new PeerInfo(PeerId.createFromCID(id))
56-
addrs.forEach(addr => peerInfo.multiaddrs.add(addr))
57-
return peerInfo
54+
return {
55+
id,
56+
addrs
57+
}
5858
})
5959
} catch (err) {
6060
if (err.message.includes('not found')) {

test/index.spec.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ describe('DelegatedPeerRouting', function () {
111111
describe('findPeers', () => {
112112
it('should be able to find peers via the delegate with a peer id string', async () => {
113113
const opts = delegatedNode.apiAddr.toOptions()
114+
114115
const router = new DelegatedPeerRouting({
115116
protocol: 'http',
116117
port: opts.port,
117118
host: opts.host
118119
})
119120

120-
const peer = await router.findPeer(peerIdToFind.id)
121-
expect(peer).to.exist()
122-
expect(peer.id.toB58String()).to.eql(peerIdToFind.id)
121+
const { id, addrs } = await router.findPeer(peerIdToFind.id)
122+
expect(id).to.exist()
123+
expect(addrs).to.exist()
124+
expect(id).to.eql(peerIdToFind.id)
123125
})
124126

125127
it('should be able to find peers via the delegate with a peerid', async () => {
@@ -130,9 +132,11 @@ describe('DelegatedPeerRouting', function () {
130132
host: opts.host
131133
})
132134

133-
const peer = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id))
134-
expect(peer).to.exist()
135-
expect(peer.id.toB58String()).to.eql(peerIdToFind.id)
135+
const { id, addrs } = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id))
136+
expect(id).to.exist()
137+
expect(addrs).to.exist()
138+
139+
expect(id).to.eql(peerIdToFind.id)
136140
})
137141

138142
it('should be able to specify a timeout', async () => {
@@ -143,9 +147,11 @@ describe('DelegatedPeerRouting', function () {
143147
host: opts.host
144148
})
145149

146-
const peer = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id), { timeout: 2000 })
147-
expect(peer).to.exist()
148-
expect(peer.id.toB58String()).to.eql(peerIdToFind.id)
150+
const { id, addrs } = await router.findPeer(PeerID.createFromB58String(peerIdToFind.id), { timeout: 2000 })
151+
expect(id).to.exist()
152+
expect(addrs).to.exist()
153+
154+
expect(id).to.eql(peerIdToFind.id)
149155
})
150156

151157
it('should not be able to find peers not on the network', async () => {

0 commit comments

Comments
 (0)