Skip to main content

Crate iroh_live_node

Crate iroh_live_node 

Source
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:

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:

FutureCancellation safeWhen dropped
Node::connect, Node::connect_with, Node::subscribe, Node::subscribe_ticket, Session::subscribeyesa dial it started continues for other callers
[policy::Queue::next]yesloses nothing
RelayLink::detachyesthe link’s task finishes the close
Publication::withdrawn, Subscription::closed, Session::closedyesloses nothing
ValueReader::latest, ValueReader::nextyesloses nothing
Node::closedyesloses nothing
next() on Node::acceptedyesloses nothing
Node::shutdownnocall it again to finish

Re-exports§

pub use moq_json as json;
pub use moq_net;

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§

BroadcastTicket
A publisher’s endpoint id and the path of one of its broadcasts.
ConnectOptions
How to dial a peer with Node::connect_with.
EndpointConfig
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.
MinimalPreset
An iroh preset that sets only the crypto provider.
MoqPreset
iroh’s N0 preset with BBR3 congestion control.
NetworkPath
One open network path of a Session, as returned by Session::network_paths.
NetworkSample
One reading of the link a broadcast arrives over.
Node
A MoQ node on an iroh endpoint.
NodeConfig
The configuration of a Node.
PathClaim
A claim on one path of one peer, held for as long as it widens the peer’s grant.
Publication
A published broadcast.
RelayConfig
How to attach to a media relay.
RelayLink
A media relay this node stays attached to.
ServingLink
The link serving a subscription, and its latest reading.
Session
A direct session with a peer.
SessionRequest
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.
UnknownCongestion
An error returned when a name is not that of a Congestion controller.
UnpublishOnDrop
A Publication that is unpublished when this guard drops.
ValueError
An error from a value track: a moq_json::Error that ? can convert.
ValueReader
A reader of a latest-value JSON track that follows its Subscription.
ValueWriter
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.
EndpointError
An error from EndpointConfig::from_env or EndpointConfig::bind.
Error
An error from a Node or one of its handles.
LinkKind
What kind of link a session or a media relay attachment is.
Mdns
How an endpoint uses mDNS on the local network.
NetworkPathKind
The kind of address a NetworkPath goes to.
Reach
How Node::subscribe reaches a path the route table has no route to yet.
RelayStatus
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.