From 4d1a998cd79c12fafbcc10ecebbe50a7282deddc Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 19 Jun 2020 11:15:46 +0200 Subject: [PATCH] Deprecate StreamMuxer::is_remote_acknowledged --- core/src/connection.rs | 8 -------- core/src/connection/substream.rs | 7 ------- core/src/either.rs | 7 ------- core/src/muxing.rs | 18 +++++------------- core/src/muxing/singleton.rs | 13 +------------ muxers/mplex/src/lib.rs | 8 -------- muxers/yamux/src/lib.rs | 13 +------------ 7 files changed, 7 insertions(+), 67 deletions(-) diff --git a/core/src/connection.rs b/core/src/connection.rs index 82747f602b1..deaa272a7e0 100644 --- a/core/src/connection.rs +++ b/core/src/connection.rs @@ -230,14 +230,6 @@ where self.handler.inject_event(event); } - /// Returns `true` if the remote has shown any sign of activity - /// since the connection has been established. - /// - /// See also [`StreamMuxer::is_remote_acknowledged`]. - pub fn is_remote_acknowledged(&self) -> bool { - self.muxing.is_remote_acknowledged() - } - /// Begins an orderly shutdown of the connection, returning a /// `Future` that resolves when connection shutdown is complete. pub fn close(self) -> Close { diff --git a/core/src/connection/substream.rs b/core/src/connection/substream.rs index f496e43a5f1..6dcaa875143 100644 --- a/core/src/connection/substream.rs +++ b/core/src/connection/substream.rs @@ -123,13 +123,6 @@ where self.outbound_substreams.push((user_data, raw)); } - /// Returns `true` if the remote has shown any sign of activity after the muxer has been open. - /// - /// See `StreamMuxer::is_remote_acknowledged`. - pub fn is_remote_acknowledged(&self) -> bool { - self.inner.is_remote_acknowledged() - } - /// Destroys the node stream and returns all the pending outbound substreams, plus an object /// that signals the remote that we shut down the connection. #[must_use] diff --git a/core/src/either.rs b/core/src/either.rs index e5052b79819..1db0980f245 100644 --- a/core/src/either.rs +++ b/core/src/either.rs @@ -297,13 +297,6 @@ where } } - fn is_remote_acknowledged(&self) -> bool { - match self { - EitherOutput::First(inner) => inner.is_remote_acknowledged(), - EitherOutput::Second(inner) => inner.is_remote_acknowledged() - } - } - fn close(&self, cx: &mut Context) -> Poll> { match self { EitherOutput::First(inner) => inner.close(cx).map_err(|e| e.into()), diff --git a/core/src/muxing.rs b/core/src/muxing.rs index 64a93051baa..1a83d585f3b 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -64,8 +64,7 @@ mod singleton; /// /// The state of a muxer, as exposed by this API, is the following: /// -/// - A connection to the remote. The `is_remote_acknowledged`, `flush_all` and `close` methods -/// operate on this. +/// - A connection to the remote. The `flush_all` and `close` methods operate on this. /// - A list of substreams that are open. The `poll_inbound`, `poll_outbound`, `read_substream`, /// `write_substream`, `flush_substream`, `shutdown_substream` and `destroy_substream` methods /// allow controlling these entries. @@ -180,7 +179,10 @@ pub trait StreamMuxer { /// allowed to assume that the handshake has succeeded when it didn't in fact succeed. This /// method can be called in order to determine whether the remote has accepted our handshake or /// has potentially not received it yet. - fn is_remote_acknowledged(&self) -> bool; + #[deprecated(note = "This method is unused and will be removed in the future")] + fn is_remote_acknowledged(&self) -> bool { + true + } /// Closes this `StreamMuxer`. /// @@ -525,11 +527,6 @@ impl StreamMuxer for StreamMuxerBox { self.inner.close(cx) } - #[inline] - fn is_remote_acknowledged(&self) -> bool { - self.inner.is_remote_acknowledged() - } - #[inline] fn flush_all(&self, cx: &mut Context) -> Poll> { self.inner.flush_all(cx) @@ -631,11 +628,6 @@ where self.inner.close(cx).map_err(|e| e.into()) } - #[inline] - fn is_remote_acknowledged(&self) -> bool { - self.inner.is_remote_acknowledged() - } - #[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 bc2521ad21e..75694ec931a 100644 --- a/core/src/muxing/singleton.rs +++ b/core/src/muxing/singleton.rs @@ -35,8 +35,6 @@ pub struct SingletonMuxer { substream_extracted: AtomicBool, /// Our local endpoint. Always the same value as was passed to `new`. endpoint: Endpoint, - /// If true, we have received data from the remote. - remote_acknowledged: AtomicBool, } impl SingletonMuxer { @@ -49,7 +47,6 @@ impl SingletonMuxer { inner: Mutex::new(inner), substream_extracted: AtomicBool::new(false), endpoint, - remote_acknowledged: AtomicBool::new(false), } } } @@ -101,11 +98,7 @@ where } fn read_substream(&self, cx: &mut Context, _: &mut Self::Substream, buf: &mut [u8]) -> Poll> { - let res = AsyncRead::poll_read(Pin::new(&mut *self.inner.lock()), cx, buf); - if let Poll::Ready(Ok(_)) = res { - self.remote_acknowledged.store(true, Ordering::Release); - } - res + AsyncRead::poll_read(Pin::new(&mut *self.inner.lock()), cx, buf) } fn write_substream(&self, cx: &mut Context, _: &mut Self::Substream, buf: &[u8]) -> Poll> { @@ -123,10 +116,6 @@ where fn destroy_substream(&self, _: Self::Substream) { } - fn is_remote_acknowledged(&self) -> bool { - self.remote_acknowledged.load(Ordering::Acquire) - } - fn close(&self, cx: &mut Context) -> Poll> { // The `StreamMuxer` trait requires that `close()` implies `flush_all()`. self.flush_all(cx) diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index d8350606888..ceb77f33bf1 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -110,7 +110,6 @@ impl MplexConfig { to_wake: Mutex::new(Default::default()), }), is_shutdown: false, - is_acknowledged: false, }) } } @@ -203,8 +202,6 @@ struct MultiplexInner { /// If true, the connection has been shut down. We need to be careful not to accidentally /// call `Sink::poll_complete` or `Sink::start_send` after `Sink::close`. is_shutdown: bool, - /// If true, the remote has sent data to us. - is_acknowledged: bool, } struct Notifier { @@ -295,7 +292,6 @@ where C: AsyncRead + AsyncWrite + Unpin, }; trace!("Received message: {:?}", elem); - inner.is_acknowledged = true; // Handle substreams opening/closing. match elem { @@ -587,10 +583,6 @@ where C: AsyncRead + AsyncWrite + Unpin }) } - fn is_remote_acknowledged(&self) -> bool { - self.inner.lock().is_acknowledged - } - fn close(&self, cx: &mut Context) -> Poll> { let inner = &mut *self.inner.lock(); if inner.is_shutdown { diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index fb25c803e4e..2b49dc6f312 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -43,8 +43,6 @@ struct Inner { incoming: S, /// Handle to control the connection. control: yamux::Control, - /// True, once we have received an inbound substream. - acknowledged: bool } /// A token to poll for an outbound substream. @@ -66,7 +64,6 @@ where _marker: std::marker::PhantomData }, control: ctrl, - acknowledged: false }; Yamux(Mutex::new(inner)) } @@ -87,7 +84,6 @@ where _marker: std::marker::PhantomData }, control: ctrl, - acknowledged: false }; Yamux(Mutex::new(inner)) } @@ -106,10 +102,7 @@ where fn poll_inbound(&self, c: &mut Context) -> Poll { let mut inner = self.0.lock(); match ready!(inner.incoming.poll_next_unpin(c)) { - Some(Ok(s)) => { - inner.acknowledged = true; - Poll::Ready(Ok(s)) - } + Some(Ok(s)) => Poll::Ready(Ok(s)), Some(Err(e)) => Poll::Ready(Err(e)), None => Poll::Ready(Err(yamux::ConnectionError::Closed.into())) } @@ -146,10 +139,6 @@ where fn destroy_substream(&self, _: Self::Substream) { } - fn is_remote_acknowledged(&self) -> bool { - self.0.lock().acknowledged - } - fn close(&self, c: &mut Context) -> Poll<()> { let mut inner = self.0.lock(); if let std::task::Poll::Ready(x) = Pin::new(&mut inner.control).poll_close(c) {