From 5f1180e0113fa71a99126fefdc58eabb0b9b16dd Mon Sep 17 00:00:00 2001 From: ftaft Date: Fri, 17 Jun 2022 08:28:30 +0800 Subject: [PATCH 1/2] bugfix issue 195 --- src/sctp_transport/mod.rs | 34 +++++++++++++++------- src/sctp_transport/sctp_transport_state.rs | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/sctp_transport/mod.rs b/src/sctp_transport/mod.rs index fb27b26c9..0a804603a 100644 --- a/src/sctp_transport/mod.rs +++ b/src/sctp_transport/mod.rs @@ -64,7 +64,9 @@ pub struct RTCSctpTransport { pub(crate) dtls_transport: Arc, // State represents the current state of the SCTP transport. - state: AtomicU8, //SCTPTransportState, + + // bugfix@Udp connection not close (reopen #174) #195 + state: AtomicU8, // RTCSctpTransportState // SCTPTransportState doesn't have an enum to distinguish between New/Connecting // so we need a dedicated field @@ -145,15 +147,27 @@ impl RTCSctpTransport { let dtls_transport = self.transport(); if let Some(net_conn) = &dtls_transport.conn().await { - let sctp_association = Arc::new( - sctp::association::Association::client(sctp::association::Config { - net_conn: Arc::clone(net_conn) as Arc, - max_receive_buffer_size: 0, - max_message_size: 0, - name: String::new(), - }) - .await?, - ); + // bugfix@Udp connection not close (reopen #174) #195 + let sctp_association = loop { + tokio::select! { + _ = self.notify_tx.notified() => { + // It seems like notify_tx is only notified on Stop so perhaps this check + // is redundant. + // TODO: Consider renaming notify_tx to shutdown_tx. + if self.state.load(Ordering::SeqCst) == RTCSctpTransportState::Closed as u8 { + return Err(Error::ErrSCTPTransportDTLS); + } + }, + association = sctp::association::Association::client(sctp::association::Config { + net_conn: Arc::clone(net_conn) as Arc, + max_receive_buffer_size: 0, + max_message_size: 0, + name: String::new(), + }) => { + break Arc::new(association?); + } + }; + }; { let mut sa = self.sctp_association.lock().await; diff --git a/src/sctp_transport/sctp_transport_state.rs b/src/sctp_transport/sctp_transport_state.rs index f27f29ebe..18c3f11d3 100644 --- a/src/sctp_transport/sctp_transport_state.rs +++ b/src/sctp_transport/sctp_transport_state.rs @@ -2,6 +2,7 @@ use std::fmt; /// SCTPTransportState indicates the state of the SCTP transport. #[derive(Debug, Copy, Clone, PartialEq)] +#[repr(u8)] // bugfix@Udp connection not close (reopen #174) #195 pub enum RTCSctpTransportState { Unspecified, From 66138d345a6041da4216121cae7f07949d43ca35 Mon Sep 17 00:00:00 2001 From: ftaft Date: Mon, 20 Jun 2022 15:15:53 +0800 Subject: [PATCH 2/2] bugfix@Udp connection not close (reopen #174) #195 --- src/sctp_transport/mod.rs | 3 --- src/sctp_transport/sctp_transport_state.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/sctp_transport/mod.rs b/src/sctp_transport/mod.rs index 0a804603a..a1b8342fb 100644 --- a/src/sctp_transport/mod.rs +++ b/src/sctp_transport/mod.rs @@ -64,8 +64,6 @@ pub struct RTCSctpTransport { pub(crate) dtls_transport: Arc, // State represents the current state of the SCTP transport. - - // bugfix@Udp connection not close (reopen #174) #195 state: AtomicU8, // RTCSctpTransportState // SCTPTransportState doesn't have an enum to distinguish between New/Connecting @@ -147,7 +145,6 @@ impl RTCSctpTransport { let dtls_transport = self.transport(); if let Some(net_conn) = &dtls_transport.conn().await { - // bugfix@Udp connection not close (reopen #174) #195 let sctp_association = loop { tokio::select! { _ = self.notify_tx.notified() => { diff --git a/src/sctp_transport/sctp_transport_state.rs b/src/sctp_transport/sctp_transport_state.rs index 18c3f11d3..67378eabc 100644 --- a/src/sctp_transport/sctp_transport_state.rs +++ b/src/sctp_transport/sctp_transport_state.rs @@ -2,7 +2,7 @@ use std::fmt; /// SCTPTransportState indicates the state of the SCTP transport. #[derive(Debug, Copy, Clone, PartialEq)] -#[repr(u8)] // bugfix@Udp connection not close (reopen #174) #195 +#[repr(u8)] pub enum RTCSctpTransportState { Unspecified,