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

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
vasco-santos and jacobheun committed Nov 13, 2019
1 parent ed5e24c commit 8d509fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/topology/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface-topology

> Implementation of the topology interface used by the `js-libp2p` registrar.
This interface has two main purposes. It uniforms the registration of libp2p protocols and enables a smarter connection management.
Topologies can be used in conjunction with `js-libp2p` to help shape its network and the overlays of its subsystems, such as pubsub and the DHT.

## Table of Contents

Expand Down Expand Up @@ -60,9 +60,6 @@ const toplogy = new MulticodecTopology({
onDisconnect: (peerInfo) => {}
}
})

// Needs to set registrar in order to listen for peer changes
topology.registrar = registrar
```

## API
Expand All @@ -72,8 +69,8 @@ The `MulticodecTopology` extends the `Topology`, which makes the `Topology` API
### Topology

- `Topology`
- `peers.set<function(id, PeerInfo)>`: Sets a peer in the topology.
- `disconnect<function(PeerInfo)>`: Disconnects a peer from the topology.
- `peers<Map<string, PeerInfo>>`: A Map of peers belonging to the topology.
- `disconnect<function(PeerInfo)>`: Called when a peer has been disconnected

#### Constructor

Expand Down Expand Up @@ -103,7 +100,7 @@ const toplogy = new Topology({
Add a peer to the topology.

**Parameters**
- `id` is the `b58string` that identifies the peer to add.
- `id` is the `string` that identifies the peer to add.
- `peerInfo` is the [PeerInfo][peer-info] of the peer to add.

#### Notify about a peer disconnected event
Expand All @@ -116,8 +113,8 @@ Add a peer to the topology.
### Multicodec Topology

- `MulticodecTopology`
- `registrar<Registrar>`: Sets the registrar in the topology.
- `peers.set<function(id, PeerInfo)>`: Sets a peer in the topology.
- `registrar<Registrar>`: The `Registrar` of the topology. This is set by the `Registrar` during registration.
- `peers<Map<string, PeerInfo>>`: The Map of peers that belong to the topology
- `disconnect<function(PeerInfo)>`: Disconnects a peer from the topology.

#### Constructor
Expand All @@ -142,9 +139,3 @@ const toplogy = new MulticodecTopology({
- `handlers` is an optional `Object` containing the handler called when a peer is connected or disconnected.
- `onConnect` is a `function` called everytime a peer is connected in the topology context.
- `onDisconnect` is a `function` called everytime a peer is disconnected in the topology context.

#### Set the registrar

- `topology.registrar = registrar`

Set the registrar the topology, which will be used to gather information on peers being connected and disconnected, as well as their modifications in terms of supported protocols.
4 changes: 4 additions & 0 deletions src/topology/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Topology {
this.peers = new Map()
}

set registrar (registrar) {
this._registrar = registrar
}

/**
* Notify about peer disconnected event.
* @param {PeerInfo} peerInfo
Expand Down

0 comments on commit 8d509fb

Please sign in to comment.