New config subsystem
This commit is contained in:
parent
85ee55f309
commit
fa2a0b9b79
37 changed files with 1628 additions and 1254 deletions
|
@ -36,6 +36,7 @@
|
|||
#include "api/interfaces/IApiListener.h"
|
||||
#include "api/requests/HttpApiRequest.h"
|
||||
#include "api/v1/ApiRouter.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "common/crypto/keccak.h"
|
||||
#include "core/config/Config.h"
|
||||
|
@ -48,17 +49,17 @@
|
|||
#endif
|
||||
|
||||
|
||||
xmrig::Api::Api(Controller *controller) :
|
||||
xmrig::Api::Api(Base *base) :
|
||||
m_base(base),
|
||||
m_id(),
|
||||
m_workerId(),
|
||||
m_controller(controller),
|
||||
m_httpd(nullptr)
|
||||
{
|
||||
controller->addListener(this);
|
||||
base->addListener(this);
|
||||
|
||||
genId(m_controller->config()->apiId());
|
||||
genId(base->config()->apiId());
|
||||
|
||||
m_v1 = new ApiRouter(controller);
|
||||
m_v1 = new ApiRouter(base);
|
||||
addListener(m_v1);
|
||||
}
|
||||
|
||||
|
@ -75,7 +76,7 @@ xmrig::Api::~Api()
|
|||
|
||||
void xmrig::Api::request(const HttpRequest &req)
|
||||
{
|
||||
HttpApiRequest request(req, m_controller->config()->http().isRestricted());
|
||||
HttpApiRequest request(req, m_base->config()->http().isRestricted());
|
||||
|
||||
exec(request);
|
||||
}
|
||||
|
@ -83,10 +84,10 @@ void xmrig::Api::request(const HttpRequest &req)
|
|||
|
||||
void xmrig::Api::start()
|
||||
{
|
||||
genWorkerId(m_controller->config()->apiWorkerId());
|
||||
genWorkerId(m_base->config()->apiWorkerId());
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
m_httpd = new Httpd(m_controller);
|
||||
m_httpd = new Httpd(m_base);
|
||||
m_httpd->start();
|
||||
# endif
|
||||
}
|
||||
|
@ -155,7 +156,7 @@ void xmrig::Api::genId(const String &id)
|
|||
uint8_t hash[200];
|
||||
const size_t addrSize = sizeof(interfaces[i].phys_addr);
|
||||
const size_t inSize = strlen(APP_KIND) + addrSize + sizeof(uint16_t);
|
||||
const uint16_t port = static_cast<uint16_t>(m_controller->config()->http().port());
|
||||
const uint16_t port = static_cast<uint16_t>(m_base->config()->http().port());
|
||||
|
||||
uint8_t *input = new uint8_t[inSize]();
|
||||
memcpy(input, &port, sizeof(uint16_t));
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IControllerListener.h"
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ApiRouter;
|
||||
class Controller;
|
||||
class Base;
|
||||
class Httpd;
|
||||
class HttpRequest;
|
||||
class IApiListener;
|
||||
|
@ -44,10 +44,10 @@ class IApiRequest;
|
|||
class String;
|
||||
|
||||
|
||||
class Api : public IControllerListener
|
||||
class Api : public IBaseListener
|
||||
{
|
||||
public:
|
||||
Api(Controller *controller);
|
||||
Api(Base *base);
|
||||
~Api() override;
|
||||
|
||||
inline const char *id() const { return m_id; }
|
||||
|
@ -67,9 +67,9 @@ private:
|
|||
void genWorkerId(const String &id);
|
||||
|
||||
ApiRouter *m_v1;
|
||||
Base *m_base;
|
||||
char m_id[32];
|
||||
char m_workerId[128];
|
||||
Controller *m_controller;
|
||||
Httpd *m_httpd;
|
||||
std::vector<IApiListener *> m_listeners;
|
||||
};
|
||||
|
|
|
@ -48,13 +48,13 @@ static size_t faviconSize = 0;
|
|||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Httpd::Httpd(Controller *controller) :
|
||||
m_controller(controller),
|
||||
xmrig::Httpd::Httpd(Base *base) :
|
||||
m_base(base),
|
||||
m_http(nullptr),
|
||||
m_server(nullptr),
|
||||
m_port(0)
|
||||
{
|
||||
controller->addListener(this);
|
||||
base->addListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ xmrig::Httpd::~Httpd()
|
|||
|
||||
bool xmrig::Httpd::start()
|
||||
{
|
||||
const Http &config = m_controller->config()->http();
|
||||
const Http &config = m_base->config()->http();
|
||||
|
||||
if (!config.isEnabled()) {
|
||||
return true;
|
||||
|
@ -157,7 +157,7 @@ void xmrig::Httpd::onHttpRequest(const HttpRequest &req)
|
|||
}
|
||||
|
||||
if (req.method != HTTP_GET) {
|
||||
if (m_controller->config()->http().isRestricted()) {
|
||||
if (m_base->config()->http().isRestricted()) {
|
||||
return HttpApiResponse(req.id(), HTTP_STATUS_FORBIDDEN).end();
|
||||
}
|
||||
|
||||
|
@ -166,13 +166,13 @@ void xmrig::Httpd::onHttpRequest(const HttpRequest &req)
|
|||
}
|
||||
}
|
||||
|
||||
m_controller->api()->request(req);
|
||||
m_base->api()->request(req);
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Httpd::auth(const HttpRequest &req) const
|
||||
{
|
||||
const Http &config = m_controller->config()->http();
|
||||
const Http &config = m_base->config()->http();
|
||||
|
||||
if (!req.headers.count(kAuthorization)) {
|
||||
return config.isAuthRequired() ? HTTP_STATUS_UNAUTHORIZED : HTTP_STATUS_OK;
|
||||
|
|
|
@ -29,22 +29,22 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IControllerListener.h"
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Controller;
|
||||
class Base;
|
||||
class HttpServer;
|
||||
class TcpServer;
|
||||
|
||||
|
||||
class Httpd : public IControllerListener, public IHttpListener
|
||||
class Httpd : public IBaseListener, public IHttpListener
|
||||
{
|
||||
public:
|
||||
Httpd(Controller *controller);
|
||||
Httpd(Base *base);
|
||||
~Httpd() override;
|
||||
|
||||
bool start();
|
||||
|
@ -57,7 +57,7 @@ protected:
|
|||
private:
|
||||
int auth(const HttpRequest &req) const;
|
||||
|
||||
Controller *m_controller;
|
||||
Base *m_base;
|
||||
HttpServer *m_http;
|
||||
TcpServer *m_server;
|
||||
uint16_t m_port;
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
|
||||
#include "api/interfaces/IApiRequest.h"
|
||||
#include "api/v1/ApiRouter.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "common/cpu/Cpu.h"
|
||||
#include "common/Platform.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "version.h"
|
||||
|
@ -50,8 +50,8 @@ static inline double normalize(double d)
|
|||
}
|
||||
|
||||
|
||||
xmrig::ApiRouter::ApiRouter(xmrig::Controller *controller) :
|
||||
m_controller(controller)
|
||||
xmrig::ApiRouter::ApiRouter(Base *base) :
|
||||
m_base(base)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,14 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
|||
}
|
||||
|
||||
request.accept();
|
||||
m_controller->config()->getJSON(request.doc());
|
||||
m_base->config()->getJSON(request.doc());
|
||||
}
|
||||
}
|
||||
else if (request.method() == IApiRequest::METHOD_PUT || request.method() == IApiRequest::METHOD_POST) {
|
||||
if (request.url() == "/1/config") {
|
||||
request.accept();
|
||||
|
||||
if (!m_controller->config()->reload(request.json())) {
|
||||
if (!m_base->reload(request.json())) {
|
||||
return request.done(400);
|
||||
}
|
||||
|
||||
|
@ -142,9 +142,9 @@ void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &do
|
|||
reply.AddMember("kind", APP_KIND, allocator);
|
||||
reply.AddMember("ua", StringRef(Platform::userAgent()), allocator);
|
||||
reply.AddMember("cpu", cpu, allocator);
|
||||
reply.AddMember("algo", StringRef(m_controller->config()->algorithm().name()), allocator);
|
||||
reply.AddMember("algo", StringRef(m_base->config()->algorithm().shortName()), allocator);
|
||||
reply.AddMember("hugepages", Workers::hugePages() > 0, allocator);
|
||||
reply.AddMember("donate_level", m_controller->config()->pools().donateLevel(), allocator);
|
||||
reply.AddMember("donate_level", m_base->config()->pools().donateLevel(), allocator);
|
||||
}
|
||||
|
||||
|
||||
|
@ -156,7 +156,7 @@ void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &
|
|||
|
||||
Workers::threadsSummary(doc);
|
||||
|
||||
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
|
||||
const std::vector<IThread *> &threads = m_base->config()->threads();
|
||||
Value list(kArrayType);
|
||||
|
||||
size_t i = 0;
|
||||
|
|
|
@ -36,13 +36,13 @@ class Hashrate;
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Controller;
|
||||
class Base;
|
||||
|
||||
|
||||
class ApiRouter : public xmrig::IApiListener
|
||||
{
|
||||
public:
|
||||
ApiRouter(Controller *controller);
|
||||
ApiRouter(Base *base);
|
||||
~ApiRouter() override;
|
||||
|
||||
protected:
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
|
||||
Controller *m_controller;
|
||||
Base *m_base;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue