Skip to main content

QuinnRpcServer

Struct QuinnRpcServer 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_connection_limit(self, limit: usize) -> Self

Override the concurrent-connection cap (#162, builder style).

Source

pub fn with_stream_limit(self, limit: usize) -> Self

Override the server-wide concurrent-stream cap (builder style).

Source

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.

Source

pub fn with_rpc_config(self, cfg: &RpcConfig) -> Self

Apply all tunables from an super::rpc_session::RpcConfig in one call (#197).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn capacity(&self) -> u32

The configured server-wide concurrent-stream capacity.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,