Compare commits

..

9 Commits

Author SHA1 Message Date
XMRig
7ddbcb0c21 v2.15.1-beta 2019-04-01 19:06:32 +07:00
XMRig
beeaf14784 Merge branch 'evo' into beta 2019-04-01 19:06:03 +07:00
xmrig
b1ef6268aa Update CHANGELOG.md 2019-04-01 19:02:23 +07:00
XMRig
0bfee737cb Fixed wrong status code for "GET /1/config" and updated app.rc. 2019-04-01 17:37:03 +07:00
XMRig
1158294789 Sync changes. 2019-04-01 12:31:49 +07:00
XMRig
b49a51e569 Better compatibility with previous configs. 2019-04-01 00:28:09 +07:00
XMRig
f7f8e54498 Fixed malformed HTTP response on Linux. 2019-04-01 00:20:11 +07:00
XMRig
916eb43349 Fix compile issue. 2019-04-01 00:01:10 +07:00
XMRig
294dd9f2e1 Merge branch 'feature-httpd' into evo 2019-03-31 23:38:35 +07:00
12 changed files with 81 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
# v2.15.1-beta
- [#1007](https://github.com/xmrig/xmrig/issues/1007) Old HTTP API backend based on libmicrohttpd, replaced to custom HTTP server (libuv + http_parser).
- [#257](https://github.com/xmrig/xmrig-nvidia/pull/257) New logging subsystem, file and syslog now always without colors.
# v2.15.0-beta

View File

@@ -1,7 +1,7 @@
#include <windows.h>
#include "../src/version.h"
IDI_ICON1 ICON DISCARDABLE "app.ico"
101 ICON "app.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,0

View File

@@ -30,7 +30,7 @@
#include "App.h"
#include "base/io/log/Log.h"
#include "core/Config.h"
#include "core/config/Config.h"
#include "core/Controller.h"

View File

@@ -40,6 +40,11 @@ namespace xmrig {
static const char *kAuthorization = "authorization";
static const char *kContentType = "content-type";
#ifdef _WIN32
static const char *favicon = nullptr;
static size_t faviconSize = 0;
#endif
} // namespace xmrig
@@ -85,6 +90,17 @@ bool xmrig::Httpd::start()
m_port = static_cast<uint16_t>(rc);
# ifdef _WIN32
HRSRC src = FindResource(nullptr, MAKEINTRESOURCE(1), RT_ICON);
if (src != nullptr) {
HGLOBAL res = LoadResource(nullptr, src);
if (res != nullptr) {
favicon = static_cast<const char *>(LockResource(res));
faviconSize = SizeofResource(nullptr, src);
}
}
# endif
return true;
}
@@ -118,6 +134,19 @@ void xmrig::Httpd::onHttpRequest(const HttpRequest &req)
return HttpApiResponse(req.id()).end();
}
if (req.method == HTTP_GET && req.url == "/favicon.ico") {
# ifdef _WIN32
if (favicon != nullptr) {
HttpResponse response(req.id());
response.setHeader("Content-Type", "image/x-icon");
return response.end(favicon, faviconSize);
}
# endif
return HttpResponse(req.id(), 404).end();
}
if (req.method > 4) {
return HttpApiResponse(req.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
}

View File

@@ -88,6 +88,7 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
return request.done(403);
}
request.accept();
m_controller->config()->getJSON(request.doc());
}
}

View File

@@ -30,6 +30,7 @@
#endif
#include <algorithm>
#include <string.h>
#include <string>
#include <time.h>

View File

@@ -30,20 +30,22 @@
#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"
namespace xmrig {
static const char *kCRLF = "\r\n";
static const char *kCRLF = "\r\n";
static const char *kUserAgent = "user-agent";
} // namespace xmrig
xmrig::HttpResponse::HttpResponse(uint64_t id) :
xmrig::HttpResponse::HttpResponse(uint64_t id, int statusCode) :
m_id(id),
m_statusCode(HTTP_STATUS_OK)
m_statusCode(statusCode)
{
}
@@ -97,11 +99,40 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
# ifdef _WIN32
bufs[1].len = static_cast<unsigned int>(size);
# else
bufs[0].len = size;
bufs[1].len = size;
# endif
}
HttpContext *ctx = HttpContext::get(m_id);
# ifndef APP_DEBUG
if (statusCode() >= 400)
# endif
{
const bool err = statusCode() >= 400;
char ip[46] = {};
sockaddr_storage addr = {};
int aSize = sizeof(addr);
uv_tcp_getpeername(ctx->tcp, reinterpret_cast<sockaddr*>(&addr), &aSize);
if (reinterpret_cast<sockaddr_in *>(&addr)->sin_family == AF_INET6) {
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(&addr), ip, 45);
}
else {
uv_ip4_name(reinterpret_cast<sockaddr_in*>(&addr), ip, 16);
}
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\""),
ip,
http_method_str(static_cast<http_method>(ctx->method)),
ctx->url.c_str(),
err ? 31 : 32,
statusCode(),
header.size() + size,
ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr
);
}
uv_try_write(ctx->stream(), bufs, data ? 2 : 1);
ctx->close();

View File

@@ -38,7 +38,7 @@ namespace xmrig {
class HttpResponse
{
public:
HttpResponse(uint64_t id);
HttpResponse(uint64_t id, int statusCode = 200);
inline int statusCode() const { return m_statusCode; }
inline void setHeader(const std::string &key, const std::string &value) { m_headers.insert({ key, value }); }

View File

@@ -355,6 +355,8 @@ void xmrig::CommonConfig::parseJSON(const rapidjson::Value &json)
if (api.IsObject() && api.HasMember("port")) {
m_upgrade = true;
m_http.load(api);
m_http.setEnabled(Json::getUint(api, "port") > 0);
m_http.setHost("0.0.0.0");
}
else {
m_http.load(json["http"]);

View File

@@ -4,11 +4,14 @@
"algo": "cryptonight",
"algo-ext": true,
"api": {
"id": null,
"worker-id": null
},
"http": {
"enabled": false,
"host": "127.0.0.1",
"port": 0,
"access-token": null,
"id": null,
"worker-id": null,
"ipv6": false,
"restricted": true
},
"background": false,
@@ -54,6 +57,7 @@
"dhparam": null
},
"user-agent": null,
"syslog": false,
"verbose": false,
"watch": true,
"workers": true

View File

@@ -126,7 +126,7 @@ bool xmrig::Miner::accept(uv_stream_t *server)
uv_tcp_getpeername(m_socket, reinterpret_cast<sockaddr*>(&addr), &size);
if (m_ipv6) {
if (reinterpret_cast<sockaddr_in *>(&addr)->sin_family == AF_INET6) {
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(&addr), m_ip, 45);
} else {
uv_ip4_name(reinterpret_cast<sockaddr_in*>(&addr), m_ip, 16);

View File

@@ -28,7 +28,7 @@
#define APP_ID "xmrig-proxy"
#define APP_NAME "xmrig-proxy"
#define APP_DESC "XMRig Stratum proxy"
#define APP_VERSION "2.15.1-evo"
#define APP_VERSION "2.15.1-beta"
#define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com"