Expand description
MoQ over iroh.
A Node publishes broadcasts at paths and subscribes to paths. It
keeps one route table fed by every link it has: direct sessions with peers,
and media relays it is attached to. A path resolves to its cheapest route,
and moq moves a subscription to another route of the same instance when
that route dies.
use iroh::EndpointId;
use iroh_live_node::{Audience, MoqPreset, Node, NodeConfig, Reach};
let endpoint = iroh::Endpoint::bind(MoqPreset).await?;
let node = Node::new(endpoint, NodeConfig::default());
// Publish a broadcast this process writes, created in the route table.
let publication = node.publish("demo/studio", Audience::Granted)?;
let _track = publication.broadcast().create_track("video", None).ok_or("the track exists")?;
// Resolve a peer's broadcast, dialing the peer if no route exists yet.
let subscription = node.subscribe("demo/camera", Reach::Both(peer)).await?;
let remote = subscription.broadcast();The main types:
Node: the node. Mount it on aRouterwithNode::mount.Publication: a published broadcast. ItsAudiencesays who sees it.Publication::unpublish_on_dropscopes it to a guard.Subscription: a path resolved in the route table.Session: a direct session with a peer. ItsGrantsays what the peer may subscribe to and publish.RelayLink: a media relay the node stays attached to.MoqPreset: iroh’s N0 preset with BBR3, to bind the node’s endpoint with.Congestionnames the controllers to compare it against.EndpointConfigbinds an endpoint with it, a secret key and mDNS.crypto_provider: the rustls crypto provider iroh and moq share, picked by thecrypto-*features.MinimalPresetsets only it.layout::LiveLayout: the<root>/<peer>/<name>path convention, with the policy that lets each peer publish only under its own id.
Every link runs a connection monitor, and Subscription::serving_link
returns its latest NetworkSample, with the rates bytes arrive and leave
at. Subscription::session returns the direct session that serves a
subscription now, and Session::sample the same reading for a session
the application holds. Session::moq gives the moq-net session itself,
with its raw statistics, and Session::connection the iroh connection,
with its paths.
Every link serves only this node’s own publications, never a route it
learned from another link. A peer sees the paths of the publications whose
audience admits it, within its Grant. The node re-authorizes every
session when a publication or an audience changes, so a peer taken out of
an audience loses the path at once, and what it read there ends with
moq_net::Error::Unauthorized.
A policy decides who may hold a session and with which grant, on accept
and on dial (see NodeConfig::policy). The node asks it again when an
authorization expires, and on Node::reauthorize.
Grant::publish_under lets a peer publish only at paths that name it, so
it cannot stand in for another peer.
Node::subscribe_ticket claims a BroadcastTicket’s path for its peer
with Node::claim_path, which widens the peer’s grant to exactly that
path while the subscription lives. The peer has to own the path (see
NodeConfig::layout), so a claim never overlaps another peer’s paths.
The grants also keep one publisher from taking over another’s readers. moq moves a reader between routes that claim the same instance, so a peer or media relay that announces another publisher’s instance could take over its readers. The table’s contents prevent it:
- A direct peer announces only paths its grant lets it publish.
- An instance is a random string that only reaches the links whose grant lets them see the publication.
- A media relay is trusted with the paths it forwards. Attach only media relays that keep each publisher to its own paths, as moq-relay’s tokens do.
The futures differ in what dropping them leaves behind:
| Future | Cancellation safe | When dropped |
|---|---|---|
Node::connect, Node::connect_with, Node::subscribe, Node::subscribe_ticket, Session::subscribe | yes | a dial it started continues for other callers |
[policy::Queue::next] | yes | loses nothing |
RelayLink::detach | yes | the link’s task finishes the close |
Publication::withdrawn, Subscription::closed, Session::closed | yes | loses nothing |
ValueReader::latest, ValueReader::next | yes | loses nothing |
Node::closed | yes | loses nothing |
next() on Node::accepted | yes | loses nothing |
Node::shutdown | no | call it again to finish |
Re-exports§
Modules§
- layout
- The
<root>/<peer>/<name>path layout. - policy
- Policies that decide who may hold a session with a node, and with which rights.
Structs§
- Broadcast
Ticket - A publisher’s endpoint id and the path of one of its broadcasts.
- Connect
Options - How to dial a peer with
Node::connect_with. - Endpoint
Config - An endpoint with
MoqPreset, a key and mDNS. - Grant
- What a session may subscribe to from this node, and publish into it.
- LinkId
- The id of one link of a node: a session or a media relay.
- Minimal
Preset - An iroh preset that sets only the crypto provider.
- MoqPreset
- iroh’s N0 preset with BBR3 congestion control.
- Network
Path - One open network path of a
Session, as returned bySession::network_paths. - Network
Sample - One reading of the link a broadcast arrives over.
- Node
- A MoQ node on an iroh endpoint.
- Node
Config - The configuration of a
Node. - Path
Claim - A claim on one path of one peer, held for as long as it widens the peer’s grant.
- Publication
- A published broadcast.
- Relay
Config - How to attach to a media relay.
- Relay
Link - A media relay this node stays attached to.
- Serving
Link - The link serving a subscription, and its latest reading.
- Session
- A direct session with a peer.
- Session
Request - What a peer asked for when it opened a session. What a peer asked for when it opened a session.
- Subscription
- A path resolved in a route table.
- Unknown
Congestion - An error returned when a name is not that of a
Congestioncontroller. - Unpublish
OnDrop - A
Publicationthat is unpublished when this guard drops. - Value
Error - An error from a value track: a
moq_json::Errorthat?can convert. - Value
Reader - A reader of a latest-value JSON track that follows its
Subscription. - Value
Writer - Writes a latest-value JSON track, stamping each update with the time it is made.
Enums§
- Congestion
- A QUIC congestion controller.
- Direction
- Which side opened a session.
- Endpoint
Error - An error from
EndpointConfig::from_envorEndpointConfig::bind. - Error
- An error from a
Nodeor one of its handles. - Link
Kind - What kind of link a session or a media relay attachment is.
- Mdns
- How an endpoint uses mDNS on the local network.
- Network
Path Kind - The kind of address a
NetworkPathgoes to. - Reach
- How
Node::subscribereaches a path the route table has no route to yet. - Relay
Status - The state of a relay link.
Constants§
- ALPN
- The newest MoQ version this build speaks.
- DECIDE_
TIMEOUT - How long the node waits for its policy by default.
- HANDSHAKE_
TIMEOUT - How long a connection may take to open its MoQ session, dialed or accepted.
Functions§
- alpns
- Returns every ALPN a server accepts, newest MoQ version first.
- crypto_
provider - Returns the rustls crypto provider for iroh’s and moq’s TLS.
- load_
or_ create_ secret_ key - Loads the secret key stored at
path, or generates one and stores it there.
Type Aliases§
- Audience
- Who may see a publication.