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

feat: enable manual identify #1784

Merged
merged 12 commits into from
Jul 20, 2023
Merged

feat: enable manual identify #1784

merged 12 commits into from
Jul 20, 2023

Conversation

wemeetagain
Copy link
Member

@wemeetagain wemeetagain commented Jun 1, 2023

In some applications, automatically dialing identify is not desired, and more manual control is useful.

To that end, this PR contains two edits that act together

  • Add an additional identify init boolean option runOnConnectionOpen, which controls whether to listen to 'connection:open' events to trigger identify
  • Add a return value to the identify method

@maschad maschad requested a review from achingbrain June 1, 2023 19:23
Copy link
Member

@maschad maschad left a comment

Choose a reason for hiding this comment

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

I see the potential benefits of having more control over when streams are opened, but could you elaborate a bit more on your use case? I don't think this is in accordance with the spec since identify is used to inform known peers about changes which will happen whilst the node is running (which suggests it should always be run when opening a new connection).

@wemeetagain
Copy link
Member Author

The spec doesn't say anything about when the identify protocol should be dialed. I think the 'dial on connection open' behavior is just a common practice that is useful amd sufficient for most usecases. (Identify/push, a separate protocol, is used to inform peers about changes, but again, the spec gives no commands about when that protocol must or should be dialed)

In our usecase, we have another protocol that we want to dial first on connection open (We call it the 'status' protocol). Then depending on the result of that, either success or failure (note that failure can be failure to support that protocol, or responding to that protocol with a response that we don't like), the peer will either be disconnected or more protocols will be dialed, along with identify, which we use mainly for the agent version string.
We'd like to avoid the unnecessary identify in the case that the first protocol result is a failure.

@maschad
Copy link
Member

maschad commented Jun 2, 2023

The spec doesn't say anything about when the identify protocol should be dialed. I think the 'dial on connection open' behavior is just a common practice that is useful amd sufficient for most usecases. (Identify/push, a separate protocol, is used to inform peers about changes, but again, the spec gives no commands about when that protocol must or should be dialed)

That's true I do agree that the matter of when is more open to interpretation, so since this would be enabled by default this doesn't change anything functionally.

In our usecase, we have another protocol that we want to dial first on connection open (We call it the 'status' protocol). Then depending on the result of that, either success or failure (note that failure can be failure to support that protocol, or responding to that protocol with a response that we don't like), the peer will either be disconnected or more protocols will be dialed, along with identify, which we use mainly for the agent version string.
We'd like to avoid the unnecessary identify in the case that the first protocol result is a failure.

Thanks for explaining, I think this is reasonable.

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 in theory, though I fear people will call this function without specifying the only-run-manually config option which will lead to hard-to-predict stream closures due to the default stream limits so this introduces a bit of a foot gun.

This PR is missing tests, please can you add some to prevent future regressions.

src/identify/identify.ts Outdated Show resolved Hide resolved
src/identify/identify.ts Outdated Show resolved Hide resolved
@maschad maschad requested a review from achingbrain June 22, 2023 16:46
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.

Nearly there, just a few small things to address.

packages/libp2p/test/connection-manager/direct.spec.ts Outdated Show resolved Hide resolved
packages/libp2p/test/connection-manager/direct.spec.ts Outdated Show resolved Hide resolved
packages/libp2p/src/identify/index.ts Outdated Show resolved Hide resolved
packages/libp2p/src/identify/index.ts Outdated Show resolved Hide resolved
@maschad maschad requested a review from achingbrain June 28, 2023 20:32
@maschad maschad marked this pull request as draft July 4, 2023 21:22
@maschad maschad marked this pull request as ready for review July 4, 2023 23:19
@achingbrain achingbrain merged commit 06f4901 into master Jul 20, 2023
@achingbrain achingbrain deleted the feat/manual-identify branch July 20, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants