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

Commit 0627fa1

Browse files
chore: apply suggestions from code review
Co-Authored-By: Jacob Heun <[email protected]>
1 parent 3daa016 commit 0627fa1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/topology/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Add a peer to the topology.
108108
- `topology.disconnect(peerId)`
109109

110110
**Parameters**
111-
- `peerId` is the [PeerIid][peer-id] of the peer disconnected.
111+
- `peerId` is the [PeerId][peer-id] of the peer disconnected.
112112

113113
### Multicodec Topology
114114

@@ -139,3 +139,5 @@ const toplogy = new MulticodecTopology({
139139
- `handlers` is an optional `Object` containing the handler called when a peer is connected or disconnected.
140140
- `onConnect` is a `function` called everytime a peer is connected in the topology context.
141141
- `onDisconnect` is a `function` called everytime a peer is disconnected in the topology context.
142+
143+
[peer-id]: https://github.com/libp2p/js-peer-id

src/topology/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ class Topology {
2626
this._onConnect = handlers.onConnect || noop
2727
this._onDisconnect = handlers.onDisconnect || noop
2828

29-
// TODO: can this be a set?
30-
this.peers = new Map()
29+
/**
30+
* Set of peers that support the protocol.
31+
* @type {Set<string>}
32+
*/
33+
this.peers = new Set()
3134
}
3235

3336
set registrar (registrar) {

src/topology/multicodec-topology.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class MulticodecTopology extends Topology {
5555

5656
/**
5757
* Update topology.
58-
* @param {Array<PeerData>} peerDataIterable
58+
* @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>}>} peerDataIterable
5959
* @returns {void}
6060
*/
6161
_updatePeers (peerDataIterable) {
6262
for (const peerData of peerDataIterable) {
6363
if (this.multicodecs.filter(multicodec => peerData.protocols.includes(multicodec)).length) {
6464
// Add the peer regardless of whether or not there is currently a connection
65-
this.peers.set(peerData.id.toB58String(), peerData.id)
65+
this.peers.add(peerData.id.toB58String())
6666
// If there is a connection, call _onConnect
6767
const connection = this._registrar.getConnection(peerData.id)
6868
connection && this._onConnect(peerData.id, connection)
@@ -80,7 +80,7 @@ class MulticodecTopology extends Topology {
8080
* @param {Array<string>} props.protocols
8181
*/
8282
_onProtocolChange ({ peerId, protocols }) {
83-
const existingPeer = this.peers.get(peerId.toB58String())
83+
const existingPeer = this.peers.has(peerId.toB58String())
8484
const hasProtocol = protocols.filter(protocol => this.multicodecs.includes(protocol))
8585

8686
// Not supporting the protocol anymore?

0 commit comments

Comments
 (0)