fix: multicodec topology update peers with multicodec (#10)

This commit is contained in:
Vasco Santos 2019-11-15 14:48:43 +01:00 committed by Jacob Heun
parent 5969270ce6
commit 21d8ae6d96
2 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -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,