2013-10-27 15:29:34 +00:00
|
|
|
#ifndef TIMESTAMP_H__
|
|
|
|
#define TIMESTAMP_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
2018-11-16 17:49:04 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <boost/asio.hpp>
|
2013-10-27 15:29:34 +00:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2018-11-14 16:06:53 +00:00
|
|
|
uint64_t GetMillisecondsSinceEpoch ();
|
|
|
|
uint32_t GetHoursSinceEpoch ();
|
|
|
|
uint64_t GetSecondsSinceEpoch ();
|
2013-10-27 15:29:34 +00:00
|
|
|
|
2019-03-07 16:55:47 +00:00
|
|
|
void GetCurrentDate (char * date); // returns date as YYYYMMDD string, 9 bytes
|
2019-04-12 18:05:07 +00:00
|
|
|
void GetDateString (uint64_t timestamp, char * date); // timestap is seconds since epoch, returns date as YYYYMMDD string, 9 bytes
|
2019-03-07 16:55:47 +00:00
|
|
|
|
2018-11-16 17:49:04 +00:00
|
|
|
class NTPTimeSync
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NTPTimeSync ();
|
|
|
|
~NTPTimeSync ();
|
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Run ();
|
|
|
|
void Sync ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool m_IsRunning;
|
|
|
|
std::unique_ptr<std::thread> m_Thread;
|
|
|
|
boost::asio::io_service m_Service;
|
|
|
|
boost::asio::deadline_timer m_Timer;
|
|
|
|
int m_SyncInterval;
|
|
|
|
std::vector<std::string> m_NTPServersList;
|
|
|
|
};
|
2013-10-27 15:29:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|