Skip to content

Commit

Permalink
remove agent_transport.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 9, 2024
1 parent 8b1adff commit 2cc7f87
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 389 deletions.
85 changes: 65 additions & 20 deletions rtc-ice/src/agent/agent_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,52 @@ impl Agent {
}
}

pub(crate) fn get_selected_pair(&self) -> Option<usize> {
self.selected_pair
}

pub(crate) fn get_best_available_candidate_pair(&self) -> Option<usize> {
let mut best: Option<usize> = None;

for (index, p) in self.checklist.iter().enumerate() {
if p.state == CandidatePairState::Failed {
continue;
}

if let Some(best_index) = &mut best {
let b = &self.checklist[*best_index];
if b.priority() < p.priority() {
*best_index = index;
}
} else {
best = Some(index);
}
}

best
}

pub(crate) fn get_best_valid_candidate_pair(&self) -> Option<usize> {
let mut best: Option<usize> = None;

for (index, p) in self.checklist.iter().enumerate() {
if p.state != CandidatePairState::Succeeded {
continue;
}

if let Some(best_index) = &mut best {
let b = &self.checklist[*best_index];
if b.priority() < p.priority() {
*best_index = index;
}
} else {
best = Some(index);
}
}

best
}

pub(crate) fn start(&mut self) {
if self.is_controlling {
ControllingSelector::start(self);
Expand Down Expand Up @@ -177,25 +223,24 @@ impl ControllingSelector for Agent {

let nominated_pair_is_some = self.nominated_pair.is_some();

if self.agent_conn.get_selected_pair().is_some() {
if self.get_selected_pair().is_some() {
if self.validate_selected_pair() {
log::trace!("[{}]: checking keepalive", self.get_name());
self.check_keepalive();
}
} else if nominated_pair_is_some {
self.nominate_pair();
} else {
let has_nominated_pair =
if let Some(index) = self.agent_conn.get_best_valid_candidate_pair() {
let p = self.agent_conn.checklist[index];
self.is_nominatable(p.local, true) && self.is_nominatable(p.remote, false)
} else {
false
};
let has_nominated_pair = if let Some(index) = self.get_best_valid_candidate_pair() {
let p = self.checklist[index];
self.is_nominatable(p.local, true) && self.is_nominatable(p.remote, false)
} else {
false
};

if has_nominated_pair {
if let Some(index) = self.agent_conn.get_best_valid_candidate_pair() {
let p = &mut self.agent_conn.checklist[index];
if let Some(index) = self.get_best_valid_candidate_pair() {
let p = &mut self.checklist[index];
log::trace!(
"Nominatable pair found, nominating ({}, {})",
self.local_candidates[p.local],
Expand Down Expand Up @@ -260,10 +305,10 @@ impl ControllingSelector for Agent {
remote,
local
);
let selected_pair_is_none = self.agent_conn.get_selected_pair().is_none();
let selected_pair_is_none = self.get_selected_pair().is_none();

if let Some(index) = self.find_pair(local, remote) {
let p = &mut self.agent_conn.checklist[index];
let p = &mut self.checklist[index];
p.state = CandidatePairState::Succeeded;
log::trace!(
"Found valid candidate pair: {}, p.state: {}, isUseCandidate: {}, {}",
Expand Down Expand Up @@ -293,21 +338,21 @@ impl ControllingSelector for Agent {
log::trace!("controllingSelector: sendBindingSuccess");

if let Some(index) = self.find_pair(local, remote) {
let p = &self.agent_conn.checklist[index];
let p = &self.checklist[index];
let nominated_pair_is_none = self.nominated_pair.is_none();

log::trace!(
"controllingSelector: after findPair {}, p.state: {}, {}",
p,
p.state,
nominated_pair_is_none,
//self.agent_conn.get_selected_pair().await.is_none() //, {}
//self.get_selected_pair().await.is_none() //, {}
);
if p.state == CandidatePairState::Succeeded
&& nominated_pair_is_none
&& self.agent_conn.get_selected_pair().is_none()
&& self.get_selected_pair().is_none()
{
if let Some(best_pair) = self.agent_conn.get_best_available_candidate_pair() {
if let Some(best_pair) = self.get_best_available_candidate_pair() {
log::trace!(
"controllingSelector: getBestAvailableCandidatePair {}",
best_pair
Expand Down Expand Up @@ -339,7 +384,7 @@ impl ControlledSelector for Agent {
// A lite selector should not contact candidates
if self.lite {
self.validate_selected_pair();
} else if self.agent_conn.get_selected_pair().is_some() {
} else if self.get_selected_pair().is_some() {
if self.validate_selected_pair() {
log::trace!("[{}]: checking keepalive", self.get_name());
self.check_keepalive();
Expand Down Expand Up @@ -405,7 +450,7 @@ impl ControlledSelector for Agent {
);

if let Some(index) = self.find_pair(local, remote) {
let p = &mut self.agent_conn.checklist[index];
let p = &mut self.checklist[index];
p.state = CandidatePairState::Succeeded;
log::trace!("Found valid candidate pair: {}", *p);
} else {
Expand All @@ -427,7 +472,7 @@ impl ControlledSelector for Agent {
}

if let Some(index) = self.find_pair(local, remote) {
let p = &self.agent_conn.checklist[index];
let p = &self.checklist[index];
let use_candidate = m.contains(ATTR_USE_CANDIDATE);
if use_candidate {
// https://tools.ietf.org/html/rfc8445#section-7.3.1.5
Expand All @@ -437,7 +482,7 @@ impl ControlledSelector for Agent {
// previously sent by this pair produced a successful response and
// generated a valid pair (Section 7.2.5.3.2). The agent sets the
// nominated flag value of the valid pair to true.
if self.agent_conn.get_selected_pair().is_none() {
if self.get_selected_pair().is_none() {
self.set_selected_pair(Some(index));
}
self.send_binding_success(m, local, remote);
Expand Down
5 changes: 2 additions & 3 deletions rtc-ice/src/agent/agent_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ impl Default for CandidateStats {
impl Agent {
/// Returns a list of candidate pair stats.
pub fn get_candidate_pairs_stats(&self) -> Vec<CandidatePairStats> {
let checklist = &self.agent_conn.checklist;
let mut res = Vec::with_capacity(checklist.len());
for cp in checklist {
let mut res = Vec::with_capacity(self.checklist.len());
for cp in &self.checklist {
let stat = CandidatePairStats {
timestamp: Instant::now(),
local_candidate_id: self.local_candidates[cp.local].id(),
Expand Down
211 changes: 0 additions & 211 deletions rtc-ice/src/agent/agent_transport.rs

This file was deleted.

Loading

0 comments on commit 2cc7f87

Please sign in to comment.