Restored "GET /1/summary" endpoint.
This commit is contained in:
parent
691b2fabbf
commit
d9164c0b7b
14 changed files with 199 additions and 108 deletions
|
@ -185,19 +185,6 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::Network::onRequest(IApiRequest &request)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
if (request.method() == IApiRequest::METHOD_GET && (request.url() == "/1/summary" || request.url() == "/api.json")) {
|
||||
request.accept();
|
||||
|
||||
getResults(request.reply(), request.doc());
|
||||
getConnection(request.reply(), request.doc());
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_state.add(result, error);
|
||||
|
@ -223,6 +210,19 @@ void xmrig::Network::onVerifyAlgorithm(IStrategy *, const IClient *, const Algor
|
|||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
void xmrig::Network::onRequest(IApiRequest &request)
|
||||
{
|
||||
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
||||
request.accept();
|
||||
|
||||
getResults(request.reply(), request.doc(), request.version());
|
||||
getConnection(request.reply(), request.doc(), request.version());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||
{
|
||||
if (job.height()) {
|
||||
|
@ -256,7 +256,7 @@ void xmrig::Network::tick()
|
|||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document &doc, int version) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
@ -271,13 +271,16 @@ void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document
|
|||
connection.AddMember("failures", m_state.failures, allocator);
|
||||
connection.AddMember("tls", m_state.tls().toJSON(), allocator);
|
||||
connection.AddMember("tls-fingerprint", m_state.fingerprint().toJSON(), allocator);
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
|
||||
if (version == 1) {
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
}
|
||||
|
||||
reply.AddMember("connection", connection, allocator);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &doc, int version) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
@ -295,8 +298,11 @@ void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &do
|
|||
best.PushBack(m_state.topDiff[i], allocator);
|
||||
}
|
||||
|
||||
results.AddMember("best", best, allocator);
|
||||
results.AddMember("error_log", Value(kArrayType), allocator);
|
||||
results.AddMember("best", best, allocator);
|
||||
|
||||
if (version == 1) {
|
||||
results.AddMember("error_log", Value(kArrayType), allocator);
|
||||
}
|
||||
|
||||
reply.AddMember("results", results, allocator);
|
||||
}
|
||||
|
|
|
@ -65,10 +65,13 @@ protected:
|
|||
void onJobResult(const JobResult &result) override;
|
||||
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
void onRequest(IApiRequest &request) override;
|
||||
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
|
||||
void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) override;
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
void onRequest(IApiRequest &request) override;
|
||||
# endif
|
||||
|
||||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
|
@ -76,8 +79,8 @@ private:
|
|||
void tick();
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
void getConnection(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getResults(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getConnection(rapidjson::Value &reply, rapidjson::Document &doc, int version) const;
|
||||
void getResults(rapidjson::Value &reply, rapidjson::Document &doc, int version) const;
|
||||
# endif
|
||||
|
||||
Controller *m_controller;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue