Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 8a99f1b

Browse files
committed
chore: peer-discovery not using peer-info
BREAKING CHANGE: peer event emits an object with id and multiaddr instead of a peer-info
1 parent a87c1f7 commit 8a99f1b

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"debug": "^4.1.1",
3737
"mafmt": "^7.0.0",
3838
"multiaddr": "^7.2.1",
39-
"peer-id": "^0.13.5",
40-
"peer-info": "^0.17.0"
39+
"peer-id": "^0.13.5"
4140
},
4241
"pre-push": [
4342
"lint",

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 multiaddr = require('multiaddr')
65
const mafmt = require('mafmt')
76
const { EventEmitter } = require('events')
@@ -50,7 +49,7 @@ class Bootstrap extends EventEmitter {
5049
* Emit each address in the list as a PeerInfo.
5150
*/
5251
_discoverBootstrapPeers () {
53-
this._list.forEach(async (candidate) => {
52+
this._list.forEach((candidate) => {
5453
if (!mafmt.P2P.matches(candidate)) {
5554
return log.error('Invalid multiaddr')
5655
}
@@ -60,9 +59,10 @@ class Bootstrap extends EventEmitter {
6059
const peerId = PeerId.createFromB58String(ma.getPeerId())
6160

6261
try {
63-
const peerInfo = await PeerInfo.create(peerId)
64-
peerInfo.multiaddrs.add(ma)
65-
this.emit('peer', peerInfo)
62+
this.emit('peer', {
63+
id: peerId,
64+
multiaddrs: [ma]
65+
})
6666
} catch (err) {
6767
log.error('Invalid bootstrap peer id', err)
6868
}

test/bootstrap.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const chai = require('chai')
55
chai.use(require('dirty-chai'))
66
const { expect } = chai
77

8+
const mafmt = require('mafmt')
9+
const PeerId = require('peer-id')
10+
811
const Bootstrap = require('../src')
912
const peerList = require('./default-peers')
1013
const partialValidPeerList = require('./some-invalid-peers')
11-
const mafmt = require('mafmt')
1214

1315
describe('bootstrap', () => {
1416
it('should throw if no peer list is provided', () => {
@@ -42,10 +44,11 @@ describe('bootstrap', () => {
4244
})
4345

4446
const p = new Promise((resolve) => {
45-
r.once('peer', (peer) => {
46-
const peerList = peer.multiaddrs.toArray()
47-
expect(peerList.length).to.eq(1)
48-
expect(mafmt.IPFS.matches(peerList[0].toString())).equals(true)
47+
r.once('peer', ({ id, multiaddrs }) => {
48+
expect(id).to.exist()
49+
expect(PeerId.isPeerId(id)).to.eql(true)
50+
expect(multiaddrs.length).to.eq(1)
51+
expect(mafmt.IPFS.matches(multiaddrs[0].toString())).equals(true)
4952
resolve()
5053
})
5154
})

0 commit comments

Comments
 (0)