-
Notifications
You must be signed in to change notification settings - Fork 446
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
Conversation
7432d59
to
d7bbde6
Compare
880b2fa
to
8d6e211
Compare
64b9115
to
a3cdc08
Compare
a3cdc08
to
49bfb49
Compare
49bfb49
to
fdf31c9
Compare
There was a problem hiding this 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
src/connection-manager/index.js
Outdated
@@ -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) | |||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Co-Authored-By: Jacob Heun <[email protected]>
1ac45cc
to
fb5252f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR refactors the
connectionManager
andregistrar
, 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 theconnectionManager
and adds theconnectionManager
API to the docs.Previously,
js-libp2p
was emittingpeer:connect
andpeer: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 theconnectionManager
, we can simplify a lot theupgrader
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 theconnectionManager
, 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 theconnectionManager
, in the same way as the upgrader does, without any need to provide the connection to the other components/subsystems (registrar
.identify
,metrics
, ...).Needs