![]() |
Mads
Multi-Agent Distributed System
|
Per-clock-domain adoption of the smallest-delay measurement heard from any agent sharing that domain (§2.1 of the design): agents on one host announce their own measurements, and every agent applies this same deterministic rule – so they converge on one offset without an election. More...
#include <clock_offset.hpp>
Public Member Functions | |
| ClockConsensus (std::chrono::milliseconds stale=std::chrono::seconds(30)) | |
| void | record (const std::string &domain, const ClockOffsetResult &r, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now()) |
| ClockOffsetResult | adopted (const std::string &domain, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now()) const |
| bool | is_winner (const std::string &domain, const std::string &agent_id, std::chrono::steady_clock::time_point now=std::chrono::steady_clock::now()) const |
| void | clear () |
Per-clock-domain adoption of the smallest-delay measurement heard from any agent sharing that domain (§2.1 of the design): agents on one host announce their own measurements, and every agent applies this same deterministic rule – so they converge on one offset without an election.
The comparator (delay_us asc, hops asc, agent_id asc) is a total order: the winner never depends on the order record() calls arrive in, and a worse measurement can never displace an already-adopted better one. record()/adopted() are the only clock reads this class needs, and both take now as a parameter – exactly like Mads::TopicStats – so convergence is directly testable with synthetic timestamps.
Definition at line 138 of file clock_offset.hpp.
|
explicit |
| ClockOffsetResult Mads::ClockConsensus::adopted | ( | const std::string & | domain, |
| std::chrono::steady_clock::time_point | now = std::chrono::steady_clock::now() |
||
| ) | const |
The current winner for domain among non-stale entries, or {valid=false} if none is known.
| void Mads::ClockConsensus::clear | ( | ) |
| bool Mads::ClockConsensus::is_winner | ( | const std::string & | domain, |
| const std::string & | agent_id, | ||
| std::chrono::steady_clock::time_point | now = std::chrono::steady_clock::now() |
||
| ) | const |
True iff agent_id is domain's current winner, i.e. the one expected to keep re-measuring when clock_interval_ms > 0 (§2.3): a deterministic function of adopted(), so exactly one agent per domain ever answers true.
| void Mads::ClockConsensus::record | ( | const std::string & | domain, |
| const ClockOffsetResult & | r, | ||
| std::chrono::steady_clock::time_point | now = std::chrono::steady_clock::now() |
||
| ) |
Records (or replaces) domain's entry for r.origin_agent_id. Ignored if r is invalid or has no origin_agent_id. now – not r.measured_at – is what staleness is measured from, so a remotely-stamped instant (a different host's steady_clock) is never compared against this host's clock.