Skip to content

Commit

Permalink
fix ice/candidate_pair_test/candidate_test
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 9, 2024
1 parent 0732397 commit 49b71f4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 98 deletions.
36 changes: 16 additions & 20 deletions rtc-ice/src/candidate/candidate_base.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crc::{Crc, CRC_32_ISCSI};
use std::fmt;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::{Duration, Instant};
use std::time::Instant;

use super::*;
use crate::candidate::candidate_host::CandidateHostConfig;
Expand Down Expand Up @@ -36,9 +35,8 @@ pub struct CandidateBase {

pub(crate) resolved_addr: SocketAddr,

pub(crate) baseline_time: Instant,
pub(crate) last_sent: AtomicU64,
pub(crate) last_received: AtomicU64,
pub(crate) last_sent: Instant,
pub(crate) last_received: Instant,

//todo: pub(crate) closed_ch: Arc<Mutex<Option<broadcast::Sender<()>>>>,
pub(crate) foundation_override: String,
Expand All @@ -65,9 +63,8 @@ impl Default for CandidateBase {

resolved_addr: SocketAddr::new(IpAddr::from([0, 0, 0, 0]), 0),

baseline_time: Instant::now(),
last_sent: AtomicU64::new(0),
last_received: AtomicU64::new(0),
last_sent: Instant::now(),
last_received: Instant::now(),

//todo: closed_ch: Arc::new(Mutex::new(None)),
foundation_override: String::new(),
Expand Down Expand Up @@ -136,12 +133,12 @@ impl Candidate for CandidateBase {

/// Returns a time indicating the last time this candidate was received.
fn last_received(&self) -> Instant {
self.baseline_time + Duration::from_nanos(self.last_received.load(Ordering::SeqCst))
self.last_received
}

/// Returns a time indicating the last time this candidate was sent.
fn last_sent(&self) -> Instant {
self.baseline_time + Duration::from_nanos(self.last_sent.load(Ordering::SeqCst))
self.last_sent
}

/// Returns candidate NetworkType.
Expand Down Expand Up @@ -235,17 +232,17 @@ impl Candidate for CandidateBase {
Ok(())
}

fn seen(&self, outbound: bool) {
let d = Instant::now().duration_since(self.baseline_time);
fn seen(&mut self, outbound: bool) {
let now = Instant::now();

if outbound {
self.set_last_sent(d);
self.set_last_sent(now);
} else {
self.set_last_received(d);
self.set_last_received(now);
}
}

fn write_to(&self, _raw: &[u8], _dst: &dyn Candidate) -> Result<usize> {
fn write_to(&mut self, _raw: &[u8], _dst: &dyn Candidate) -> Result<usize> {
let n = /*TODO: if let Some(conn) = &self.conn {
let addr = dst.addr();
conn.send_to(raw, addr).await?
Expand Down Expand Up @@ -280,13 +277,12 @@ impl Candidate for CandidateBase {
}

impl CandidateBase {
pub fn set_last_received(&self, d: Duration) {
self.last_received
.store(d.as_nanos() as u64, Ordering::SeqCst);
pub fn set_last_received(&mut self, now: Instant) {
self.last_received = now;
}

pub fn set_last_sent(&self, d: Duration) {
self.last_sent.store(d.as_nanos() as u64, Ordering::SeqCst);
pub fn set_last_sent(&mut self, now: Instant) {
self.last_sent = now;
}

/// Returns the local preference for this candidate.
Expand Down
40 changes: 20 additions & 20 deletions rtc-ice/src/candidate/candidate_pair_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,64 +61,64 @@ fn test_candidate_pair_priority() -> Result<()> {
let tests = vec![
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(host_candidate()?),
Box::new(host_candidate()?),
Box::new(host_candidate()?),
false,
),
9151314440652587007,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(host_candidate()?),
Box::new(host_candidate()?),
Box::new(host_candidate()?),
true,
),
9151314440652587007,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(prflx_candidate()?),
Box::new(host_candidate()?),
Box::new(prflx_candidate()?),
true,
),
7998392936314175488,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(prflx_candidate()?),
Box::new(host_candidate()?),
Box::new(prflx_candidate()?),
false,
),
7998392936314175487,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(srflx_candidate()?),
Box::new(host_candidate()?),
Box::new(srflx_candidate()?),
true,
),
7277816996102668288,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(srflx_candidate()?),
Box::new(host_candidate()?),
Box::new(srflx_candidate()?),
false,
),
7277816996102668287,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(relay_candidate()?),
Box::new(host_candidate()?),
Box::new(relay_candidate()?),
true,
),
72057593987596288,
),
(
CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(relay_candidate()?),
Box::new(host_candidate()?),
Box::new(relay_candidate()?),
false,
),
72057593987596287,
Expand All @@ -139,13 +139,13 @@ fn test_candidate_pair_priority() -> Result<()> {
#[test]
fn test_candidate_pair_equality() -> Result<()> {
let pair_a = CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(srflx_candidate()?),
Box::new(host_candidate()?),
Box::new(srflx_candidate()?),
true,
);
let pair_b = CandidatePair::new(
Arc::new(host_candidate()?),
Arc::new(srflx_candidate()?),
Box::new(host_candidate()?),
Box::new(srflx_candidate()?),
false,
);

Expand Down
Loading

0 comments on commit 49b71f4

Please sign in to comment.