Enum librice::stun::agent::StunOrData
source · pub enum StunOrData {
Stun(Message, SocketAddr),
Data(Vec<u8>, SocketAddr),
}
Variants§
Stun(Message, SocketAddr)
Data(Vec<u8>, SocketAddr)
Implementations§
source§impl StunOrData
impl StunOrData
sourcepub fn stun(self) -> Option<(Message, SocketAddr)>
pub fn stun(self) -> Option<(Message, SocketAddr)>
Examples found in repository?
src/stun/agent.rs (line 474)
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
pub async fn perform(&self) -> Result<(Message, SocketAddr), StunError> {
StunAgent::maybe_store_message(&self.agent.inner.state, self.msg.clone());
let tid = self.msg.transaction_id();
let (send_abortable, send_abort_handle) =
futures::future::abortable(Self::send_request(&self.agent, self.msg.clone(), self.to));
let to = self.to;
let mut receive_s =
self.agent
.receive_stream_filter(move |stun_or_data| match stun_or_data {
StunOrData::Stun(msg, from) => tid == msg.transaction_id() && from == &to,
_ => false,
});
let (recv_abortable, recv_abort_handle) = {
let send_abort_handle = send_abort_handle.clone();
futures::future::abortable(clock::timeout(
self.agent.clock.clone(),
Duration::from_secs(40),
receive_s.next().then(|msg| async move {
send_abort_handle.abort();
msg.and_then(|msg| msg.stun())
.ok_or(StunError::ResourceNotFound)
}),
))
};
{
let mut inner = self.inner.lock().unwrap();
inner.send_abort = Some(send_abort_handle);
inner.recv_abort = Some(recv_abort_handle);
}
futures::pin_mut!(send_abortable);
futures::pin_mut!(recv_abortable);
// race the sending and receiving futures returning the first that succeeds
let ret = match futures::future::try_select(send_abortable, recv_abortable).await {
Ok(Either::Left((x, _))) => x.map(|_| (Message::new_error(&self.msg), self.to)),
Ok(Either::Right((y, _))) => y.map_err(|_| StunError::TimedOut)?,
Err(Either::Left((_send_aborted, recv_abortable))) => {
// if both have been aborted, then we return aborted, otherwise, we continue
// waiting for a response until timeout
recv_abortable
.await
.map_err(|_| StunError::Aborted)?
.unwrap_or(Err(StunError::TimedOut))
}
_ => unreachable!(),
};
let _ = StunAgent::take_outstanding_request(
&self.agent.inner.state,
&self.msg.transaction_id(),
);
ret
}
pub fn data(self) -> Option<(Vec<u8>, SocketAddr)>
pub fn addr(&self) -> SocketAddr
Trait Implementations§
source§impl Clone for StunOrData
impl Clone for StunOrData
source§fn clone(&self) -> StunOrData
fn clone(&self) -> StunOrData
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more