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(SwarmBuilder): add with_connection_timeout method #5575

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ rust-version = "1.75.0"
asynchronous-codec = { version = "0.7.0" }
futures-bounded = { version = "0.2.4" }
futures-rustls = { version = "0.26.0", default-features = false }
libp2p = { version = "0.54.1", path = "libp2p" }
libp2p = { version = "0.54.2", path = "libp2p" }
libp2p-allow-block-list = { version = "0.4.1", path = "misc/allow-block-list" }
libp2p-autonat = { version = "0.13.0", path = "protocols/autonat" }
libp2p-connection-limits = { version = "0.4.0", path = "misc/connection-limits" }
Expand Down
5 changes: 5 additions & 0 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.54.2

- Add `with_connection_timeout` on `SwarmBuilder` to allow configuration of the connection_timeout parameter.
See [PR 5575](https://github.com/libp2p/rust-libp2p/pull/5575).

## 0.54.1

- Update individual crates.
Expand Down
2 changes: 1 addition & 1 deletion libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition = "2021"
rust-version = { workspace = true }
description = "Peer-to-peer networking library"
version = "0.54.1"
version = "0.54.2"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
20 changes: 13 additions & 7 deletions libp2p/src/builder/phase/build.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
use std::time::Duration;

#[allow(unused_imports)]
use super::*;

use crate::SwarmBuilder;
use libp2p_core::Transport;
use libp2p_core::{transport::timeout::TransportTimeout, Transport};
use libp2p_swarm::Swarm;

pub struct BuildPhase<T, B> {
pub(crate) behaviour: B,
pub(crate) transport: T,
pub(crate) swarm_config: libp2p_swarm::Config,
pub(crate) connection_timeout: Duration,
}

const CONNECTION_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
#[allow(unused)] // used in `../swarm.rs` but due to feature flag combinations, clippy gives an unnecessary warning.
pub(crate) const DEFAULT_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);
stormshield-frb marked this conversation as resolved.
Show resolved Hide resolved

impl<Provider, T: AuthenticatedMultiplexedTransport, B: libp2p_swarm::NetworkBehaviour>
SwarmBuilder<Provider, BuildPhase<T, B>>
{
/// Timeout of the [`TransportTimeout`] wrapping the transport.
pub fn with_connection_timeout(mut self, connection_timeout: Duration) -> Self {
self.phase.connection_timeout = connection_timeout;
self
}

pub fn build(self) -> Swarm<B> {
Swarm::new(
libp2p_core::transport::timeout::TransportTimeout::new(
self.phase.transport,
CONNECTION_TIMEOUT,
)
.boxed(),
TransportTimeout::new(self.phase.transport, self.phase.connection_timeout).boxed(),
self.phase.behaviour,
self.keypair.public().to_peer_id(),
self.phase.swarm_config,
Expand Down
1 change: 1 addition & 0 deletions libp2p/src/builder/phase/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ macro_rules! impl_with_swarm_config {
behaviour: self.phase.behaviour,
transport: self.phase.transport,
swarm_config: constructor($config),
connection_timeout: DEFAULT_CONNECTION_TIMEOUT,
},
keypair: self.keypair,
phantom: std::marker::PhantomData,
Expand Down
Loading