Skip to content

feat(iroh)!: cleanup preset API#4014

Merged
dignifiedquire merged 5 commits intomainfrom
feat-clean-presets
Mar 16, 2026
Merged

feat(iroh)!: cleanup preset API#4014
dignifiedquire merged 5 commits intomainfrom
feat-clean-presets

Conversation

@dignifiedquire
Copy link
Copy Markdown
Contributor

@dignifiedquire dignifiedquire commented Mar 12, 2026

Description

The current default builder approach hardcodes the number 0 servers directly, to make this more explicit, but still have a clean API for examples everywhere this refactors the builder and bind API of the endpoint.

Breaking Changes

  • iroh::Endpoint::builder now takes a preset
  • iroh::Endpoint::bind now takes a preset
  • iroh::Endpoint::empty_builder now assumes RelayMode::Disabled and takes no arguments
  • iroh::EndpointBuilder::empty now assumes RelayMode::Disabled and takes no arguments

Example

// Before
let endpoint = Endpoint::bind().await?;

// After
let endpoint = Endpoint::bind(presets::N0).await?;

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 12, 2026

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/4014/docs/iroh/

Last updated: 2026-03-16T11:41:14Z

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 12, 2026

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 5a59352

@n0bot n0bot bot added this to iroh Mar 12, 2026
@github-project-automation github-project-automation bot moved this to 🚑 Needs Triage in iroh Mar 12, 2026

// Build a `Endpoint`, which uses PublicKeys as endpoint identifiers, uses QUIC for directly connecting to other endpoints, and uses the relay protocol and relay servers to holepunch direct connections between endpoints when there are NATs or firewalls preventing direct connections. If no direct connection can be made, packets are relayed over the relay servers.
let endpoint = Endpoint::builder()
let endpoint = Endpoint::builder(presets::N0)
Copy link
Copy Markdown
Member

@Frando Frando Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super sure but I think I'd prefer N0Preset to presets::N0, i.e. rename N0 to N0Preset. People use auto-imports and then you'd often have N0 which reads weird. Also N0Preset is better discoverable with auto-complete. maye PresetN0 would be even better for autocomplete, unsure.

This is not new to this PR, but this PR makes presets appear at many more places, so this warrants a new discussion on this I think.

Copy link
Copy Markdown
Member

@Frando Frando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

I'll miss Endpoint::bind() I think, but @okdistribute argued well that we should not ship n0 defaults silently. Endpoint::bind(preset::N0) (or maybe Endpoint::bind(N0Preset), tbd) is still reasonably short for examples etc and makes things obvious. So yeah, let's do this.

We current default builder approach harcodes the number 0 servers directly, to make this more explicit, but still have a clean API for examples everywhere this refactors the builder and bind API of the endpoint.
@rklaehn
Copy link
Copy Markdown
Contributor

rklaehn commented Mar 12, 2026

I am very much in favour of requiring presets everywhere, simply because having a preset going away due to a feature flag being disabled is much less weird than an essential fn like bind() or builder() going away or changing behaviour.

@dignifiedquire dignifiedquire added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit 759f14e Mar 16, 2026
30 of 31 checks passed
@github-project-automation github-project-automation bot moved this from 🚑 Needs Triage to ✅ Done in iroh Mar 16, 2026
@matheus23 matheus23 deleted the feat-clean-presets branch March 19, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants