Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
Mads::ClockConsensus Class Reference

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 ()
 

Detailed Description

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.

Examples
/home/runner/work/MADS/MADS/src/agent.hpp.

Definition at line 138 of file clock_offset.hpp.

Constructor & Destructor Documentation

◆ ClockConsensus()

Mads::ClockConsensus::ClockConsensus ( std::chrono::milliseconds  stale = std::chrono::seconds(30))
explicit

Member Function Documentation

◆ adopted()

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.

◆ clear()

void Mads::ClockConsensus::clear ( )

◆ is_winner()

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.

◆ record()

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.


The documentation for this class was generated from the following file: