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

Allow OneShotHandler's max_dial_negotiate limit to be configurable. #1936

Merged
merged 3 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions swarm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.27.1 [unreleased]

- Make `OneShotHandler`s `max_dial_negotiate` limit configurable.
[PR 1936](https://github.com/libp2p/rust-libp2p/pull/1936).

# 0.27.0 [2021-01-12]

- Update dependencies.
Expand Down
2 changes: 1 addition & 1 deletion swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.27.0"
version = "0.27.1"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
8 changes: 4 additions & 4 deletions swarm/src/protocols_handler/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ where
dial_queue: SmallVec<[TOutbound; 4]>,
/// Current number of concurrent outbound substreams being opened.
dial_negotiated: u32,
/// Maximum number of concurrent outbound substreams being opened. Value is never modified.
max_dial_negotiated: u32,
/// Value to return from `connection_keep_alive`.
keep_alive: KeepAlive,
/// The configuration container for the handler
Expand All @@ -71,7 +69,6 @@ where
events_out: SmallVec::new(),
dial_queue: SmallVec::new(),
dial_negotiated: 0,
max_dial_negotiated: 8,
keep_alive: KeepAlive::Yes,
config,
}
Expand Down Expand Up @@ -204,7 +201,7 @@ where
}

if !self.dial_queue.is_empty() {
if self.dial_negotiated < self.max_dial_negotiated {
if self.dial_negotiated < self.config.max_dial_negotiated {
self.dial_negotiated += 1;
let upgrade = self.dial_queue.remove(0);
return Poll::Ready(
Expand Down Expand Up @@ -233,13 +230,16 @@ pub struct OneShotHandlerConfig {
pub keep_alive_timeout: Duration,
/// Timeout for outbound substream upgrades.
pub outbound_substream_timeout: Duration,
/// Maximum number of concurrent outbound substreams being opened.
pub max_dial_negotiated: u32,
}

impl Default for OneShotHandlerConfig {
fn default() -> Self {
OneShotHandlerConfig {
keep_alive_timeout: Duration::from_secs(10),
outbound_substream_timeout: Duration::from_secs(10),
max_dial_negotiated: 8,
}
}
}
Expand Down