Commit 4b1bd7d6 authored by gabi-250's avatar gabi-250 🤸
Browse files

proto: Make the ClientDataStreamCtrl optional throughout

We will reuse `DataStream` for relay exit streams, and those aren't
going to have a `ClientDataStreamCtrl`.

Part of #2557
parent 7617442c
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -140,8 +140,10 @@ pub struct DataStream {
    r: DataReader,
    /// A control object that can be used to monitor and control this stream
    /// without needing to own it.
    ///
    /// Set to `None` if this is not a client stream.
    #[cfg(feature = "stream-ctrl")]
    ctrl: Arc<ClientDataStreamCtrl>,
    ctrl: Option<Arc<ClientDataStreamCtrl>>,
}
assert_impl_all! { DataStream: Send, Sync }

@@ -205,8 +207,10 @@ struct DataWriterInner {

    /// A control object that can be used to monitor and control this stream
    /// without needing to own it.
    ///
    /// Set to `None` if this is not a client stream.
    #[cfg(feature = "stream-ctrl")]
    ctrl: Arc<ClientDataStreamCtrl>,
    ctrl: Option<Arc<ClientDataStreamCtrl>>,
}

/// The write half of a [`DataStream`], implementing [`futures::io::AsyncWrite`].
@@ -292,9 +296,11 @@ impl DataWriter {

    /// Return a [`ClientDataStreamCtrl`] object that can be used to monitor and
    /// interact with this stream without holding the stream itself.
    ///
    /// Returns `None` if this is not a client stream.
    #[cfg(feature = "stream-ctrl")]
    pub fn client_stream_ctrl(&self) -> Option<&Arc<ClientDataStreamCtrl>> {
        Some(self.writer.inner().client_stream_ctrl())
        self.writer.inner().client_stream_ctrl()
    }
}

@@ -362,9 +368,11 @@ impl DataReader {

    /// Return a [`ClientDataStreamCtrl`] object that can be used to monitor and
    /// interact with this stream without holding the stream itself.
    ///
    /// Returns `None` if this is not a client stream.
    #[cfg(feature = "stream-ctrl")]
    pub fn client_stream_ctrl(&self) -> Option<&Arc<ClientDataStreamCtrl>> {
        Some(self.reader.inner().client_stream_ctrl())
        self.reader.inner().client_stream_ctrl()
    }
}

@@ -419,8 +427,10 @@ pub(crate) struct DataReaderInner {

    /// A control object that can be used to monitor and control this stream
    /// without needing to own it.
    ///
    /// Set to `None` if this is not a client stream.
    #[cfg(feature = "stream-ctrl")]
    ctrl: Arc<ClientDataStreamCtrl>,
    ctrl: Option<Arc<ClientDataStreamCtrl>>,
}

impl BufferIsEmpty for DataReaderInner {
@@ -605,11 +615,11 @@ impl DataStream {
                crate::stream::Tunnel::Relay(_) => panic!("created a relay tunnel in the client?!"),
            };

            Arc::new(ClientDataStreamCtrl {
            Some(Arc::new(ClientDataStreamCtrl {
                tunnel,
                status: status.clone(),
                _memquota: memquota.clone(),
            })
            }))
        };
        let r = DataReaderInner {
            state: Some(DataReaderState::Open(DataReaderImpl {
@@ -691,7 +701,7 @@ impl DataStream {
    /// interact with this stream without holding the stream itself.
    #[cfg(feature = "stream-ctrl")]
    pub fn client_stream_ctrl(&self) -> Option<&Arc<ClientDataStreamCtrl>> {
        Some(&self.ctrl)
        self.ctrl.as_ref()
    }
}

@@ -803,8 +813,8 @@ struct DataWriterImpl {
impl DataWriterInner {
    /// See [`DataWriter::client_stream_ctrl`].
    #[cfg(feature = "stream-ctrl")]
    fn client_stream_ctrl(&self) -> &Arc<ClientDataStreamCtrl> {
        &self.ctrl
    fn client_stream_ctrl(&self) -> Option<&Arc<ClientDataStreamCtrl>> {
        self.ctrl.as_ref()
    }

    /// Helper for poll_flush() and poll_close(): Performs a flush, then
@@ -991,8 +1001,8 @@ impl DataReaderInner {
    /// Return a [`ClientDataStreamCtrl`] object that can be used to monitor and
    /// interact with this stream without holding the stream itself.
    #[cfg(feature = "stream-ctrl")]
    pub(crate) fn client_stream_ctrl(&self) -> &Arc<ClientDataStreamCtrl> {
        &self.ctrl
    pub(crate) fn client_stream_ctrl(&self) -> Option<&Arc<ClientDataStreamCtrl>> {
        self.ctrl.as_ref()
    }
}