Skip to content

Commit

Permalink
refactor add_local/remote_candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 9, 2024
1 parent e5fa49e commit 6747597
Show file tree
Hide file tree
Showing 38 changed files with 41 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"rtc-datachannel",
"rtc-dtls",
"rtc",
"rtc-ice",
"rtc-turn",
"rtc-rtcp",
"rtc-rtp",
Expand All @@ -11,7 +12,6 @@ members = [
"rtc-shared",
"rtc-srtp",
"rtc-stun",
"ice",
"reserved/rtc-interceptor",
"reserved/rtc-mdns",
"reserved/rtc-media",
Expand Down
14 changes: 0 additions & 14 deletions reserved/rtc-ice/Cargo.toml

This file was deleted.

2 changes: 0 additions & 2 deletions reserved/rtc-ice/src/lib.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletions ice/Cargo.toml → rtc-ice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[package]
name = "ice"
name = "rtc-ice"
version = "0.0.0"
authors = ["Rain Liu <[email protected]>"]
edition = "2021"
description = "ICE in Rust"
description = "RTC ICE in Rust"
license = "MIT/Apache-2.0"
documentation = "https://docs.rs/rtc-ice"
homepage = "https://webrtc.rs"
repository = "https://github.com/webrtc-rs/rtc"

[dependencies]
shared = { path = "../shared", package = "shared", default-features = false, features = [] }
stun = { path = "../stun", package = "stun" }
shared = { path = "../rtc-shared", package = "rtc-shared", default-features = false, features = [] }
stun = { path = "../rtc-stun", package = "rtc-stun" }

crc = "3.0"
log = "0.4.16"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
4 changes: 3 additions & 1 deletion ice/examples/ping_pong.rs → rtc-ice/examples/ping_pong.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
/*TODO: use std::io;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -421,3 +421,5 @@ async fn main() -> Result<(), Error> {
Ok(())
}
*/
fn main() {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 16 additions & 20 deletions ice/src/agent/mod.rs → rtc-ice/src/agent/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
mod agent_test;
#[cfg(test)]
mod agent_transport_test;
//TODO:#[cfg(test)]
//TODO:mod agent_test;
//TODO:#[cfg(test)]
//TODO:mod agent_transport_test;

pub mod agent_config;
pub mod agent_selector;
Expand Down Expand Up @@ -235,16 +235,16 @@ impl Agent {
}

/// Adds a new local candidate.
pub fn add_local_candidate(&mut self, c: &Rc<dyn Candidate>) -> Result<()> {
pub fn add_local_candidate(&mut self, c: Rc<dyn Candidate>) -> Result<()> {
/*todo:let initialized_ch = {
let started_ch_tx = self.started_ch_tx.lock().await;
(*started_ch_tx).as_ref().map(|tx| tx.subscribe())
};*/

self.start_candidate(c /*, initialized_ch*/);
self.start_candidate(&c /*, initialized_ch*/);

for cand in &self.local_candidates {
if cand.equal(&**c) {
if cand.equal(&*c) {
if let Err(err) = c.close() {
log::warn!(
"[{}]: Failed to close duplicate candidate: {}",
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Agent {
}

/// Adds a new remote candidate.
pub fn add_remote_candidate(&mut self, c: &Rc<dyn Candidate>) -> Result<()> {
pub fn add_remote_candidate(&mut self, c: Rc<dyn Candidate>) -> Result<()> {
// If we have a mDNS Candidate lets fully resolve it before adding it locally
if c.candidate_type() == CandidateType::Host && c.address().ends_with(".local") {
log::warn!(
Expand All @@ -287,7 +287,7 @@ impl Agent {
}

for cand in &self.remote_candidates {
if cand.equal(&**c) {
if cand.equal(&*c) {
return Ok(());
}
}
Expand Down Expand Up @@ -344,9 +344,8 @@ impl Agent {
return Err(Error::ErrRemotePwdEmpty);
}

let mut ufrag_pwd = &mut self.ufrag_pwd;
ufrag_pwd.remote_ufrag = remote_ufrag;
ufrag_pwd.remote_pwd = remote_pwd;
self.ufrag_pwd.remote_ufrag = remote_ufrag;
self.ufrag_pwd.remote_pwd = remote_pwd;
Ok(())
}

Expand All @@ -368,13 +367,10 @@ impl Agent {
}

// Clear all agent needed to take back to fresh state
{
let mut ufrag_pwd = &mut self.ufrag_pwd;
ufrag_pwd.local_ufrag = ufrag;
ufrag_pwd.local_pwd = pwd;
ufrag_pwd.remote_ufrag = String::new();
ufrag_pwd.remote_pwd = String::new();
}
self.ufrag_pwd.local_ufrag = ufrag;
self.ufrag_pwd.local_pwd = pwd;
self.ufrag_pwd.remote_ufrag = String::new();
self.ufrag_pwd.remote_pwd = String::new();

self.pending_binding_requests = vec![];

Expand Down Expand Up @@ -1040,7 +1036,7 @@ impl Agent {
}
}

/// Runs the candidate using the provided connection.
// Runs the candidate using the provided connection.
fn start_candidate(
&self,
candidate: &Rc<dyn Candidate>,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod control_test;
//TODO:#[cfg(test)]
//TODO:mod control_test;

use std::fmt;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::*;
use crate::error::Result;
use shared::error::{Error, Result};

#[test]
fn test_priority_get_from() -> Result<()> {
let mut m = Message::new();
let mut p = PriorityAttr::default();
let result = p.get_from(&m);
if let Err(err) = result {
assert_eq!(err, stun::Error::ErrAttributeNotFound, "unexpected error");
assert_eq!(err, Error::ErrAttributeNotFound, "unexpected error");
} else {
panic!("expected error, but got ok");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod use_candidate_test;
//TODO:#[cfg(test)]
//TODO:mod use_candidate_test;

use shared::error::*;
use stun::attributes::ATTR_USE_CANDIDATE;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ice/src/candidate/mod.rs → rtc-ice/src/candidate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod candidate_test;
//TODO: #[cfg(test)]
//TODO: mod candidate_test;

pub mod candidate_base;
pub mod candidate_host;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod state_test;
//TODO:#[cfg(test)]
//TODO:mod state_test;

use std::fmt;

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ice/src/rand/mod.rs → rtc-ice/src/rand/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod rand_test;
//TODO:#[cfg(test)]
//TODO:mod rand_test;

use rand::{thread_rng, Rng};

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ice/src/url/mod.rs → rtc-ice/src/url/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod url_test;
//TODO: #[cfg(test)]
//TODO: mod url_test;

use std::borrow::Cow;
use std::convert::From;
Expand Down
File renamed without changes.

0 comments on commit 6747597

Please sign in to comment.