From 4c03ac98aef17aed81945f87342d4d12c33c0890 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Dec 2024 13:20:26 +0700 Subject: [PATCH 1/3] transports/tcp: Config.nodelay doesn't need to an Option --- transports/tcp/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index fefa18fb431..dd603b4eb8b 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -59,8 +59,8 @@ use socket2::{Domain, Socket, Type}; pub struct Config { /// TTL to set for opened sockets, or `None` to keep default. ttl: Option, - /// `TCP_NODELAY` to set for opened sockets, or `None` to keep default. - nodelay: Option, + /// `TCP_NODELAY` to set for opened sockets. + nodelay: bool, /// Size of the listen backlog for listen sockets. backlog: u32, } @@ -138,7 +138,7 @@ impl Config { pub fn new() -> Self { Self { ttl: None, - nodelay: Some(false), // Disable Nagle's algorithm by default + nodelay: false, // Disable Nagle's algorithm by default backlog: 1024, } } @@ -151,7 +151,7 @@ impl Config { /// Configures the `TCP_NODELAY` option for new sockets. pub fn nodelay(mut self, value: bool) -> Self { - self.nodelay = Some(value); + self.nodelay = value; self } @@ -198,9 +198,7 @@ impl Config { if let Some(ttl) = self.ttl { socket.set_ttl(ttl)?; } - if let Some(nodelay) = self.nodelay { - socket.set_nodelay(nodelay)?; - } + socket.set_nodelay(self.nodelay)?; socket.set_reuse_address(true)?; #[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))] if port_use == PortUse::Reuse { From 86c1e5da0c3f667922944421c7033304e1ca30a8 Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Dec 2024 13:23:03 +0700 Subject: [PATCH 2/3] transports/tcp: make TCP_NODELAY the default --- transports/tcp/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index dd603b4eb8b..7eb25c81e92 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -130,7 +130,7 @@ impl PortReuse { impl Config { /// Creates a new configuration for a TCP/IP transport: /// - /// * Nagle's algorithm, i.e. `TCP_NODELAY`, is _enabled_. See [`Config::nodelay`]. + /// * Nagle's algorithm is _disabled_, i.e. `TCP_NODELAY` _enabled_. See [`Config::nodelay`]. /// * Reuse of listening ports is _disabled_. See [`Config::port_reuse`]. /// * No custom `IP_TTL` is set. The default of the OS TCP stack applies. See [`Config::ttl`]. /// * The size of the listen backlog for new listening sockets is `1024`. See @@ -138,7 +138,7 @@ impl Config { pub fn new() -> Self { Self { ttl: None, - nodelay: false, // Disable Nagle's algorithm by default + nodelay: true, // Disable Nagle's algorithm by default. backlog: 1024, } } From 9b8c8806ff3bb3a0502e99581d9b7d317995437e Mon Sep 17 00:00:00 2001 From: Elena Frank Date: Wed, 25 Dec 2024 13:42:37 +0700 Subject: [PATCH 3/3] transports/tcp: bump version, add CHANGELOG entry --- Cargo.lock | 2 +- Cargo.toml | 2 +- transports/tcp/CHANGELOG.md | 5 +++++ transports/tcp/Cargo.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 308c3c45e5c..77fddee1d28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3351,7 +3351,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.42.0" +version = "0.42.1" dependencies = [ "async-io", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 4e0652ce3d0..59b280d12db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,7 @@ libp2p-stream = { version = "0.2.0-alpha.1", path = "protocols/stream" } libp2p-swarm = { version = "0.45.2", path = "swarm" } libp2p-swarm-derive = { version = "=0.35.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. libp2p-swarm-test = { version = "0.5.0", path = "swarm-test" } -libp2p-tcp = { version = "0.42.0", path = "transports/tcp" } +libp2p-tcp = { version = "0.42.1", path = "transports/tcp" } libp2p-tls = { version = "0.5.0", path = "transports/tls" } libp2p-uds = { version = "0.41.0", path = "transports/uds" } libp2p-upnp = { version = "0.3.1", path = "protocols/upnp" } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index 107d0d13ece..6d9c51b45be 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.42.1 + +- Fix the disabling of Nagle's algorithm, which requires setting `TCP_NODELAY` to _true_. + See [PR 5764](https://github.com/libp2p/rust-libp2p/pull/5764) + ## 0.42.0 - Implement refactored `Transport`. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index baa3b2f46dd..279d57af706 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-tcp" edition = "2021" rust-version = { workspace = true } description = "TCP/IP transport protocol for libp2p" -version = "0.42.0" +version = "0.42.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p"