Introduce repo stats

master
Melroy van den Berg 2021-08-17 18:42:22 +02:00
parent 0aa25b4062
commit b913c86021
No known key found for this signature in database
GPG Key ID: 71D11FF23454B9D7
4 changed files with 32 additions and 1 deletions

@ -1 +1 @@
Subproject commit c6af4bfbf02729b80ccb2ccc378361b6139bd402
Subproject commit 0e0908048eb08cad112bbc02acbf0e127ff390f7

View File

@ -112,6 +112,29 @@ std::map<std::string, float> IPFS::getBandwidthRates()
return bandwidthRates;
}
/**
* \brief Get the stats of the current Repo
* \return Map with repo stats (with keys: 'total_size' and 'path')
*/
std::map<std::string, std::variant<int, std::string>> IPFS::getRepoStats()
{
std::map<std::string, std::variant<int, std::string>> repoStats;
try
{
ipfs::Json repo_stats;
client.StatsRepo(&repo_stats);
int repoSize = (int) repo_stats["RepoSize"] / 1000000; // Convert from bytes to MB
std::string repoPath = repo_stats["RepoPath"];
repoStats.insert(std::pair<std::string, int>("total_size", repoSize));
repoStats.insert(std::pair<std::string, std::string>("path", repoPath));
}
catch (const std::runtime_error &error)
{
// ignore connection issues
}
return repoStats;
}
/**
* \brief Fetch file from IFPS network (create a new client object each time - which is thread-safe), static method
* \param path File path

View File

@ -2,6 +2,7 @@
#define IPFS_H
#include <string>
#include <variant>
#include "ipfs/client.h"
/**
@ -17,6 +18,7 @@ public:
std::string const getClientPublicKey();
std::string const getVersion();
std::map<std::string, float> getBandwidthRates();
std::map<std::string, std::variant<int, std::string>> getRepoStats();
std::string const fetch(const std::string &path);
std::string const add(const std::string &path, const std::string &content);

View File

@ -525,10 +525,16 @@ bool MainWindow::update_connection_status()
std::string in = std::string(buf, std::snprintf(buf, sizeof buf, "%.1f", rates.at("in") / 1000.0));
std::string out = std::string(buf, std::snprintf(buf, sizeof buf, "%.1f", rates.at("out") / 1000.0));
std::map<std::string, std::variant<int, std::string>> repoStats = ipfs.getRepoStats();
int totalRepoSize = std::get<int>(repoStats.at("total_size"));
std::string repoPath = std::get<std::string>(repoStats.at("path"));
// And also update text
m_statusLabel.set_text("IPFS Network Stats:\n\nConnected peers: " + std::to_string(nrPeers) +
"\nRate in: " + in + " kB/s" +
"\nRate out: " + out + " kB/s" +
"\n\nTotal repo size: " + std::to_string(totalRepoSize) + " MB" +
"\nRepo path: " + repoPath +
"\n\nIPFS version: " + this->ipfsVersion);
}
else