diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h index 926d6477..44dd8719 100644 --- a/include/opendht/dht_proxy_server.h +++ b/include/opendht/dht_proxy_server.h @@ -149,44 +149,12 @@ public: /** Node Info **/ std::shared_ptr nodeInfo {}; - std::string toString() const { - auto ret = fmt::format("Listens: {}, Puts: {}, PushListeners: {}\n" - "Push requests in the last {}: [Android: {}], [iOS: {}], [Unified: {}]\n" - "Requests: {} per second.", - listenCount, putCount, pushListenersCount, - print_duration(lastUpdated - serverStartTime), - androidPush.toString(), iosPush.toString(), unifiedPush.toString(), - requestRate); - if (nodeInfo) { - auto& ipv4 = nodeInfo->ipv4; - if (ipv4.table_depth > 1) - ret += fmt::format("IPv4 Network estimation: {}\n", ipv4.getNetworkSizeEstimation()); - auto& ipv6 = nodeInfo->ipv6; - if (ipv6.table_depth > 1) - ret += fmt::format("IPv6 Network estimation: {}\n", ipv6.getNetworkSizeEstimation()); - } - return ret; - } + std::string toString() const; /** * Build a json object from a NodeStats */ - Json::Value toJson() const { - Json::Value result; - result["listenCount"] = static_cast(listenCount); - result["putCount"] = static_cast(putCount); - result["totalPermanentPuts"] = static_cast(totalPermanentPuts); - result["pushListenersCount"] = static_cast(pushListenersCount); - result["serverStartTime"] = static_cast(to_time_t(serverStartTime)); - result["lastUpdated"] = static_cast(to_time_t(lastUpdated)); - result["androidPush"] = androidPush.toJson(); - result["iosPush"] = iosPush.toJson(); - result["unifiedPush"] = unifiedPush.toJson(); - result["requestRate"] = requestRate; - if (nodeInfo) - result["nodeInfo"] = nodeInfo->toJson(); - return result; - } + Json::Value toJson() const; }; std::shared_ptr stats() const { return stats_; } diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 137b029c..659407e2 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -100,6 +100,47 @@ private: std::shared_ptr m_logger; }; + +std::string +DhtProxyServer::ServerStats::toString() const +{ + auto ret = fmt::format("Listens: {}, Puts: {}, PushListeners: {}\n" + "Push requests in the last {}: [Android: {}], [iOS: {}], [Unified: {}]\n" + "Requests: {} per second.", + listenCount, putCount, pushListenersCount, + print_duration(lastUpdated - serverStartTime), + androidPush.toString(), iosPush.toString(), unifiedPush.toString(), + requestRate); + if (nodeInfo) { + auto& ipv4 = nodeInfo->ipv4; + if (ipv4.table_depth > 1) + ret += fmt::format("IPv4 Network estimation: {}\n", ipv4.getNetworkSizeEstimation()); + auto& ipv6 = nodeInfo->ipv6; + if (ipv6.table_depth > 1) + ret += fmt::format("IPv6 Network estimation: {}\n", ipv6.getNetworkSizeEstimation()); + } + return ret; +} + +Json::Value +DhtProxyServer::ServerStats::toJson() const +{ + Json::Value result; + result["listenCount"] = static_cast(listenCount); + result["putCount"] = static_cast(putCount); + result["totalPermanentPuts"] = static_cast(totalPermanentPuts); + result["pushListenersCount"] = static_cast(pushListenersCount); + result["serverStartTime"] = static_cast(to_time_t(serverStartTime)); + result["lastUpdated"] = static_cast(to_time_t(lastUpdated)); + result["androidPush"] = androidPush.toJson(); + result["iosPush"] = iosPush.toJson(); + result["unifiedPush"] = unifiedPush.toJson(); + result["requestRate"] = requestRate; + if (nodeInfo) + result["nodeInfo"] = nodeInfo->toJson(); + return result; +} + restinio::request_handling_status_t DhtProxyServer::serverError(restinio::request_t& request) { auto response = initHttpResponse(request.create_response(restinio::status_internal_server_error()));