Fixed some bugs in Dashboard

* Added client Version to tooltip
* Add version check and "update available" notification to Dashboard
This commit is contained in:
BenDroid 2017-11-23 19:27:48 +01:00
parent f87f1efe2a
commit 5c38710c5c
7 changed files with 142 additions and 100 deletions

View file

@ -25,6 +25,7 @@
#include <fstream>
#include <3rdparty/rapidjson/stringbuffer.h>
#include <3rdparty/rapidjson/prettywriter.h>
#include <version.h>
#include "CCClient.h"
#include "App.h"
@ -41,16 +42,18 @@
#if _WIN32
# include "winsock2.h"
#else
# include "unistd.h"
#endif
CCClient *CCClient::m_self = nullptr;
CCClient* CCClient::m_self = nullptr;
uv_mutex_t CCClient::m_mutex;
CCClient::CCClient(Options* options, uv_async_t* async)
: m_options(options),
m_async(async)
: m_options(options),
m_async(async)
{
uv_mutex_init(&m_mutex);
@ -59,10 +62,10 @@ CCClient::CCClient(Options* options, uv_async_t* async)
std::string clientId;
if (m_options->ccWorkerId()) {
clientId = m_options->ccWorkerId();
} else{
} else {
char hostname[128];
memset(hostname, 0, sizeof(hostname));
gethostname(hostname, sizeof(hostname)-1);
gethostname(hostname, sizeof(hostname) - 1);
clientId = std::string(hostname);
}
@ -76,6 +79,7 @@ CCClient::CCClient(Options* options, uv_async_t* async)
m_clientStatus.setHugepages(Mem::isHugepagesAvailable());
m_clientStatus.setDoubleHashMode(Mem::isDoubleHash());
m_clientStatus.setVersion(Version::string());
m_clientStatus.setCpuBrand(Cpu::brand());
m_clientStatus.setCpuAES(Cpu::hasAES());
m_clientStatus.setCpuCores(Cpu::cores());
@ -98,7 +102,7 @@ CCClient::~CCClient()
m_self = nullptr;
}
void CCClient::updateHashrate(const Hashrate *hashrate)
void CCClient::updateHashrate(const Hashrate* hashrate)
{
if (m_self) {
uv_mutex_lock(&m_mutex);
@ -113,7 +117,7 @@ void CCClient::updateHashrate(const Hashrate *hashrate)
}
void CCClient::updateNetworkState(const NetworkState &network)
void CCClient::updateNetworkState(const NetworkState& network)
{
if (m_self) {
uv_mutex_lock(&m_mutex);
@ -139,7 +143,7 @@ void CCClient::publishClientStatusReport()
LOG_ERR("[CC-Client] error: unable to performRequest POST -> http://%s:%d%s",
m_self->m_options->ccHost(), m_self->m_options->ccPort(), requestUrl.c_str());
} else if (res->status != 200) {
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
m_self->m_options->ccPort(), requestUrl.c_str());
} else {
ControlCommand controlCommand;
@ -161,7 +165,7 @@ void CCClient::publishClientStatusReport()
LOG_WARN("[CC-Client] Command: SHUTDOWN received -> shutdown");
}
m_self->m_async->data = reinterpret_cast<void *>(controlCommand.getCommand());
m_self->m_async->data = reinterpret_cast<void*>(controlCommand.getCommand());
uv_async_send(m_self->m_async);
} else {
LOG_ERR("[CC-Client] Unknown command received from CC Server.");
@ -179,7 +183,7 @@ void CCClient::updateConfig()
LOG_ERR("[CC-Client] error: unable to performRequest GET -> http://%s:%d%s",
m_self->m_options->ccHost(), m_self->m_options->ccPort(), requestUrl.c_str());
} else if (res->status != 200) {
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
LOG_ERR("[CC-Client] error: \"%d\" -> http://%s:%d%s", res->status, m_self->m_options->ccHost(),
m_self->m_options->ccPort(), requestUrl.c_str());
} else {
rapidjson::Document document;
@ -198,7 +202,7 @@ void CCClient::updateConfig()
} else {
LOG_ERR("[CC-Client] Not able to store client config to file %s.", m_self->m_options->configFile());
}
} else{
} else {
LOG_ERR("[CC-Client] Not able to store client config. received client config is broken!");
}
}
@ -244,7 +248,7 @@ void CCClient::onThreadStarted(void* handle)
uv_run(&m_self->m_client_loop, UV_RUN_DEFAULT);
}
void CCClient::onReport(uv_timer_t *handle)
void CCClient::onReport(uv_timer_t* handle)
{
if (m_self) {
m_self->publishClientStatusReport();

View file

@ -115,6 +115,16 @@ void ClientStatus::setExternalIp(const std::string& externalIp)
m_externalIp = externalIp;
}
std::string ClientStatus::getVersion() const
{
return m_version;
}
void ClientStatus::setVersion(const std::string& version)
{
m_version = version;
}
bool ClientStatus::hasHugepages() const
{
return m_hasHugepages;
@ -321,6 +331,10 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
m_externalIp = clientStatus["external_ip"].GetString();
}
if (clientStatus.HasMember("version")) {
m_version = clientStatus["version"].GetString();
}
if (clientStatus.HasMember("hugepages_available")) {
m_hasHugepages = clientStatus["hugepages_available"].GetBool();
}
@ -411,6 +425,7 @@ rapidjson::Value ClientStatus::toJson(rapidjson::MemoryPoolAllocator<rapidjson::
clientStatus.AddMember("current_algo_name", rapidjson::StringRef(m_currentAlgoName.c_str()), allocator);
clientStatus.AddMember("cpu_brand", rapidjson::StringRef(m_cpuBrand.c_str()), allocator);
clientStatus.AddMember("external_ip", rapidjson::StringRef(m_externalIp.c_str()), allocator);
clientStatus.AddMember("version", rapidjson::StringRef(m_version.c_str()), allocator);
clientStatus.AddMember("hugepages_available", m_hasHugepages, allocator);
clientStatus.AddMember("hugepages_enabled", m_isHugepagesEnabled, allocator);

View file

@ -68,13 +68,16 @@ public:
void setCurrentPool(const std::string& currentPool);
std::string getCurrentAlgoName() const;
void setCurrentAlgoName(const std::string &algoName);
void setCurrentAlgoName(const std::string& algoName);
std::string getCpuBrand() const;
void setCpuBrand(const std::string &cpuBrand);
void setCpuBrand(const std::string& cpuBrand);
std::string getExternalIp() const;
void setExternalIp(const std::string &externalIp);
void setExternalIp(const std::string& externalIp);
std::string getVersion() const;
void setVersion(const std::string& version);
bool hasHugepages() const;
void setHugepages(bool hasHugepages);
@ -148,6 +151,7 @@ private:
std::string m_currentAlgoName;
std::string m_cpuBrand;
std::string m_externalIp;
std::string m_version;
bool m_hasHugepages;
bool m_isHugepagesEnabled;

View file

@ -32,6 +32,7 @@
#include <3rdparty/rapidjson/filereadstream.h>
#include <3rdparty/rapidjson/error/en.h>
#include <3rdparty/rapidjson/prettywriter.h>
#include <version.h>
#include "log/Log.h"
#include "Service.h"
@ -194,6 +195,7 @@ unsigned Service::getClientStatusList(std::string& resp)
clientStatusList.PushBack(clientStatusEntry, allocator);
}
document.AddMember("current_version", rapidjson::StringRef(Version::string().c_str()), allocator);
document.AddMember("client_status_list", clientStatusList, allocator);
rapidjson::StringBuffer buffer(0, 4096);

View file

@ -36,14 +36,14 @@
#define APP_DESC "XMRigCC CPU miner"
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
#endif
#define APP_VERSION "1.1.0 (based on XMRig 2.4.2)"
#define APP_VERSION "1.1.1 (based on XMRig 2.4.2)"
#define APP_DOMAIN ""
#define APP_SITE "https://github.com/Bendr0id/xmrigCC"
#define APP_KIND "cpu"
#define APP_VER_MAJOR 1
#define APP_VER_MINOR 1
#define APP_VER_BUILD 0
#define APP_VER_BUILD 1
#define APP_VER_REV 0
#ifdef _MSC_VER
@ -62,4 +62,24 @@
# endif
#endif
#include <string>
class Version
{
public:
inline static std::string string()
{
std::string version = std::to_string(APP_VER_MAJOR) + std::string(".") + std::to_string(APP_VER_MINOR) +
std::string(".") + std::to_string(APP_VER_BUILD);
return version;
}
inline static int code()
{
std::string version = std::to_string(APP_VER_MAJOR) + std::to_string(APP_VER_MINOR) + std::to_string(APP_VER_BUILD);
return std::stoi(version);
}
};
#endif /* __VERSION_H__ */