Skip to main content

Consumer

Struct Consumer 

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

Cheap read handle over an origin’s route table.

Clones share the underlying state without allocating any per-cursor resources. To receive route announcements, call Self::announced; to resolve a path into a broadcast, call Self::request.

Implementations§

Source§

impl Consumer

Source

pub fn node(&self) -> NonZeroU64

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

Source

pub fn local(self) -> Self

A view of the routes that entered here: every route a handle marked Link::Peer or Link::Upstream announced is hidden from Self::announced and never resolved by Self::request.

On a relay, this is what the relay ingests itself, from clients and in-process producers, as opposed to what its cluster peers forward. An embedder that records, republishes, or meters each broadcast once, on the node that ingests it, reads this view.

Source

pub fn with_hidden(self, hidden: bool) -> Self

A clone whose announced also reports hidden routes: those with a segment starting with . below the requested prefix. Hidden routes are left out by default, so a platform can add .-named broadcasts without them turning up in apps that list everything.

Source

pub fn covering(self) -> Self

A clone whose announced also reports every route that could serve a path in scope, not just those whose literal name matches it.

A route is a prefix that serves every path beneath it, so a route at room can serve room/lobby.chat under a **/*.chat scope, and one above the root covers all of it. Code that routes requests or forwards announcements needs those routes; a session serving its peer always uses this view. Listing broadcasts does not. Requests resolve through covering routes either way.

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: announced leaves out the routes at or beneath it and a request for a path there fails with Error::Unauthorized. A route announced above prefix is still reported. allowed is unchanged.

Source

pub fn with_stats(self, session: Session) -> Self

Attach an egress stats context: broadcasts handed out through this handle (and any handle derived from it) are attributed to session on the publisher (egress) side. Pass stats::Session::default to opt out.

Source

pub fn announced(&self) -> AnnounceConsumer

List the paths announced in this consumer’s scope, each present or absent.

A path stays present while any route covers it, whichever identity serves it: hold a follow to see the broadcast change. Scope, hiding and sync behave as for routes. Drop the returned announce::Consumer to unregister.

Source

pub fn routes(&self) -> Routes

Every change to the routes announced in this consumer’s scope, for relays and stats: route metadata and identity replacements included.

Allocates a per-cursor coalescing buffer and replays the currently announced routes as initial updates. Routes stay prefixes and are named relative to this consumer’s root; its scope only decides visibility. Only routes the scope covers are reported, unless covering asks for every route that could serve them. Routes with a segment starting with . below a prefix of the scope are hidden unless with_hidden opted in. The stream also watches its scope: a client session fed by this origin asks its peer about the scope while any stream watches it. Drop the returned Routes to unregister.

Source

pub fn consume(&self) -> Self

Returns a cheap duplicate of this read handle.

Source

pub fn follow( &self, path: impl TryInto<Path, Error: Into<Error>>, identity: impl Into<Option<Identity>>, ) -> Result<Following, Error>

Follow the broadcast at path across the identities that serve it.

The first poll_available resolves the identity serving the path once one is announced, retrying route churn but returning a selected handler’s refusal; the call after a refusal waits for the serving route to change. Each later call returns another identity taking over, or None once the path goes offline, then whatever serves it next, even the same identity. Drop what was read from the previous broadcast then: its tracks end with an error once its routes go. Another route of the same identity, or another epoch of it, is not a change.

Pass an owned Identity to follow only that stream: another one taking over ends it, and the identity is handed out again when it serves the path again. Fails with Error::Unauthorized when this consumer’s scope can never cover the path, and with Error::InvalidPath when it holds a *.

Source

pub fn scope( &self, root: impl TryInto<Path, Error: Into<Error>>, prefixes: &Prefixes, ) -> Result<Consumer, Error>

Returns a consumer rooted at root and restricted to prefixes, each covering its whole subtree.

root is relative to this consumer’s root, and prefixes are relative to the new root. Returns Error::Unauthorized when the requested scope has no overlap with this consumer’s scope, or Error::BoundsExceeded when rooting the prefixes would exceed the path limit or the root holds a *.

Source

pub fn request( &self, path: impl TryInto<Path, Error: Into<Error>>, identity: impl Into<Option<Identity>>, ) -> Pending<Requesting> ⓘ

Resolve a broadcast by exact path, optionally pinning its Identity.

Returns a [kio::Pending] future, mirroring track::Consumer::fetch_group. Every path resolves through a front the origin’s Driver runs: the request mints one or joins the one already serving the path, and the front picks one identity’s route covering it and materializes it, from the broadcast itself or from the peer that announced the route. The order is the most specific prefix, then, within one identity, only its highest epoch is eligible, cheaper or not. Among identities it is the preferred link (Producer::with_priority), then the cheapest, then a broadcast published on this origin, then the shortest hop chain, then a hash of the identity and the path, which every relay agrees on and which spreads a pool’s paths over its hosts.

When its serving source dies or a better route of the same identity appears, including a higher epoch, the front switches to it, invisibly to subscribers: the identity promises one continuous key space. Its routes retracting with no replacement ends the broadcast, and the next request re-serves the path; tracks already in flight carry on to their own end. The broadcast also ends once no handle holds it and none of its tracks has been read for a linger, and the next request re-serves the path then too.

Another identity winning the path leaves the broadcast to its readers until its routes go, while the next request resolves the winner on a fresh broadcast. Consumer::routes reports that as RouteKind::Restart, and Self::follow yields the next broadcast. A job’s exact route answering a claim’s request continues the claim’s identity, so it is no restart.

Pass an owned Identity to refuse a different stream, both when requesting and when an asynchronous answer resolves. None leaves lookup unpinned.

The request owns discovery for its path and retries when its covering routes change. It reports Error::Unroutable once discovery has synced without a covering route for the requested identity. A selected handler’s explicit refusal is returned as-is. A broadcast resolved through a discovered route keeps its path watched until dropped; no separate announcement watcher is needed. A route claims capability, not inventory: resolving a covered path succeeds optimistically, and a path that names nothing surfaces as Error::NotFound on its tracks instead.

Source

pub fn root(&self) -> &Path

Returns the prefix that is automatically stripped from all paths.

Source

pub fn allowed(&self) -> Prefixes

The prefixes this consumer may reach, 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 Consumer

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

impl Consume<Consumer> for Consumer

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