Skip to content

Commit

Permalink
fix ConnectionState::Failed
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Mar 11, 2024
1 parent 5c9d9cd commit f3998c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 8 additions & 1 deletion rtc-ice/examples/ping_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ async fn main() -> Result<(), Error> {

let port = if cli.controlling { 4000 } else { 4001 };
let udp_socket = UdpSocket::bind(("0.0.0.0", port)).await?;
let mut ice_agent = Agent::new(AgentConfig::default())?;
let mut ice_agent = Agent::new(AgentConfig {
disconnected_timeout: Some(Duration::from_secs(5)),
failed_timeout: Some(Duration::from_secs(5)),
..Default::default()
})?;

let client = Arc::new(Client::new());

Expand Down Expand Up @@ -260,6 +264,9 @@ async fn main() -> Result<(), Error> {

ice_agent.start_connectivity_checks(cli.controlling, remote_ufrag, remote_pwd)?;

println!("Press 'Enter' when both processes have started");
let _ = io::stdin().read_line(&mut input)?;

println!("Enter bye to stop");
let (mut tx, mut rx) = futures::channel::mpsc::channel(8);
std::thread::spawn(move || {
Expand Down
16 changes: 10 additions & 6 deletions rtc-ice/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub struct Agent {
pub(crate) keepalive_interval: Duration,
// How often should we run our internal taskLoop to check for state changes when connecting
pub(crate) check_interval: Duration,
pub(crate) checking_duration: Instant,
pub(crate) last_checking_time: Instant,

pub(crate) candidate_types: Vec<CandidateType>,
Expand Down Expand Up @@ -239,6 +240,7 @@ impl Agent {
} else {
config.check_interval
},
checking_duration: Instant::now(),
last_checking_time: Instant::now(),
last_connection_state: ConnectionState::Unspecified,

Expand Down Expand Up @@ -520,12 +522,12 @@ impl Agent {
if self.connection_state == ConnectionState::Checking {
// We have just entered checking for the first time so update our checking timer
if self.last_connection_state != self.connection_state {
self.last_checking_time = now;
self.checking_duration = now;
}

// We have been in checking longer then Disconnect+Failed timeout, set the connection to Failed
if now
.checked_duration_since(self.last_checking_time)
.checked_duration_since(self.checking_duration)
.unwrap_or_else(|| Duration::from_secs(0))
> self.disconnected_timeout + self.failed_timeout
{
Expand Down Expand Up @@ -661,7 +663,7 @@ impl Agent {
};

if valid {
// Only allow transitions to failed if a.failedTimeout is non-zero
// Only allow transitions to fail if a.failedTimeout is non-zero
if self.failed_timeout != Duration::from_secs(0) {
self.failed_timeout += self.disconnected_timeout;
}
Expand Down Expand Up @@ -833,12 +835,14 @@ impl Agent {
}

*pending_binding_requests = temp;
let bind_requests_removed = initial_size - pending_binding_requests.len();
let bind_requests_remaining = pending_binding_requests.len();
let bind_requests_removed = initial_size - bind_requests_remaining;
if bind_requests_removed > 0 {
trace!(
"[{}]: Discarded {} binding requests because they expired",
"[{}]: Discarded {} binding requests because they expired, still {} remaining",
self.get_name(),
bind_requests_removed
bind_requests_removed,
bind_requests_remaining,
);
}
}
Expand Down

0 comments on commit f3998c6

Please sign in to comment.