diff --git a/Cargo.lock b/Cargo.lock index fdeada37500..ab11cfb6fdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3125,7 +3125,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.44.0" +version = "0.44.1" dependencies = [ "futures", "futures-timer", diff --git a/Cargo.toml b/Cargo.toml index 9e65d1ab62f..8c31a3d7da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ libp2p-stream = { version = "0.4.0-alpha", path = "protocols/stream" } libp2p-swarm = { version = "0.47.0", path = "swarm" } libp2p-swarm-derive = { version = "=0.35.1", 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.6.0", path = "swarm-test" } -libp2p-tcp = { version = "0.44.0", path = "transports/tcp" } +libp2p-tcp = { version = "0.44.1", path = "transports/tcp" } libp2p-tls = { version = "0.6.2", path = "transports/tls" } libp2p-uds = { version = "0.43.1", path = "transports/uds" } libp2p-upnp = { version = "0.6.0", path = "protocols/upnp" } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index fc5e869988f..c41d69b4992 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.44.1 +- Expose `socket2`'s `set_linger` config option. + See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/5955) + ## 0.44.0 - Remove `async-std` support. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index f04dab46f52..cbff8517593 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-tcp" edition.workspace = true rust-version = { workspace = true } description = "TCP/IP transport protocol for libp2p" -version = "0.44.0" +version = "0.44.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 5abce4acd19..3ead5338f70 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -59,6 +59,9 @@ pub struct Config { ttl: Option, /// `TCP_NODELAY` to set for opened sockets. nodelay: bool, + /// `SO_LINGER` to set for opened sockets, + /// by default is `None`. + linger: Option, /// Size of the listen backlog for listen sockets. backlog: u32, } @@ -137,6 +140,7 @@ impl Config { Self { ttl: None, nodelay: true, // Disable Nagle's algorithm by default. + linger: None, backlog: 1024, } } @@ -159,6 +163,12 @@ impl Config { self } + /// Configures the `SO_LINGER` option for new sockets. + pub fn linger(mut self, duration: Option) -> Self { + self.linger = duration; + self + } + /// Configures port reuse for local sockets, which implies /// reuse of listening ports for outgoing connections to /// enhance NAT traversal capabilities. @@ -196,6 +206,8 @@ impl Config { if let Some(ttl) = self.ttl { socket.set_ttl_v4(ttl)?; } + + socket.set_linger(self.linger)?; socket.set_tcp_nodelay(self.nodelay)?; socket.set_reuse_address(true)?; #[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))]