Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
chore: peer-discovery not using peer-info (#213)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: peer event emits with id and multiaddrs properties instead of peer-info
  • Loading branch information
vasco-santos authored Apr 21, 2020
1 parent 74be193 commit ab4aafe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const webrtcSupport = require('webrtcsupport')
const multiaddr = require('multiaddr')
const mafmt = require('mafmt')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')

const { CODE_CIRCUIT } = require('./constants')
const createListener = require('./listener')
Expand Down Expand Up @@ -233,9 +232,11 @@ class WebRTCStar {

const ma = multiaddr(maStr)
const peerId = PeerId.createFromB58String(ma.getPeerId())
const peerInfo = new PeerInfo(peerId)
peerInfo.multiaddrs.add(ma)
this.discovery.emit('peer', peerInfo)

this.discovery.emit('peer', {
id: peerId,
multiaddrs: [ma]
})
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,23 @@ describe('interface-transport compliance', function () {
})

describe('interface-discovery compliance', () => {
let intervalId

testsDiscovery({
setup () {
const mockUpgrader = {
upgradeInbound: maConn => maConn,
upgradeOutbound: maConn => maConn
}
const ws = new WStar({ upgrader: mockUpgrader, wrtc: wrtc })
const maStr = '/ip4/127.0.0.1/tcp/15555/ws/p2p-webrtc-star/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSooo2d'

intervalId = setInterval(() => ws._peerDiscovered(maStr), 1000)

return ws.discovery
},
teardown () {
clearInterval(intervalId)
}
})
})
4 changes: 2 additions & 2 deletions test/transport/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = (create) => {
ws2.discovery.start()

const p = new Promise((resolve) => {
ws1.discovery.once('peer', (peerInfo) => {
expect(peerInfo.multiaddrs.has(ws2._signallingAddr)).to.equal(true)
ws1.discovery.once('peer', ({ multiaddrs }) => {
expect(multiaddrs.some((m) => m.equals(ws2._signallingAddr))).to.equal(true)
resolve()
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/transport/reconnect.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = (create) => {
ws2 = await create()

const p = new Promise((resolve) => {
ws1.discovery.once('peer', (peerInfo) => {
expect(peerInfo.multiaddrs.has(ws2._signallingAddr)).to.equal(true)
ws1.discovery.once('peer', ({ multiaddrs }) => {
expect(multiaddrs.some((m) => m.equals(ws2._signallingAddr))).to.equal(true)
resolve()
})
})
Expand Down Expand Up @@ -71,8 +71,8 @@ module.exports = (create) => {
await listener.listen(signallerAddr)

await new Promise((resolve) => {
ws1.discovery.once('peer', (peerInfo) => {
expect(peerInfo.multiaddrs.has(ws3._signallingAddr)).to.equal(true)
ws1.discovery.once('peer', ({ multiaddrs }) => {
expect(multiaddrs.some((m) => m.equals(ws3._signallingAddr))).to.equal(true)
resolve()
})
})
Expand Down

0 comments on commit ab4aafe

Please sign in to comment.