Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pubsub #467

Merged
merged 9 commits into from
Nov 15, 2019
Merged

refactor: pubsub #467

merged 9 commits into from
Nov 15, 2019

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Oct 23, 2019

This PR aims to add the pubsub subsystem into js-libp2p.

In order to make it possible, the peer-store was created, as well as the registrar.

The peer-store will replace peer-book, using the same name as go-libp2p, being this the initial step for libp2p/js-libp2p#453, as well as for the new version of peer-store, which we will be working on after the refactor.

The registrar aims to be a bridge between all subsystems and js-libp2p (peer-store + connection-manager). Before this refactor, js-libp2p subsystems like pubsub and dht were responsible for tracking new peers that appear in the network and try to dial them using their respective protocols. Other than that, each subsystem was responsible for managing the connections and dials they were doing. This way, we aim to centralize this logic and enable subsystems to only care about their work, and leave the dialing and connection management for who should take care of them. It is also important pointing out that this is the first step to enable us to enhance the connection-manager. More context on libp2p/notes#13

Needs:

package.json Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/peer-store.js Outdated Show resolved Hide resolved
src/peer-store.js Outdated Show resolved Hide resolved
src/peer-store.js Outdated Show resolved Hide resolved
src/peer-store.js Outdated Show resolved Hide resolved
src/peer-store.js Outdated Show resolved Hide resolved
src/registrar.js Outdated Show resolved Hide resolved
src/registrar.js Outdated Show resolved Hide resolved
src/registrar.js Outdated Show resolved Hide resolved

peers: promisify((topic, callback) => {
getPeersSubscribed: (topic) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would we ever have pubsub peers that aren't subscribed, if so, are those different? Just trying to get a better understanding of what this is expected to return. Might be good to add some jsdocs to the methods missing them.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can have peers connected with pubsub, but that did not subscribe the topic provided.

I will add jsdocs here and more concrete stuff like examples in the docs PR

test/pubsub/implementations.node.js Outdated Show resolved Hide resolved
test/pubsub/implementations.node.js Outdated Show resolved Hide resolved
test/pubsub/implementations.node.js Outdated Show resolved Hide resolved
test/pubsub/operation.node.js Outdated Show resolved Hide resolved
test/pubsub/operation.node.js Outdated Show resolved Hide resolved
test/pubsub/operation.node.js Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the refactor/pubsub branch 2 times, most recently from b48661e to 3355780 Compare November 14, 2019 15:13
})

// TODO: Needs identify push
describe.skip('pubsub started after connect', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This suite should be able to be run now.

}
throw new Error('should fail to register a protocol if the onDisconnect handler is not provided')
})
// TODO: not valid topology
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you want to add something for this?

src/upgrader.js Outdated
@@ -186,7 +186,7 @@ class Upgrader {
const { stream, protocol } = await mss.handle(Array.from(this.protocols.keys()))
log('%s: incoming stream opened on %s', direction, protocol)
connection.addStream(stream, protocol)
this._onStream({ connection, stream, protocol })
this._onStream({ connection, stream, protocol, remotePeer })
Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a need to pass the remotePeer, as it's on the connection, connection.remotePeer. Same with the other two changes below

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.

1 minor thing with the Topology check, otherwise this looks good

src/registrar.js Outdated
Comment on lines 114 to 117
assert(
Topology.isTopology(topology) ||
MulticodecTopology.isMulticodecTopology(topology),
'topology must be an instance of interfaces/topology')
Copy link
Contributor

Choose a reason for hiding this comment

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

is-class should handle the base class extension check, so we should just need to check that it is a Topology, Topology.isTopology(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.

Cool, that works :)

@vasco-santos vasco-santos force-pushed the refactor/pubsub branch 2 times, most recently from 1ca2d87 to b33aca0 Compare November 15, 2019 15:13
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.

🚀

@jacobheun jacobheun merged commit 392c440 into refactor/async-await Nov 15, 2019
@jacobheun jacobheun deleted the refactor/pubsub branch November 15, 2019 15:48
dirkmc pushed a commit that referenced this pull request Nov 26, 2019
* feat: peer-store v0

* chore: apply suggestions from code review

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

* chore: address review

* refactor: pubsub subsystem

* chore: address review

* chore: use topology interface

* chore: address review

* chore: address review

* chore: simplify tests
dirkmc pushed a commit that referenced this pull request Nov 26, 2019
* feat: peer-store v0

* chore: apply suggestions from code review

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

* chore: address review

* refactor: pubsub subsystem

* chore: address review

* chore: use topology interface

* chore: address review

* chore: address review

* chore: simplify tests
jacobheun pushed a commit that referenced this pull request Dec 12, 2019
* feat: peer-store v0

* chore: apply suggestions from code review

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

* chore: address review

* refactor: pubsub subsystem

* chore: address review

* chore: use topology interface

* chore: address review

* chore: address review

* chore: simplify tests
jacobheun pushed a commit that referenced this pull request Jan 24, 2020
* feat: peer-store v0

* chore: apply suggestions from code review

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

* chore: address review

* refactor: pubsub subsystem

* chore: address review

* chore: use topology interface

* chore: address review

* chore: address review

* chore: simplify tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants