This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ Add a peer to the topology.
108
108
- ` topology.disconnect(peerId) `
109
109
110
110
** Parameters**
111
- - ` peerId ` is the [ PeerIid ] [ peer-id ] of the peer disconnected.
111
+ - ` peerId ` is the [ PeerId ] [ peer-id ] of the peer disconnected.
112
112
113
113
### Multicodec Topology
114
114
@@ -139,3 +139,5 @@ const toplogy = new MulticodecTopology({
139
139
- ` handlers ` is an optional ` Object ` containing the handler called when a peer is connected or disconnected.
140
140
- ` onConnect ` is a ` function ` called everytime a peer is connected in the topology context.
141
141
- ` 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
Original file line number Diff line number Diff line change @@ -26,8 +26,11 @@ class Topology {
26
26
this . _onConnect = handlers . onConnect || noop
27
27
this . _onDisconnect = handlers . onDisconnect || noop
28
28
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 ( )
31
34
}
32
35
33
36
set registrar ( registrar ) {
Original file line number Diff line number Diff line change @@ -55,14 +55,14 @@ class MulticodecTopology extends Topology {
55
55
56
56
/**
57
57
* Update topology.
58
- * @param {Array<PeerData > } peerDataIterable
58
+ * @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>} > } peerDataIterable
59
59
* @returns {void }
60
60
*/
61
61
_updatePeers ( peerDataIterable ) {
62
62
for ( const peerData of peerDataIterable ) {
63
63
if ( this . multicodecs . filter ( multicodec => peerData . protocols . includes ( multicodec ) ) . length ) {
64
64
// 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 ( ) )
66
66
// If there is a connection, call _onConnect
67
67
const connection = this . _registrar . getConnection ( peerData . id )
68
68
connection && this . _onConnect ( peerData . id , connection )
@@ -80,7 +80,7 @@ class MulticodecTopology extends Topology {
80
80
* @param {Array<string> } props.protocols
81
81
*/
82
82
_onProtocolChange ( { peerId, protocols } ) {
83
- const existingPeer = this . peers . get ( peerId . toB58String ( ) )
83
+ const existingPeer = this . peers . has ( peerId . toB58String ( ) )
84
84
const hasProtocol = protocols . filter ( protocol => this . multicodecs . includes ( protocol ) )
85
85
86
86
// Not supporting the protocol anymore?
You can’t perform that action at this time.
0 commit comments