Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/data_channel/data_channel_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataChannel> = 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");
Expand Down Expand Up @@ -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<DataChannel> = 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");
Expand Down Expand Up @@ -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<DataChannel> = 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");
Expand Down Expand Up @@ -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<DataChannel> = 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 {
Expand Down Expand Up @@ -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<DataChannel> = 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;
Expand Down Expand Up @@ -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<DataChannel> = 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);
Expand Down
20 changes: 12 additions & 8 deletions src/data_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,22 +79,25 @@ impl DataChannel {
}

/// Accept is used to accept incoming data channels over SCTP
pub async fn accept(
pub async fn accept<T>(
association: &Arc<Association>,
config: Config,
existing_channels: Vec<DataChannel>,
) -> Result<Self> {
existing_channels: &[T],
) -> Result<Self>
where
T: Borrow<Self>,
{
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);
}
}

Expand Down Expand Up @@ -661,6 +665,6 @@ impl fmt::Debug for PollDataChannel {

impl AsRef<DataChannel> for PollDataChannel {
fn as_ref(&self) -> &DataChannel {
&*self.data_channel
&self.data_channel
}
}