23 #ifndef FREEDM_CLOCK_HPP 24 #define FREEDM_CLOCK_HPP 31 #include <boost/asio.hpp> 32 #include <boost/asio/deadline_timer.hpp> 33 #include <boost/noncopyable.hpp> 58 typedef std::pair<std::string,std::string>
MapIndex;
60 typedef std::map< MapIndex, boost::posix_time::time_duration >
OffsetMap;
62 typedef std::pair<unsigned int, boost::posix_time::ptime>
QueryRecord;
64 typedef std::map< MapIndex, QueryRecord >
QueryMap;
66 typedef std::pair<boost::posix_time::ptime, boost::posix_time::ptime>
TimeTuple;
72 typedef std::map< MapIndex, double >
SkewMap;
76 typedef std::map< MapIndex, DecayingWeight >
WeightMap;
85 void Exchange(
const boost::system::error_code& err );
126 static double TDToDouble(boost::posix_time::time_duration td);
129 static boost::posix_time::time_duration
DoubleToTD(
double td);
unsigned int m_kcounter
The current k for identifying the freshness.
Definition: CClockSynchronizer.hpp:107
std::pair< boost::posix_time::ptime, boost::posix_time::ptime > TimeTuple
Tuples of challenge query/response stuff.
Definition: CClockSynchronizer.hpp:66
std::map< MapIndex, ResponseList > ResponseMap
Stores the challenge responses.
Definition: CClockSynchronizer.hpp:70
void HandleExchangeResponse(const ExchangeResponseMessage &msg, CPeerNode peer)
Handler for clock exchange responses.
Definition: CClockSynchronizer.cpp:165
std::map< MapIndex, DecayingWeight > WeightMap
Type used by the weights.
Definition: CClockSynchronizer.hpp:76
Base interface for agents/broker modules.
Definition: CPeerNode.hpp:37
double GetWeight(MapIndex i) const
Gets the weight with a decay.
Definition: CClockSynchronizer.cpp:446
void Run()
Starts the synchronization algorithm.
Definition: CClockSynchronizer.cpp:84
boost::posix_time::time_duration m_myoffset
My offset.
Definition: CClockSynchronizer.hpp:112
boost::posix_time::ptime m_lastinteraction
Time between interactions.
Definition: CClockSynchronizer.hpp:105
void HandleExchange(const ExchangeMessage &msg, CPeerNode peer)
Receiver for clock exchange requests.
Definition: CClockSynchronizer.cpp:147
void Exchange(const boost::system::error_code &err)
Sends clock exchange requests to other processes.
Definition: CClockSynchronizer.cpp:301
CClockSynchronizer(boost::asio::io_service &ios)
Initialize module.
Definition: CClockSynchronizer.cpp:61
std::pair< unsigned int, boost::posix_time::ptime > QueryRecord
Query Tuple.
Definition: CClockSynchronizer.hpp:62
std::pair< std::string, std::string > MapIndex
Does the i,j referencing.
Definition: CClockSynchronizer.hpp:58
static double TDToDouble(boost::posix_time::time_duration td)
Turn a time duration into a double.
Definition: CClockSynchronizer.cpp:484
void Stop()
Stops the syncrhonization algorithm.
Definition: CClockSynchronizer.cpp:99
boost::asio::deadline_timer m_exchangetimer
Time for the exchange.
Definition: CClockSynchronizer.hpp:117
LastResponseMap m_lastresponse
The last time a node responded.
Definition: CClockSynchronizer.hpp:109
Definition: CClockSynchronizer.hpp:41
SkewMap m_skews
Relative skews.
Definition: CClockSynchronizer.hpp:97
ResponseMap m_responses
Old responses.
Definition: CClockSynchronizer.hpp:103
OffsetMap m_offsets
Relative offsets.
Definition: CClockSynchronizer.hpp:95
static boost::posix_time::time_duration DoubleToTD(double td)
Turn a double into a time duration.
Definition: CClockSynchronizer.cpp:500
An interface for an object which can handle recieving incoming messages.
Definition: IDGIModule.hpp:36
std::map< MapIndex, double > SkewMap
Type used by skews.
Definition: CClockSynchronizer.hpp:72
std::map< MapIndex, unsigned int > LastResponseMap
Last responses type.
Definition: CClockSynchronizer.hpp:78
QueryMap m_queries
Outstanding Clock Queries.
Definition: CClockSynchronizer.hpp:101
std::pair< double, boost::posix_time::ptime > DecayingWeight
Container for decaying weights.
Definition: CClockSynchronizer.hpp:74
General FREEDM Namespace.
Definition: CBroker.cpp:53
double m_myskew
My skew.
Definition: CClockSynchronizer.hpp:114
void HandleIncomingMessage(boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
Processes incoming messages from other modules.
Definition: CClockSynchronizer.cpp:112
void SetWeight(MapIndex i, double w)
Sets the weight for a process.
Definition: CClockSynchronizer.cpp:467
std::map< MapIndex, QueryRecord > QueryMap
Stores the outstanding clock queries.
Definition: CClockSynchronizer.hpp:64
static ModuleMessage PrepareForSending(const ClockSynchronizerMessage &message)
Wraps a clock synchronizer message in a ModuleMessage.
Definition: CClockSynchronizer.cpp:519
std::map< MapIndex, boost::posix_time::time_duration > OffsetMap
Stores the relative offsets.
Definition: CClockSynchronizer.hpp:60
ModuleMessage CreateExchangeResponse(unsigned int k)
Generate the exchange response message.
Definition: CClockSynchronizer.cpp:403
ModuleMessage CreateExchangeMessage(unsigned int k)
Generate the exchange message.
Definition: CClockSynchronizer.cpp:382
boost::posix_time::ptime GetSynchronizedTime() const
Returns the synchronized time.
Definition: CClockSynchronizer.cpp:431
WeightMap m_weights
Relative weights.
Definition: CClockSynchronizer.hpp:99
std::list< TimeTuple > ResponseList
Stores the response pairs.
Definition: CClockSynchronizer.hpp:68