Skip to content

feat(iroh): introduce EndpointHooks#3688

Merged
dignifiedquire merged 24 commits intofeat-multipathfrom
Frando/middleware
Nov 25, 2025
Merged

feat(iroh): introduce EndpointHooks#3688
dignifiedquire merged 24 commits intofeat-multipathfrom
Frando/middleware

Conversation

@Frando
Copy link
Copy Markdown
Member

@Frando Frando commented Nov 20, 2025

Description

This adds the conecpt of hooks to the iroh endpoint. Hooks are structs implementing the EndpointHooks trait and are used to intercept the establishment of connections. Multiple hooks 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 EndpointHooks 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 hook 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-hook 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
Copy Markdown

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-25T10:03:44Z

@github-actions
Copy link
Copy Markdown

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

@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 force-pushed the Frando/middleware branch 3 times, most recently from 5a6f995 to e9f0b52 Compare November 21, 2025 09:58
@Frando Frando changed the title draft: add middleware to endpoint feat(iroh): add middleware to endpoint Nov 21, 2025
@rklaehn
Copy link
Copy Markdown
Contributor

rklaehn commented Nov 22, 2025

I don't think the name middleware is appropriate here. I would associate middleware with something that I can use to actually transform incoming requests and outgoing responses, more in line with what I am doing for compression in iroh-blobs.

These are connection lifecycle hooks. Not sure what a short name is. Will this always be just about connections, or is it possible that we will add endpoint hooks to this later as well?

@dignifiedquire dignifiedquire changed the title feat(iroh): add middleware to endpoint feat(iroh): introduce EndpointHooks Nov 23, 2025
.register_connection(info.endpoint_id, conn.weak_handle());

// Check hooks
// TODO: avoid endpoint clone?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this TODO need to be addressed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

resolved

@rklaehn
Copy link
Copy Markdown
Contributor

rklaehn commented Nov 23, 2025

I like EndpointHooks much better!

@dignifiedquire dignifiedquire merged commit 1efd2b5 into feat-multipath Nov 25, 2025
21 of 28 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Nov 25, 2025
@dignifiedquire dignifiedquire deleted the Frando/middleware branch November 25, 2025 10:12
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.

4 participants