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

fix(tcp): make TCP_NODELAY actually the default #5764

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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 @@ -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" }
Expand Down
5 changes: 5 additions & 0 deletions transports/tcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion transports/tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
14 changes: 6 additions & 8 deletions transports/tcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
/// `TCP_NODELAY` to set for opened sockets, or `None` to keep default.
nodelay: Option<bool>,
/// `TCP_NODELAY` to set for opened sockets.
nodelay: bool,
/// Size of the listen backlog for listen sockets.
backlog: u32,
}
Expand Down Expand Up @@ -130,15 +130,15 @@ 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
/// [`Config::listen_backlog`].
pub fn new() -> Self {
Self {
ttl: None,
nodelay: Some(false), // Disable Nagle's algorithm by default
nodelay: true, // Disable Nagle's algorithm by default.
backlog: 1024,
}
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading