pub enum StunOrData {
    Stun(MessageSocketAddr),
    Data(Vec<u8>, SocketAddr),
}

Variants§

Implementations§

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
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more