Implemented PATCH requests.
This commit is contained in:
parent
79c96418c7
commit
03cd56ed73
21 changed files with 14102 additions and 9 deletions
|
@ -18,9 +18,15 @@
|
|||
|
||||
|
||||
#include "backend/common/Benchmark.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "backend/common/interfaces/IBackend.h"
|
||||
#include "backend/common/interfaces/IWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/net/http/Fetch.h"
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "base/net/stratum/benchmark/BenchConfig.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
@ -49,6 +55,7 @@ xmrig::Benchmark::Benchmark(const Job &job, size_t workers, const IBackend *back
|
|||
m_end(job.benchSize()),
|
||||
m_hash(job.benchHash())
|
||||
{
|
||||
m_httpListener = std::make_shared<HttpListener>(this, Tags::bench());
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,12 +70,24 @@ bool xmrig::Benchmark::finish(uint64_t totalHashCount)
|
|||
|
||||
const double dt = static_cast<double>(m_doneTime - m_startTime) / 1000.0;
|
||||
uint64_t checkData = referenceHash();
|
||||
|
||||
const char *color = checkData ? ((m_data == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
|
||||
const char *color = checkData ? ((m_data == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
|
||||
|
||||
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);
|
||||
LOG_INFO("%s " WHITE_BOLD("press ") MAGENTA_BOLD("Ctrl+C") WHITE_BOLD(" to exit"), Tags::bench());
|
||||
|
||||
if (!m_token.isEmpty()) {
|
||||
using namespace rapidjson;
|
||||
|
||||
Document doc(kObjectType);
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
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);
|
||||
|
||||
send(doc);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -76,6 +95,15 @@ bool xmrig::Benchmark::finish(uint64_t totalHashCount)
|
|||
void xmrig::Benchmark::start()
|
||||
{
|
||||
m_startTime = Chrono::steadyMSecs();
|
||||
|
||||
if (!m_token.isEmpty()) {
|
||||
using namespace rapidjson;
|
||||
|
||||
Document doc(kObjectType);
|
||||
doc.AddMember("steady_start_ts", m_startTime, doc.GetAllocator());
|
||||
|
||||
send(doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,6 +139,22 @@ void xmrig::Benchmark::tick(IWorker *worker)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Benchmark::onHttpData(const HttpData &data)
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
|
||||
try {
|
||||
doc = data.json();
|
||||
} catch (const std::exception &ex) {
|
||||
return setError(ex.what());
|
||||
}
|
||||
|
||||
if (data.status != 200) {
|
||||
return setError(data.statusName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Benchmark::referenceHash() const
|
||||
{
|
||||
if (m_hash) {
|
||||
|
@ -128,3 +172,18 @@ uint64_t xmrig::Benchmark::referenceHash() const
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
req.headers.insert({ "Authorization", fmt::format("Bearer {}", m_token)});
|
||||
|
||||
fetch(std::move(req), m_httpListener);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Benchmark::setError(const char *message)
|
||||
{
|
||||
LOG_ERR("%s " RED("benchmark failed ") RED_BOLD("\"%s\""), Tags::bench(), message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue