Skip to content

Commit

Permalink
refactor DtlsHandler by moving DtlsEndpoint to Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 1, 2024
1 parent 0897c89 commit 43a8420
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 132 deletions.
20 changes: 1 addition & 19 deletions examples/sfu_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ mod sync_transport;

use crate::sfu_impl::sync_transport::SyncTransport;
use bytes::{Bytes, BytesMut};
use dtls::config::HandshakeConfig;
use dtls::extension::extension_use_srtp::SrtpProtectionProfile;
use retty::channel::{InboundPipeline, Pipeline};
use retty::transport::{TaggedBytesMut, TransportContext};
use rouille::{Request, Response, ResponseBody};
Expand Down Expand Up @@ -108,19 +106,6 @@ pub fn run_sfu(
rx: Receiver<SignalingMessage>,
server_config: Arc<ServerConfig>,
) -> anyhow::Result<()> {
let dtls_handshake_config = Arc::new(
dtls::config::ConfigBuilder::default()
.with_certificates(
server_config
.certificates
.iter()
.map(|c| c.dtls_certificate.clone())
.collect(),
)
.with_srtp_protection_profiles(vec![SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_80])
.with_extended_master_secret(dtls::config::ExtendedMasterSecretType::Require)
.build(false, None)?,
);
let sctp_endpoint_config = Arc::new(sctp::EndpointConfig::default());

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

Expand Down Expand Up @@ -228,7 +212,6 @@ fn build_pipeline(
local_addr: SocketAddr,
writer: Rc<RefCell<VecDeque<TaggedBytesMut>>>,
server_states: Rc<RefCell<ServerStates>>,
dtls_handshake_config: Arc<HandshakeConfig>,
sctp_endpoint_config: Arc<sctp::EndpointConfig>,
) -> Rc<Pipeline<TaggedBytesMut, TaggedBytesMut>> {
let pipeline: Pipeline<TaggedBytesMut, TaggedBytesMut> = Pipeline::new();
Expand All @@ -238,8 +221,7 @@ fn build_pipeline(
let write_exception_handler = ExceptionHandler::new();
let stun_handler = StunHandler::new();
// DTLS
let dtls_handler =
DtlsHandler::new(local_addr, Rc::clone(&server_states), dtls_handshake_config);
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 data_channel_handler = DataChannelHandler::new();
Expand Down
2 changes: 1 addition & 1 deletion rtc
Submodule rtc updated from 1271de to 4b62d3
14 changes: 13 additions & 1 deletion src/endpoint/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,22 @@ impl Transport {
&self.candidate
}

pub(crate) fn dtls_endpoint(&self) -> &dtls::endpoint::Endpoint {
pub(crate) fn get_mut_dtls_endpoint(&mut self) -> &mut dtls::endpoint::Endpoint {
&mut self.dtls_endpoint
}

pub(crate) fn get_dtls_endpoint(&self) -> &dtls::endpoint::Endpoint {
&self.dtls_endpoint
}

pub(crate) fn get_mut_sctp_endpoint(&mut self) -> &mut sctp::Endpoint {
&mut self.sctp_endpoint
}

pub(crate) fn get_sctp_endpoint(&self) -> &sctp::Endpoint {
&self.sctp_endpoint
}

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

0 comments on commit 43a8420

Please sign in to comment.