Skip to main content

Producer

Struct Producer 

Source
pub struct Producer { /* private fields */ }
Expand description

Publishes broadcasts and announces routes into an origin.

Implementations§

Source§

impl Producer

Source

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.

Source

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.

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.

Source

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.

Source

pub fn config(&self) -> Config

This origin’s construction config, less its Node ID: an origin built from it is a new node.

Source

pub fn node(&self) -> NonZeroU64

This origin’s Node ID, random for each run.

Source

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.

Source

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.

Source

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.

Source

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 *.

Source

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.

Source

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 *.

Source

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.

Source

pub fn root(&self) -> &Path

Returns the root that is automatically stripped from all paths.

Source

pub fn allowed(&self) -> Prefixes

The prefixes this producer may publish under, relative to its root.

Source

pub fn absolute( &self, path: impl TryInto<Path, Error: Into<Error>>, ) -> Result<Path, Error>

Converts a relative path to an absolute path.

Trait Implementations§

Source§

impl Clone for Producer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Consume<Consumer> for Producer

Source§

fn consume(&self) -> Consumer

Derive a read view (a consumer) from this handle.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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