docs(architecture): clarify iroh ALPN integration — use Endpoint directly, not Router
iroh's Endpoint natively supports ALPN negotiation and set_alpns(). Our HandlerRegistry dispatches exactly like iroh's own ProtocolMap/Router pattern, but shared across both quinn and iroh connection sources. We use iroh::Endpoint directly (not iroh::Router) because our HandlerRegistry and AuthContext are shared across sources.
This commit is contained in:
@@ -93,14 +93,20 @@ loop {
|
||||
|
||||
### iroh accept loop (P2P relay-assisted)
|
||||
|
||||
iroh's `Endpoint` natively supports ALPN negotiation (step 4 of its connection establishment). The `iroh::Endpoint::set_alpns()` method configures which ALPNs the endpoint advertises — the same mechanism iroh's own `Router` uses internally with its `ProtocolMap`.
|
||||
|
||||
We use `iroh::Endpoint` directly (not iroh's `Router`) because our `HandlerRegistry` is shared between quinn and iroh connection sources, and our `AuthContext` construction differs per source. Our accept loop replaces iroh's `Router` accept loop with our own dispatch:
|
||||
|
||||
```
|
||||
loop {
|
||||
tokio::select! {
|
||||
incoming = iroh_endpoint.accept() => {
|
||||
let connection = incoming.await; // iroh QUIC connection + ALPN
|
||||
match connection {
|
||||
Ok(conn) => dispatch(conn),
|
||||
Err(e) => { /* log connection error, continue */ }
|
||||
// incoming is an iroh::endpoint::Incoming
|
||||
let accepting = incoming.accept(); // Accepting state
|
||||
let alpn = accepting.alpn().await; // ALPN from TLS handshake
|
||||
match alpn {
|
||||
Ok(alpn) => dispatch(alpn, accepting),
|
||||
Err(e) => { /* log handshake failure, continue */ }
|
||||
}
|
||||
}
|
||||
_ = shutdown.changed() => break,
|
||||
@@ -108,6 +114,8 @@ loop {
|
||||
}
|
||||
```
|
||||
|
||||
See iroh's `protocol.rs` (`/workspace/iroh/iroh/src/protocol.rs`) for the reference implementation of this pattern — `handle_connection()` reads the ALPN, looks up the handler in `ProtocolMap`, and calls `handler.accept(connection)`. Our dispatch is the same pattern with our `HandlerRegistry`.
|
||||
|
||||
### Dispatch function (shared)
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user