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

Commit

Permalink
fix: multicodec topology update peers with multicodec (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and jacobheun committed Nov 15, 2019
1 parent 5969270 commit 21d8ae6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/topology/multicodec-topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MulticodecTopology extends Topology {
*/
_updatePeers (peerInfoIterable) {
for (const peerInfo of peerInfoIterable) {
if (this.multicodecs.filter(multicodec => peerInfo.protocols.has(multicodec))) {
if (this.multicodecs.filter(multicodec => peerInfo.protocols.has(multicodec)).length) {
// Add the peer regardless of whether or not there is currently a connection
this.peers.set(peerInfo.id.toB58String(), peerInfo)
// If there is a connection, call _onConnect
Expand Down
6 changes: 4 additions & 2 deletions src/topology/tests/multicodec-topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = (test) => {

const id2 = await PeerId.createFromJSON(peers[1])
const peer2 = await PeerInfo.create(id2)
topology.multicodecs.forEach((m) => peer2.protocols.add(m))

const peerStore = topology._registrar.peerStore
peerStore.emit('change:protocols', {
Expand All @@ -66,16 +67,17 @@ module.exports = (test) => {

const id2 = await PeerId.createFromJSON(peers[1])
const peer2 = await PeerInfo.create(id2)
const peerStore = topology._registrar.peerStore
topology.multicodecs.forEach((m) => peer2.protocols.add(m))

// Peer with the protocol
const peerStore = topology._registrar.peerStore
peerStore.emit('change:protocols', {
peerInfo: peer2,
protocols: Array.from(topology.multicodecs)
})

expect(topology.peers.size).to.eql(1)

topology.multicodecs.forEach((m) => peer2.protocols.delete(m))
// Peer does not support the protocol anymore
peerStore.emit('change:protocols', {
peerInfo: peer2,
Expand Down

0 comments on commit 21d8ae6

Please sign in to comment.