Skip to main content

Node

Struct Node 

Source
pub struct Node<const X: usize = 4> { /* private fields */ }
Expand description

The mutable part of a B/IP node: up to X management exchanges at once (at least 1, at most 256), a foreign device’s registration, the broadcasts held for it, and their timers.

Sans-IO: each call takes the current time, nothing reads a clock or a socket, and what the caller must do comes out of poll_action, which it polls until Action::Idle after every call. Sleep until next_deadline and call on_deadline with the time actually woken; every other call first catches up on deadlines passed, so the order the caller makes them in at one instant doesn’t change the outcome. Time never runs backwards: an earlier now than the last is taken as the last.

Implementations§

Source§

impl<const X: usize> Node<X>

Source

pub fn new(link: Link, now: Instant) -> Result<Self, ConfigError>

A node on link, starting at now. A foreign device’s first registration attempt is due at once.

The node’s link.

Source

pub fn receive<'d>( &mut self, datagram: &Datagram<'d>, now: Instant, policy: &mut impl Policy, ) -> Inbound<'d>

Link::receive, then resolve a response.

Source

pub fn resolve<'d>( &mut self, response: Response<'d>, now: Instant, ) -> Inbound<'d>

Match a response to the live exchange it answers.

A table ACK answers its table read; a NAK, the operation it names (BvlcFunction::nak); a success, the peer’s one live operation a success answers. A malformed BVLC-Result never completes anything. A Distribute-Broadcast-To-Network NAK from a foreign device’s own BBMD that matches nothing says the BBMD has no registration for it (Annex J.4.5), and with Retry::Backoff pulls the next attempt forward; Retry::AtRenewal keeps its schedule.

Source

pub fn admit_broadcast( &mut self, now: Instant, ) -> Result<Admission, SendRefusal>

Whether a foreign device sends, holds or refuses a broadcast at now. Other modes always send.

Until the first registration attempt is answered or times out, up to Foreign::hold broadcasts are held, and one more is refused with SendRefusal::HoldFull. Then they are all sent; the ones sent while no lease is live are counted.

Source

pub fn begin_exchange<'r>( &mut self, peer: SocketAddrV4, request: Bvll<'r>, timeout: Duration, now: Instant, ) -> Result<(ExchangeId, Outgoing<'r>), ExchangeRefusal>

Admit a manual management exchange: request to peer, answered within timeout of its send. Encode and send the returned message, then report it with exchange_sent or exchange_failed.

A foreign device refuses a request a success answers to its own BBMD (ExchangeRefusal::ManagedRegistration): the node owns that registration. A normal node or a BBMD may send any.

Source

pub fn exchange_sent(&mut self, exchange: ExchangeId, now: Instant) -> bool

The request of exchange was sent at now; its response timeout starts. true when a response that beat the send settles it now. A stale or already reported exchange changes nothing.

Source

pub fn exchange_failed( &mut self, exchange: ExchangeId, why: LocalFailure, now: Instant, )

The caller ended exchange itself: its send failed, or it gave up. A stale exchange changes nothing.

Source

pub fn next_deadline(&self) -> Option<Instant>

The earliest time the node has something to do without being asked: an exchange’s response timeout, a registration attempt, or a lease’s end.

Source

pub fn on_deadline(&mut self, now: Instant)

Do what is due at now, the time the caller actually woke.

Source

pub fn retarget( &mut self, foreign: Foreign, now: Instant, ) -> Result<(), ConfigError>

Register a foreign device with foreign from now on: another BBMD, time-to-live or timing. The lifecycle restarts with an attempt to the new BBMD due at once, which the next poll_action hands out. The automatic attempt in flight ends as cancelled, so a late answer to it counts as unmatched. A lease proven by the same BBMD stands, since its entry does; one from another BBMD is dropped, and broadcasts are held again, as at start, until that BBMD’s first answer (admit_broadcast). Manual exchanges carry on.

Refused, changing nothing, outside foreign mode (ConfigError::NotForeign) or with a registration Link::validate refuses.

Source

pub fn set_subnet(&mut self, subnet: LocalSubnet) -> Result<(), ConfigError>

Move the node to another LocalSubnet: where its broadcasts go and which destination counts as one. A B/IP-M node that joins, changes or leaves its multicast group (Annex J.8) does this, and so must every copy of the link the host decides on. Nothing else changes: exchanges and a foreign device’s registration carry on.

Refused, changing nothing, with a link Link::validate refuses.

Source

pub fn poll_action(&mut self) -> Action

The next thing to do, or Action::Idle.

Source

pub fn registration(&self, now: Instant) -> Option<RegistrationSnapshot>

A foreign device’s registration as of now; None in the other modes.

Source

pub fn take_counters(&mut self) -> NodeCounters

The counts since the counters were last taken, which then start again from zero: add them to the host’s own totals, as wide as it needs. Each count is a u32 that saturates between takes.

Source

pub const fn counters(&self) -> NodeCounters

The counts since the counters were last taken, as take_counters would return them, without taking them: for a look between takes. A node whose counters are never taken counts from its start.

Trait Implementations§

Source§

impl<const X: usize> Clone for Node<X>

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<const X: usize> Debug for Node<X>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const X: usize> Freeze for Node<X>
where Exchanges<X>: Freeze, Actions<X>: Freeze,

§

impl<const X: usize> RefUnwindSafe for Node<X>
where Exchanges<X>: RefUnwindSafe, Actions<X>: RefUnwindSafe,

§

impl<const X: usize> Send for Node<X>
where Exchanges<X>: Send, Actions<X>: Send,

§

impl<const X: usize> Sync for Node<X>
where Exchanges<X>: Sync, Actions<X>: Sync,

§

impl<const X: usize> Unpin for Node<X>
where Exchanges<X>: Unpin, Actions<X>: Unpin,

§

impl<const X: usize> UnsafeUnpin for Node<X>
where Exchanges<X>: UnsafeUnpin, Actions<X>: UnsafeUnpin,

§

impl<const X: usize> UnwindSafe for Node<X>
where Exchanges<X>: UnwindSafe, Actions<X>: 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> 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, 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, 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.