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

fix: emit peer:connect after all #1171

Merged
merged 3 commits into from
Apr 22, 2022

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Mar 18, 2022

Motivation

In lodestar, when we handle "peer:connect" event, we dial the peer which gives another "peer:connect" event and it causes other issues

Motivation

In onConnect function, "peer:connect" event should be emitted after we add connection to the connections map so that when app dial the peer in "peer:connect" event handler, it uses the same/existing connection

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

LGTM

@achingbrain
Copy link
Member

achingbrain commented Mar 18, 2022

This seems fine to me, and a better way to do it since libp2p should make sure it's internal tracking of connections/addresses/etc is done before informing the outside world a new peer has connected to us.

I'm a little confused though:

In lodestar, when we handle "peer:connect" event, we dial the peer

peer:connect occurs when a new connection to a peer has been created, e.g. either when we dial them or when they dial us - there's no need to dial them again in another 'peer:connect' handler since we already have a connection.

Would you not just open a protocol stream to the peer instead?

That aside, CI appears to be failing due to this change - could you please try running the tests locally and ensure they pass?

@twoeths
Copy link
Contributor Author

twoeths commented Mar 21, 2022

peer:connect occurs when a new connection to a peer has been created, e.g. either when we dial them or when they dial us - there's no need to dial them again in another 'peer:connect' handler since we already have a connection.

Would you not just open a protocol stream to the peer instead?

what we did is to issue a p2p request in lodestar, which does a dialProtocol() behind the scene in libp2p. Since the connection is not added, it'd try to open a new one, all of this logic happen in libp2p

That aside, CI appears to be failing due to this change - could you please try running the tests locally and ensure they pass?

thanks @achingbrain , this is fixed

@mpetrunic
Copy link
Member

Rebase, fix conflicts, add test and lgtm :)

@twoeths twoeths force-pushed the tuyen/peer-connect-event branch from 3899344 to 9687f5e Compare March 31, 2022 06:49
Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

LGTM, just needs some small improvements to the tests

@twoeths
Copy link
Contributor Author

twoeths commented Apr 20, 2022

thanks @achingbrain, this pEvent is super helpful! Could you help with the failed CI check? It's not related to the fix so I have no ideas.

@achingbrain
Copy link
Member

The error message is in the CI output:

[08:36:25] dependency-check (production only) [failed]
Command failed with exit code 1: dependency-check package.json src/**/*.js src/**/*.cjs dist/src/**/*.js utils/**/*.js utils/**/*.cjs --missing --no-dev -i @types/* -i @types/* --extensions cjs:detective-cjs --extensions js:detective-es6
Fail! Dependencies not listed in package.json: @libp2p/tracked-map, it-pair

Basically aegir has got better at spotting unused/missing deps. @libp2p/tracked-map and it-pair are production deps that are erroneously declared as development deps, they just need moving from the "devDependencies" block to the the "dependencies" block in the project's package.json file.

@twoeths twoeths force-pushed the tuyen/peer-connect-event branch from 51dda1e to 3852d69 Compare April 21, 2022 03:09
@achingbrain
Copy link
Member

Could you rebase/merge master into this branch? It should resolve the last few problems with the build.

@twoeths twoeths force-pushed the tuyen/peer-connect-event branch from 3852d69 to 2da9977 Compare April 22, 2022 01:24
@achingbrain
Copy link
Member

The fix for the final failing build job was merged as part of #1194 - this is good to go.

@achingbrain achingbrain merged commit d16817c into libp2p:master Apr 22, 2022
@achingbrain achingbrain changed the title Emit peer:connect after all fix: emit peer:connect after all Apr 22, 2022
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.

4 participants