Restored "GET /1/summary" endpoint.
This commit is contained in:
parent
691b2fabbf
commit
d9164c0b7b
14 changed files with 199 additions and 108 deletions
|
@ -120,7 +120,7 @@ void xmrig::Api::exec(IApiRequest &request)
|
|||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
if (request.method() == IApiRequest::METHOD_GET && (request.url() == "/1/summary" || request.url() == "/api.json")) {
|
||||
if (request.type() == IApiRequest::REQ_SUMMARY) {
|
||||
auto &allocator = request.doc().GetAllocator();
|
||||
|
||||
request.accept();
|
||||
|
@ -145,14 +145,6 @@ void xmrig::Api::exec(IApiRequest &request)
|
|||
features.PushBack("tls", allocator);
|
||||
# endif
|
||||
request.reply().AddMember("features", features, allocator);
|
||||
|
||||
Value algorithms(kArrayType);
|
||||
|
||||
for (int i = 0; i < Algorithm::MAX; ++i) {
|
||||
algorithms.PushBack(StringRef(Algorithm(static_cast<Algorithm::Id>(i)).shortName()), allocator);
|
||||
}
|
||||
|
||||
request.reply().AddMember("algorithms", algorithms, allocator);
|
||||
}
|
||||
|
||||
for (IApiListener *listener : m_listeners) {
|
||||
|
|
|
@ -35,7 +35,9 @@ class IApiListener
|
|||
public:
|
||||
virtual ~IApiListener() = default;
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
virtual void onRequest(IApiRequest &request) = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -50,6 +52,12 @@ public:
|
|||
};
|
||||
|
||||
|
||||
enum RequestType {
|
||||
REQ_UNKNOWN,
|
||||
REQ_SUMMARY
|
||||
};
|
||||
|
||||
|
||||
virtual ~IApiRequest() = default;
|
||||
|
||||
virtual bool isDone() const = 0;
|
||||
|
@ -57,9 +65,11 @@ public:
|
|||
virtual bool isRestricted() const = 0;
|
||||
virtual const rapidjson::Value &json() const = 0;
|
||||
virtual const String &url() const = 0;
|
||||
virtual int version() const = 0;
|
||||
virtual Method method() const = 0;
|
||||
virtual rapidjson::Document &doc() = 0;
|
||||
virtual rapidjson::Value &reply() = 0;
|
||||
virtual RequestType type() const = 0;
|
||||
virtual Source source() const = 0;
|
||||
virtual void accept() = 0;
|
||||
virtual void done(int status) = 0;
|
||||
|
|
|
@ -28,8 +28,7 @@
|
|||
|
||||
xmrig::ApiRequest::ApiRequest(Source source, bool restricted) :
|
||||
m_restricted(restricted),
|
||||
m_source(source),
|
||||
m_state(STATE_NEW)
|
||||
m_source(source)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -43,10 +43,15 @@ protected:
|
|||
inline bool isDone() const override { return m_state == STATE_DONE; }
|
||||
inline bool isNew() const override { return m_state == STATE_NEW; }
|
||||
inline bool isRestricted() const override { return m_restricted; }
|
||||
inline int version() const override { return m_version; }
|
||||
inline RequestType type() const override { return m_type; }
|
||||
inline Source source() const override { return m_source; }
|
||||
inline void accept() override { m_state = STATE_ACCEPTED; }
|
||||
inline void done(int) override { m_state = STATE_DONE; }
|
||||
|
||||
int m_version = 1;
|
||||
RequestType m_type = REQ_UNKNOWN;
|
||||
|
||||
private:
|
||||
enum State {
|
||||
STATE_NEW,
|
||||
|
@ -56,7 +61,7 @@ private:
|
|||
|
||||
bool m_restricted;
|
||||
Source m_source;
|
||||
State m_state;
|
||||
State m_state = STATE_NEW;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,17 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) :
|
|||
m_res(req.id()),
|
||||
m_url(req.url.c_str())
|
||||
{
|
||||
if (method() == METHOD_GET) {
|
||||
if (url() == "/1/summary" || url() == "/2/summary" || url() == "/api.json") {
|
||||
m_type = REQ_SUMMARY;
|
||||
}
|
||||
}
|
||||
|
||||
if (url().size() > 4) {
|
||||
if (memcmp(url().data(), "/2/", 3) == 0) {
|
||||
m_version = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,18 +38,6 @@
|
|||
#include "version.h"
|
||||
|
||||
|
||||
static inline rapidjson::Value normalize(double d)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
if (!std::isnormal(d)) {
|
||||
return Value(kNullType);
|
||||
}
|
||||
|
||||
return Value(floor(d * 100.0) / 100.0);
|
||||
}
|
||||
|
||||
|
||||
xmrig::ApiRouter::ApiRouter(Base *base) :
|
||||
m_base(base)
|
||||
{
|
||||
|
@ -64,12 +52,7 @@ xmrig::ApiRouter::~ApiRouter()
|
|||
void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
||||
{
|
||||
if (request.method() == IApiRequest::METHOD_GET) {
|
||||
if (request.url() == "/1/summary" || request.url() == "/api.json") {
|
||||
request.accept();
|
||||
getMiner(request.reply(), request.doc());
|
||||
// getHashrate(request.reply(), request.doc());
|
||||
}
|
||||
else if (request.url() == "/1/threads") {
|
||||
if (request.url() == "/1/threads") {
|
||||
request.accept();
|
||||
getThreads(request.reply(), request.doc());
|
||||
}
|
||||
|
@ -96,57 +79,6 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
|||
}
|
||||
|
||||
|
||||
//void xmrig::ApiRouter::getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
//{
|
||||
// using namespace rapidjson;
|
||||
// auto &allocator = doc.GetAllocator();
|
||||
|
||||
// Value hashrate(kObjectType);
|
||||
// Value total(kArrayType);
|
||||
// Value threads(kArrayType);
|
||||
|
||||
// const Hashrate *hr = WorkersLegacy::hashrate();
|
||||
|
||||
// total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator);
|
||||
// total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
|
||||
// total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
|
||||
|
||||
// for (size_t i = 0; i < WorkersLegacy::threads(); i++) {
|
||||
// Value thread(kArrayType);
|
||||
// thread.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
|
||||
// thread.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
|
||||
// thread.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
|
||||
|
||||
// threads.PushBack(thread, allocator);
|
||||
// }
|
||||
|
||||
// hashrate.AddMember("total", total, allocator);
|
||||
// hashrate.AddMember("highest", normalize(hr->highest()), allocator);
|
||||
// hashrate.AddMember("threads", threads, allocator);
|
||||
// reply.AddMember("hashrate", hashrate, allocator);
|
||||
//}
|
||||
|
||||
|
||||
void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value cpu(kObjectType);
|
||||
cpu.AddMember("brand", StringRef(Cpu::info()->brand()), allocator);
|
||||
cpu.AddMember("aes", Cpu::info()->hasAES(), allocator);
|
||||
cpu.AddMember("x64", Cpu::info()->isX64(), allocator);
|
||||
cpu.AddMember("sockets", Cpu::info()->sockets(), allocator);
|
||||
|
||||
reply.AddMember("version", APP_VERSION, allocator);
|
||||
reply.AddMember("kind", APP_KIND, allocator);
|
||||
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
||||
reply.AddMember("cpu", cpu, allocator);
|
||||
reply.AddMember("hugepages", false, allocator); // FIXME hugepages
|
||||
reply.AddMember("donate_level", m_base->config()->pools().donateLevel(), allocator);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
{
|
||||
// using namespace rapidjson;
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace xmrig {
|
|||
class Base;
|
||||
|
||||
|
||||
class ApiRouter : public xmrig::IApiListener
|
||||
class ApiRouter : public IApiListener
|
||||
{
|
||||
public:
|
||||
ApiRouter(Base *base);
|
||||
|
@ -49,8 +49,6 @@ protected:
|
|||
void onRequest(IApiRequest &request) override;
|
||||
|
||||
private:
|
||||
// void getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
|
||||
Base *m_base;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue