Skip to content

Commit

Permalink
Allow OneShotHandler's max_dial_negotiate limit to be configurable. (
Browse files Browse the repository at this point in the history
…#1936)

* Allow OneShotHandler's `max_dial_negotiate` limit to be configurable.

* Update version and CHANGELOG.,

Co-authored-by: Roman S. Borschel <roman@parity.io>
Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 27, 2021
1 parent ac97982 commit 8aeb7b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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 <admin@parity.io>"]
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

0 comments on commit 8aeb7b3

Please sign in to comment.