2020-05-22 13:18:41 +00:00
|
|
|
/*
|
2022-02-01 23:43:11 +00:00
|
|
|
* Copyright (c) 2013-2022, The PurpleI2P Project
|
2020-05-22 13:18:41 +00:00
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
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 ();
|
|
|
|
uint64_t GetSecondsSinceEpoch ();
|
2020-10-23 19:53:22 +00:00
|
|
|
uint32_t GetMinutesSinceEpoch ();
|
|
|
|
uint32_t GetHoursSinceEpoch ();
|
2013-10-27 15:29:34 +00:00
|
|
|
|
2020-03-01 10:25:50 +00:00
|
|
|
void GetCurrentDate (char * date); // returns date as YYYYMMDD string, 9 bytes
|
|
|
|
void GetDateString (uint64_t timestamp, char * date); // timestap is seconds since epoch, returns date as YYYYMMDD string, 9 bytes
|
2022-02-01 23:43:11 +00:00
|
|
|
void AdjustTimeOffset (int64_t offset); // in seconds from current
|
2022-05-20 16:56:05 +00:00
|
|
|
|
2018-11-16 17:49:04 +00:00
|
|
|
class NTPTimeSync
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NTPTimeSync ();
|
|
|
|
~NTPTimeSync ();
|
|
|
|
|
|
|
|
void Start ();
|
2020-03-01 10:25:50 +00:00
|
|
|
void Stop ();
|
2018-11-16 17:49:04 +00:00
|
|
|
|
|
|
|
private:
|
2020-03-01 10:25:50 +00:00
|
|
|
|
2018-11-16 17:49:04 +00:00
|
|
|
void Run ();
|
2020-03-01 10:25:50 +00:00
|
|
|
void Sync ();
|
2018-11-16 17:49:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool m_IsRunning;
|
2020-03-01 10:25:50 +00:00
|
|
|
std::unique_ptr<std::thread> m_Thread;
|
2018-11-16 17:49:04 +00:00
|
|
|
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
|