pub struct Producer { /* private fields */ }Expand description
Publishes broadcasts and announces routes into an origin.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn new(config: Config) -> (Self, Driver)
pub fn new(config: Config) -> (Self, Driver)
Build a producer from a Config (identity + cache pool) with no scoped
prefix and no pre-existing broadcasts, paired with the Driver that runs
the origin’s lifecycle work.
Poll the driver with caller-supplied time for the origin to make progress.
moq_tokio::origin::spawn wraps this for tokio callers.
Sourcepub fn with_stats(self, session: Session) -> Self
pub fn with_stats(self, session: Session) -> Self
Attach an ingress stats context: broadcasts created through this handle (and
any handle derived from it) are attributed to session on the subscriber
(ingress) side. Pass stats::Session::default to opt out.
Sourcepub fn with_link(self, link: Link) -> Self
pub fn with_link(self, link: Link) -> Self
Set the link this handle (and any handle derived from it) is given to.
Hand a session with another relay a Link::Peer handle, so this origin can
tell what entered here from what a peer forwarded. Hand a Link::Upstream
handle to a session with a peer that should reach everything here without this
relay carrying its traffic to other upstreams, such as an edge’s link to a core
or a drone’s link to its CDN: a Consumer taken from it hides every route an
upstream handle announced.
Sourcepub fn with_priority(self, priority: Priority) -> Self
pub fn with_priority(self, priority: Priority) -> Self
Rank the link this handle (and any handle derived from it) is given to:
higher wins, and every handle starts at the neutral Priority::default.
Applies to the routes a session lands from its peer through this handle, not to a route created here. Only an identity’s newest epoch is eligible, but among eligible routes priority decides before cost, so links to different operators rank by this instead of comparing their metrics. Hand each CDN’s session its own rank to use the primary while it has a route and fail over to the next.
A moq-lite-07 route ranks by the lowest priority of any link on its path, so two relays never prefer each other’s paths forever. A link promoted above the links before it gains nothing there: demote the fallbacks instead.
Sourcepub fn config(&self) -> Config
pub fn config(&self) -> Config
This origin’s construction config, less its Node ID: an origin built from it is a new node.
Sourcepub fn node(&self) -> NonZeroU64
pub fn node(&self) -> NonZeroU64
This origin’s Node ID, random for each run.
Sourcepub fn is_own(&self, id: NonZeroU64) -> bool
pub fn is_own(&self, id: NonZeroU64) -> bool
Whether id, as a peer declared it, names this origin: its node id, which is also
the relay its moq-lite-07 Node ID names.
Sourcepub fn route(
&self,
path: impl TryInto<Path, Error: Into<Error>>,
options: RouteOptions,
) -> Result<Route, Error>
pub fn route( &self, path: impl TryInto<Path, Error: Into<Error>>, options: RouteOptions, ) -> Result<Route, Error>
Create a route at exactly path, owning a new broadcast to fill.
This is how local content enters an origin. Fill the broadcast through
Route::broadcast. The route serves a fresh random identity, minted here and
kept for its lifetime, across Route::withdraw and Route::announce, since
its keys continue: a new route is a new stream that never splices into an
old one. A publisher that continues one key space across restarts may name
a stable identity instead (RouteOptions::with_identity).
Announced at once unless created RouteOptions::hidden. A hidden route exists
for nobody until Route::announce: until then no announce cursor lists it and
a request for its path fails with Error::Unroutable, for a consumer of this
origin exactly as for a peer. Create it hidden when the tracks a subscriber needs
first, such as a catalog, are not there yet. To serve paths on demand without
publishing each one, use Self::claim.
Announcing is visible to local consumers before it returns; only lifecycle work
(track serving, teardown) waits for the Driver to be polled. Register a
broadcast::Producer::requests handler before announcing, so the first
consumer finds the tracks it serves.
Dropping the last clone of the route retracts it, as does closing its broadcast.
Fails with Error::Unauthorized if path is outside the prefixes this
producer may publish under (after scope) or beneath a
mount,
Error::BoundsExceeded if the full rooted path exceeds
Path::MAX_PARTS or Path::MAX_BYTES, Error::InvalidPath if it holds a *,
Error::NavigationSegment for a literal . or .., or Error::Closed once the origin’s
Driver has been dropped.
Sourcepub fn claim(
&self,
prefix: impl TryInto<Path, Error: Into<Error>>,
options: RouteOptions,
) -> Result<Claim, Error>
pub fn claim( &self, prefix: impl TryInto<Path, Error: Into<Error>>, options: RouteOptions, ) -> Result<Claim, Error>
Create a Claim over prefix that serves the requests beneath it.
A route is always a prefix on the wire: a claim covers prefix and every path
beneath it (the empty prefix claims every path). A service that only serves some of
them, say pid/*.hang, advertises the covering prefix and refuses the
rest as they are requested; consumers narrow what they list locally.
This is the one shape every wire carries, so a route means the same
thing on every hop.
A consumer resolving a path under it through this route is handed to
Claim::poll_requested as a Request: answer it by serving a broadcast already
held (Request::serve), under this route’s identity, or by creating the path’s
own exact route (Request::route). This is how a service answers a whole
subtree without publishing each path ahead of time; a publisher that
knows its broadcasts creates each one’s exact route with Self::route
instead, so subscribers can enumerate them.
Unless options names an identity, the route lends the one it mints to the exact
routes answering its requests, so a reader that resolved a path through it
continues on that path’s answer rather than restarting. Once an exact route holding
the lent identity stops serving it (withdrawn, closed, or renamed), this route moves
to a fresh identity, as a restarted job’s keys are another stream: see
Claim::identity. A claim naming a stable identity lends nothing, and its
answers each mint their own.
The claim is priced, credentialed and shown like an exact route. It is visible
for as long as the returned Claim (and every clone) lives, unless withdrawn.
The prefix must overlap this producer’s scope. Individual requests remain authoritative and are refused when the scope does not cover them.
Sourcepub fn scope(
&self,
root: impl TryInto<Path, Error: Into<Error>>,
prefixes: &Prefixes,
) -> Result<Producer, Error>
pub fn scope( &self, root: impl TryInto<Path, Error: Into<Error>>, prefixes: &Prefixes, ) -> Result<Producer, Error>
Returns a producer rooted at root and restricted to prefixes, each covering
its whole subtree.
root is relative to this producer’s root, and prefixes are relative to
the new root. Returns Error::Unauthorized when the requested scope has
no overlap with this producer’s scope, or Error::BoundsExceeded when
rooting the prefixes would exceed the path limit or the root holds a *.
Sourcepub fn exclude(
&self,
prefix: impl TryInto<Path, Error: Into<Error>>,
) -> Result<Self, Error>
pub fn exclude( &self, prefix: impl TryInto<Path, Error: Into<Error>>, ) -> Result<Self, Error>
A clone that never reaches the subtree at prefix, relative to this root:
nothing is published or announced at or beneath it, and a consumer derived
from the result does not see it. allowed is unchanged.
Sourcepub fn mount(
&self,
at: impl TryInto<Path, Error: Into<Error>>,
target: impl TryInto<Path, Error: Into<Error>>,
) -> Result<Producer, Error>
pub fn mount( &self, at: impl TryInto<Path, Error: Into<Error>>, target: impl TryInto<Path, Error: Into<Error>>, ) -> Result<Producer, Error>
Returns a producer that reads the subtree at at from target instead.
Both are relative to this producer’s root. A consumer derived from the
result resolves at/rest at target/rest, through the one front serving
that path, and presents the routes under target (or covering it) under
at. Permissions stay named from the handle’s side: a later
scope authorizes at/rest as written. The mount is
read-only: nothing is published at or beneath at, so what a reader finds
there is only ever target’s. Whatever the origin holds at at itself is
hidden from the mounted handle.
Returns Error::Unauthorized unless this producer reaches all of
target, none of it excluded, so a mount never widens a scope, and Error::Duplicate when
at or target overlaps a mount point this producer already has, or at
overlaps an existing target or its own: mounts never chain, in whatever order they are added,
so a target is always read as the origin holds it. Mounts may share a target.
Error::BoundsExceeded if either rooted path exceeds Path::MAX_PARTS or Path::MAX_BYTES,
and Error::InvalidPath if at holds a *.
Sourcepub fn consume(&self) -> Consumer
pub fn consume(&self) -> Consumer
Cheap read handle over this origin’s route table.
Use Consumer::announced to register interest and start receiving
announcement events; the consumer itself does not allocate any channels.