pub struct Server { /* private fields */ }Expand description
Server for accepting MoQ connections.
Accepts QUIC (and optionally WebSocket), plus plaintext qmux over TCP
(--server-tcp-bind) and Unix sockets (--server-unix-bind). Create via
ServerConfig::init or Server::new.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(config: ServerConfig) -> Result<Self>
pub fn new(config: ServerConfig) -> Result<Self>
Build a server from its config, binding the QUIC socket up front.
The stream (tcp/unix) listeners bind lazily on the first
accept, since they need a runtime.
Sourcepub fn with_websocket(self, websocket: Listener) -> Self
pub fn with_websocket(self, websocket: Listener) -> Self
Add a standalone WebSocket listener on a separate TCP port.
This is useful for simple applications that want WebSocket on a dedicated port.
For applications that need WebSocket on the same HTTP port (e.g. moq-relay),
use qmux::Session::accept() with your own HTTP framework instead.
Sourcepub fn with_publisher(self, publish: impl Consume<Consumer>) -> Self
pub fn with_publisher(self, publish: impl Consume<Consumer>) -> Self
Publish the given origin to every session this server accepts.
Sourcepub fn with_subscriber(self, subscribe: Producer) -> Self
pub fn with_subscriber(self, subscribe: Producer) -> Self
Subscribe to every session’s broadcasts, ingesting them into the given origin.
Sourcepub fn with_stats(self, stats: Session) -> Self
pub fn with_stats(self, stats: Session) -> Self
Attach a per-connection moq_net::stats::Session context to all sessions
accepted by this server.
Sourcepub async fn serve_publish(self, origin: Consumer) -> Result<()>
pub async fn serve_publish(self, origin: Consumer) -> Result<()>
Accept sessions until the listener stops, serving origin to each subscriber.
Spawns a task per session and logs (rather than propagates) per-session
errors, so one bad peer never tears down the listener. Returns when
interrupted (Ctrl-C) or on a fatal bind failure. For per-session auth or
routing, drive accept yourself instead.
Sourcepub async fn serve_consume(self, origin: Producer) -> Result<()>
pub async fn serve_consume(self, origin: Producer) -> Result<()>
Accept sessions until the listener stops, ingesting each publisher into origin.
The mirror of serve_publish for the consume direction.
Sourcepub async fn serve_both(
self,
publish: Consumer,
subscribe: Producer,
) -> Result<()>
pub async fn serve_both( self, publish: Consumer, subscribe: Producer, ) -> Result<()>
Accept sessions until the listener stops, serving publish to each subscriber
and ingesting each publisher into subscribe.
The both-directions counterpart of serve_publish and
serve_consume, so an inbound session can subscribe to
the origin and publish into it over one connection.
Sourcepub fn certificates(&self) -> Certificates
pub fn certificates(&self) -> Certificates
A live handle to the certificates this server is serving.
Use it to publish the SHA-256 fingerprints of a generated certificate at
/certificate.sha256, which an http:// client pins to reach a
self-signed server. The handle tracks cert hot reloads, so hold it rather
than the values it returns.
Empty when no TLS-bearing backend is configured (e.g. a stream-only server).
Sourcepub fn accept_health(&self) -> Vec<Health>
pub fn accept_health(&self) -> Vec<Health>
The accept-loop health of every listener this server owns that performs a real
accept(2): the tcp/unix stream listeners and, if one was set,
with_websocket.
Empty on a QUIC-only server, which is the honest answer rather than a
convenient one: a QUIC backend multiplexes every session over one UDP socket,
so it never calls accept and has nothing that could fail this way. Publishing
a zero for it would read as a watch that is passing when it can never fire.
Available before listen, so an owner can register these with
a metrics endpoint at startup even though the sockets bind later.
Sourcepub async fn listen(&mut self) -> Result<()>
pub async fn listen(&mut self) -> Result<()>
Bind the listeners that bind lazily, so a bind failure surfaces here.
The QUIC socket is bound by ServerConfig::init, but the stream
(tcp/unix) listeners need a runtime, so they wait for the first
accept instead. That makes a bind failure arrive as a None
from accept, which a caller cannot tell apart from an ordinary shutdown.
Call this first and the two are distinct: the error is yours to handle, and a
later None means the server stopped.
Idempotent: a call that fails binds nothing at all (any listener it did bind
is torn down again), so a retry starts from the same place. Optional, too:
accept still binds them itself, logging the failure, for a caller that
doesn’t call this.
Call it after with_publisher and friends: the stream
listeners serve what is configured at the moment they bind.
Sourcepub async fn accept(&mut self) -> Option<Request>
pub async fn accept(&mut self) -> Option<Request>
Returns the next partially established session, across every configured transport (QUIC, WebSocket, and plaintext qmux over TCP/Unix).
This returns a Request instead of a session so the connection can be rejected early on an invalid path or missing auth. Call Request::ok or Request::close to complete the handshake.
None means the server stopped: it was interrupted (Ctrl-C), or a lazy
listener failed to bind. Call listen up front to tell those
two apart.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
The address the QUIC listener bound to, useful when the config asked for port 0.
Errors with Error::NoBackend on a stream-only server, which has no
QUIC listener.
Sourcepub fn websocket_local_addr(&self) -> Option<SocketAddr>
pub fn websocket_local_addr(&self) -> Option<SocketAddr>
The address the WebSocket listener from
with_websocket bound to, if one was set.