webrtc-rs / webrtc

A pure Rust implementation of WebRTC
https://webrtc.rs
Apache License 2.0
4.08k stars 363 forks source link

[ICE] How to restart the ICE agent? #554

Open JustusvonderBeek opened 5 months ago

JustusvonderBeek commented 5 months ago

I'm trying to use the restart functionality of the ICE agent, however I cannot get this function to work. When I'm trying to call dial/accept a second time a ErrMultipleStart error is thrown. I'm not sure if this is due to an error on my side or some other problem. Maybe you can guide me into the right direction of calls to make?

To reproduce (simplified client side, server side replaces the dial with accept()):

let agent = Agent::new(
    network_types: vec![NetworkType::Udp4],
    udp_network,
    ..Default::default()
);
agent.on_candidate(Box::new(move |c| {
    // sending the ICE candidate to the other side...
}));
agent.gather_candidates().unwrap();
match agent.dial(cancel_rx, remote_ufrag.clone(). remote_pwd.clone()).await {
    Ok(_) => {},
    Err(e) => {
        error!("Failed to connect to remote: {}", e);
    },
};
agent.restart(local_ufrag.clone(), local_pwd.clone()).await.unwrap();
agent.gather_candidates().unwrap();
match agent.dial(cancel_rx, remote_ufrag.clone(). remote_pwd.clone()).await {
    Ok(_) => {},
    Err(e) => {
        error!("Failed to connect to remote: {}", e); // <- Fails with **ErrMultipleStart**, 
        //due to the self.started_ch_tx: Sender() channel being taken in the
        // call to start_connectivity_check inside of AgentInternal
    },
};

When calling the dial/accept a second time the ErrMultipleStart mentioned above is returned. I tracked the issue down to the: self.started_ch_tx: Sender() which is being taken (take()) in the call to start_connectivity_checks inside of the AgentInternal and never reassigned.

Is this use-case of repeatedly searching for new paths currently supported in the ICE implementation? Or am I supposed to create a new ICE agent to search again?