modem-mgmt 0.3.0

The management plane of zenoh-modem as a library: serve every device on a host over Zenoh, for any driver that links the contract
Documentation
//! What each device guarantees about the bytes it carries, as `state` (I6).
//!
//! `state/modem/device/{device}/security` is published for **every** device,
//! whatever moves its bytes: the subject is unconditional in the registry,
//! and a reader is entitled to find it under a netdev as much as under an
//! SDU device. It is built from [`Device::security`](modem_device::Device::security),
//! so a device that provides nothing says so in properties (`provider:
//! none`, no guarantees), and a layer that seals SDUs (#158) or a radio that
//! encrypts below the driver says exactly what it provides. Refreshed at the
//! state cadence, like the identity.

use std::time::Duration;

use modem_contract::registry::modem::{Subject, key};
use zenkey::origin::LocalOrigin;
use zenoh::Session;

use crate::oper::Source;

pub(super) async fn publish_loop(
    session: Session,
    origin: LocalOrigin,
    device: String,
    source: Source,
    ttl_s: u64,
) {
    let subject = Subject::device_security(&device);
    let doc_key = key(&origin, &subject);
    let qos = subject.qos();
    let refresh = Duration::from_secs((ttl_s / 2).max(1));
    loop {
        let props = source.security();
        crate::state::put(
            &session,
            &doc_key,
            &super::SecurityState::of(&device, props.as_ref()),
            qos,
        )
        .await;
        tokio::time::sleep(refresh).await;
    }
}