dcs2 0.1.0

An extensible distributed control system framework made in rust with no-std support.
Documentation
use crate::nodes::SystemNodeId;

pub const UNKNOWN_ROUTE_STARTING_ID: u32 = 1_000_000;

/// Returns true if the provided id does not belong to a cluster. Most likely it comes form
/// a client interaction.
pub fn is_unknown_route_id(id: SystemNodeId) -> bool {
    id >= SystemNodeId::from(UNKNOWN_ROUTE_STARTING_ID)
}

#[non_exhaustive]
#[derive(Debug)]
pub enum RouterError {
    RouterFullError,
}

/// Routers are interfaces between lower level adresses and higher level adresses. For example:
/// from ip or bluetooth to [`SystemNodeId`]
pub trait Router {
    type Address;

    /// Returns the lower level address belonging to a node
    fn route(&mut self, id: &SystemNodeId) -> Option<&Self::Address>;
    /// Returns a higher level address belonging to a lower level address
    fn inverse(&mut self, address: &Self::Address) -> Option<&SystemNodeId>;
    /// Updates the router to contain a reference to `address`. Similar to [inverse](Router::inverse)
    /// but if the address is not present then a [`SystemNodeId`] will be generated. Said id is greater
    /// than `UNKNOWN_ROUTE_STARTING_ID`.
    fn register(&mut self, address: Self::Address) -> Option<SystemNodeId>;
    /// Removes the `id` from the router returning it's associated lower level address if it
    /// exists.
    fn unregister(&mut self, id: SystemNodeId) -> Option<Self::Address>;
    /// Same as [unregister](Router::unregister) but takes a lower level addres.
    fn drop(&mut self, address: Self::Address) -> Option<SystemNodeId>;
    /// Generates an association betwen `source` and `address` the former being the higher level
    /// address and the latter the lower level address.
    fn update(&mut self, source: SystemNodeId, address: Self::Address) -> Result<(), RouterError>;
    /// Marks an association as removable.
    fn keep(&mut self, id: SystemNodeId, status: bool);
    /// Removes all unused associations (according to the TTL).
    fn clean(&mut self);
}