pub struct LocalDevice { /* private fields */ }Expand description
Device state for one authorized route.
Completed operations are retained for at least the configured replay window. Size the window for broker message expiry and the equipment’s retry policy.
Implementations§
Source§impl LocalDevice
impl LocalDevice
Sourcepub fn initialize_trust(
&mut self,
trust: Vec<TrustEntry>,
) -> Result<(), EngineError>
pub fn initialize_trust( &mut self, trust: Vec<TrustEntry>, ) -> Result<(), EngineError>
Import a previously commissioned equipment inventory once on a fresh local route. Later changes use a confirmed replacement or Self::pairing_established.
Sourcepub fn trust_revision(&self) -> Option<u64>
pub fn trust_revision(&self) -> Option<u64>
Revision of the active local trust replacement. Capture this value when starting asynchronous SHIP pairing. Each newly accepted replacement advances the revision, including a successful clear. A replayed control returns its saved outcome and leaves the revision unchanged. Device checkpoints preserve it on restart.
Sourcepub fn pairing_established(
&mut self,
revision: u64,
for_id: &str,
for_par: &str,
ski: &str,
) -> Result<bool, EngineError>
pub fn pairing_established( &mut self, revision: u64, for_id: &str, for_par: &str, ski: &str, ) -> Result<bool, EngineError>
Record the authenticated SHIP peer’s SKI in its original pairing entry. Returns true for a new observation and false for an identical duplicate. The revision, case-sensitive SHIP ID and certificate fingerprint must match. A pending replacement requires reconciliation before reporting a result. On success, checkpoint the updated inventory before publishing its readback. The original pairing ID, fingerprint and secret remain in the authorized state response. KEO 1.2.0 state trust semantics
Source§impl LocalDevice
impl LocalDevice
Sourcepub fn checkpoint(&mut self, now: Clock) -> Result<Vec<u8>, EngineError>
pub fn checkpoint(&mut self, now: Clock) -> Result<Vec<u8>, EngineError>
Create a point-in-time checkpoint. It can contain pairing secrets. Store atomically under application access controls, before actuation and before sending its acknowledgement.
Sourcepub fn restore(self, bytes: &[u8], now: Clock) -> Result<Self, EngineError>
pub fn restore(self, bytes: &[u8], now: Clock) -> Result<Self, EngineError>
Resume from an application-controlled checkpoint using externally provisioned identity, target kind, capacity and replay window. Use a fresh engine and synchronized UTC. Commit checkpoints atomically with one writer per route and protect them against rollback. Recovered pending operations remain blocked from dispatch until equipment confirms their outcome.
Source§impl LocalDevice
impl LocalDevice
Sourcepub fn new(
route: impl Into<String>,
source: impl Into<String>,
subsequent: bool,
capacity: usize,
) -> Self
pub fn new( route: impl Into<String>, source: impl Into<String>, subsequent: bool, capacity: usize, ) -> Self
Create an engine with a 24-hour replay window and a hard entry/meter capacity.
Sourcepub fn with_replay_window(self, seconds: u64) -> Result<Self, EngineError>
pub fn with_replay_window(self, seconds: u64) -> Result<Self, EngineError>
Set the minimum retention for completed IDs. Configure before admitting any operation.
Sourcepub fn pending(&self) -> impl Iterator<Item = (&str, &Control)>
pub fn pending(&self) -> impl Iterator<Item = (&str, &Control)>
Inspect operations requiring equipment reconciliation, including after restart.
Sourcepub fn control_for_dispatch(
&mut self,
id: &str,
now: Clock,
) -> Result<Option<Control>, EngineError>
pub fn control_for_dispatch( &mut self, id: &str, now: Clock, ) -> Result<Option<Control>, EngineError>
Recalculate a queued operation immediately before its first equipment write.
A timed activation or deactivation which expired in the queue returns None;
complete it as rejected.
Restored pending operations require independent reconciliation before any reissue.
Sourcepub fn read_control(&mut self, id: &str) -> Result<Message, EngineError>
pub fn read_control(&mut self, id: &str) -> Result<Message, EngineError>
Request the backend’s accumulated control. Only one read can be outstanding.
Sourcepub fn cancel_read(&mut self)
pub fn cancel_read(&mut self)
Cancel the outstanding local read on timeout.
Sourcepub fn capabilities(
&mut self,
id: &str,
values: Vec<String>,
now: Clock,
) -> Result<Message, EngineError>
pub fn capabilities( &mut self, id: &str, values: Vec<String>, now: Clock, ) -> Result<Message, EngineError>
Update locally discovered capabilities and return an immediate state advertisement.
Sourcepub fn observe_meters(&mut self, meters: Vec<Meter>) -> Result<(), EngineError>
pub fn observe_meters(&mut self, meters: Vec<Meter>) -> Result<(), EngineError>
Replace observations with the adapter’s complete source inventory. Omit lost sources and invalid readings. Readback then reflects the current inventory immediately.
Sourcepub fn snapshot(&mut self, now: Clock) -> Result<State, EngineError>
pub fn snapshot(&mut self, now: Clock) -> Result<State, EngineError>
Build current state at the supplied time without emitting a notification.
Sourcepub fn notification(
&mut self,
id: &str,
now: Clock,
) -> Result<Option<Message>, EngineError>
pub fn notification( &mut self, id: &str, now: Clock, ) -> Result<Option<Message>, EngineError>
Poll an active notification schedule. A late poll coalesces missed intervals.
Sourcepub fn receive(
&mut self,
route: &str,
message: &Message,
reply_id: &str,
now: Clock,
) -> Result<DeviceEvent, EngineError>
pub fn receive( &mut self, route: &str, message: &Message, reply_id: &str, now: Clock, ) -> Result<DeviceEvent, EngineError>
Process a validated publication for this route. Equipment must only act on DeviceEvent::Apply.