diff --git a/src/topology/multicodec-topology.js b/src/topology/multicodec-topology.js index 5d72e73b2..5c1086ae9 100644 --- a/src/topology/multicodec-topology.js +++ b/src/topology/multicodec-topology.js @@ -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 diff --git a/src/topology/tests/multicodec-topology.js b/src/topology/tests/multicodec-topology.js index 96d245afb..bfb12f61a 100644 --- a/src/topology/tests/multicodec-topology.js +++ b/src/topology/tests/multicodec-topology.js @@ -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', { @@ -66,9 +67,9 @@ 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) @@ -76,6 +77,7 @@ module.exports = (test) => { 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,