add gossip info to systemd status

* adds next and last gossip datetimes
* adds a few things for time points, like ostream operator overloads for time point
pull/1905/head
Jeff 2 years ago
parent 3c44a06403
commit 18e1272c76
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -1,5 +1,7 @@
#pragma once
#include <llarp/router_contact.hpp>
#include <llarp/util/time.hpp>
#include <optional>
namespace llarp
{
@ -15,7 +17,7 @@ namespace llarp
virtual bool
GossipRC(const RouterContact& rc) = 0;
using Time_t = std::chrono::milliseconds;
using Time_t = Duration_t;
virtual void
Decay(Time_t now) = 0;
@ -31,5 +33,13 @@ namespace llarp
/// forget the replay filter entry given pubkey
virtual void
Forget(const RouterID& router) = 0;
/// returns the time point when we will send our next gossip at
virtual TimePoint_t
NextGossipAt() const = 0;
/// returns the time point when we sent our last gossip at or nullopt if we never did
virtual std::optional<TimePoint_t>
LastGossipAt() const = 0;
};
} // namespace llarp

@ -50,6 +50,22 @@ namespace llarp
m_LastGossipedOurRC = 0s;
}
TimePoint_t
RCGossiper::NextGossipAt() const
{
if (auto maybe = LastGossipAt())
return *maybe + GossipOurRCInterval;
return DateClock_t::now();
}
std::optional<TimePoint_t>
RCGossiper::LastGossipAt() const
{
if (m_LastGossipedOurRC == 0s)
return std::nullopt;
return DateClock_t::time_point{m_LastGossipedOurRC};
}
bool
RCGossiper::GossipRC(const RouterContact& rc)
{

@ -32,6 +32,12 @@ namespace llarp
void
Forget(const RouterID& router) override;
TimePoint_t
NextGossipAt() const override;
std::optional<TimePoint_t>
LastGossipAt() const override;
private:
RouterID m_OurRouterID;
Time_t m_LastGossipedOurRC = 0s;

@ -869,7 +869,16 @@ namespace llarp
ss << " snode | known/svc/clients: " << nodedb()->NumLoaded() << "/"
<< NumberOfConnectedRouters() << "/" << NumberOfConnectedClients() << " | "
<< pathContext().CurrentTransitPaths() << " active paths | "
<< "block " << (m_lokidRpcClient ? m_lokidRpcClient->BlockHeight() : 0);
<< "block " << (m_lokidRpcClient ? m_lokidRpcClient->BlockHeight() : 0) << " | gossip: "
<< "(next/last) " << _rcGossiper.NextGossipAt() << "/";
if (auto maybe = _rcGossiper.LastGossipAt())
{
ss << *maybe;
}
else
{
ss << "never";
}
}
else
{

@ -1,20 +1,24 @@
#include "time.hpp"
#include <chrono>
#include <iomanip>
namespace llarp
{
using Clock_t = std::chrono::system_clock;
template <typename Res, typename Clock>
static Duration_t
time_since_epoch(std::chrono::time_point<Clock> point)
namespace
{
return std::chrono::duration_cast<Res>(point.time_since_epoch());
}
using Clock_t = std::chrono::system_clock;
template <typename Res, typename Clock>
static Duration_t
time_since_epoch(std::chrono::time_point<Clock> point)
{
return std::chrono::duration_cast<Res>(point.time_since_epoch());
}
const static auto started_at_system = Clock_t::now();
const static auto started_at_system = Clock_t::now();
const static auto started_at_steady = std::chrono::steady_clock::now();
const static auto started_at_steady = std::chrono::steady_clock::now();
} // namespace
uint64_t
ToMS(Duration_t ms)
@ -74,4 +78,11 @@ namespace llarp
out.fill(old_fill);
return out << "s";
}
std::ostream&
operator<<(std::ostream& out, const TimePoint_t& tp)
{
auto t = TimePoint_t::clock::to_time_t(tp);
return out << std::put_time(std::localtime(&t), "%c %Z");
}
} // namespace llarp

@ -26,4 +26,7 @@ namespace llarp
nlohmann::json
to_json(const Duration_t& t);
std::ostream&
operator<<(std::ostream& out, const TimePoint_t& t);
} // namespace llarp

@ -14,6 +14,9 @@ namespace llarp
/// convert to milliseconds
uint64_t
ToMS(Duration_t duration);
using DateClock_t = std::chrono::system_clock;
using TimePoint_t = DateClock_t::time_point;
} // namespace llarp
using llarp_time_t = llarp::Duration_t;

Loading…
Cancel
Save