mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-03-16 13:50:50 +00:00
fix: multicodec topology update peers with multicodec (#10)
This commit is contained in:
parent
5969270ce6
commit
21d8ae6d96
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user