Add uptime to crawl data (RIPD-997)

This commit is contained in:
Miguel Portilla
2015-07-27 13:28:19 -04:00
committed by Nik Bougalis
parent 1a3e2e3f36
commit 6cf75f0fc2
3 changed files with 14 additions and 1 deletions

View File

@@ -744,6 +744,7 @@ OverlayImpl::size()
Json::Value
OverlayImpl::crawl()
{
using namespace std::chrono;
Json::Value jv;
auto& av = jv["active"] = Json::Value(Json::arrayValue);
std::lock_guard <decltype(mutex_)> lock (mutex_);
@@ -752,12 +753,14 @@ OverlayImpl::crawl()
if (auto const sp = e.second.lock())
{
auto& pv = av.append(Json::Value(Json::objectValue));
pv[jss::type] = "peer";
pv[jss::public_key] = beast::base64_encode(
sp->getNodePublic().getNodePublic().data(),
sp->getNodePublic().getNodePublic().size());
pv[jss::type] = sp->slot()->inbound() ?
"in" : "out";
pv[jss::uptime] =
static_cast<std::uint32_t>(duration_cast<seconds>(
sp->uptime()).count());
if (sp->crawl())
{
pv[jss::ip] = sp->getRemoteAddress().address().to_string();

View File

@@ -75,6 +75,7 @@ PeerImp::PeerImp (id_t id, endpoint_type remote_endpoint,
, sanity_ (Sanity::unknown)
, insaneTime_ (clock_type::now())
, publicKey_(publicKey)
, creationTime_ (clock_type::now())
, hello_(hello)
, usage_(consumer)
, fee_ (Resource::feeLightPeer)

View File

@@ -143,6 +143,7 @@ private:
std::chrono::milliseconds latency_ = std::chrono::milliseconds (-1);
std::uint64_t lastPingSeq_ = 0;
clock_type::time_point lastPingTime_;
clock_type::time_point creationTime_;
std::mutex mutable recentLock_;
protocol::TMStatusChange last_status_;
@@ -279,6 +280,13 @@ public:
std::string
getVersion() const;
// Return the connection elapsed time.
clock_type::duration
uptime() const
{
return clock_type::now() - creationTime_;
}
Json::Value
json() override;
@@ -497,6 +505,7 @@ PeerImp::PeerImp (std::unique_ptr<beast::asio::ssl_bundle>&& ssl_bundle,
, sanity_ (Sanity::unknown)
, insaneTime_ (clock_type::now())
, publicKey_ (legacyPublicKey)
, creationTime_ (clock_type::now())
, hello_ (std::move(hello))
, usage_ (usage)
, fee_ (Resource::feeLightPeer)