|
|
@ -6,24 +6,39 @@ namespace llarp
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using Clock_t = std::chrono::system_clock;
|
|
|
|
using Clock_t = std::chrono::system_clock;
|
|
|
|
|
|
|
|
|
|
|
|
template < typename Res >
|
|
|
|
template < typename Res, typename Clock >
|
|
|
|
static llarp_time_t
|
|
|
|
static llarp_time_t
|
|
|
|
time_since_epoch()
|
|
|
|
time_since_epoch()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast< Res >(
|
|
|
|
return std::chrono::duration_cast< Res >(Clock::now().time_since_epoch())
|
|
|
|
llarp::Clock_t::now().time_since_epoch())
|
|
|
|
|
|
|
|
.count();
|
|
|
|
.count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// use std::chrono because otherwise the network breaks with Daylight Savings
|
|
|
|
const static llarp_time_t started_at_system =
|
|
|
|
// this time, it doesn't get truncated -despair
|
|
|
|
time_since_epoch< std::chrono::milliseconds, Clock_t >();
|
|
|
|
// that concern is what drove me back to the POSIX C time functions
|
|
|
|
|
|
|
|
// in the first place
|
|
|
|
const static llarp_time_t started_at_steady =
|
|
|
|
|
|
|
|
time_since_epoch< std::chrono::milliseconds,
|
|
|
|
|
|
|
|
std::chrono::steady_clock >();
|
|
|
|
|
|
|
|
/// get our uptime in ms
|
|
|
|
|
|
|
|
static llarp_time_t
|
|
|
|
|
|
|
|
time_since_started()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return time_since_epoch< std::chrono::milliseconds,
|
|
|
|
|
|
|
|
std::chrono::steady_clock >()
|
|
|
|
|
|
|
|
- started_at_steady;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
llarp_time_t
|
|
|
|
llarp_time_t
|
|
|
|
time_now_ms()
|
|
|
|
time_now_ms()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static llarp_time_t lastTime = 0;
|
|
|
|
static llarp_time_t lastTime = 0;
|
|
|
|
auto t = llarp::time_since_epoch< std::chrono::milliseconds >();
|
|
|
|
auto t = time_since_started();
|
|
|
|
|
|
|
|
#ifdef TESTNET_SPEED
|
|
|
|
|
|
|
|
t /= TESTNET_SPEED;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
t += started_at_system;
|
|
|
|
|
|
|
|
|
|
|
|
if(t <= lastTime)
|
|
|
|
if(t <= lastTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lastTime;
|
|
|
|
return lastTime;
|
|
|
|