diff --git a/src/data_channel/data_channel_test.rs b/src/data_channel/data_channel_test.rs index 9b3ae0b..8763ea9 100644 --- a/src/data_channel/data_channel_test.rs +++ b/src/data_channel/data_channel_test.rs @@ -188,7 +188,8 @@ async fn pr_ordered_unordered_test(channel_type: ChannelType, is_ordered: bool) let dc0 = DataChannel::dial(&a0, 100, cfg.clone()).await?; bridge_process_at_least_one(&br).await; - let dc1 = DataChannel::accept(&a1, Config::default(), Vec::new()).await?; + let existing_data_channels: Vec = Vec::new(); + let dc1 = DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?; bridge_process_at_least_one(&br).await; assert_eq!(dc0.config, cfg, "local config should match"); @@ -274,7 +275,8 @@ async fn test_data_channel_channel_type_reliable_ordered() -> Result<()> { let dc0 = DataChannel::dial(&a0, 100, cfg.clone()).await?; bridge_process_at_least_one(&br).await; - let dc1 = DataChannel::accept(&a1, Config::default(), Vec::new()).await?; + let existing_data_channels: Vec = Vec::new(); + let dc1 = DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?; bridge_process_at_least_one(&br).await; assert_eq!(dc0.config, cfg, "local config should match"); @@ -336,7 +338,8 @@ async fn test_data_channel_channel_type_reliable_unordered() -> Result<()> { let dc0 = DataChannel::dial(&a0, 100, cfg.clone()).await?; bridge_process_at_least_one(&br).await; - let dc1 = DataChannel::accept(&a1, Config::default(), Vec::new()).await?; + let existing_data_channels: Vec = Vec::new(); + let dc1 = DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?; bridge_process_at_least_one(&br).await; assert_eq!(dc0.config, cfg, "local config should match"); @@ -434,7 +437,8 @@ async fn test_data_channel_buffered_amount() -> Result<()> { ); bridge_process_at_least_one(&br).await; - let dc1 = Arc::new(DataChannel::accept(&a1, Config::default(), Vec::new()).await?); + let existing_data_channels: Vec = Vec::new(); + let dc1 = Arc::new(DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?); bridge_process_at_least_one(&br).await; while dc0.buffered_amount() > 0 { @@ -535,7 +539,8 @@ async fn test_stats() -> Result<()> { let dc0 = DataChannel::dial(&a0, 100, cfg.clone()).await?; bridge_process_at_least_one(&br).await; - let dc1 = DataChannel::accept(&a1, Config::default(), Vec::new()).await?; + let existing_data_channels: Vec = Vec::new(); + let dc1 = DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?; bridge_process_at_least_one(&br).await; let mut bytes_sent = 0; @@ -628,7 +633,8 @@ async fn test_poll_data_channel() -> Result<()> { let dc0 = Arc::new(DataChannel::dial(&a0, 100, cfg.clone()).await?); bridge_process_at_least_one(&br).await; - let dc1 = Arc::new(DataChannel::accept(&a1, Config::default(), Vec::new()).await?); + let existing_data_channels: Vec = Vec::new(); + let dc1 = Arc::new(DataChannel::accept(&a1, Config::default(), &existing_data_channels).await?); bridge_process_at_least_one(&br).await; let mut poll_dc0 = PollDataChannel::new(dc0); diff --git a/src/data_channel/mod.rs b/src/data_channel/mod.rs index c1fd558..1731440 100644 --- a/src/data_channel/mod.rs +++ b/src/data_channel/mod.rs @@ -14,6 +14,7 @@ use util::marshal::*; use bytes::{Buf, Bytes}; use derive_builder::Builder; +use std::borrow::Borrow; use std::fmt; use std::future::Future; use std::io; @@ -78,22 +79,25 @@ impl DataChannel { } /// Accept is used to accept incoming data channels over SCTP - pub async fn accept( + pub async fn accept( association: &Arc, config: Config, - existing_channels: Vec, - ) -> Result { + existing_channels: &[T], + ) -> Result + where + T: Borrow, + { let stream = association .accept_stream() .await .ok_or(Error::ErrStreamClosed)?; - for channel in existing_channels.iter() { + for channel in existing_channels.iter().map(|ch| ch.borrow()) { if channel.stream_identifier() == stream.stream_identifier() { - channel - .stream + let ch = channel.to_owned(); + ch.stream .set_default_payload_type(PayloadProtocolIdentifier::Binary); - return Ok(channel.to_owned()); + return Ok(ch); } } @@ -661,6 +665,6 @@ impl fmt::Debug for PollDataChannel { impl AsRef for PollDataChannel { fn as_ref(&self) -> &DataChannel { - &*self.data_channel + &self.data_channel } }