mirror of https://github.com/oxen-io/lokinet
remove Time_t, add operator overload for printing llarp_time_t and add to_json function for serializing llarp_time_t to json
This commit is contained in:
parent
ecdab10dac
commit
bf0416cab8
|
@ -42,7 +42,7 @@ namespace llarp
|
|||
std::transform(
|
||||
timeouts.begin(), timeouts.end(), std::back_inserter(timeoutsObjs),
|
||||
[](const auto& item) -> util::StatusObject {
|
||||
return util::StatusObject{{"time", item.second.count()},
|
||||
return util::StatusObject{{"time", to_json(item.second)},
|
||||
{"target", item.first.ToString()}};
|
||||
});
|
||||
obj["timeouts"] = timeoutsObjs;
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace llarp
|
|||
{"ip", m_IP.ToString()},
|
||||
{"txRate", m_TxRate},
|
||||
{"rxRate", m_RxRate},
|
||||
{"createdAt", createdAt.count()},
|
||||
{"createdAt", to_json(createdAt)},
|
||||
{"exiting", !m_RewriteSource},
|
||||
{"looksDead", LooksDead(now)},
|
||||
{"expiresSoon", ExpiresSoon(now)},
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace llarp
|
|||
BaseSession::ExtractStatus() const
|
||||
{
|
||||
auto obj = path::Builder::ExtractStatus();
|
||||
obj["lastExitUse"] = m_LastUse.count();
|
||||
obj["lastExitUse"] = to_json(m_LastUse);
|
||||
auto pub = m_ExitIdentity.toPublic();
|
||||
obj["exitIdentity"] = pub.ToString();
|
||||
return obj;
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace llarp
|
|||
util::StatusObject ips{};
|
||||
for(const auto &item : m_IPActivity)
|
||||
{
|
||||
util::StatusObject ipObj{{"lastActive", item.second.count()}};
|
||||
util::StatusObject ipObj{{"lastActive", to_json(item.second)}};
|
||||
std::string remoteStr;
|
||||
AlignedBuffer< 32 > addr = m_IPToAddr.at(item.first);
|
||||
if(m_SNodes.at(addr))
|
||||
|
|
|
@ -320,8 +320,8 @@ namespace llarp
|
|||
{"rxMsgQueueSize", m_RXMsgs.size()},
|
||||
{"remoteAddr", m_RemoteAddr.ToString()},
|
||||
{"remoteRC", m_RemoteRC.ExtractStatus()},
|
||||
{"created", m_CreatedAt.count()},
|
||||
{"uptime", Time_t(now - m_CreatedAt).count()}};
|
||||
{"created", to_json(m_CreatedAt)},
|
||||
{"uptime", to_json(now - m_CreatedAt)}};
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace llarp
|
|||
CreatePacket(Command cmd, size_t plainsize, size_t min_pad = 16,
|
||||
size_t pad_variance = 16);
|
||||
/// Time how long we try delivery for
|
||||
static constexpr std::chrono::millseconds DeliveryTimeout = 500ms;
|
||||
static constexpr std::chrono::milliseconds DeliveryTimeout = 500ms;
|
||||
/// Time how long we wait to recieve a message
|
||||
static constexpr auto ReceivalTimeout = (DeliveryTimeout * 8) / 5;
|
||||
/// How long to keep a replay window for
|
||||
|
@ -28,13 +28,15 @@ namespace llarp
|
|||
/// How often to retransmit TX fragments
|
||||
static constexpr auto TXFlushInterval = (DeliveryTimeout / 5) * 4;
|
||||
/// How often we send a keepalive
|
||||
static constexpr std::chrono::millseconds PingInterval = 5s;
|
||||
static constexpr std::chrono::milliseconds PingInterval = 5s;
|
||||
/// How long we wait for a session to die with no tx from them
|
||||
static constexpr auto SessionAliveTimeout = PingInterval * 5;
|
||||
|
||||
struct Session : public ILinkSession,
|
||||
public std::enable_shared_from_this< Session >
|
||||
{
|
||||
using Time_t = std::chrono::milliseconds;
|
||||
|
||||
/// maximum number of messages we can ack in a multiack
|
||||
static constexpr std::size_t MaxACKSInMACK = 1024 / sizeof(uint64_t);
|
||||
|
||||
|
|
|
@ -401,16 +401,15 @@ namespace llarp
|
|||
if(self->record.work && self->record.work->IsValid(now))
|
||||
{
|
||||
llarp::LogDebug("LRCM extended lifetime by ",
|
||||
self->record.work->extendedLifetime.count(), " for ",
|
||||
info);
|
||||
self->record.work->extendedLifetime, " for ", info);
|
||||
self->hop->lifetime += self->record.work->extendedLifetime;
|
||||
}
|
||||
else if(self->record.lifetime < path::default_lifetime
|
||||
&& self->record.lifetime > 10s)
|
||||
{
|
||||
self->hop->lifetime = self->record.lifetime;
|
||||
llarp::LogDebug("LRCM short lifespan set to ",
|
||||
self->hop->lifetime.count(), " ms for ", info);
|
||||
llarp::LogDebug("LRCM short lifespan set to ", self->hop->lifetime,
|
||||
" for ", info);
|
||||
}
|
||||
|
||||
// TODO: check if we really want to accept it
|
||||
|
|
|
@ -280,8 +280,7 @@ namespace llarp
|
|||
}
|
||||
else if(st == ePathEstablished && _status == ePathBuilding)
|
||||
{
|
||||
LogInfo("path ", Name(), " is built, took ",
|
||||
Time_t(now - buildStarted).count(), " ms");
|
||||
LogInfo("path ", Name(), " is built, took ", now - buildStarted, " ms");
|
||||
}
|
||||
else if(st == ePathTimeout && _status == ePathEstablished)
|
||||
{
|
||||
|
@ -299,7 +298,7 @@ namespace llarp
|
|||
util::StatusObject
|
||||
PathHopConfig::ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{{"lifetime", lifetime.count()},
|
||||
util::StatusObject obj{{"lifetime", to_json(lifetime)},
|
||||
{"router", rc.pubkey.ToHex()},
|
||||
{"txid", txID.ToHex()},
|
||||
{"rxid", rxID.ToHex()}};
|
||||
|
@ -311,17 +310,18 @@ namespace llarp
|
|||
{
|
||||
auto now = llarp::time_now_ms();
|
||||
|
||||
util::StatusObject obj{{"intro", intro.ExtractStatus()},
|
||||
{"lastRecvMsg", m_LastRecvMessage.count()},
|
||||
{"lastLatencyTest", m_LastLatencyTestTime.count()},
|
||||
{"buildStarted", buildStarted.count()},
|
||||
{"expired", Expired(now)},
|
||||
{"expiresSoon", ExpiresSoon(now)},
|
||||
{"expiresAt", ExpireTime().count()},
|
||||
{"ready", IsReady()},
|
||||
{"txRateCurrent", m_LastTXRate},
|
||||
{"rxRateCurrent", m_LastRXRate},
|
||||
{"hasExit", SupportsAnyRoles(ePathRoleExit)}};
|
||||
util::StatusObject obj{
|
||||
{"intro", intro.ExtractStatus()},
|
||||
{"lastRecvMsg", to_json(m_LastRecvMessage)},
|
||||
{"lastLatencyTest", to_json(m_LastLatencyTestTime)},
|
||||
{"buildStarted", to_json(buildStarted)},
|
||||
{"expired", Expired(now)},
|
||||
{"expiresSoon", ExpiresSoon(now)},
|
||||
{"expiresAt", to_json(ExpireTime())},
|
||||
{"ready", IsReady()},
|
||||
{"txRateCurrent", m_LastTXRate},
|
||||
{"rxRateCurrent", m_LastRXRate},
|
||||
{"hasExit", SupportsAnyRoles(ePathRoleExit)}};
|
||||
|
||||
std::vector< util::StatusObject > hopsObj;
|
||||
std::transform(hops.begin(), hops.end(), std::back_inserter(hopsObj),
|
||||
|
@ -379,8 +379,8 @@ namespace llarp
|
|||
m_RXRate = 0;
|
||||
m_TXRate = 0;
|
||||
|
||||
m_UpstreamReplayFilter.Decay(Time_t(now));
|
||||
m_DownstreamReplayFilter.Decay(Time_t(now));
|
||||
m_UpstreamReplayFilter.Decay(now);
|
||||
m_DownstreamReplayFilter.Decay(now);
|
||||
|
||||
if(_status == ePathBuilding)
|
||||
{
|
||||
|
@ -391,8 +391,7 @@ namespace llarp
|
|||
const auto dlt = now - buildStarted;
|
||||
if(dlt >= path::build_timeout)
|
||||
{
|
||||
LogWarn(Name(), " waited for ", dlt.count(),
|
||||
"ms and no path was built");
|
||||
LogWarn(Name(), " waited for ", dlt, " and no path was built");
|
||||
r->routerProfiling().MarkPathFail(this);
|
||||
EnterState(ePathExpired, now);
|
||||
return;
|
||||
|
@ -418,8 +417,7 @@ namespace llarp
|
|||
const auto delay = now - m_LastRecvMessage;
|
||||
if(m_CheckForDead && m_CheckForDead(shared_from_this(), delay))
|
||||
{
|
||||
LogWarn(Name(), " waited for ", dlt.count(),
|
||||
"ms and path is unresponsive");
|
||||
LogWarn(Name(), " waited for ", dlt, " and path is unresponsive");
|
||||
r->routerProfiling().MarkPathFail(this);
|
||||
EnterState(ePathTimeout, now);
|
||||
}
|
||||
|
@ -428,8 +426,7 @@ namespace llarp
|
|||
{
|
||||
if(m_CheckForDead && m_CheckForDead(shared_from_this(), dlt))
|
||||
{
|
||||
LogWarn(Name(), " waited for ", dlt.count(),
|
||||
"ms and path looks dead");
|
||||
LogWarn(Name(), " waited for ", dlt, " and path looks dead");
|
||||
r->routerProfiling().MarkPathFail(this);
|
||||
EnterState(ePathTimeout, now);
|
||||
}
|
||||
|
@ -705,8 +702,7 @@ namespace llarp
|
|||
if(m_BuiltHook)
|
||||
m_BuiltHook(shared_from_this());
|
||||
m_BuiltHook = nullptr;
|
||||
LogDebug("path latency is now ", intro.latency.count(), " for ",
|
||||
Name());
|
||||
LogDebug("path latency is now ", intro.latency, " for ", Name());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -798,7 +794,7 @@ namespace llarp
|
|||
}
|
||||
LogInfo(Name(), " ", Endpoint(), " Rejected exit");
|
||||
MarkActive(r->Now());
|
||||
return InformExitResult(Time_t(msg.B));
|
||||
return InformExitResult(llarp_time_t(msg.B));
|
||||
}
|
||||
LogError(Name(), " got unwarranted RXM");
|
||||
return false;
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace llarp
|
|||
/// nonce for key exchange
|
||||
TunnelNonce nonce;
|
||||
// lifetime
|
||||
Time_t lifetime = default_lifetime;
|
||||
llarp_time_t lifetime = default_lifetime;
|
||||
|
||||
util::StatusObject
|
||||
ExtractStatus() const;
|
||||
|
|
|
@ -297,7 +297,7 @@ namespace llarp
|
|||
PathContext::ExpirePaths(llarp_time_t now)
|
||||
{
|
||||
// decay limits
|
||||
m_PathLimits.Decay(Time_t(now));
|
||||
m_PathLimits.Decay(now);
|
||||
|
||||
{
|
||||
SyncTransitMap_t::Lock_t lock(m_TransitPaths.first);
|
||||
|
|
|
@ -456,7 +456,7 @@ namespace llarp
|
|||
{
|
||||
buildIntervalLimit = MIN_PATH_BUILD_INTERVAL;
|
||||
m_router->routerProfiling().MarkPathSuccess(p.get());
|
||||
LogInfo(p->Name(), " built latency=", p->intro.latency.count(), "ms");
|
||||
LogInfo(p->Name(), " built latency=", p->intro.latency);
|
||||
m_BuildStats.success++;
|
||||
}
|
||||
|
||||
|
@ -471,13 +471,11 @@ namespace llarp
|
|||
void
|
||||
Builder::DoPathBuildBackoff()
|
||||
{
|
||||
static constexpr std::chrono::milliseconds MaxBuildInterval = 30s;
|
||||
// linear backoff
|
||||
static constexpr auto MaxBuildInterval = 30s;
|
||||
buildIntervalLimit =
|
||||
std::min(MIN_PATH_BUILD_INTERVAL + buildIntervalLimit,
|
||||
Time_t(MaxBuildInterval));
|
||||
LogWarn(Name(), " build interval is now ", buildIntervalLimit.count(),
|
||||
"ms");
|
||||
buildIntervalLimit = std::min(
|
||||
MIN_PATH_BUILD_INTERVAL + buildIntervalLimit, MaxBuildInterval);
|
||||
LogWarn(Name(), " build interval is now ", buildIntervalLimit);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace llarp
|
|||
ShortHash nonceXOR;
|
||||
llarp_time_t started = 0s;
|
||||
// 10 minutes default
|
||||
Time_t lifetime = default_lifetime;
|
||||
llarp_time_t lifetime = default_lifetime;
|
||||
llarp_proto_version_t version;
|
||||
llarp_time_t m_LastActivity = 0s;
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace llarp
|
|||
virtual bool
|
||||
GossipRC(const RouterContact &rc) = 0;
|
||||
|
||||
using Time_t = std::chrono::milliseconds;
|
||||
|
||||
virtual void
|
||||
Decay(Time_t now) = 0;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace llarp
|
|||
return false;
|
||||
m_Filter.Insert(pubkey);
|
||||
|
||||
const auto now = time_now();
|
||||
const auto now = time_now_ms();
|
||||
// is this our rc?
|
||||
if(IsOurRC(rc))
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static constexpr auto ROUTER_TICK_INTERVAL = 1s;
|
||||
static constexpr std::chrono::milliseconds ROUTER_TICK_INTERVAL = 1s;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -658,11 +658,10 @@ namespace llarp
|
|||
if(IsServiceNode())
|
||||
{
|
||||
LogInfo(NumberOfConnectedClients(), " client connections");
|
||||
LogInfo(_rc.Age(now).count(), " ms since we last updated our RC");
|
||||
LogInfo(_rc.TimeUntilExpires(now).count(), " ms until our RC expires");
|
||||
LogInfo(_rc.Age(now), " since we last updated our RC");
|
||||
LogInfo(_rc.TimeUntilExpires(now), " until our RC expires");
|
||||
}
|
||||
LogInfo(now.count(), " system time");
|
||||
LogInfo(m_LastStatsReport.count(), " last reported stats");
|
||||
LogInfo(m_LastStatsReport, " last reported stats");
|
||||
m_LastStatsReport = now;
|
||||
}
|
||||
|
||||
|
@ -691,7 +690,7 @@ namespace llarp
|
|||
|
||||
const bool isSvcNode = IsServiceNode();
|
||||
|
||||
if(_rc.ExpiresSoon(now, Time_t(randint() % 10000))
|
||||
if(_rc.ExpiresSoon(now, std::chrono::milliseconds(randint() % 10000))
|
||||
|| (now - _rc.last_updated) > rcRegenInterval)
|
||||
{
|
||||
LogInfo("regenerating RC");
|
||||
|
|
|
@ -260,7 +260,7 @@ namespace llarp
|
|||
bool enableRPCServer = false;
|
||||
std::unique_ptr< rpc::Server > rpcServer;
|
||||
std::string rpcBindAddr = DefaultRPCBindAddr;
|
||||
const Time_t _randomStartDelay;
|
||||
const llarp_time_t _randomStartDelay;
|
||||
|
||||
/// lokid caller
|
||||
std::unique_ptr< rpc::Caller > rpcCaller;
|
||||
|
|
|
@ -369,7 +369,7 @@ namespace llarp
|
|||
return true;
|
||||
};
|
||||
router->hiddenServiceContext().ForEachService(visitor);
|
||||
const Response resp{{"uptime", router->Uptime().count()},
|
||||
const Response resp{{"uptime", to_json(router->Uptime())},
|
||||
{"servicesTotal", numServices},
|
||||
{"servicesReady", numServicesReady},
|
||||
{"services", services}};
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace llarp
|
|||
{
|
||||
const auto val = atoi(v.c_str());
|
||||
if(val > 0)
|
||||
m_MinPathLatency = Time_t(val);
|
||||
m_MinPathLatency = std::chrono::milliseconds(val);
|
||||
}
|
||||
if(k == "paths")
|
||||
{
|
||||
|
@ -116,8 +116,8 @@ namespace llarp
|
|||
util::StatusObject
|
||||
EndpointState::ExtractStatus(util::StatusObject& obj) const
|
||||
{
|
||||
obj["lastPublished"] = m_LastPublish.count();
|
||||
obj["lastPublishAttempt"] = m_LastPublishAttempt.count();
|
||||
obj["lastPublished"] = to_json(m_LastPublish);
|
||||
obj["lastPublishAttempt"] = to_json(m_LastPublishAttempt);
|
||||
obj["introset"] = m_IntroSet.ExtractStatus();
|
||||
|
||||
if(!m_Tag.IsZero())
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace llarp
|
|||
Introduction::ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{{"router", router.ToHex()},
|
||||
{"expiresAt", expiresAt.count()},
|
||||
{"latency", latency.count()},
|
||||
{"expiresAt", to_json(expiresAt)},
|
||||
{"latency", to_json(latency)},
|
||||
{"version", uint64_t(version)}};
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace llarp
|
|||
{
|
||||
const auto sz = introsetPayload.size();
|
||||
return {{"location", derivedSigningKey.ToString()},
|
||||
{"signedAt", signedAt.count()},
|
||||
{"signedAt", to_json(signedAt)},
|
||||
{"size", sz}};
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace llarp
|
|||
util::StatusObject
|
||||
IntroSet::ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{{"published", T.count()}};
|
||||
util::StatusObject obj{{"published", to_json(T)}};
|
||||
std::vector< util::StatusObject > introsObjs;
|
||||
std::transform(I.begin(), I.end(), std::back_inserter(introsObjs),
|
||||
[](const auto& intro) -> util::StatusObject {
|
||||
|
|
|
@ -251,11 +251,11 @@ namespace llarp
|
|||
auto obj = path::Builder::ExtractStatus();
|
||||
obj["currentConvoTag"] = currentConvoTag.ToHex();
|
||||
obj["remoteIntro"] = remoteIntro.ExtractStatus();
|
||||
obj["sessionCreatedAt"] = createdAt.count();
|
||||
obj["lastGoodSend"] = lastGoodSend.count();
|
||||
obj["sessionCreatedAt"] = to_json(createdAt);
|
||||
obj["lastGoodSend"] = to_json(lastGoodSend);
|
||||
obj["seqno"] = sequenceNo;
|
||||
obj["markedBad"] = markedBad;
|
||||
obj["lastShift"] = lastShift.count();
|
||||
obj["lastShift"] = to_json(lastShift);
|
||||
obj["remoteIdentity"] = remoteIdent.Addr().ToString();
|
||||
obj["currentRemoteIntroset"] = currentIntroSet.ExtractStatus();
|
||||
obj["nextIntro"] = m_NextIntro.ExtractStatus();
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace llarp
|
|||
util::StatusObject
|
||||
Session::ExtractStatus() const
|
||||
{
|
||||
util::StatusObject obj{{"lastUsed", lastUsed.count()},
|
||||
util::StatusObject obj{{"lastUsed", to_json(lastUsed)},
|
||||
{"replyIntro", replyIntro.ExtractStatus()},
|
||||
{"remote", remote.Addr().ToString()},
|
||||
{"seqno", seqno},
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace llarp
|
|||
util::StatusObject
|
||||
ExtractStatus() const;
|
||||
bool
|
||||
IsExpired(llarp_time_t now, Time_t lifetime = SessionLifetime) const;
|
||||
IsExpired(llarp_time_t now,
|
||||
llarp_time_t lifetime = SessionLifetime) const;
|
||||
};
|
||||
|
||||
} // namespace service
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace llarp
|
|||
template < typename Val_t, typename Hash_t = typename Val_t::Hash >
|
||||
struct DecayingHashSet
|
||||
{
|
||||
using Time_t = std::chrono::milliseconds;
|
||||
|
||||
DecayingHashSet(Time_t cacheInterval = 5s)
|
||||
: m_CacheInterval(cacheInterval)
|
||||
{
|
||||
|
@ -28,7 +30,7 @@ namespace llarp
|
|||
Insert(const Val_t& v, Time_t now = 0s)
|
||||
{
|
||||
if(now == 0s)
|
||||
now = llarp::time_now();
|
||||
now = llarp::time_now_ms();
|
||||
return m_Values.emplace(v, now).second;
|
||||
}
|
||||
|
||||
|
@ -37,7 +39,7 @@ namespace llarp
|
|||
Decay(Time_t now = 0s)
|
||||
{
|
||||
if(now == 0s)
|
||||
now = llarp::time_now();
|
||||
now = llarp::time_now_ms();
|
||||
|
||||
auto itr = m_Values.begin();
|
||||
while(itr != m_Values.end())
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace llarp
|
|||
const std::string& nodename, const std::string msg)
|
||||
{
|
||||
json::Object obj;
|
||||
obj["time"] = llarp::time_now_ms().count();
|
||||
obj["time"] = to_json(llarp::time_now_ms());
|
||||
obj["nickname"] = nodename;
|
||||
obj["file"] = std::string(fname);
|
||||
obj["line"] = lineno;
|
||||
|
|
|
@ -28,12 +28,6 @@ namespace llarp
|
|||
- started_at_steady;
|
||||
}
|
||||
|
||||
Time_t
|
||||
time_now()
|
||||
{
|
||||
return time_now_ms();
|
||||
}
|
||||
|
||||
llarp_time_t
|
||||
time_now_ms()
|
||||
{
|
||||
|
@ -65,4 +59,39 @@ namespace llarp
|
|||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
nlohmann::json
|
||||
to_json(const llarp_time_t &t)
|
||||
{
|
||||
return t.count();
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &out, const llarp_time_t &t)
|
||||
{
|
||||
std::chrono::milliseconds amount = t;
|
||||
auto h = std::chrono::duration_cast< std::chrono::hours >(amount);
|
||||
amount -= h;
|
||||
auto m = std::chrono::duration_cast< std::chrono::minutes >(amount);
|
||||
amount -= m;
|
||||
auto s = std::chrono::duration_cast< std::chrono::seconds >(amount);
|
||||
amount -= s;
|
||||
auto ms = amount;
|
||||
auto old_fill = out.fill('0');
|
||||
if(h > 0h)
|
||||
{
|
||||
out << h.count() << 'h';
|
||||
out.width(2); // 0-fill minutes if we have hours
|
||||
}
|
||||
if(h > 0h || m > 0min)
|
||||
{
|
||||
out << m.count() << 'm';
|
||||
out.width(2); // 0-fill seconds if we have minutes
|
||||
}
|
||||
out << s.count() << '.';
|
||||
out.width(3);
|
||||
out << ms.count();
|
||||
out.fill(old_fill);
|
||||
return out << "s";
|
||||
}
|
||||
} // namespace llarp
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define LLARP_TIME_HPP
|
||||
|
||||
#include <util/types.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
@ -10,9 +11,12 @@ namespace llarp
|
|||
/// get time right now as milliseconds, this is monotonic
|
||||
llarp_time_t
|
||||
time_now_ms();
|
||||
/// get time right now as a Time_t, monotonic
|
||||
Time_t
|
||||
time_now();
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &out, const llarp_time_t &t);
|
||||
|
||||
nlohmann::json
|
||||
to_json(const llarp_time_t &t);
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
|
|
|
@ -7,12 +7,7 @@
|
|||
using byte_t = uint8_t;
|
||||
using llarp_proto_version_t = std::uint8_t;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
using Time_t = std::chrono::milliseconds;
|
||||
}
|
||||
|
||||
using llarp_time_t = llarp::Time_t;
|
||||
using llarp_time_t = std::chrono::milliseconds;
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
|
|
@ -22,8 +22,8 @@ TEST_CASE("DecayingHashSet test decay static time", "[decaying-hashset]")
|
|||
|
||||
TEST_CASE("DecayingHashSet tset decay dynamic time", "[decaying-hashset]")
|
||||
{
|
||||
static constexpr auto timeout = 5s;
|
||||
const llarp::Time_t now = llarp::time_now();
|
||||
static constexpr llarp_time_t timeout = 5s;
|
||||
const llarp_time_t now = llarp::time_now_ms();
|
||||
llarp::util::DecayingHashSet< llarp::RouterID > hashset(timeout);
|
||||
const llarp::RouterID zero;
|
||||
REQUIRE(zero.IsZero());
|
||||
|
|
Loading…
Reference in New Issue