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 #pragma once
#include <llarp/router_contact.hpp> #include <llarp/router_contact.hpp>
#include <llarp/util/time.hpp>
#include <optional>
namespace llarp namespace llarp
{ {
@ -15,7 +17,7 @@ namespace llarp
virtual bool virtual bool
GossipRC(const RouterContact& rc) = 0; GossipRC(const RouterContact& rc) = 0;
using Time_t = std::chrono::milliseconds; using Time_t = Duration_t;
virtual void virtual void
Decay(Time_t now) = 0; Decay(Time_t now) = 0;
@ -31,5 +33,13 @@ namespace llarp
/// forget the replay filter entry given pubkey /// forget the replay filter entry given pubkey
virtual void virtual void
Forget(const RouterID& router) = 0; 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 } // namespace llarp

@ -50,6 +50,22 @@ namespace llarp
m_LastGossipedOurRC = 0s; 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 bool
RCGossiper::GossipRC(const RouterContact& rc) RCGossiper::GossipRC(const RouterContact& rc)
{ {

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

@ -869,7 +869,16 @@ namespace llarp
ss << " snode | known/svc/clients: " << nodedb()->NumLoaded() << "/" ss << " snode | known/svc/clients: " << nodedb()->NumLoaded() << "/"
<< NumberOfConnectedRouters() << "/" << NumberOfConnectedClients() << " | " << NumberOfConnectedRouters() << "/" << NumberOfConnectedClients() << " | "
<< pathContext().CurrentTransitPaths() << " active paths | " << 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 else
{ {

@ -1,20 +1,24 @@
#include "time.hpp" #include "time.hpp"
#include <chrono> #include <chrono>
#include <iomanip>
namespace llarp namespace llarp
{ {
using Clock_t = std::chrono::system_clock; namespace
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()); 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 uint64_t
ToMS(Duration_t ms) ToMS(Duration_t ms)
@ -74,4 +78,11 @@ namespace llarp
out.fill(old_fill); out.fill(old_fill);
return out << "s"; 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 } // namespace llarp

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

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

Loading…
Cancel
Save