iroh_http_core/endpoint/config.rs
1//! Node configuration types passed to [`super::IrohEndpoint::bind`].
2
3use crate::http::server::stack::CompressionOptions;
4
5/// Networking / QUIC transport configuration.
6#[derive(Debug, Clone, Default)]
7pub struct NetworkingOptions {
8 /// Relay server mode. `"default"`, `"staging"`, `"disabled"`, or `"custom"`. Default: `"default"`.
9 pub relay_mode: Option<String>,
10 /// Custom relay server URLs. Only used when `relay_mode` is `"custom"`.
11 pub relays: Vec<String>,
12 /// UDP socket addresses to bind. Empty means OS-assigned.
13 pub bind_addrs: Vec<String>,
14 /// Milliseconds before an idle QUIC connection is cleaned up.
15 pub idle_timeout_ms: Option<u64>,
16 /// HTTP proxy URL for relay traffic.
17 pub proxy_url: Option<String>,
18 /// Read `HTTP_PROXY` / `HTTPS_PROXY` env vars for proxy config.
19 pub proxy_from_env: bool,
20 /// Disable relay servers and DNS discovery entirely. Overrides `relay_mode`.
21 /// Useful for in-process tests where endpoints connect via direct addresses.
22 pub disabled: bool,
23}
24
25/// DNS-based peer discovery configuration.
26#[derive(Debug, Clone)]
27pub struct DiscoveryOptions {
28 /// DNS discovery server URL. Uses n0 DNS defaults when `None`.
29 pub dns_server: Option<String>,
30 /// Whether to enable DNS discovery. Default: `true`.
31 pub enabled: bool,
32}
33
34impl Default for DiscoveryOptions {
35 fn default() -> Self {
36 Self {
37 dns_server: None,
38 enabled: true,
39 }
40 }
41}
42
43/// Connection-pool tuning.
44#[derive(Debug, Clone, Default)]
45pub struct PoolOptions {
46 /// Maximum number of idle connections to keep in the pool.
47 pub max_connections: Option<usize>,
48 /// Milliseconds a pooled connection may remain idle before being evicted.
49 pub idle_timeout_ms: Option<u64>,
50}
51
52/// Body-streaming and handle-store configuration.
53#[derive(Debug, Clone, Default)]
54pub struct StreamingOptions {
55 /// Capacity (in chunks) of each body channel. Default: 32.
56 pub channel_capacity: Option<usize>,
57 /// Maximum byte length of a single chunk in `send_chunk`. Default: 65536.
58 pub max_chunk_size_bytes: Option<usize>,
59 /// Milliseconds to wait for a slow body reader. Default: 30000.
60 pub drain_timeout_ms: Option<u64>,
61 /// TTL in ms for slab handle entries. `0` disables sweeping. Default: 300000.
62 pub handle_ttl_ms: Option<u64>,
63 /// How often (in ms) the TTL sweep task runs. Default: 60000 (60 s).
64 /// Reducing this lowers the worst-case leaked-handle window at the cost of
65 /// more frequent write-lock acquisitions on every handle registry.
66 /// Useful for short-lived endpoints and test fixtures.
67 pub sweep_interval_ms: Option<u64>,
68}
69
70/// Configuration passed to [`super::IrohEndpoint::bind`].
71#[derive(Debug, Clone, Default)]
72pub struct NodeOptions {
73 /// 32-byte Ed25519 secret key. Generate a fresh one when `None`.
74 pub key: Option<[u8; 32]>,
75 /// Networking / QUIC transport configuration.
76 pub networking: NetworkingOptions,
77 /// DNS-based peer discovery configuration.
78 pub discovery: DiscoveryOptions,
79 /// Connection-pool tuning.
80 pub pool: PoolOptions,
81 /// Body-streaming and handle-store configuration.
82 pub streaming: StreamingOptions,
83 /// ALPN capabilities to advertise.
84 ///
85 /// Valid values: [`ALPN_STR`](crate::ALPN_STR) (`"iroh-http/2"`) and
86 /// [`ALPN_DUPLEX_STR`](crate::ALPN_DUPLEX_STR) (`"iroh-http/2-duplex"`).
87 ///
88 /// When empty (the default), both protocols are advertised. When non-empty,
89 /// the base protocol (`iroh-http/2`) is automatically injected if not
90 /// already present. Unknown values cause [`super::IrohEndpoint::bind`] to
91 /// return an error.
92 pub capabilities: Vec<String>,
93 /// Write TLS session keys to $SSLKEYLOGFILE. Dev/debug only.
94 pub keylog: bool,
95 /// Maximum byte size of the HTTP/1.1 request or response head.
96 /// `None` = 65536. `Some(0)` is rejected.
97 pub max_header_size: Option<usize>,
98 /// Maximum decompressed response body bytes the client will accept per
99 /// outgoing `fetch()`. Default: 256 MiB. Protects against compression
100 /// bombs from malicious peers.
101 pub max_response_body_bytes: Option<usize>,
102 pub compression: Option<CompressionOptions>,
103}