File
Blob: firmware/vendor/str0m/tests/ice-lite-connectivity.rs
| 1 | use std::net::Ipv4Addr; |
| 2 | use std::time::{Duration, Instant}; |
| 3 | |
| 4 | use netem::NetemConfig; |
| 5 | use str0m::{Event, IceConnectionState, RtcConfig, RtcError}; |
| 6 | use tracing::info_span; |
| 7 | |
| 8 | mod common; |
| 9 | use common::{Peer, TestRtc, init_crypto_default, init_log, progress}; |
| 10 | |
| 11 | #[test] |
| 12 | pub fn ice_lite_premature_disconnect() -> Result<(), RtcError> { |
| 13 | init_log(); |
| 14 | init_crypto_default(); |
| 15 | |
| 16 | let mut l = TestRtc::new(Peer::Left); |
| 17 | |
| 18 | let rtc = RtcConfig::new().set_ice_lite(true).build(Instant::now()); |
| 19 | let mut r = TestRtc::new_with_rtc(info_span!("R"), rtc); |
| 20 | |
| 21 | r.set_netem(NetemConfig::new().latency(Duration::from_millis(5))); |
| 22 | |
| 23 | l.add_host_candidate((Ipv4Addr::new(1, 1, 1, 1), 1000).into()); |
| 24 | r.add_host_candidate((Ipv4Addr::new(2, 2, 2, 2), 2000).into()); |
| 25 | |
| 26 | let mut change = l.sdp_api(); |
| 27 | change.add_channel("ch".into()); |
| 28 | let (offer, pending) = change.apply().unwrap(); |
| 29 | let answer = r.sdp_api().accept_offer(offer)?; |
| 30 | l.sdp_api().accept_answer(pending, answer)?; |
| 31 | |
| 32 | loop { |
| 33 | if l.duration() > Duration::from_secs(5) { |
| 34 | panic!("Timeout waiting for connection"); |
| 35 | } |
| 36 | |
| 37 | let r_disconnected = r.events.iter().any(|(_, e)| { |
| 38 | matches!( |
| 39 | e, |
| 40 | Event::IceConnectionStateChange(IceConnectionState::Disconnected) |
| 41 | ) |
| 42 | }); |
| 43 | |
| 44 | if r_disconnected { |
| 45 | panic!("ICE-lite peer disconnected before receiving binding requests"); |
| 46 | } |
| 47 | |
| 48 | if l.is_connected() && r.is_connected() { |
| 49 | break; |
| 50 | } |
| 51 | |
| 52 | progress(&mut l, &mut r)?; |
| 53 | } |
| 54 | |
| 55 | Ok(()) |
| 56 | } |