diff --git a/CMakeLists.txt b/CMakeLists.txt index f5df77184..6cc9eb89c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(HEADERS src/3rdparty/align.h src/api/Api.h src/api/ApiState.h - src/api/Results.h + src/api/NetworkState.h src/App.h src/Console.h src/Cpu.h @@ -65,7 +65,7 @@ set(HEADERS_CRYPTO set(SOURCES src/api/Api.cpp src/api/ApiState.cpp - src/api/Results.cpp + src/api/NetworkState.cpp src/App.cpp src/Console.cpp src/log/ConsoleLog.cpp diff --git a/src/api/Api.cpp b/src/api/Api.cpp index dd120408a..20882133e 100644 --- a/src/api/Api.cpp +++ b/src/api/Api.cpp @@ -81,13 +81,13 @@ void Api::tick(const Hashrate *hashrate) } -void Api::tick(const Results &results) +void Api::tick(const NetworkState &network) { if (!m_state) { return; } uv_mutex_lock(&m_mutex); - m_state->tick(results); + m_state->tick(network); uv_mutex_unlock(&m_mutex); } diff --git a/src/api/Api.h b/src/api/Api.h index d228fb387..dc5a09e05 100644 --- a/src/api/Api.h +++ b/src/api/Api.h @@ -30,7 +30,7 @@ class ApiState; class Hashrate; -class Results; +class NetworkState; class Api @@ -41,7 +41,7 @@ public: static const char *get(const char *url, size_t *size, int *status); static void tick(const Hashrate *hashrate); - static void tick(const Results &results); + static void tick(const NetworkState &results); private: static ApiState *m_state; diff --git a/src/api/ApiState.cpp b/src/api/ApiState.cpp index af51f6dc4..66af86bfb 100644 --- a/src/api/ApiState.cpp +++ b/src/api/ApiState.cpp @@ -112,9 +112,9 @@ void ApiState::tick(const Hashrate *hashrate) } -void ApiState::tick(const Results &results) +void ApiState::tick(const NetworkState &network) { - m_results = results; + m_network = network; } @@ -216,14 +216,15 @@ void ApiState::getResults(json_t *reply) const json_t *results = json_object(); json_t *best = json_array(); - json_object_set(reply, "results", results); - json_object_set(results, "diff_current", json_integer(m_results.diff)); - json_object_set(results, "shares_good", json_integer(m_results.accepted)); - json_object_set(results, "shares_total", json_integer(m_results.accepted + m_results.rejected)); - json_object_set(results, "hashes_total", json_integer(m_results.total)); - json_object_set(results, "best", best); + json_object_set(reply, "results", results); + json_object_set(results, "diff_current", json_integer(m_network.diff)); + json_object_set(results, "shares_good", json_integer(m_network.accepted)); + json_object_set(results, "shares_total", json_integer(m_network.accepted + m_network.rejected)); + json_object_set(results, "hashes_total", json_integer(m_network.total)); + json_object_set(results, "best", best); + json_object_set(results, "error_log", json_array()); - for (size_t i = 0; i < m_results.topDiff.size(); ++i) { - json_array_append(best, json_integer(m_results.topDiff[i])); + for (size_t i = 0; i < m_network.topDiff.size(); ++i) { + json_array_append(best, json_integer(m_network.topDiff[i])); } } diff --git a/src/api/ApiState.h b/src/api/ApiState.h index e4c4740bd..14c4c1357 100644 --- a/src/api/ApiState.h +++ b/src/api/ApiState.h @@ -25,7 +25,7 @@ #define __APISTATE_H__ -#include "api/Results.h" +#include "api/NetworkState.h" #include "jansson.h" @@ -40,7 +40,7 @@ public: const char *get(const char *url, size_t *size) const; void tick(const Hashrate *hashrate); - void tick(const Results &results); + void tick(const NetworkState &results); private: const char *finalize(json_t *reply, size_t *size) const; @@ -58,7 +58,7 @@ private: double m_totalHashrate[3]; int m_threads; mutable char m_buf[4096]; - Results m_results; + NetworkState m_network; }; #endif /* __APISTATE_H__ */ diff --git a/src/api/Results.cpp b/src/api/NetworkState.cpp similarity index 93% rename from src/api/Results.cpp rename to src/api/NetworkState.cpp index 80f721d4f..08c64c219 100644 --- a/src/api/Results.cpp +++ b/src/api/NetworkState.cpp @@ -25,11 +25,11 @@ #include -#include "api/Results.h" +#include "api/NetworkState.h" #include "net/SubmitResult.h" -void Results::add(const SubmitResult &result, const char *error) +void NetworkState::add(const SubmitResult &result, const char *error) { if (error) { rejected++; diff --git a/src/api/Results.h b/src/api/NetworkState.h similarity index 91% rename from src/api/Results.h rename to src/api/NetworkState.h index 3f3296ef6..6832f5343 100644 --- a/src/api/Results.h +++ b/src/api/NetworkState.h @@ -21,8 +21,8 @@ * along with this program. If not, see . */ -#ifndef __RESULTS_H__ -#define __RESULTS_H__ +#ifndef __NETWORKSTATE_H__ +#define __NETWORKSTATE_H__ #include @@ -32,10 +32,10 @@ class SubmitResult; -class Results +class NetworkState { public: - inline Results() : + inline NetworkState() : diff(0), accepted(0), rejected(0), @@ -51,4 +51,4 @@ public: uint64_t total; }; -#endif /* __RESULTS_H__ */ +#endif /* __NETWORKSTATE_H__ */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 9f83ee6da..840a77f80 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -141,17 +141,17 @@ void Network::onPause(IStrategy *strategy) void Network::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { - m_results.add(result, error); + m_state.add(result, error); if (error) { LOG_INFO(m_options->colors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)", - m_results.accepted, m_results.rejected, result.diff, error, result.elapsed); + m_state.accepted, m_state.rejected, result.diff, error, result.elapsed); } else { LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)", - m_results.accepted, m_results.rejected, result.diff, result.elapsed); + m_state.accepted, m_state.rejected, result.diff, result.elapsed); } } @@ -165,7 +165,7 @@ void Network::setJob(Client *client, const Job &job) LOG_INFO("new job from %s:%d diff %d", client->host(), client->port(), job.diff()); } - m_results.diff = job.diff(); + m_state.diff = job.diff(); Workers::setJob(job); } @@ -180,7 +180,7 @@ void Network::tick() m_donate->tick(now); } - Api::tick(m_results); + Api::tick(m_state); } diff --git a/src/net/Network.h b/src/net/Network.h index 54a4f8d64..fe13d9b71 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -29,7 +29,7 @@ #include -#include "api/Results.h" +#include "api/NetworkState.h" #include "interfaces/IJobResultListener.h" #include "interfaces/IStrategyListener.h" @@ -66,7 +66,7 @@ private: const Options *m_options; IStrategy *m_donate; IStrategy *m_strategy; - Results m_results; + NetworkState m_state; uv_timer_t m_timer; };