Skip to content

Commit ba8da16

Browse files
authored
fix(tcp): make TCP_NODELAY actually the default
Nagle's algorithm is actually disabled by setting `TCP_NODELAY` to _true_. In the current master, it is set to _false_, i.e. Nagle's algorithm is enabled. This PR sets `TCP_NODELAY` per default to `true` and fixes the description of `tcp::Config::new`. Fixes #4890. Pull-Request: #5764.
1 parent a8b7e0e commit ba8da16

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ libp2p-stream = { version = "0.2.0-alpha.1", path = "protocols/stream" }
103103
libp2p-swarm = { version = "0.45.2", path = "swarm" }
104104
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.
105105
libp2p-swarm-test = { version = "0.5.0", path = "swarm-test" }
106-
libp2p-tcp = { version = "0.42.0", path = "transports/tcp" }
106+
libp2p-tcp = { version = "0.42.1", path = "transports/tcp" }
107107
libp2p-tls = { version = "0.5.0", path = "transports/tls" }
108108
libp2p-uds = { version = "0.41.0", path = "transports/uds" }
109109
libp2p-upnp = { version = "0.3.1", path = "protocols/upnp" }

transports/tcp/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.42.1
2+
3+
- Fix the disabling of Nagle's algorithm, which requires setting `TCP_NODELAY` to _true_.
4+
See [PR 5764](https://github.com/libp2p/rust-libp2p/pull/5764)
5+
16
## 0.42.0
27

38
- Implement refactored `Transport`.

transports/tcp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-tcp"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "TCP/IP transport protocol for libp2p"
6-
version = "0.42.0"
6+
version = "0.42.1"
77
authors = ["Parity Technologies <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

transports/tcp/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ use socket2::{Domain, Socket, Type};
5959
pub struct Config {
6060
/// TTL to set for opened sockets, or `None` to keep default.
6161
ttl: Option<u32>,
62-
/// `TCP_NODELAY` to set for opened sockets, or `None` to keep default.
63-
nodelay: Option<bool>,
62+
/// `TCP_NODELAY` to set for opened sockets.
63+
nodelay: bool,
6464
/// Size of the listen backlog for listen sockets.
6565
backlog: u32,
6666
}
@@ -130,15 +130,15 @@ impl PortReuse {
130130
impl Config {
131131
/// Creates a new configuration for a TCP/IP transport:
132132
///
133-
/// * Nagle's algorithm, i.e. `TCP_NODELAY`, is _enabled_. See [`Config::nodelay`].
133+
/// * Nagle's algorithm is _disabled_, i.e. `TCP_NODELAY` _enabled_. See [`Config::nodelay`].
134134
/// * Reuse of listening ports is _disabled_. See [`Config::port_reuse`].
135135
/// * No custom `IP_TTL` is set. The default of the OS TCP stack applies. See [`Config::ttl`].
136136
/// * The size of the listen backlog for new listening sockets is `1024`. See
137137
/// [`Config::listen_backlog`].
138138
pub fn new() -> Self {
139139
Self {
140140
ttl: None,
141-
nodelay: Some(false), // Disable Nagle's algorithm by default
141+
nodelay: true, // Disable Nagle's algorithm by default.
142142
backlog: 1024,
143143
}
144144
}
@@ -151,7 +151,7 @@ impl Config {
151151

152152
/// Configures the `TCP_NODELAY` option for new sockets.
153153
pub fn nodelay(mut self, value: bool) -> Self {
154-
self.nodelay = Some(value);
154+
self.nodelay = value;
155155
self
156156
}
157157

@@ -198,9 +198,7 @@ impl Config {
198198
if let Some(ttl) = self.ttl {
199199
socket.set_ttl(ttl)?;
200200
}
201-
if let Some(nodelay) = self.nodelay {
202-
socket.set_nodelay(nodelay)?;
203-
}
201+
socket.set_nodelay(self.nodelay)?;
204202
socket.set_reuse_address(true)?;
205203
#[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))]
206204
if port_use == PortUse::Reuse {

0 commit comments

Comments
 (0)