iroh_net/
relay.rs

1//! Package `relay` implements a revised version of the Designated Encrypted Relay for Packets (DERP)
2//! protocol written by Tailscale.
3//
4//! The relay routes packets to clients using curve25519 keys as addresses.
5//
6//! The relay is used to proxy encrypted QUIC packets through the relay servers when
7//! a direct path cannot be found or opened. The relay is a last resort. If both sides
8//! have very aggressive NATs, or firewalls, or no IPv6, we use the relay connection.
9//! Based on tailscale/derp/derp.go
10
11#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
12
13pub(crate) mod client;
14pub(crate) mod codec;
15pub mod http;
16mod map;
17#[cfg(feature = "iroh-relay")]
18#[cfg_attr(iroh_docsrs, doc(cfg(feature = "iroh-relay")))]
19pub mod server;
20
21pub use iroh_base::node_addr::RelayUrl;
22
23/// Environment variable to force the use of staging relays.
24#[cfg_attr(iroh_docsrs, doc(cfg(not(test))))]
25pub const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS";
26
27/// Returns `true` if the use of staging relays is forced.
28pub fn force_staging_infra() -> bool {
29    matches!(std::env::var(ENV_FORCE_STAGING_RELAYS), Ok(value) if !value.is_empty())
30}
31
32pub use self::{
33    client::{
34        conn::{Conn as RelayConn, ReceivedMessage},
35        Client as HttpClient, ClientBuilder as HttpClientBuilder, ClientError as HttpClientError,
36        ClientReceiver as HttpClientReceiver,
37    },
38    codec::MAX_PACKET_SIZE,
39    map::{RelayMap, RelayMode, RelayNode},
40};