|
|
|
@ -96,6 +96,77 @@ namespace llarp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
|
Router::ExtractSummaryStatus() const
|
|
|
|
|
{
|
|
|
|
|
if (!_running)
|
|
|
|
|
return util::StatusObject{{"running", false}};
|
|
|
|
|
|
|
|
|
|
auto services = _hiddenServiceContext.ExtractStatus();
|
|
|
|
|
auto link_types = _linkManager.ExtractStatus();
|
|
|
|
|
|
|
|
|
|
uint64_t tx_rate = 0;
|
|
|
|
|
uint64_t rx_rate = 0;
|
|
|
|
|
uint64_t peers = 0;
|
|
|
|
|
for (const auto& links : link_types)
|
|
|
|
|
{
|
|
|
|
|
for (const auto& link : links)
|
|
|
|
|
{
|
|
|
|
|
if (link.empty())
|
|
|
|
|
continue;
|
|
|
|
|
for (const auto& peer : link["sessions"]["established"])
|
|
|
|
|
{
|
|
|
|
|
tx_rate += peer["tx"].get<uint64_t>();
|
|
|
|
|
rx_rate += peer["rx"].get<uint64_t>();
|
|
|
|
|
peers++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compute all stats on all path builders on the default endpoint
|
|
|
|
|
// Merge snodeSessions, remoteSessions and default into a single array
|
|
|
|
|
std::vector<nlohmann::json> builders;
|
|
|
|
|
auto snode_sessions = services["default"]["snodeSessions"];
|
|
|
|
|
for (const auto& session : snode_sessions)
|
|
|
|
|
builders.push_back(session["buildStats"]);
|
|
|
|
|
|
|
|
|
|
auto remote_sessions = services["default"]["remoteSessions"];
|
|
|
|
|
for (const auto& session : remote_sessions)
|
|
|
|
|
builders.push_back(session["buildStats"]);
|
|
|
|
|
|
|
|
|
|
builders.push_back(services["default"]["buildStats"]);
|
|
|
|
|
|
|
|
|
|
// Iterate over all items on this array to build the global pathStats
|
|
|
|
|
uint64_t paths = 0;
|
|
|
|
|
uint64_t success = 0;
|
|
|
|
|
uint64_t attempts = 0;
|
|
|
|
|
for (const auto& builder : builders)
|
|
|
|
|
{
|
|
|
|
|
if (builder.is_null())
|
|
|
|
|
continue;
|
|
|
|
|
if (builder["length"].is_number())
|
|
|
|
|
paths += builder["length"].get<uint64_t>();
|
|
|
|
|
if (builder["success"].is_number())
|
|
|
|
|
success += builder["success"].get<uint64_t>();
|
|
|
|
|
if (builder["attempts"].is_number())
|
|
|
|
|
attempts += builder["attempts"].get<uint64_t>();
|
|
|
|
|
}
|
|
|
|
|
double ratio = static_cast<double>(success) / (attempts + 1);
|
|
|
|
|
|
|
|
|
|
return util::StatusObject{
|
|
|
|
|
{"running", true},
|
|
|
|
|
{"authCodes", services["default"]["authCodes"]},
|
|
|
|
|
{"exitMap", services["default"]["exitMap"]},
|
|
|
|
|
{"lokiAddress", services["default"]["identity"]},
|
|
|
|
|
{"numPathsBuilt", paths},
|
|
|
|
|
{"numPeersConnected", peers},
|
|
|
|
|
{"numRoutersKnown", _nodedb->NumLoaded()},
|
|
|
|
|
{"ratio", ratio},
|
|
|
|
|
{"txRate", tx_rate},
|
|
|
|
|
{"rxRate", rx_rate},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Router::HandleRecvLinkMessageBuffer(ILinkSession* session, const llarp_buffer_t& buf)
|
|
|
|
|
{
|
|
|
|
|