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

chore: refactor conn mgr and registrar #611

Merged
merged 2 commits into from
Apr 27, 2020

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Apr 19, 2020

This PR refactors the connectionManager and registrar, as both were keeping a record of the connection without a need for it.

Briefly, except for having connection kept only in the connectionManager, this PR moves the connection based events to into the connectionManager and adds the connectionManager API to the docs.

Previously, js-libp2p was emitting peer:connect and peer:disconnect with false positives. We could get cases where we have 2 connections to the same peer and both events where emitted as well for those cases. Moreover, as this PRs moves the events to the connectionManager, we can simplify a lot the upgrader handlers.

Instead of registrar, identify, metrics (and others in the future), need to keep track of the connections on the upgraders handler, now they can just rely on listening events of the connectionManager, making thinks simpler and more clear. In addition, when we support protocols such as QUIC (with a built in "upgrader"), the connections should need to be added to the connectionManager, in the same way as the upgrader does, without any need to provide the connection to the other components/subsystems (registrar. identify, metrics, ...).

Needs

@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch from 7432d59 to d7bbde6 Compare April 19, 2020 15:32
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch 3 times, most recently from 880b2fa to 8d6e211 Compare April 23, 2020 07:38
doc/API.md Outdated Show resolved Hide resolved
@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch 3 times, most recently from 64b9115 to a3cdc08 Compare April 24, 2020 14:34
@vasco-santos vasco-santos mentioned this pull request Apr 24, 2020
8 tasks
@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch from a3cdc08 to 49bfb49 Compare April 27, 2020 07:00
@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch from 49bfb49 to fdf31c9 Compare April 27, 2020 07:23
@vasco-santos vasco-santos marked this pull request as ready for review April 27, 2020 07:23
@vasco-santos vasco-santos mentioned this pull request Apr 27, 2020
2 tasks
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.

Just a few minor things

doc/API.md Outdated Show resolved Hide resolved
doc/API.md Outdated Show resolved Hide resolved
@@ -122,21 +172,63 @@ class ConnectionManager {
* @param {Connection} connection
*/
onConnect (connection) {
if (!Connection.isConnection(connection)) {
throw errcode(new Error('conn must be an instance of interface-connection'), ERR_INVALID_PARAMETERS)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

onConnect is an internal handler, we should avoid throwing errors as this is going to be fatal. Log and return instead.

@@ -45,16 +45,28 @@ class IdentifyService {
/**
* @constructor
* @param {object} options
* @param {Registrar} options.registrar
* @param {PeerStore} options.peerStore
* @param {ConnectionManager} options.connectionManager
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably just take libp2p, similar to the direction we're going with other services

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 am doing it in #612 . Can we wait for it instead?

@vasco-santos vasco-santos force-pushed the chore/refactor-conn-mgr-and-registrar branch from 1ac45cc to fb5252f Compare April 27, 2020 14:14
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.

LGTM

@vasco-santos vasco-santos merged commit e87b42b into 0.28.x Apr 27, 2020
@achingbrain achingbrain deleted the chore/refactor-conn-mgr-and-registrar branch May 18, 2023 13:39
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