Introduce repo stats
parent
0aa25b4062
commit
b913c86021
|
@ -1 +1 @@
|
|||
Subproject commit c6af4bfbf02729b80ccb2ccc378361b6139bd402
|
||||
Subproject commit 0e0908048eb08cad112bbc02acbf0e127ff390f7
|
23
src/ipfs.cc
23
src/ipfs.cc
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue