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

Merge branch 'stream-ctrl-opt' into 'main'

proto: Make the ClientDataStreamCtrl optional throughout

See merge request !4074
parents 7617442c 20eed1e8
Loading
Loading
Loading
Loading
Loading
+28 −16
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 {
@@ -600,16 +610,18 @@ impl DataStream {
        #[cfg(feature = "stream-ctrl")]
        let ctrl = {
            let tunnel = match target.tunnel() {
                crate::stream::Tunnel::Client(t) => Arc::downgrade(t),
                crate::stream::Tunnel::Client(t) => Some(Arc::downgrade(t)),
                #[cfg(feature = "relay")]
                crate::stream::Tunnel::Relay(_) => panic!("created a relay tunnel in the client?!"),
                crate::stream::Tunnel::Relay(_) => None,
            };

            tunnel.map(|tunnel| {
                Arc::new(ClientDataStreamCtrl {
                    tunnel,
                    status: status.clone(),
                    _memquota: memquota.clone(),
                })
            })
        };
        let r = DataReaderInner {
            state: Some(DataReaderState::Open(DataReaderImpl {
@@ -691,7 +703,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 +815,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 +1003,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()
    }
}

+0 −1
Original line number Diff line number Diff line
@@ -786,7 +786,6 @@ pub(crate) mod test {

    #[traced_test]
    #[test]
    #[ignore] // TODO(relay): Sad trombone, this is not yet supported
    fn data_stream() {
        tor_rtmock::MockRuntime::test_with_various(|rt| async move {
            const TO_SEND: &[u8] = b"The bells were musical in the silvery sun";