From 63274b8c1134243b4c68671352c1cc847bc7ebb8 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sun, 15 May 2022 22:03:44 +1000 Subject: [PATCH 1/3] Remove the `StreamMuxer::flush_all` function `libp2p-core` provides the `StreamMuxer` abstraction so it can provide functionality that abstracts over this trait. We never use the `flush_all` function as part of our abstractions. No one else is going to use it so we can remove it from the abstraction. --- core/src/either.rs | 7 ------- core/src/muxing.rs | 17 ----------------- core/src/muxing/singleton.rs | 9 ++------- muxers/mplex/src/lib.rs | 4 ---- muxers/yamux/src/lib.rs | 4 ---- 5 files changed, 2 insertions(+), 39 deletions(-) diff --git a/core/src/either.rs b/core/src/either.rs index df7caf600bd..96180ee7e17 100644 --- a/core/src/either.rs +++ b/core/src/either.rs @@ -352,13 +352,6 @@ where EitherOutput::Second(inner) => inner.close(cx).map_err(|e| e.into()), } } - - fn flush_all(&self, cx: &mut Context<'_>) -> Poll> { - match self { - EitherOutput::First(inner) => inner.flush_all(cx).map_err(|e| e.into()), - EitherOutput::Second(inner) => inner.flush_all(cx).map_err(|e| e.into()), - } - } } #[derive(Debug, Copy, Clone)] diff --git a/core/src/muxing.rs b/core/src/muxing.rs index 12beb51d9dd..84fe8ada9c7 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -227,13 +227,6 @@ pub trait StreamMuxer { /// > properly informing the remote, there is no difference between this and /// > immediately dropping the muxer. fn close(&self, cx: &mut Context<'_>) -> Poll>; - - /// Flush this `StreamMuxer`. - /// - /// This drains any write buffers of substreams and delivers any pending shutdown notifications - /// due to `shutdown_substream` or `close`. One may thus shutdown groups of substreams - /// followed by a final `flush_all` instead of having to do `flush_substream` for each. - fn flush_all(&self, cx: &mut Context<'_>) -> Poll>; } /// Event about a connection, reported by an implementation of [`StreamMuxer`]. @@ -620,11 +613,6 @@ impl StreamMuxer for StreamMuxerBox { fn close(&self, cx: &mut Context<'_>) -> Poll> { self.inner.close(cx) } - - #[inline] - fn flush_all(&self, cx: &mut Context<'_>) -> Poll> { - self.inner.flush_all(cx) - } } struct Wrap @@ -761,9 +749,4 @@ where fn close(&self, cx: &mut Context<'_>) -> Poll> { self.inner.close(cx).map_err(|e| e.into()) } - - #[inline] - fn flush_all(&self, cx: &mut Context<'_>) -> Poll> { - self.inner.flush_all(cx).map_err(|e| e.into()) - } } diff --git a/core/src/muxing/singleton.rs b/core/src/muxing/singleton.rs index 749e9cd673e..cce0a6e3254 100644 --- a/core/src/muxing/singleton.rs +++ b/core/src/muxing/singleton.rs @@ -149,12 +149,7 @@ where fn destroy_substream(&self, _: Self::Substream) {} - fn close(&self, cx: &mut Context<'_>) -> Poll> { - // The `StreamMuxer` trait requires that `close()` implies `flush_all()`. - self.flush_all(cx) - } - - fn flush_all(&self, cx: &mut Context<'_>) -> Poll> { - AsyncWrite::poll_flush(Pin::new(&mut *self.inner.lock()), cx) + fn close(&self, _: &mut Context<'_>) -> Poll> { + Poll::Ready(Ok(())) } } diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index 0f8598c5eef..83756357909 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -172,10 +172,6 @@ where fn close(&self, cx: &mut Context<'_>) -> Poll> { self.io.lock().poll_close(cx) } - - fn flush_all(&self, cx: &mut Context<'_>) -> Poll> { - self.io.lock().poll_flush(cx) - } } /// Active attempt to open an outbound substream. diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 2ce0b065345..68354888c78 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -191,10 +191,6 @@ where } Poll::Pending } - - fn flush_all(&self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } } /// The yamux configuration. From c6acbd8e943fe18ce43e4e8209f974688fc2403e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 23 May 2022 10:22:58 +0200 Subject: [PATCH 2/3] Add changelog entry --- core/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 3a2cffea52a..b230f3776a0 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.33.0 [unreleased] - Have methods on `Transport` take `&mut self` instead of `self`. See [PR 2529]. +- Remove `StreamMuxer::flush_all` [PR 2529]: https://github.com/libp2p/rust-libp2p/pull/2529 From bfad916901eb6c2e39dfc83f27fe33cf91eb4730 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Sun, 29 May 2022 17:02:20 +0200 Subject: [PATCH 3/3] Update core/src/muxing/singleton.rs --- core/src/muxing/singleton.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/muxing/singleton.rs b/core/src/muxing/singleton.rs index 3f1e2b180d0..529fa147f9c 100644 --- a/core/src/muxing/singleton.rs +++ b/core/src/muxing/singleton.rs @@ -149,7 +149,7 @@ where fn destroy_substream(&self, _: Self::Substream) {} - fn poll_close(&self, cx: &mut Context<'_>) -> Poll> { + fn poll_close(&self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } }