feat(iroh): introduce EndpointHooks#3688
Merged
dignifiedquire merged 24 commits intofeat-multipathfrom Nov 25, 2025
Merged
Conversation
c9b9c39 to
6297150
Compare
|
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 |
5a6f995 to
e9f0b52
Compare
Contributor
|
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? |
11 tasks
ramfox
reviewed
Nov 23, 2025
ramfox
reviewed
Nov 23, 2025
iroh/src/endpoint/connection.rs
Outdated
| .register_connection(info.endpoint_id, conn.weak_handle()); | ||
|
|
||
| // Check hooks | ||
| // TODO: avoid endpoint clone? |
Member
There was a problem hiding this comment.
Does this TODO need to be addressed?
Contributor
|
I like EndpointHooks much better! |
a7397d2 to
fca7a0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds the conecpt of hooks to the iroh endpoint.
Hooksare structs implementing theEndpointHookstrait 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
EndpointHookstrait:before_connectis invoked before an outgoing connection is started.after_handshakeis invoked for incoming and outgoing connections once the TLS handshake has completedBoth methods return an
Outcome, which can either beRejectorAccept. If any hook returnsReject, 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 aclosedmethod that returns a future which completes once the connection closes (without keeping the connection alive).The PR includes two examples:
auth-hookimplements 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-connnectionsmonitors incoming and outgoing connections and prints connection stats once a connection closes.Breaking Changes
Notes & open questions
Change checklist
quic-rpciroh-gossipiroh-blobsdumbpipesendme