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
Changes from 1 commit
1425886
a98cf04
2c97c01
8c08b30
7a3fb18
2b187af
885a96b
baabefa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
/// A wrapper for an underlying [`ConnectionHandler`]. | ||
/// | ||
/// It extends [`ConnectionHandler`] with: | ||
|
@@ -243,6 +247,11 @@ where | |
) { | ||
match endpoint { | ||
SubstreamEndpoint::Listener => { | ||
if self.negotiating_in.len() == MAX_NUM_NEGOTIATING_IN { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this check here, we could create a wrapper around There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
log::warn!("Incoming substream exceeding `MAX_NUM_NEGOTIATING_IN`. Dropping.",); | ||
return; | ||
} | ||
|
||
let protocol = self.handler.listen_protocol(); | ||
let timeout = *protocol.timeout(); | ||
let (upgrade, user_data) = protocol.into_upgrade(); | ||
|
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.
How was this number chosen?