Fixed build without HTTP.

This commit is contained in:
XMRig 2020-11-03 00:21:22 +07:00
parent 51690ebad6
commit 99e9073993
No known key found for this signature in database
GPG key ID: 446A53638BE94409
6 changed files with 58 additions and 13 deletions

View file

@ -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<HttpListener>(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

View file

@ -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;

View file

@ -35,8 +35,6 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &benchmark, I
m_listener(listener),
m_benchmark(benchmark)
{
m_httpListener = std::make_shared<HttpListener>(this, Tags::bench());
std::vector<char> blob(112 * 2 + 1, '0');
blob.back() = '\0';
@ -47,6 +45,7 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &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<BenchConfig> &benchmark, I
return;
}
# endif
m_job.setId("00000000");
@ -74,7 +74,8 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &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<HttpListener>(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

View file

@ -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;

View file

@ -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

View file

@ -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