mosaik 0.4.2

A Rust runtime for building self-organizing, leaderless distributed systems.
Documentation
use crate::{
	discovery::{PeerEntry, rtt::Rtt},
	network::PeerId,
};

/// Information about an eligible handler peer for a function, as tracked
/// by a [`Caller`](crate::functions::caller::Caller).
///
/// Candidates satisfy the caller's discovery, `require` predicate, and
/// ticket criteria at the time of the last catalog update. Tickets are
/// re-validated against the freshest entry before every call attempt.
#[derive(Debug, Clone)]
pub struct CandidateInfo {
	pub(in crate::functions) entry: PeerEntry,
	pub(in crate::functions) rtt: Option<Rtt>,
}

impl CandidateInfo {
	/// The candidate handler's discovery entry.
	pub const fn entry(&self) -> &PeerEntry {
		&self.entry
	}

	/// The locally measured smoothed round-trip time to this handler, if
	/// available. Callers rank candidates by RTT and invoke the best one
	/// first.
	pub const fn rtt(&self) -> Option<Rtt> {
		self.rtt
	}
}

/// A snapshot of all currently eligible handler peers, keyed by peer id.
pub type CandidatesMap = im::HashMap<PeerId, CandidateInfo>;