Navigation Menu

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

swarm/: Limit negotiating inbound substreams per connection #2697

Merged
merged 8 commits into from Jun 8, 2022

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Jun 7, 2022

Description

This limit is shared across all ConnectionHandlers on a single connection. It
only enforces a limit on the number of negotiating substreams. Once negotiated a
ConnectionHandler manages the lifecycle of the substream and has to enforce
limits themselves.

Links to any relevant issues

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

This limit is shared across all `ConnectionHandler`s on a single connection. It
only enforces a limit on the number of negotiating substreams. Once negotiated a
`ConnectionHandler` manages the lifecycle of the substream and has to enforce
limits themselves.
@@ -243,6 +247,11 @@ where
) {
match endpoint {
SubstreamEndpoint::Listener => {
if self.negotiating_in.len() == MAX_NUM_NEGOTIATING_IN {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this check here, we could create a wrapper around FuturesUnordered that enforces a limit on the number of concurrent futures. This would foster reuse and actually enforce this limit. At the moment, there is a risk that this check is circumvented in case the FuturesUnordered is modified in a different place without this check.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 for the reusable abstraction, though I would much rather like to remove the entire upgrade mechanism for substreams in the future.

swarm/src/connection/handler_wrapper.rs Outdated Show resolved Hide resolved
@@ -35,6 +35,10 @@ use libp2p_core::{
};
use std::{error, fmt, pin::Pin, task::Context, task::Poll, time::Duration};

/// The maximum number of incoming streams concurrently negotiated. Streams are
/// dropped and thus reset.
const MAX_NUM_NEGOTIATING_IN: usize = 128;
Copy link
Contributor

Choose a reason for hiding this comment

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

How was this number chosen?

Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Lgtm!

swarm/CHANGELOG.md Outdated Show resolved Hide resolved
@mxinden mxinden merged commit 2acbb45 into libp2p:master Jun 8, 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.

None yet

3 participants