What Are iroh Presets and Which One Should You Use?
Iroh presets are reusable configuration bundles that implement the Preset trait to inject predefined defaults—including crypto providers, DNS services, and relay modes—into an Endpoint builder, with presets::N0 being the recommended choice for most production applications.
Iroh presets provide a streamlined way to configure endpoints in the n0-computer/iroh repository without manually specifying every builder option. These reusable bundles implement a common trait that applies sets of defaults for crypto providers, address lookup services, and relay modes. Understanding which iroh preset matches your networking requirements ensures you start with the appropriate security and connectivity baseline.
Understanding the Preset Trait
According to the iroh source code, presets are defined in iroh/src/endpoint/presets.rs as types implementing the Preset trait. Each preset exposes a single method:
fn apply(self, builder: Builder) -> Builder
This method consumes the preset and returns a modified builder containing the preset's configuration. Presets gate behind the with_crypto_provider feature flag, requiring either tls-ring or tls-aws-lc-rs Cargo features to be enabled at compile time.
Available Preset Options
The iroh library provides four distinct presets ranging from empty bundles to full production defaults.
presets::Empty
The Empty preset returns the builder unchanged without setting any mandatory options. You must manually configure every aspect including the crypto provider, address lookup, and relay mode.
Use this when you need full manual control over the endpoint configuration.
presets::Minimal
The Minimal preset configures only mandatory options, specifically selecting the crypto provider based on your compiled TLS implementation (ring or aws-lc-rs).
Use this when you want a working minimal endpoint without higher-level services like relay servers or DNS resolution.
presets::N0
The N0 preset (named after Number 0) provides production-ready defaults by:
- Calling
Minimalto set the crypto provider - Publishing and resolving PKARR records via the
iroh.linkDNS service - Adding a fallback DNS resolver (outside browsers)
- Enabling the default relay mode
This is the recommended preset for most applications as it provides immediate peer discovery via public relay and DNS services.
presets::N0DisableRelay
Identical to N0 but forces RelayMode::Disabled, this preset configures all production defaults while disabling the relay infrastructure.
Use this when you operate in peer-to-peer only environments or utilize custom relay infrastructure rather than the public iroh relay network.
Selecting the Right iroh Preset for Your Use Case
Choose your configuration bundle based on connectivity requirements:
- General purpose networking: Use
presets::N0for immediate connectivity with public relay and DNS services. - Restricted environments: Use
presets::N0DisableRelaywhen relay servers are unavailable or undesired. - Embedded systems: Use
presets::Minimalwhen you need minimal code footprint and no external service dependencies. - Custom stacks: Use
presets::Emptywhen integrating proprietary crypto providers or custom discovery mechanisms.
Implementation Examples
The following examples demonstrate how to apply each preset when building an endpoint. All examples assume the with_crypto_provider feature is enabled with either tls-ring or tls-aws-lc-rs.
Production-ready configuration with full defaults:
let endpoint = iroh::Endpoint::builder(presets::N0).bind().await?;
Peer-to-peer only without relay:
let endpoint = iroh::Endpoint::builder(presets::N0DisableRelay)
.bind()
.await?;
Minimal configuration:
let endpoint = iroh::Endpoint::builder(presets::Minimal).bind().await?;
Manual configuration with Empty preset:
let endpoint = iroh::Endpoint::builder(presets::Empty)
.crypto_provider(Arc::new(rustls::crypto::ring::default_provider()))
.bind()
.await?;
Summary
- Iroh presets are reusable configuration bundles defined in
iroh/src/endpoint/presets.rsthat implement thePresettrait'sapplymethod. - The
N0preset provides production-ready defaults including crypto providers, DNS resolution, and relay connectivity. N0DisableRelayoffers identical configuration but disables relay functionality for pure peer-to-peer networking.Minimalconfigures only mandatory crypto providers without external services.Emptyprovides no defaults, requiring manual configuration of all options.- All presets require the
with_crypto_providerfeature and a TLS backend (tls-ringortls-aws-lc-rs).
Frequently Asked Questions
What is the Preset trait in iroh?
The Preset trait is defined in the iroh source code as a configuration interface that exposes a single method fn apply(self, builder: Builder) -> Builder. This method allows preset types to inject predefined configurations into an Endpoint builder before binding, enabling reusable configuration patterns across different deployment scenarios.
When should I use presets::Empty instead of presets::N0?
Use presets::Empty when your application requires full manual control over every configuration aspect, such as when integrating custom crypto providers not covered by the standard ring or aws-lc-rs implementations, or when implementing proprietary address lookup mechanisms. Unlike presets::N0, which automatically configures DNS and relay services, Empty leaves the builder unchanged and requires you to explicitly set all mandatory options including the crypto provider.
How do I disable the relay server in iroh?
Apply the presets::N0DisableRelay preset when constructing your endpoint, which configures all production defaults from presets::N0 but explicitly sets RelayMode::Disabled. This approach maintains the DNS resolution and crypto provider configuration while preventing the endpoint from utilizing the public relay infrastructure, forcing direct peer-to-peer connections only.
What Cargo features are required to use iroh presets?
All presets require the with_crypto_provider feature flag to be enabled in your Cargo.toml, along with either tls-ring or tls-aws-lc-rs to specify the underlying TLS implementation. These features determine which crypto provider the Minimal, N0, and N0DisableRelay presets automatically configure in the endpoint builder.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →