Skip to content

Conversation

@Frando
Copy link
Member

@Frando Frando commented Nov 20, 2025

Description

This adds the conecpt of middlewares to the iroh endpoint. Middlewares are structs implementing the Middleware trait and are used to intercept the establishment of connections. Multiple middlewares can be added to the endpoint, and they will be invoked for each hook in the order they have been added to the endpoint.

Currently there's two methods on the Middleware trait:

  • before_connect is invoked before an outgoing connection is started.
  • after_handshake is invoked for incoming and outgoing connections once the TLS handshake has completed

Both methods return an Outcome, which can either be Reject or Accept. If any middleware returns Reject, the connection or connection attempt will be rejected.

The PR also adds ConnectionInfo, which is a struct that has information about a connection, but does not keep the connection itself alive. It allows to inspect stats and paths, and there's a closed method that returns a future which completes once the connection closes (without keeping the connection alive).

The PR includes two examples:

  • auth-middleware implements authentication for iroh protocols through a middleware and a separate authentication protocol. Individual protocols don't need to be aware of authentication at all.
  • monitor-connnections monitors incoming and outgoing connections and prints connection stats once a connection closes.

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.
    • List all breaking changes in the above "Breaking Changes" section.
    • Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are:

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

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

Last updated: 2025-11-22T12:33:12Z

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

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: 6426975

@n0bot n0bot bot added this to iroh Nov 20, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Nov 20, 2025
@Frando Frando changed the title draft: add middleware to endpoint feat(iroh): add middleware to endpoint Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

3 participants