Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime<C: Config, const S: usize = 16, const X: usize = 64, const I: usize = 8, const R: usize = 4, const Q: usize = 4, const B: usize = SCRATCH> { /* private fields */ }
Available on crate feature rustcrypto only.
Expand description

The node runtime.

S sessions and X exchanges size the messaging stack (Messaging’s own defaults); I interactions in progress; R datagrams kept for retransmission; Q datagrams queued for sending; B octets of attribute scratch (SCRATCH). The defaults fit DefaultConfig and satisfy every specification minimum for five fabrics; a device with less RAM lowers I, R and Q first.

About 60 KiB with the defaults, almost all of it datagram buffers and the subscription table, so a device puts it in a static rather than on a task’s stack.

Implementations§

Source§

impl<C: Config, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Runtime<C, S, X, I, R, Q, B>

Source

pub async fn run<K, G, H, Ac, Gk, Ev, V, U, M, T, const F: usize, const AF: usize, const A: usize>( &mut self, device: &Device<'_, C, K, G, H, Ac, Gk, Ev, V, F>, matter: &U, mdns: Mdns<'_, M>, advertiser: &mut Advertiser<AF, A>, timer: &T, on_notice: impl FnMut(Notice), ) -> !
where K: KeyStore, G: Rng, H: ClusterHandler, Ac: AccessList, Gk: GroupKeyStore, Ev: EventLog, V: ChangeLog, U: Udp, M: Udp, T: Timer,

Runs the node: Matter datagrams, mDNS queries, timers, for ever.

Every iteration does the time-driven work first (Runtime::poll) and only then waits, whichever source woke it. A select that returns the first ready source starves whichever it polls last, and both orderings fail: sockets first starves the timer on a link with steady mDNS traffic, timer first starves the sockets the moment any deadline is overdue. Waiting may prefer the sockets because nothing time-driven happens in it.

on_notice hears every Notice, in order.

Source§

impl<C: Config, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Runtime<C, S, X, I, R, Q, B>

Source

pub fn new(rng: &impl Rng) -> Result<Self>

A runtime with no sessions, its ids and counters drawn from rng.

§Errors

The rng failed.

Source

pub fn with_max_paths_per_invoke(self, max: u16) -> Self

Sets MaxPathsPerInvoke (§8.8.2.3) — what Basic Information advertises.

Source

pub const fn messaging(&self) -> &Messaging<C, S, X>

The messaging stack.

Source

pub const fn messaging_mut(&mut self) -> &mut Messaging<C, S, X>

The messaging stack, for installing a session directly or registering protocols.

Source

pub const fn subscriptions(&self) -> &Subscriptions<C>

The subscriptions.

Source

pub const fn channel(&self) -> &Channel

The secure channel.

Source

pub fn transmit(&mut self) -> Option<(Peer, &[u8])>

The next datagram to send, and where. Valid until the next call.

Source

pub fn notice(&mut self) -> Option<Notice>

The oldest notice not yet taken.

Source

pub fn receive<K, G, H, Ac, Gk, Ev, V, const F: usize>( &mut self, device: &Device<'_, C, K, G, H, Ac, Gk, Ev, V, F>, datagram: &mut [u8], from: Peer, now: Instant, )

One datagram in.

Whatever it owes — a reply, an acknowledgement, a CloseSession to an evicted peer — is queued for Self::transmit. datagram is decrypted in place.

Source

pub fn poll<K, G, H, Ac, Gk, Ev, V, const F: usize>( &mut self, device: &Device<'_, C, K, G, H, Ac, Gk, Ev, V, F>, now: Instant, )

Everything time-driven.

Call it whenever Self::next_deadline passes, and after every Self::receive — the driver does both on every iteration, whichever event woke it, because a loop that runs time-driven work only when the timer wins a race against the sockets starves one or the other.

Source

pub fn next_deadline<K, G, H, Ac, Gk, Ev, V, const F: usize>( &self, device: &Device<'_, C, K, G, H, Ac, Gk, Ev, V, F>, ) -> Option<Instant>

The earliest instant Self::poll has work, if any.

Trait Implementations§

Source§

impl<C: Debug + Config, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Debug for Runtime<C, S, X, I, R, Q, B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Forget for Runtime<C, S, X, I, R, Q, B>

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Freeze for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: Freeze, Im<C, I>: Freeze, Outbox<Q>: Freeze, Resend<R>: Freeze, Buffers<B>: Freeze,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Move for Runtime<C, S, X, I, R, Q, B>

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> RefUnwindSafe for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: RefUnwindSafe, Im<C, I>: RefUnwindSafe, Outbox<Q>: RefUnwindSafe, Resend<R>: RefUnwindSafe, Buffers<B>: RefUnwindSafe,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Send for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: Send, Im<C, I>: Send, Outbox<Q>: Send, Resend<R>: Send, Buffers<B>: Send,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Sync for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: Sync, Im<C, I>: Sync, Outbox<Q>: Sync, Resend<R>: Sync, Buffers<B>: Sync,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> Unpin for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: Unpin, Im<C, I>: Unpin, Outbox<Q>: Unpin, Resend<R>: Unpin, Buffers<B>: Unpin,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> UnsafeUnpin for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: UnsafeUnpin, Im<C, I>: UnsafeUnpin, Outbox<Q>: UnsafeUnpin, Resend<R>: UnsafeUnpin, Buffers<B>: UnsafeUnpin,

§

impl<C, const S: usize, const X: usize, const I: usize, const R: usize, const Q: usize, const B: usize> UnwindSafe for Runtime<C, S, X, I, R, Q, B>
where Messaging<C, S, X>: UnwindSafe, Im<C, I>: UnwindSafe, Outbox<Q>: UnwindSafe, Resend<R>: UnwindSafe, Buffers<B>: UnwindSafe,

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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.