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>
impl<const X: usize> Node<X>
Sourcepub fn new(link: Link, now: Instant) -> Result<Self, ConfigError>
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.
Sourcepub fn receive<'d>(
&mut self,
datagram: &Datagram<'d>,
now: Instant,
policy: &mut impl Policy,
) -> Inbound<'d>
pub fn receive<'d>( &mut self, datagram: &Datagram<'d>, now: Instant, policy: &mut impl Policy, ) -> Inbound<'d>
Link::receive, then resolve a response.
Sourcepub fn resolve<'d>(
&mut self,
response: Response<'d>,
now: Instant,
) -> Inbound<'d>
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.
Sourcepub fn admit_broadcast(
&mut self,
now: Instant,
) -> Result<Admission, SendRefusal>
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.
Sourcepub fn begin_exchange<'r>(
&mut self,
peer: SocketAddrV4,
request: Bvll<'r>,
timeout: Duration,
now: Instant,
) -> Result<(ExchangeId, Outgoing<'r>), ExchangeRefusal>
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.
Sourcepub fn exchange_sent(&mut self, exchange: ExchangeId, now: Instant) -> bool
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.
Sourcepub fn exchange_failed(
&mut self,
exchange: ExchangeId,
why: LocalFailure,
now: Instant,
)
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.
Sourcepub fn next_deadline(&self) -> Option<Instant>
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.
Sourcepub fn on_deadline(&mut self, now: Instant)
pub fn on_deadline(&mut self, now: Instant)
Do what is due at now, the time the caller actually woke.
Sourcepub fn retarget(
&mut self,
foreign: Foreign,
now: Instant,
) -> Result<(), ConfigError>
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.
Sourcepub fn set_subnet(&mut self, subnet: LocalSubnet) -> Result<(), ConfigError>
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.
Sourcepub fn poll_action(&mut self) -> Action
pub fn poll_action(&mut self) -> Action
The next thing to do, or Action::Idle.
Sourcepub fn registration(&self, now: Instant) -> Option<RegistrationSnapshot>
pub fn registration(&self, now: Instant) -> Option<RegistrationSnapshot>
A foreign device’s registration as of now; None in the other
modes.
Sourcepub fn take_counters(&mut self) -> NodeCounters
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.
Sourcepub const fn counters(&self) -> NodeCounters
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.