1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Utilities used in [`iroh-net`][`crate`]
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
pub(crate) mod chain;
/// Resolves to pending if the inner is `None`.
#[derive(Debug)]
pub(crate) struct MaybeFuture<T> {
/// Future to be polled.
pub inner: Option<T>,
}
// NOTE: explicit implementation to bypass derive unnecessary bounds
impl<T> Default for MaybeFuture<T> {
fn default() -> Self {
MaybeFuture { inner: None }
}
}
impl<T: Future + Unpin> Future for MaybeFuture<T> {
type Output = T::Output;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match self.inner {
Some(ref mut t) => Pin::new(t).poll(cx),
None => Poll::Pending,
}
}
}
/// Check if we are running in "relay only" mode, as informed
/// by the compile time env var `DEV_RELAY_ONLY`.
///
/// "relay only" mode implies we only use the relay to communicate
/// and do not attempt to do any hole punching.
pub(crate) fn relay_only_mode() -> bool {
std::option_env!("DEV_RELAY_ONLY").is_some()
}