From 99e9073993ed89ea502447277c30243233cdbe36 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 3 Nov 2020 00:21:22 +0700 Subject: [PATCH] Fixed build without HTTP. --- src/backend/common/Benchmark.cpp | 17 +++++++- src/backend/common/Benchmark.h | 3 ++ .../net/stratum/benchmark/BenchClient.cpp | 41 ++++++++++++++----- src/base/net/stratum/benchmark/BenchClient.h | 6 ++- src/core/config/Config_platform.h | 2 + src/core/config/usage.h | 2 + 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/backend/common/Benchmark.cpp b/src/backend/common/Benchmark.cpp index dbb45c59..869afb05 100644 --- a/src/backend/common/Benchmark.cpp +++ b/src/backend/common/Benchmark.cpp @@ -55,9 +55,11 @@ xmrig::Benchmark::Benchmark(const Job &job, size_t workers, const IBackend *back m_end(job.benchSize()), m_hash(job.benchHash()) { +# ifdef XMRIG_FEATURE_HTTP if (!m_token.isEmpty()) { m_httpListener = std::make_shared(this, Tags::bench()); } +# endif } @@ -76,6 +78,7 @@ bool xmrig::Benchmark::finish(uint64_t totalHashCount) LOG_NOTICE("%s " WHITE_BOLD("benchmark finished in ") CYAN_BOLD("%.3f seconds") WHITE_BOLD_S " hash sum = " CLEAR "%s%016" PRIX64 CLEAR, Tags::bench(), dt, color, m_data); +# ifdef XMRIG_FEATURE_HTTP if (!m_token.isEmpty()) { using namespace rapidjson; @@ -84,11 +87,13 @@ bool xmrig::Benchmark::finish(uint64_t totalHashCount) doc.AddMember("steady_done_ts", m_doneTime, allocator); doc.AddMember(StringRef(BenchConfig::kHash), Value(fmt::format("{:016X}", m_data).c_str(), allocator), allocator); - doc.AddMember("backend", m_backend->toJSON(doc), allocator); + doc.AddMember("backend", m_backend->toJSON(doc), allocator); // FIXME send(doc); } - else { + else +# endif + { printExit(); } @@ -100,6 +105,7 @@ void xmrig::Benchmark::start() { m_startTime = Chrono::steadyMSecs(); +# ifdef XMRIG_FEATURE_HTTP if (!m_token.isEmpty()) { using namespace rapidjson; @@ -108,6 +114,7 @@ void xmrig::Benchmark::start() send(doc); } +# endif } @@ -145,6 +152,7 @@ void xmrig::Benchmark::tick(IWorker *worker) void xmrig::Benchmark::onHttpData(const HttpData &data) { +# ifdef XMRIG_FEATURE_HTTP rapidjson::Document doc; try { @@ -161,6 +169,7 @@ void xmrig::Benchmark::onHttpData(const HttpData &data) LOG_NOTICE("%s " WHITE_BOLD("benchmark submitted ") CYAN_BOLD("https://xmrig.com/benchmark/%s"), Tags::bench(), m_id.data()); printExit(); } +# endif } @@ -170,9 +179,11 @@ uint64_t xmrig::Benchmark::referenceHash() const return m_hash; } +# ifdef XMRIG_FEATURE_HTTP if (!m_token.isEmpty()) { return 0; } +# endif const uint32_t N = (m_end / 1000000) - 1; if (((m_algo == Algorithm::RX_0) || (m_algo == Algorithm::RX_WOW)) && ((m_end % 1000000) == 0) && (N < 10)) { @@ -189,6 +200,7 @@ void xmrig::Benchmark::printExit() } +#ifdef XMRIG_FEATURE_HTTP void xmrig::Benchmark::send(const rapidjson::Value &body) { FetchRequest req(HTTP_PATCH, BenchConfig::kApiHost, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_id).c_str(), body, BenchConfig::kApiTLS, true); @@ -202,3 +214,4 @@ void xmrig::Benchmark::setError(const char *message) { LOG_ERR("%s " RED("benchmark failed ") RED_BOLD("\"%s\""), Tags::bench(), message); } +#endif diff --git a/src/backend/common/Benchmark.h b/src/backend/common/Benchmark.h index 0e388181..b13748b4 100644 --- a/src/backend/common/Benchmark.h +++ b/src/backend/common/Benchmark.h @@ -56,8 +56,11 @@ protected: private: uint64_t referenceHash() const; void printExit(); + +# ifdef XMRIG_FEATURE_HTTP void send(const rapidjson::Value &body); void setError(const char *message); +# endif bool m_reset = false; const Algorithm m_algo; diff --git a/src/base/net/stratum/benchmark/BenchClient.cpp b/src/base/net/stratum/benchmark/BenchClient.cpp index be16e3fe..51181cf8 100644 --- a/src/base/net/stratum/benchmark/BenchClient.cpp +++ b/src/base/net/stratum/benchmark/BenchClient.cpp @@ -35,8 +35,6 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr &benchmark, I m_listener(listener), m_benchmark(benchmark) { - m_httpListener = std::make_shared(this, Tags::bench()); - std::vector blob(112 * 2 + 1, '0'); blob.back() = '\0'; @@ -47,6 +45,7 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr &benchmark, I m_job.setBenchSize(m_benchmark->size()); m_job.setBenchHash(m_benchmark->hash()); +# ifdef XMRIG_FEATURE_HTTP if (m_benchmark->isSubmit()) { m_mode = ONLINE_BENCH; @@ -59,6 +58,7 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr &benchmark, I return; } +# endif m_job.setId("00000000"); @@ -74,7 +74,8 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr &benchmark, I void xmrig::BenchClient::connect() -{ +{ +# ifdef XMRIG_FEATURE_HTTP switch (m_mode) { case STATIC_BENCH: case STATIC_VERIFY: @@ -86,6 +87,9 @@ void xmrig::BenchClient::connect() case ONLINE_VERIFY: return getBench(); } +# else + start(); +# endif } @@ -97,6 +101,7 @@ void xmrig::BenchClient::setPool(const Pool &pool) void xmrig::BenchClient::onHttpData(const HttpData &data) { +# ifdef XMRIG_FEATURE_HTTP rapidjson::Document doc; try { @@ -115,11 +120,23 @@ void xmrig::BenchClient::onHttpData(const HttpData &data) else { startVerify(doc); } +# endif } +void xmrig::BenchClient::start() +{ + m_listener->onLoginSuccess(this); + m_listener->onJobReceived(this, m_job, rapidjson::Value()); +} + + + +#ifdef XMRIG_FEATURE_HTTP void xmrig::BenchClient::createBench() { + createHttpListener(); + using namespace rapidjson; Document doc(kObjectType); @@ -135,8 +152,18 @@ void xmrig::BenchClient::createBench() } +void xmrig::BenchClient::createHttpListener() +{ + if (!m_httpListener) { + m_httpListener = std::make_shared(this, Tags::bench()); + } +} + + void xmrig::BenchClient::getBench() { + createHttpListener(); + FetchRequest req(HTTP_GET, BenchConfig::kApiHost, BenchConfig::kApiPort, fmt::format("/1/benchmark/{}", m_job.id()).c_str(), BenchConfig::kApiTLS, true); fetch(std::move(req), m_httpListener); } @@ -148,13 +175,6 @@ void xmrig::BenchClient::setError(const char *message) } -void xmrig::BenchClient::start() -{ - m_listener->onLoginSuccess(this); - m_listener->onJobReceived(this, m_job, rapidjson::Value()); -} - - void xmrig::BenchClient::startBench(const rapidjson::Value &value) { m_job.setId(Json::getString(value, BenchConfig::kId)); @@ -178,3 +198,4 @@ void xmrig::BenchClient::startVerify(const rapidjson::Value &value) start(); } +#endif diff --git a/src/base/net/stratum/benchmark/BenchClient.h b/src/base/net/stratum/benchmark/BenchClient.h index f9070b34..64bb481b 100644 --- a/src/base/net/stratum/benchmark/BenchClient.h +++ b/src/base/net/stratum/benchmark/BenchClient.h @@ -75,12 +75,16 @@ private: ONLINE_VERIFY }; + void start(); + +# ifdef XMRIG_FEATURE_HTTP void createBench(); + void createHttpListener(); void getBench(); void setError(const char *message); - void start(); void startBench(const rapidjson::Value &value); void startVerify(const rapidjson::Value &value); +# endif IClientListener* m_listener; Job m_job; diff --git a/src/core/config/Config_platform.h b/src/core/config/Config_platform.h index fddf28a4..452bdd45 100644 --- a/src/core/config/Config_platform.h +++ b/src/core/config/Config_platform.h @@ -100,8 +100,10 @@ static const option options[] = { { "stress", 0, nullptr, IConfig::StressKey }, { "bench", 1, nullptr, IConfig::BenchKey }, { "benchmark", 1, nullptr, IConfig::BenchKey }, +# ifdef XMRIG_FEATURE_HTTP { "submit", 0, nullptr, IConfig::BenchSubmitKey }, { "verify", 1, nullptr, IConfig::BenchVerifyKey }, +# endif { "seed", 1, nullptr, IConfig::BenchSeedKey }, { "hash", 1, nullptr, IConfig::BenchHashKey }, # endif diff --git a/src/core/config/usage.h b/src/core/config/usage.h index 58cb0937..54e629ec 100644 --- a/src/core/config/usage.h +++ b/src/core/config/usage.h @@ -182,8 +182,10 @@ static inline const std::string &usage() # ifdef XMRIG_FEATURE_BENCHMARK u += " --stress run continuous stress test to check system stability\n"; u += " --bench=N run benchmark, N can be between 1M and 10M\n"; +# ifdef XMRIG_FEATURE_HTTP u += " --submit perform an online benchmark and submit result for sharing\n"; u += " --verify=ID verify submitted benchmark by ID\n"; +# endif u += " --seed=SEED custom RandomX seed for benchmark\n"; u += " --hash=HASH compare benchmark result with specified hash\n"; # endif