mirror of
https://github.com/xmrig/xmrig-proxy.git
synced 2026-02-09 02:59:17 +08:00
Sync changes with miner.
This commit is contained in:
@@ -22,14 +22,8 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "base/api/interfaces/IApiRequest.h"
|
||||
#include "api/v1/ApiRouter.h"
|
||||
#include "base/api/interfaces/IApiRequest.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "core/config/Config.h"
|
||||
@@ -41,6 +35,11 @@
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
static inline double normalize(double d)
|
||||
{
|
||||
if (!std::isnormal(d)) {
|
||||
@@ -57,9 +56,7 @@ xmrig::ApiRouter::ApiRouter(Base *base) :
|
||||
}
|
||||
|
||||
|
||||
xmrig::ApiRouter::~ApiRouter()
|
||||
{
|
||||
}
|
||||
xmrig::ApiRouter::~ApiRouter() = default;
|
||||
|
||||
|
||||
void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
||||
@@ -69,7 +66,6 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
|
||||
request.accept();
|
||||
getMiner(request.reply(), request.doc());
|
||||
getHashrate(request.reply(), request.doc());
|
||||
getResourcesSummary(request.reply(), request.doc());
|
||||
getMinersSummary(request.reply(), request.doc());
|
||||
getResults(request.reply(), request.doc());
|
||||
}
|
||||
@@ -196,36 +192,6 @@ void xmrig::ApiRouter::getMinersSummary(rapidjson::Value &reply, rapidjson::Docu
|
||||
}
|
||||
|
||||
|
||||
|
||||
void xmrig::ApiRouter::getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
size_t rss = 0;
|
||||
uv_resident_set_memory(&rss);
|
||||
|
||||
Value resources(kObjectType);
|
||||
Value memory(kObjectType);
|
||||
Value load_average(kArrayType);
|
||||
|
||||
memory.AddMember("total", uv_get_total_memory(), allocator);
|
||||
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);
|
||||
|
||||
double loadavg[3] = { 1.0 };
|
||||
uv_loadavg(loadavg);
|
||||
load_average.PushBack(loadavg[0], allocator);
|
||||
load_average.PushBack(loadavg[1], allocator);
|
||||
load_average.PushBack(loadavg[2], allocator);
|
||||
|
||||
resources.AddMember("memory", memory, allocator);
|
||||
resources.AddMember("load_average", load_average, allocator);
|
||||
resources.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);
|
||||
|
||||
reply.AddMember("resources", resources, allocator);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
@@ -243,8 +209,8 @@ void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &
|
||||
results.AddMember("hashes_donate", stats.donateHashes, allocator);
|
||||
|
||||
rapidjson::Value best(rapidjson::kArrayType);
|
||||
for (size_t i = 0; i < stats.topDiff.size(); ++i) {
|
||||
best.PushBack(stats.topDiff[i], allocator);
|
||||
for (uint64_t i : stats.topDiff) {
|
||||
best.PushBack(i, allocator);
|
||||
}
|
||||
|
||||
results.AddMember("best", best, allocator);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
|
||||
#include "base/api/interfaces/IApiListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "proxy/StatsData.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
@@ -40,6 +41,8 @@ class Base;
|
||||
class ApiRouter : public xmrig::IApiListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRouter)
|
||||
|
||||
ApiRouter(Base *base);
|
||||
~ApiRouter() override;
|
||||
|
||||
@@ -52,7 +55,6 @@ private:
|
||||
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getMiners(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getMinersSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getResults(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
void getWorkers(rapidjson::Value &reply, rapidjson::Document &doc) const;
|
||||
|
||||
|
||||
@@ -49,12 +49,48 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static rapidjson::Value getResources(rapidjson::Document &doc)
|
||||
{
|
||||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
size_t rss = 0;
|
||||
uv_resident_set_memory(&rss);
|
||||
|
||||
Value out(kObjectType);
|
||||
Value memory(kObjectType);
|
||||
Value load_average(kArrayType);
|
||||
|
||||
memory.AddMember("free", uv_get_free_memory(), allocator);
|
||||
memory.AddMember("total", uv_get_total_memory(), allocator);
|
||||
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);
|
||||
|
||||
double loadavg[3] = { 0.0 };
|
||||
uv_loadavg(loadavg);
|
||||
load_average.PushBack(loadavg[0], allocator);
|
||||
load_average.PushBack(loadavg[1], allocator);
|
||||
load_average.PushBack(loadavg[2], allocator);
|
||||
|
||||
out.AddMember("memory", memory, allocator);
|
||||
out.AddMember("load_average", load_average, allocator);
|
||||
out.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Api::Api(Base *base) :
|
||||
m_base(base),
|
||||
m_id(),
|
||||
m_workerId(),
|
||||
m_timestamp(Chrono::currentMSecsSinceEpoch()),
|
||||
m_httpd(nullptr)
|
||||
m_timestamp(Chrono::currentMSecsSinceEpoch())
|
||||
{
|
||||
base->addListener(this);
|
||||
|
||||
@@ -117,10 +153,13 @@ void xmrig::Api::exec(IApiRequest &request)
|
||||
auto &allocator = request.doc().GetAllocator();
|
||||
|
||||
request.accept();
|
||||
request.reply().AddMember("id", StringRef(m_id), allocator);
|
||||
request.reply().AddMember("worker_id", StringRef(m_workerId), allocator);
|
||||
request.reply().AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
|
||||
request.reply().AddMember("restricted", request.isRestricted(), allocator);
|
||||
|
||||
auto &reply = request.reply();
|
||||
reply.AddMember("id", StringRef(m_id), allocator);
|
||||
reply.AddMember("worker_id", StringRef(m_workerId), allocator);
|
||||
reply.AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
|
||||
reply.AddMember("restricted", request.isRestricted(), allocator);
|
||||
reply.AddMember("resources", getResources(request.doc()), allocator);
|
||||
|
||||
Value features(kArrayType);
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
@@ -144,7 +183,7 @@ void xmrig::Api::exec(IApiRequest &request)
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
features.PushBack("opencl", allocator);
|
||||
# endif
|
||||
request.reply().AddMember("features", features, allocator);
|
||||
reply.AddMember("features", features, allocator);
|
||||
}
|
||||
|
||||
for (IApiListener *listener : m_listeners) {
|
||||
@@ -180,9 +219,9 @@ void xmrig::Api::genId(const String &id)
|
||||
uint8_t hash[200];
|
||||
const size_t addrSize = sizeof(interfaces[i].phys_addr);
|
||||
const size_t inSize = (sizeof(APP_KIND) - 1) + addrSize + sizeof(uint16_t);
|
||||
const uint16_t port = static_cast<uint16_t>(m_base->config()->http().port());
|
||||
const auto port = static_cast<uint16_t>(m_base->config()->http().port());
|
||||
|
||||
uint8_t *input = new uint8_t[inSize]();
|
||||
auto*input = new uint8_t[inSize]();
|
||||
memcpy(input, &port, sizeof(uint16_t));
|
||||
memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize);
|
||||
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, (sizeof(APP_KIND) - 1));
|
||||
|
||||
@@ -70,10 +70,10 @@ private:
|
||||
void genWorkerId(const String &id);
|
||||
|
||||
Base *m_base;
|
||||
char m_id[32];
|
||||
char m_workerId[128];
|
||||
char m_id[32]{};
|
||||
char m_workerId[128]{};
|
||||
const uint64_t m_timestamp;
|
||||
Httpd *m_httpd;
|
||||
Httpd *m_httpd = nullptr;
|
||||
std::vector<IApiListener *> m_listeners;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "base/api/Httpd.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/api/Api.h"
|
||||
#include "base/api/Httpd.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpApiResponse.h"
|
||||
#include "base/net/http/HttpData.h"
|
||||
@@ -58,9 +58,7 @@ xmrig::Httpd::Httpd(Base *base) :
|
||||
}
|
||||
|
||||
|
||||
xmrig::Httpd::~Httpd()
|
||||
{
|
||||
}
|
||||
xmrig::Httpd::~Httpd() = default;
|
||||
|
||||
|
||||
bool xmrig::Httpd::start()
|
||||
|
||||
@@ -26,11 +26,12 @@
|
||||
#define XMRIG_HTTPD_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -44,6 +45,8 @@ class TcpServer;
|
||||
class Httpd : public IBaseListener, public IHttpListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd)
|
||||
|
||||
Httpd(Base *base);
|
||||
~Httpd() override;
|
||||
|
||||
|
||||
@@ -33,6 +33,4 @@ xmrig::ApiRequest::ApiRequest(Source source, bool restricted) :
|
||||
}
|
||||
|
||||
|
||||
xmrig::ApiRequest::~ApiRequest()
|
||||
{
|
||||
}
|
||||
xmrig::ApiRequest::~ApiRequest() = default;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "base/api/interfaces/IApiRequest.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -37,6 +38,8 @@ namespace xmrig {
|
||||
class ApiRequest : public IApiRequest
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRequest)
|
||||
|
||||
ApiRequest(Source source, bool restricted);
|
||||
~ApiRequest() override;
|
||||
|
||||
@@ -63,8 +66,8 @@ protected:
|
||||
String m_rpcMethod;
|
||||
|
||||
private:
|
||||
bool m_restricted;
|
||||
Source m_source;
|
||||
const bool m_restricted;
|
||||
const Source m_source;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -63,11 +63,6 @@
|
||||
#include "version.h"
|
||||
|
||||
|
||||
xmrig::BaseConfig::BaseConfig()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BaseConfig::printVersions()
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
#include "base/net/stratum/Pools.h"
|
||||
|
||||
|
||||
struct option;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -43,7 +40,7 @@ class IJsonReader;
|
||||
class BaseConfig : public IConfig
|
||||
{
|
||||
public:
|
||||
BaseConfig();
|
||||
BaseConfig() = default;
|
||||
|
||||
inline bool isAutoSave() const { return m_autoSave; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
AssemblyKey = 1015,
|
||||
RandomXInitKey = 1022,
|
||||
RandomXNumaKey = 1023,
|
||||
RandomXModeKey = 1029,
|
||||
CPUMaxThreadsKey = 1026,
|
||||
MemoryPoolKey = 1027,
|
||||
|
||||
@@ -125,6 +126,7 @@ public:
|
||||
TlsProtocolsKey = 1114,
|
||||
AlgoExtKey = 1115,
|
||||
ProxyPasswordKey = 1116,
|
||||
LoginFileKey = 'L',
|
||||
|
||||
// xmrig nvidia
|
||||
CudaMaxThreadsKey = 1200,
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define XMRIG_ISTRATEGY_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/Http.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/net/http/Http.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -41,10 +41,7 @@ static const char *kToken = "access-token";
|
||||
|
||||
|
||||
xmrig::Http::Http() :
|
||||
m_enabled(false),
|
||||
m_restricted(true),
|
||||
m_host(kLocalhost),
|
||||
m_port(0)
|
||||
m_host(kLocalhost)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class Http
|
||||
public:
|
||||
Http();
|
||||
|
||||
inline bool isAuthRequired() const { return m_restricted == false || !m_token.isNull(); }
|
||||
inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); }
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
inline bool isRestricted() const { return m_restricted; }
|
||||
inline const String &host() const { return m_host; }
|
||||
@@ -58,11 +58,11 @@ public:
|
||||
void setPort(int port);
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
bool m_restricted;
|
||||
bool m_enabled = false;
|
||||
bool m_restricted = true;
|
||||
String m_host;
|
||||
String m_token;
|
||||
uint16_t m_port;
|
||||
uint16_t m_port = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<ClientWriteBaton *>(req->data); }
|
||||
|
||||
|
||||
uv_buf_t bufs[2];
|
||||
uv_buf_t bufs[2]{};
|
||||
|
||||
private:
|
||||
std::string m_body;
|
||||
|
||||
@@ -24,27 +24,30 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static http_parser_settings http_settings;
|
||||
static std::map<uint64_t, HttpContext *> storage;
|
||||
static uint64_t SEQUENCE = 0;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::HttpContext::HttpContext(int parser_type, IHttpListener *listener) :
|
||||
HttpData(SEQUENCE++),
|
||||
m_wasHeaderValue(false),
|
||||
m_timestamp(Chrono::steadyMSecs()),
|
||||
m_listener(listener)
|
||||
{
|
||||
storage[id()] = this;
|
||||
@@ -96,6 +99,12 @@ std::string xmrig::HttpContext::ip() const
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::HttpContext::elapsed() const
|
||||
{
|
||||
return Chrono::steadyMSecs() - m_timestamp;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::HttpContext::close(int status)
|
||||
{
|
||||
if (status < 0 && m_listener) {
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
|
||||
size_t parse(const char *data, size_t size);
|
||||
std::string ip() const;
|
||||
uint64_t elapsed() const;
|
||||
void close(int status = 0);
|
||||
|
||||
static HttpContext *get(uint64_t id);
|
||||
@@ -74,7 +75,8 @@ private:
|
||||
|
||||
void setHeader();
|
||||
|
||||
bool m_wasHeaderValue;
|
||||
bool m_wasHeaderValue = false;
|
||||
const uint64_t m_timestamp;
|
||||
http_parser *m_parser;
|
||||
IHttpListener *m_listener;
|
||||
std::string m_lastHeaderField;
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace xmrig {
|
||||
class HttpData
|
||||
{
|
||||
public:
|
||||
inline HttpData(uint64_t id) : method(0), status(0), m_id(id) {}
|
||||
inline HttpData(uint64_t id) : m_id(id) {}
|
||||
|
||||
inline uint64_t id() const { return m_id; }
|
||||
|
||||
int method;
|
||||
int status;
|
||||
int method = 0;
|
||||
int status = 0;
|
||||
std::map<const std::string, const std::string> headers;
|
||||
std::string body;
|
||||
std::string url;
|
||||
|
||||
@@ -24,20 +24,23 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/net/http/HttpResponse.h"
|
||||
#include "3rdparty/http-parser/http_parser.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "base/net/http/HttpResponse.h"
|
||||
#include "base/tools/Baton.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static const char *kCRLF = "\r\n";
|
||||
static const char *kUserAgent = "user-agent";
|
||||
|
||||
@@ -45,6 +48,8 @@ static const char *kUserAgent = "user-agent";
|
||||
class WriteBaton : public Baton<uv_write_t>
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(WriteBaton)
|
||||
|
||||
inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) :
|
||||
m_ctx(ctx),
|
||||
m_header(ss.str())
|
||||
@@ -79,7 +84,7 @@ public:
|
||||
inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast<WriteBaton *>(req->data); }
|
||||
|
||||
|
||||
uv_buf_t bufs[2];
|
||||
uv_buf_t bufs[2]{};
|
||||
|
||||
private:
|
||||
HttpContext *m_ctx;
|
||||
@@ -98,7 +103,7 @@ xmrig::HttpResponse::HttpResponse(uint64_t id, int statusCode) :
|
||||
|
||||
bool xmrig::HttpResponse::isAlive() const
|
||||
{
|
||||
HttpContext *ctx = HttpContext::get(m_id);
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
|
||||
return ctx && uv_is_writable(ctx->stream());
|
||||
}
|
||||
@@ -129,8 +134,8 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||
|
||||
ss << kCRLF;
|
||||
|
||||
HttpContext *ctx = HttpContext::get(m_id);
|
||||
WriteBaton *baton = new WriteBaton(ss, data, size, ctx);
|
||||
auto ctx = HttpContext::get(m_id);
|
||||
auto baton = new WriteBaton(ss, data, size, ctx);
|
||||
|
||||
# ifndef APP_DEBUG
|
||||
if (statusCode() >= 400)
|
||||
@@ -138,13 +143,14 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
|
||||
{
|
||||
const bool err = statusCode() >= 400;
|
||||
|
||||
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") BLACK_BOLD("\"%s\""),
|
||||
Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""),
|
||||
ctx->ip().c_str(),
|
||||
http_method_str(static_cast<http_method>(ctx->method)),
|
||||
ctx->url.c_str(),
|
||||
err ? 31 : 32,
|
||||
statusCode(),
|
||||
baton->size(),
|
||||
ctx->elapsed(),
|
||||
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ xmrig::HttpServer::~HttpServer()
|
||||
|
||||
void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
|
||||
{
|
||||
HttpContext *ctx = new HttpContext(HTTP_REQUEST, m_listener);
|
||||
auto ctx = new HttpContext(HTTP_REQUEST, m_listener);
|
||||
uv_accept(stream, ctx->stream());
|
||||
|
||||
uv_read_start(ctx->stream(),
|
||||
@@ -65,11 +65,11 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
|
||||
},
|
||||
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
HttpContext *ctx = static_cast<HttpContext*>(tcp->data);
|
||||
auto ctx = static_cast<HttpContext*>(tcp->data);
|
||||
|
||||
if (nread >= 0) {
|
||||
const size_t size = static_cast<size_t>(nread);
|
||||
const size_t parsed = ctx->parse(buf->base, size);
|
||||
const auto size = static_cast<size_t>(nread);
|
||||
const auto parsed = ctx->parse(buf->base, size);
|
||||
|
||||
if (parsed < size) {
|
||||
ctx->close();
|
||||
|
||||
@@ -28,11 +28,12 @@
|
||||
#define XMRIG_HTTPSERVER_H
|
||||
|
||||
|
||||
typedef struct http_parser http_parser;
|
||||
typedef struct http_parser_settings http_parser_settings;
|
||||
using http_parser = struct http_parser;
|
||||
using http_parser_settings = struct http_parser_settings;
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/ITcpServerListener.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -44,6 +45,8 @@ class IHttpListener;
|
||||
class HttpServer : public ITcpServerListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpServer)
|
||||
|
||||
HttpServer(IHttpListener *listener);
|
||||
~HttpServer() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user