Skip to content

Commit

Permalink
refactor SctpHandler by moving SctpEndpoint to Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 1, 2024
1 parent 43a8420 commit 2eb24ab
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 145 deletions.
7 changes: 1 addition & 6 deletions examples/sfu_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ pub fn run_sfu(
rx: Receiver<SignalingMessage>,
server_config: Arc<ServerConfig>,
) -> anyhow::Result<()> {
let sctp_endpoint_config = Arc::new(sctp::EndpointConfig::default());

let server_states = Rc::new(RefCell::new(ServerStates::new(
server_config,
socket.local_addr()?,
Expand All @@ -121,7 +119,6 @@ pub fn run_sfu(
socket.local_addr()?,
outgoing_queue.clone(),
server_states.clone(),
sctp_endpoint_config,
);

let mut buf = vec![0; 2000];
Expand Down Expand Up @@ -212,7 +209,6 @@ fn build_pipeline(
local_addr: SocketAddr,
writer: Rc<RefCell<VecDeque<TaggedBytesMut>>>,
server_states: Rc<RefCell<ServerStates>>,
sctp_endpoint_config: Arc<sctp::EndpointConfig>,
) -> Rc<Pipeline<TaggedBytesMut, TaggedBytesMut>> {
let pipeline: Pipeline<TaggedBytesMut, TaggedBytesMut> = Pipeline::new();

Expand All @@ -222,8 +218,7 @@ fn build_pipeline(
let stun_handler = StunHandler::new();
// DTLS
let dtls_handler = DtlsHandler::new(local_addr, Rc::clone(&server_states));
let sctp_handler =
SctpHandler::new(local_addr, Rc::clone(&server_states), sctp_endpoint_config);
let sctp_handler = SctpHandler::new(local_addr, Rc::clone(&server_states));
let data_channel_handler = DataChannelHandler::new();
// SRTP
let srtp_handler = SrtpHandler::new(Rc::clone(&server_states));
Expand Down
2 changes: 1 addition & 1 deletion rtc
Submodule rtc updated from 4b62d3 to dd7992
23 changes: 23 additions & 0 deletions src/endpoint/transport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::endpoint::candidate::Candidate;
use crate::types::FourTuple;
use sctp::{Association, AssociationHandle};
use srtp::context::Context;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;

Expand All @@ -15,6 +17,7 @@ pub(crate) struct Transport {

// SCTP
sctp_endpoint: sctp::Endpoint,
sctp_associations: HashMap<AssociationHandle, Association>,

// DataChannel
association_handle: Option<usize>,
Expand All @@ -41,6 +44,7 @@ impl Transport {
dtls_endpoint: dtls::endpoint::Endpoint::new(Some(dtls_handshake_config)),

sctp_endpoint: sctp::Endpoint::new(sctp_endpoint_config, Some(sctp_server_config)),
sctp_associations: HashMap::new(),

association_handle: None,
stream_id: None,
Expand Down Expand Up @@ -74,6 +78,25 @@ impl Transport {
&self.sctp_endpoint
}

pub(crate) fn get_mut_sctp_associations(
&mut self,
) -> &mut HashMap<AssociationHandle, Association> {
&mut self.sctp_associations
}

pub(crate) fn get_mut_sctp_endpoint_associations(
&mut self,
) -> (
&mut sctp::Endpoint,
&mut HashMap<AssociationHandle, Association>,
) {
(&mut self.sctp_endpoint, &mut self.sctp_associations)
}

pub(crate) fn get_sctp_associations(&self) -> &HashMap<AssociationHandle, Association> {
&self.sctp_associations
}

pub(crate) fn local_srtp_context(&mut self) -> Option<&mut Context> {
self.local_srtp_context.as_mut()
}
Expand Down
Loading

0 comments on commit 2eb24ab

Please sign in to comment.