From 8c0b7ce776bfc77f4d03ec269d3f3ffbec250d90 Mon Sep 17 00:00:00 2001 From: Konrad Date: Fri, 21 Apr 2017 23:44:00 +0200 Subject: [PATCH] Fixed: Responds sends now correct time difference --- libresapi/src/api/IdentityHandler.cpp | 4 ++-- libresapi/src/api/PeersHandler.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libresapi/src/api/IdentityHandler.cpp b/libresapi/src/api/IdentityHandler.cpp index 67e5cb4c6..2990a745c 100644 --- a/libresapi/src/api/IdentityHandler.cpp +++ b/libresapi/src/api/IdentityHandler.cpp @@ -413,7 +413,7 @@ void IdentityHandler::handleGetIdentityDetails(Request& req, Response& resp) resp.mDataStream << makeKeyValue("pgp_name", pgp_name); time_t now = time(NULL); - resp.mDataStream << makeKeyValue("last_usage", std::to_string(now - data.mLastUsageTS)); + resp.mDataStream << makeKeyValue("last_usage", difftime(now, data.mLastUsageTS)); bool isAnonymous = false; if(!data.mPgpKnown) @@ -468,7 +468,7 @@ void IdentityHandler::handleGetIdentityDetails(Request& req, Response& resp) for(std::map::const_iterator it(details.mUseCases.begin()); it != details.mUseCases.end(); ++it) { - usagesStream.getStreamToMember() << makeKeyValue("usage_time", std::to_string(now - it->second)); + usagesStream.getStreamToMember() << makeKeyValue("usage_time", difftime(now, data.mLastUsageTS)); usagesStream.getStreamToMember() << makeKeyValue("usage_service", (int)(it->first.mServiceId)); usagesStream.getStreamToMember() << makeKeyValue("usage_case", (int)(it->first.mUsageCode)); } diff --git a/libresapi/src/api/PeersHandler.cpp b/libresapi/src/api/PeersHandler.cpp index 6649acdcb..dd03f8351 100644 --- a/libresapi/src/api/PeersHandler.cpp +++ b/libresapi/src/api/PeersHandler.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "Operators.h" #include "ApiTypes.h" @@ -745,11 +746,12 @@ void PeersHandler::handleGetNodeOptions(Request& req, Response& resp) return; } + time_t now = time(NULL); resp.mDataStream << makeKeyValue("peer_id", detail.id.toStdString()); resp.mDataStream << makeKeyValue("name", detail.name); resp.mDataStream << makeKeyValue("location", detail.location); resp.mDataStream << makeKeyValue("pgp_id", detail.gpg_id.toStdString()); - resp.mDataStream << makeKeyValue("last_contact", detail.lastConnect); + resp.mDataStream << makeKeyValue("last_contact", difftime(now, detail.lastConnect)); std::string status_message = mRsMsgs->getCustomStateString(detail.id); resp.mDataStream << makeKeyValueReference("status_message", status_message);