How to Use the presets::N0 Configuration in Iroh for Zero-Setup Networking

Use Endpoint::bind(presets::N0).await? to instantiate an Iroh endpoint with library defaults, automatic local address binding, and no relay or transport configuration required.

The n0-computer/iroh repository provides the presets::N0 configuration as a zero-boilerplate entry point for Rust developers. This preset eliminates setup complexity by applying default networking values and binding to an available local UDP socket immediately, making it ideal for prototyping and testing scenarios.

What Is the presets::N0 Configuration?

The N0 preset (often referred to as "no configuration") implements the Preset trait defined in iroh/src/endpoint/presets.rs. It supplies a filter set that leaves all default values untouched while explicitly disabling advanced features such as relay servers and custom transport tweaks. When invoked, the preset binds the endpoint to an automatically chosen local address without requiring TLS certificates, NAT traversal setup, or environment variables.

Binding Endpoints with presets::N0

The simplest method to utilize this configuration is Endpoint::bind(presets::N0), exposed publicly in iroh/src/endpoint.rs. Internally, this function calls Endpoint::builder(presets::N0) to initialize a builder with the default filter set, then executes the binding logic located in iroh/src/endpoint/bind.rs to establish the UDP socket.

use iroh::{Endpoint, endpoint::presets};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create an endpoint with the “no‑configuration” preset
    let endpoint = Endpoint::bind(presets::N0).await?;

    // The endpoint is ready to use – for example, list its local address:
    println!("Endpoint bound to {}", endpoint.local_addr());

    // Use the endpoint to connect to a remote peer (replace with a real address)
    // let remote = "...".parse()?;  
    // let conn = endpoint.connect(remote).await?;
    // …
    Ok(())
}

Customizing the presets::N0 Configuration

When you need to adjust specific parameters while maintaining the default baseline, use Endpoint::builder(presets::N0) to obtain a mutable builder instance. This approach allows you to layer custom settings—such as connection timeouts—before finalizing the bind operation.

use iroh::{Endpoint, endpoint::presets};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Start from the N0 preset and add a custom connection timeout
    let builder = Endpoint::builder(presets::N0)
        .connect_timeout(std::time::Duration::from_secs(10));

    let endpoint = builder.bind().await?;
    // …
    Ok(())
}

Source Code Implementation

The presets::N0 configuration spans several core files in the iroh codebase:

  • iroh/src/endpoint/presets.rs: Defines the N0 struct and implements the Preset trait that supplies the default configuration filter set.
  • iroh/src/endpoint.rs: Exposes the public presets module and the Endpoint::bind and Endpoint::builder methods used in the examples above.
  • iroh/src/endpoint/bind.rs: Contains the actual binding logic that executes when .bind().await is called on a builder configured with the N0 preset.
  • iroh/README.md: Provides basic usage snippets demonstrating the Endpoint::bind(presets::N0) pattern for quick starts.

Summary

  • Call Endpoint::bind(presets::N0).await? to create a functional endpoint with zero configuration files or environment setup.
  • The preset uses automatic local address selection and disables relay servers, relying purely on library defaults.
  • Implementation resides in iroh/src/endpoint/presets.rs and iroh/src/endpoint/bind.rs within the n0-computer/iroh repository.
  • Use Endpoint::builder(presets::N0) when you need to override specific settings like timeouts while keeping the default foundation.

Frequently Asked Questions

What does presets::N0 configure specifically?

The presets::N0 constant supplies a configuration filter that applies default values to all networking parameters. It disables relay functionality, ignores custom transport settings, and binds the endpoint to an available local UDP socket without requiring TLS certificates or NAT traversal configuration.

Can I use presets::N0 in production environments?

While the preset functions correctly in production, it is optimized for quick prototyping and testing scenarios. Production deployments typically require explicit relay configuration, custom transport settings, or specific bind addresses that the N0 preset intentionally omits.

How do I override specific settings when using presets::N0?

Call Endpoint::builder(presets::N0) to receive a builder instance, then chain configuration methods such as .connect_timeout() before calling .bind().await?. This pattern preserves the default baseline while allowing targeted customization.

Where is the presets::N0 constant defined in the source code?

The constant is defined in iroh/src/endpoint/presets.rs alongside the Preset trait. This file also contains the implementation logic that supplies the default configuration filter set to 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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →