pub struct QuinnRpcServer { /* private fields */ }Expand description
A quinn-backed WebTransport server for the RPC plane.
Accepts WebTransport sessions and spawns serve_rpc_connection for each.
Caps concurrent streams server-wide via a single shared [Semaphore] (DoS
bound) passed into every connection, matching the iroh handler’s
shared-semaphore drain. QuinnRpcServer::shutdown cancels the accept loop
and then drains all in-flight streams before returning, so detached
handle_stream tasks finish writing their responses rather than being
abandoned mid-flight.
Implementations§
Source§impl QuinnRpcServer
impl QuinnRpcServer
Sourcepub fn new<P: IrohRequestProcessor>(
server: Server,
processor: P,
signing_key: SigningKey,
) -> Self
pub fn new<P: IrohRequestProcessor>( server: Server, processor: P, signing_key: SigningKey, ) -> Self
Build a server from a quinn endpoint configured for WebTransport (ALPN
h3). Use [web_transport_quinn::ServerBuilder] to construct one.
Sourcepub fn with_capacity(
server: Server,
processor: Arc<dyn IrohRequestProcessor>,
signing_key: SigningKey,
stream_limit: usize,
) -> Self
pub fn with_capacity( server: Server, processor: Arc<dyn IrohRequestProcessor>, signing_key: SigningKey, stream_limit: usize, ) -> Self
Build a server with an explicit server-wide concurrent-stream cap.
Sourcepub fn with_moq_consumer(self, consumer: OriginConsumer) -> Self
pub fn with_moq_consumer(self, consumer: OriginConsumer) -> Self
Serve the moq streaming plane on the same endpoint (#274).
Sessions whose WebTransport CONNECT URL path is crate::dial::MOQ_PATH
are handed to moq_net::Server::accept against consumer; all other
paths route to the RPC core. Mirrors
crate::transport::iroh_moq::IrohMoqProtocolHandler, which serves moq
over a per-connection iroh ALPN — here the multiplex is by URL path.
Sourcepub fn with_moq_relay(self, origin: OriginProducer) -> Self
pub fn with_moq_relay(self, origin: OriginProducer) -> Self
Run the /moq plane as a RELAY (bidirectional) over origin (#358).
In relay mode each /moq session is served via
moq_net::Server::with_origin, so a connected producer’s announced
broadcasts are ingested into origin and re-served to every subscriber by
track name. This is the rendezvous endpoint a producer advertises as a
Role::Relay reach: a publisher links UP to it
(crate::moq_stream::serve_origin_to_relay_background) and a subscriber
dials it for the SAME broadcastPath — neither dials the other.
The relay is blind by construction: frames are AEAD-sealed and
chained-HMAC’d at the source; this node holds no enc_key / mac_key and
forwards opaque Bytes. Takes precedence over Self::with_moq_consumer.
Sourcepub fn with_moq_authz(self, authz: MoqAuthzConfig) -> Self
pub fn with_moq_authz(self, authz: MoqAuthzConfig) -> Self
Install the #276 subscribe-authz + per-tenant announce-scoping config for
the /moq plane.
Identity caveat (documented seam): the WebTransport /moq CONNECT is
not mutually authenticated at the TLS layer. Per-tenant announce
scoping via this config’s tenant_resolver is only effective when a
resolver yields a tenant from non-identity context (e.g. a single-tenant
endpoint) — it receives crate::moq_authz::PeerIdentity::anonymous on
the open path. For a shared multi-tenant endpoint, install
Self::with_moq_connect_authz (#1153): that authenticates the CONNECT
(bearer JWT, verified before the handshake completes), resolves the
tenant from the verified subject, and — when set — takes precedence
over this config’s anonymous resolver path, refusing unauthenticated /
tenant-less CONNECTs (fail-closed) and serving each authenticated peer
only its own tenant’s broadcasts. Cross-tenant enumeration defense for
authenticated peers over the iroh moql ALPN lives in
crate::transport::iroh_moq.
Sourcepub fn with_moq_connect_authz(self, authz: MoqConnectAuthz) -> Self
pub fn with_moq_connect_authz(self, authz: MoqConnectAuthz) -> Self
Install the #1153 CONNECT-time authenticator for the /moq plane.
When set, the accept loop verifies a bearer JWT from the CONNECT’s
HTTP/3 Authorization header before completing the WebTransport
handshake, resolves the tenant from the verified subject via the
configured resolver, and refuses the CONNECT (fail-closed) on any
failure — missing header, bad signature, expired token, or a verified
subject with no tenant. A connected peer then sees only its own
tenant’s broadcasts (structural scoping). With this unset, the /moq
plane stays single-tenant/open (no boundary), preserving the
pre-#1153 behaviour for deployments that have not opted in.
Sourcepub fn with_ninep_handler(self, handler: Arc<dyn NinePWtHandler>) -> Self
pub fn with_ninep_handler(self, handler: Arc<dyn NinePWtHandler>) -> Self
Serve the 9P export plane on the same endpoint (H1b / #765).
Sessions whose WebTransport CONNECT URL path is crate::dial::NINEP_PATH
are handed to handler (which runs the 9P Translator::serve_connection
core over the WT bidi stream); all other paths route to the RPC core (or
the moq plane for /moq). Overrides any process-global handler picked up
at construction.
Sourcepub fn with_connection_limit(self, limit: usize) -> Self
pub fn with_connection_limit(self, limit: usize) -> Self
Override the concurrent-connection cap (#162, builder style).
Sourcepub fn with_stream_limit(self, limit: usize) -> Self
pub fn with_stream_limit(self, limit: usize) -> Self
Override the server-wide concurrent-stream cap (builder style).
Sourcepub fn with_read_timeout(self, read_timeout: Duration) -> Self
pub fn with_read_timeout(self, read_timeout: Duration) -> Self
Override the per-stream request-read timeout (#159). Primarily for
tests; production uses super::rpc_session::REQUEST_READ_TIMEOUT.
Sourcepub fn with_rpc_config(self, cfg: &RpcConfig) -> Self
pub fn with_rpc_config(self, cfg: &RpcConfig) -> Self
Apply all tunables from an super::rpc_session::RpcConfig in one call (#197).
Sourcepub fn shutdown_token(&self) -> CancellationToken
pub fn shutdown_token(&self) -> CancellationToken
A handle that, when cancelled, stops the accept loop and per-connection serve loops.
Note: cancelling this token alone does not drain in-flight streams.
To wait for in-flight responses to complete, hold a clone of the server
and call QuinnRpcServer::shutdown instead (or use it via a shared
handle). The token is exposed primarily for tests and for callers that
want to stop accepting without a graceful drain.
Sourcepub async fn shutdown(
stream_limit: &Arc<Semaphore>,
capacity: u32,
token: &CancellationToken,
)
pub async fn shutdown( stream_limit: &Arc<Semaphore>, capacity: u32, token: &CancellationToken, )
Graceful shutdown mirroring [super::iroh_rpc::IrohRpcProtocolHandler::shutdown]:
cancel the accept loop, then wait for every in-flight stream to release
its permit (acquire_many(capacity)), then forget() + close() the
semaphore so any post-shutdown accept sees a closed semaphore and exits.
Takes the shared Semaphore + token by reference, so it can be called
through a clone of the relevant handles while QuinnRpcServer::run
owns self. See the quinn_shutdown_drains_in_flight test.
Sourcepub async fn shutdown_until(
stream_limit: &Arc<Semaphore>,
capacity: u32,
token: &CancellationToken,
deadline: Instant,
)
pub async fn shutdown_until( stream_limit: &Arc<Semaphore>, capacity: u32, token: &CancellationToken, deadline: Instant, )
Drain against the owner’s shared deadline, without starting a new grace.
Sourcepub fn stream_limit(&self) -> Arc<Semaphore> ⓘ
pub fn stream_limit(&self) -> Arc<Semaphore> ⓘ
The shared concurrent-stream semaphore. Pair with QuinnRpcServer::capacity
and QuinnRpcServer::shutdown_token to perform a graceful
QuinnRpcServer::shutdown while QuinnRpcServer::run owns self.
Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Run the accept loop until shutdown is cancelled. Each accepted session
is served on its own task by the transport-generic core, sharing the
server-wide [Semaphore] so QuinnRpcServer::shutdown can drain every
in-flight stream regardless of which connection it belongs to.
Auto Trait Implementations§
impl !Freeze for QuinnRpcServer
impl !RefUnwindSafe for QuinnRpcServer
impl Send for QuinnRpcServer
impl !Sync for QuinnRpcServer
impl Unpin for QuinnRpcServer
impl UnsafeUnpin for QuinnRpcServer
impl !UnwindSafe for QuinnRpcServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more