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

feat: topology #7

Merged
merged 6 commits into from
Nov 14, 2019
Merged

feat: topology #7

merged 6 commits into from
Nov 14, 2019

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Nov 7, 2019

Added topology interface


const assert = require('assert')

class Topology {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really isn't a base Topology, it's a MulticodecTopology which should extend a base. Not all topologies are going to care about multicodecs or protocol changes. Two immediate use cases that come to mind for Topologies are Priority Peers and Bootstrap Nodes, which I would categorize as a PeerSet Topology.

Let's say a js-ipfs browser node would like to stay connected to a Preload Node, QmPreload. Currently, libp2p doesn't handle that. What could happen, is a new PeerSet Topology could be created, which we should be able to achieve with the Base Topology.

const priorityTopology = new Topology()
priorityTopology.peers.set('QmPreload', preloadPeerInfo) // We could iterate over several peers.
priorityTopology.min = priorityTopology.peers.size // We want to be connected to all our peers

// ... registration

This same setup could be used for Bootstrap nodes, instead of it being a "discovery" service. The only difference is that the min can be 0, because we shouldn't really care if we're connected to them, as long as our node has at least ConnectionManager.min connections, which will be handled elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added multicodec-topology

* @param {Error} [error]
* @returns {void}
*/
disconnect (peerInfo, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your thought behind passing error here? I don't think we're propagating disconnect errors to the Registrar and I'm not sure they're needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for identifying if the disconnect was due to an error or not. I guess we can remove it until it can be useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we remove this and fill in the readme this should be gtg!

src/topology/multicodec-topology.js Outdated Show resolved Hide resolved
max = Infinity,
handlers
}) {
assert(handlers, 'the handlers should be provided')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we shouldn't require the handlers. Some topologies might not care, like the PeerSet Topologies. Multicodec needs them though. Maybe they should be required there and default to noop functions here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, I will do it

protocols: Array.from(topology.multicodecs)
})

await delay(500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the delays in this suite actually needed? I don't think the event emitter is async. If I am mistaken then delay(1) should be sufficient.

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some content suggestions, but otherwise this looks good

src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
src/topology/README.md Outdated Show resolved Hide resolved
- `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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's delete this section, I think the property overview is sufficient for now. Also, the Registrar is going to set topology.registrar on the base Topology as well during registration, every Topology will have that property once they've registered, so it might be good to add that to the Topology

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the section, added the set to the Topology and overwrite it in the MulticodecTopology

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
@jacobheun jacobheun merged commit 8bee747 into master Nov 14, 2019
@jacobheun jacobheun deleted the feat/topology branch November 14, 2019 10:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants