1
0
mirror of https://github.com/xmrig/xmrig.git synced 2026-01-01 16:02:39 -05:00

Merge branch 'master' into self-select-parse-fix

This commit is contained in:
Stan Bondi
2021-11-01 18:16:55 +04:00
committed by GitHub
401 changed files with 44736 additions and 13908 deletions

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,12 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/api/Api.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/api/requests/HttpApiRequest.h"
#include "base/crypto/keccak.h"
@@ -186,7 +184,7 @@ void xmrig::Api::exec(IApiRequest &request)
}
}
request.done(request.isNew() ? HTTP_STATUS_NOT_FOUND : HTTP_STATUS_OK);
request.done(request.isNew() ? 404 : 200);
}
@@ -199,7 +197,7 @@ void xmrig::Api::genId(const String &id)
return;
}
uv_interface_address_t *interfaces;
uv_interface_address_t *interfaces = nullptr;
int count = 0;
if (uv_interface_addresses(&interfaces, &count) < 0) {

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,9 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/api/Httpd.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/api/Api.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpApiResponse.h"
@@ -102,6 +95,7 @@ bool xmrig::Httpd::start()
m_port = static_cast<uint16_t>(rc);
# ifdef _WIN32
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
HRSRC src = FindResource(nullptr, MAKEINTRESOURCE(1), RT_ICON);
if (src != nullptr) {
HGLOBAL res = LoadResource(nullptr, src);
@@ -155,25 +149,25 @@ void xmrig::Httpd::onHttpData(const HttpData &data)
}
# endif
return HttpResponse(data.id(), HTTP_STATUS_NOT_FOUND).end();
return HttpResponse(data.id(), 404 /* NOT_FOUND */).end();
}
if (data.method > 4) {
return HttpApiResponse(data.id(), HTTP_STATUS_METHOD_NOT_ALLOWED).end();
return HttpApiResponse(data.id(), 405 /* METHOD_NOT_ALLOWED */).end();
}
const int status = auth(data);
if (status != HTTP_STATUS_OK) {
if (status != 200) {
return HttpApiResponse(data.id(), status).end();
}
if (data.method != HTTP_GET) {
if (m_base->config()->http().isRestricted()) {
return HttpApiResponse(data.id(), HTTP_STATUS_FORBIDDEN).end();
return HttpApiResponse(data.id(), 403 /* FORBIDDEN */).end();
}
if (!data.headers.count(HttpData::kContentTypeL) || data.headers.at(HttpData::kContentTypeL) != HttpData::kApplicationJson) {
return HttpApiResponse(data.id(), HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE).end();
return HttpApiResponse(data.id(), 415 /* UNSUPPORTED_MEDIA_TYPE */).end();
}
}
@@ -186,19 +180,19 @@ int xmrig::Httpd::auth(const HttpData &req) const
const Http &config = m_base->config()->http();
if (!req.headers.count(kAuthorization)) {
return config.isAuthRequired() ? HTTP_STATUS_UNAUTHORIZED : HTTP_STATUS_OK;
return config.isAuthRequired() ? 401 /* UNAUTHORIZED */ : 200;
}
if (config.token().isNull()) {
return HTTP_STATUS_UNAUTHORIZED;
return 401 /* UNAUTHORIZED */;
}
const std::string &token = req.headers.at(kAuthorization);
const size_t size = token.size();
if (token.size() < 8 || config.token().size() != size - 7 || memcmp("Bearer ", token.c_str(), 7) != 0) {
return HTTP_STATUS_FORBIDDEN;
return 403 /* FORBIDDEN */;
}
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? HTTP_STATUS_OK : HTTP_STATUS_FORBIDDEN;
return strncmp(config.token().data(), token.c_str() + 7, config.token().size()) == 0 ? 200 : 403 /* FORBIDDEN */;
}

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -24,7 +18,7 @@
#include "base/api/requests/HttpApiRequest.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
#include "base/net/http/HttpData.h"
@@ -51,10 +45,13 @@ static inline const char *rpcError(int code) {
case IApiRequest::RPC_INVALID_PARAMS:
return "Invalid params";
default:
break;
}
if (code >= HTTP_STATUS_BAD_REQUEST && code <= HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED) {
return http_status_str(static_cast<http_status>(code));
if (code >= 400 && code < 600) {
return HttpData::statusName(code);
}
return "Internal error";
@@ -155,10 +152,10 @@ void xmrig::HttpApiRequest::done(int status)
using namespace rapidjson;
auto &allocator = doc().GetAllocator();
m_res.setStatus(HTTP_STATUS_OK);
m_res.setStatus(200);
if (status != HTTP_STATUS_OK) {
setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
if (status != 200) {
setRpcError(status == 404 /* NOT_FOUND */ ? RPC_METHOD_NOT_FOUND : status);
}
else if (!reply().HasMember(kResult)) {
Value result(kObjectType);
@@ -205,6 +202,6 @@ void xmrig::HttpApiRequest::rpcDone(const char *key, rapidjson::Value &value)
reply().AddMember("jsonrpc", "2.0", allocator);
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
m_res.setStatus(HTTP_STATUS_OK);
m_res.setStatus(200);
m_res.end();
}

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,5 +1,5 @@
set(HEADERS_BASE
src/3rdparty/fmt/format.cc
src/3rdparty/epee/span.h
src/base/api/interfaces/IApiListener.h
src/base/crypto/Algorithm.h
src/base/crypto/Coin.h
@@ -32,6 +32,7 @@ set(HEADERS_BASE
src/base/kernel/interfaces/IConfigListener.h
src/base/kernel/interfaces/IConfigTransform.h
src/base/kernel/interfaces/IConsoleListener.h
src/base/kernel/interfaces/IDnsBackend.h
src/base/kernel/interfaces/IDnsListener.h
src/base/kernel/interfaces/ILineListener.h
src/base/kernel/interfaces/ILogBackend.h
@@ -43,7 +44,11 @@ set(HEADERS_BASE
src/base/kernel/Platform.h
src/base/kernel/Process.h
src/base/net/dns/Dns.h
src/base/net/dns/DnsConfig.h
src/base/net/dns/DnsRecord.h
src/base/net/dns/DnsRecords.h
src/base/net/dns/DnsRequest.h
src/base/net/dns/DnsUvBackend.h
src/base/net/http/Http.h
src/base/net/http/HttpListener.h
src/base/net/stratum/BaseClient.h
@@ -65,15 +70,24 @@ set(HEADERS_BASE
src/base/net/tools/Storage.h
src/base/tools/Arguments.h
src/base/tools/Baton.h
src/base/tools/bswap_64.h
src/base/tools/Buffer.h
src/base/tools/Chrono.h
src/base/tools/cryptonote/BlobReader.h
src/base/tools/cryptonote/BlockTemplate.h
src/base/tools/cryptonote/crypto-ops.h
src/base/tools/cryptonote/Signatures.h
src/base/tools/cryptonote/umul128.h
src/base/tools/cryptonote/WalletAddress.h
src/base/tools/Cvt.h
src/base/tools/Handle.h
src/base/tools/Span.h
src/base/tools/String.h
src/base/tools/Timer.h
)
set(SOURCES_BASE
src/3rdparty/fmt/format.cc
src/base/crypto/Algorithm.cpp
src/base/crypto/Coin.cpp
src/base/crypto/keccak.cpp
@@ -99,7 +113,10 @@ set(SOURCES_BASE
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp
src/base/net/dns/Dns.cpp
src/base/net/dns/DnsConfig.cpp
src/base/net/dns/DnsRecord.cpp
src/base/net/dns/DnsRecords.cpp
src/base/net/dns/DnsUvBackend.cpp
src/base/net/http/Http.cpp
src/base/net/stratum/BaseClient.cpp
src/base/net/stratum/Client.cpp
@@ -115,6 +132,11 @@ set(SOURCES_BASE
src/base/net/tools/LineReader.cpp
src/base/net/tools/NetBuffer.cpp
src/base/tools/Arguments.cpp
src/base/tools/cryptonote/BlockTemplate.cpp
src/base/tools/cryptonote/crypto-ops-data.c
src/base/tools/cryptonote/crypto-ops.c
src/base/tools/cryptonote/Signatures.cpp
src/base/tools/cryptonote/WalletAddress.cpp
src/base/tools/Cvt.cpp
src/base/tools/String.cpp
src/base/tools/Timer.cpp
@@ -160,7 +182,7 @@ endif()
if (WITH_HTTP)
set(HEADERS_BASE_HTTP
src/3rdparty/http-parser/http_parser.h
src/3rdparty/llhttp/llhttp.h
src/base/api/Api.h
src/base/api/Httpd.h
src/base/api/interfaces/IApiRequest.h
@@ -181,7 +203,9 @@ if (WITH_HTTP)
)
set(SOURCES_BASE_HTTP
src/3rdparty/http-parser/http_parser.c
src/3rdparty/llhttp/llhttp.c
src/3rdparty/llhttp/api.c
src/3rdparty/llhttp/http.c
src/base/api/Api.cpp
src/base/api/Httpd.cpp
src/base/api/requests/ApiRequest.cpp

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,15 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/crypto/Algorithm.h"
#include "3rdparty/rapidjson/document.h"
#include "base/tools/String.h"
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#ifdef _MSC_VER
@@ -42,93 +36,248 @@
namespace xmrig {
struct AlgoName
{
const char *name;
const char *shortName;
const Algorithm::Id id;
const char *Algorithm::kINVALID = "invalid";
const char *Algorithm::kCN = "cn";
const char *Algorithm::kCN_0 = "cn/0";
const char *Algorithm::kCN_1 = "cn/1";
const char *Algorithm::kCN_2 = "cn/2";
const char *Algorithm::kCN_R = "cn/r";
const char *Algorithm::kCN_FAST = "cn/fast";
const char *Algorithm::kCN_HALF = "cn/half";
const char *Algorithm::kCN_XAO = "cn/xao";
const char *Algorithm::kCN_RTO = "cn/rto";
const char *Algorithm::kCN_RWZ = "cn/rwz";
const char *Algorithm::kCN_ZLS = "cn/zls";
const char *Algorithm::kCN_DOUBLE = "cn/double";
const char *Algorithm::kCN_CCX = "cn/ccx";
#ifdef XMRIG_ALGO_CN_LITE
const char *Algorithm::kCN_LITE = "cn-lite";
const char *Algorithm::kCN_LITE_0 = "cn-lite/0";
const char *Algorithm::kCN_LITE_1 = "cn-lite/1";
#endif
#ifdef XMRIG_ALGO_CN_HEAVY
const char *Algorithm::kCN_HEAVY = "cn-heavy";
const char *Algorithm::kCN_HEAVY_0 = "cn-heavy/0";
const char *Algorithm::kCN_HEAVY_TUBE = "cn-heavy/tube";
const char *Algorithm::kCN_HEAVY_XHV = "cn-heavy/xhv";
#endif
#ifdef XMRIG_ALGO_CN_PICO
const char *Algorithm::kCN_PICO = "cn-pico";
const char *Algorithm::kCN_PICO_0 = "cn-pico";
const char *Algorithm::kCN_PICO_TLO = "cn-pico/tlo";
#endif
#ifdef XMRIG_ALGO_CN_FEMTO
const char *Algorithm::kCN_UPX2 = "cn/upx2";
#endif
#ifdef XMRIG_ALGO_RANDOMX
const char *Algorithm::kRX = "rx";
const char *Algorithm::kRX_0 = "rx/0";
const char *Algorithm::kRX_WOW = "rx/wow";
const char *Algorithm::kRX_ARQ = "rx/arq";
const char *Algorithm::kRX_GRAFT = "rx/graft";
const char *Algorithm::kRX_SFX = "rx/sfx";
const char *Algorithm::kRX_KEVA = "rx/keva";
#endif
#ifdef XMRIG_ALGO_ARGON2
const char *Algorithm::kAR2 = "argon2";
const char *Algorithm::kAR2_CHUKWA = "argon2/chukwa";
const char *Algorithm::kAR2_CHUKWA_V2 = "argon2/chukwav2";
const char *Algorithm::kAR2_WRKZ = "argon2/ninja";
#endif
#ifdef XMRIG_ALGO_ASTROBWT
const char *Algorithm::kASTROBWT = "astrobwt";
const char *Algorithm::kASTROBWT_DERO = "astrobwt";
#endif
#ifdef XMRIG_ALGO_KAWPOW
const char *Algorithm::kKAWPOW = "kawpow";
const char *Algorithm::kKAWPOW_RVN = "kawpow";
#endif
#define ALGO_NAME(ALGO) { Algorithm::ALGO, Algorithm::k##ALGO }
#define ALGO_ALIAS(ALGO, NAME) { NAME, Algorithm::ALGO }
#define ALGO_ALIAS_AUTO(ALGO) { Algorithm::k##ALGO, Algorithm::ALGO }
static const std::map<uint32_t, const char *> kAlgorithmNames = {
ALGO_NAME(CN_0),
ALGO_NAME(CN_1),
ALGO_NAME(CN_2),
ALGO_NAME(CN_R),
ALGO_NAME(CN_FAST),
ALGO_NAME(CN_HALF),
ALGO_NAME(CN_XAO),
ALGO_NAME(CN_RTO),
ALGO_NAME(CN_RWZ),
ALGO_NAME(CN_ZLS),
ALGO_NAME(CN_DOUBLE),
ALGO_NAME(CN_CCX),
# ifdef XMRIG_ALGO_CN_LITE
ALGO_NAME(CN_LITE_0),
ALGO_NAME(CN_LITE_1),
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
ALGO_NAME(CN_HEAVY_0),
ALGO_NAME(CN_HEAVY_TUBE),
ALGO_NAME(CN_HEAVY_XHV),
# endif
# ifdef XMRIG_ALGO_CN_PICO
ALGO_NAME(CN_PICO_0),
ALGO_NAME(CN_PICO_TLO),
# endif
# ifdef XMRIG_ALGO_CN_FEMTO
ALGO_NAME(CN_UPX2),
# endif
# ifdef XMRIG_ALGO_RANDOMX
ALGO_NAME(RX_0),
ALGO_NAME(RX_WOW),
ALGO_NAME(RX_ARQ),
ALGO_NAME(RX_GRAFT),
ALGO_NAME(RX_SFX),
ALGO_NAME(RX_KEVA),
# endif
# ifdef XMRIG_ALGO_ARGON2
ALGO_NAME(AR2_CHUKWA),
ALGO_NAME(AR2_CHUKWA_V2),
ALGO_NAME(AR2_WRKZ),
# endif
# ifdef XMRIG_ALGO_ASTROBWT
ALGO_NAME(ASTROBWT_DERO),
# endif
# ifdef XMRIG_ALGO_KAWPOW
ALGO_NAME(KAWPOW_RVN),
# endif
};
static AlgoName const algorithm_names[] = {
{ "cryptonight/0", "cn/0", Algorithm::CN_0 },
{ "cryptonight", "cn", Algorithm::CN_0 },
{ "cryptonight/1", "cn/1", Algorithm::CN_1 },
{ "cryptonight-monerov7", nullptr, Algorithm::CN_1 },
{ "cryptonight_v7", nullptr, Algorithm::CN_1 },
{ "cryptonight/2", "cn/2", Algorithm::CN_2 },
{ "cryptonight-monerov8", nullptr, Algorithm::CN_2 },
{ "cryptonight_v8", nullptr, Algorithm::CN_2 },
{ "cryptonight/r", "cn/r", Algorithm::CN_R },
{ "cryptonight_r", nullptr, Algorithm::CN_R },
{ "cryptonight/fast", "cn/fast", Algorithm::CN_FAST },
{ "cryptonight/msr", "cn/msr", Algorithm::CN_FAST },
{ "cryptonight/half", "cn/half", Algorithm::CN_HALF },
{ "cryptonight/xao", "cn/xao", Algorithm::CN_XAO },
{ "cryptonight_alloy", nullptr, Algorithm::CN_XAO },
{ "cryptonight/rto", "cn/rto", Algorithm::CN_RTO },
{ "cryptonight/rwz", "cn/rwz", Algorithm::CN_RWZ },
{ "cryptonight/zls", "cn/zls", Algorithm::CN_ZLS },
{ "cryptonight/double", "cn/double", Algorithm::CN_DOUBLE },
struct aliasCompare
{
inline bool operator()(const char *a, const char *b) const { return strcasecmp(a, b) < 0; }
};
static const std::map<const char *, Algorithm::Id, aliasCompare> kAlgorithmAliases = {
ALGO_ALIAS_AUTO(CN_0), ALGO_ALIAS(CN_0, "cryptonight/0"),
ALGO_ALIAS(CN_0, "cryptonight"),
ALGO_ALIAS(CN_0, "cn"),
ALGO_ALIAS_AUTO(CN_1), ALGO_ALIAS(CN_1, "cryptonight/1"),
ALGO_ALIAS(CN_1, "cryptonight-monerov7"),
ALGO_ALIAS(CN_1, "cryptonight_v7"),
ALGO_ALIAS_AUTO(CN_2), ALGO_ALIAS(CN_2, "cryptonight/2"),
ALGO_ALIAS(CN_2, "cryptonight-monerov8"),
ALGO_ALIAS(CN_2, "cryptonight_v8"),
ALGO_ALIAS_AUTO(CN_FAST), ALGO_ALIAS(CN_FAST, "cryptonight/fast"),
ALGO_ALIAS(CN_FAST, "cryptonight/msr"),
ALGO_ALIAS(CN_FAST, "cn/msr"),
ALGO_ALIAS_AUTO(CN_R), ALGO_ALIAS(CN_R, "cryptonight/r"),
ALGO_ALIAS(CN_R, "cryptonight_r"),
ALGO_ALIAS_AUTO(CN_XAO), ALGO_ALIAS(CN_XAO, "cryptonight/xao"),
ALGO_ALIAS(CN_XAO, "cryptonight_alloy"),
ALGO_ALIAS_AUTO(CN_HALF), ALGO_ALIAS(CN_HALF, "cryptonight/half"),
ALGO_ALIAS_AUTO(CN_RTO), ALGO_ALIAS(CN_RTO, "cryptonight/rto"),
ALGO_ALIAS_AUTO(CN_RWZ), ALGO_ALIAS(CN_RWZ, "cryptonight/rwz"),
ALGO_ALIAS_AUTO(CN_ZLS), ALGO_ALIAS(CN_ZLS, "cryptonight/zls"),
ALGO_ALIAS_AUTO(CN_DOUBLE), ALGO_ALIAS(CN_DOUBLE, "cryptonight/double"),
ALGO_ALIAS_AUTO(CN_CCX), ALGO_ALIAS(CN_CCX, "cryptonight/ccx"),
ALGO_ALIAS(CN_CCX, "cryptonight/conceal"),
ALGO_ALIAS(CN_CCX, "cn/conceal"),
# ifdef XMRIG_ALGO_CN_LITE
{ "cryptonight-lite/0", "cn-lite/0", Algorithm::CN_LITE_0 },
{ "cryptonight-lite/1", "cn-lite/1", Algorithm::CN_LITE_1 },
{ "cryptonight-lite", "cn-lite", Algorithm::CN_LITE_1 },
{ "cryptonight-light", "cn-light", Algorithm::CN_LITE_1 },
{ "cryptonight_lite", nullptr, Algorithm::CN_LITE_1 },
{ "cryptonight-aeonv7", nullptr, Algorithm::CN_LITE_1 },
{ "cryptonight_lite_v7", nullptr, Algorithm::CN_LITE_1 },
ALGO_ALIAS_AUTO(CN_LITE_0), ALGO_ALIAS(CN_LITE_0, "cryptonight-lite/0"),
ALGO_ALIAS(CN_LITE_0, "cryptonight-lite"),
ALGO_ALIAS(CN_LITE_0, "cryptonight-light"),
ALGO_ALIAS(CN_LITE_0, "cn-lite"),
ALGO_ALIAS(CN_LITE_0, "cn-light"),
ALGO_ALIAS(CN_LITE_0, "cryptonight_lite"),
ALGO_ALIAS_AUTO(CN_LITE_1), ALGO_ALIAS(CN_LITE_1, "cryptonight-lite/1"),
ALGO_ALIAS(CN_LITE_1, "cryptonight-aeonv7"),
ALGO_ALIAS(CN_LITE_1, "cryptonight_lite_v7"),
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
{ "cryptonight-heavy/0", "cn-heavy/0", Algorithm::CN_HEAVY_0 },
{ "cryptonight-heavy", "cn-heavy", Algorithm::CN_HEAVY_0 },
{ "cryptonight_heavy", nullptr, Algorithm::CN_HEAVY_0 },
{ "cryptonight-heavy/xhv", "cn-heavy/xhv", Algorithm::CN_HEAVY_XHV },
{ "cryptonight_haven", nullptr, Algorithm::CN_HEAVY_XHV },
{ "cryptonight-heavy/tube", "cn-heavy/tube", Algorithm::CN_HEAVY_TUBE },
{ "cryptonight-bittube2", nullptr, Algorithm::CN_HEAVY_TUBE },
ALGO_ALIAS_AUTO(CN_HEAVY_0), ALGO_ALIAS(CN_HEAVY_0, "cryptonight-heavy/0"),
ALGO_ALIAS(CN_HEAVY_0, "cryptonight-heavy"),
ALGO_ALIAS(CN_HEAVY_0, "cn-heavy"),
ALGO_ALIAS(CN_HEAVY_0, "cryptonight_heavy"),
ALGO_ALIAS_AUTO(CN_HEAVY_XHV), ALGO_ALIAS(CN_HEAVY_XHV, "cryptonight-heavy/xhv"),
ALGO_ALIAS(CN_HEAVY_XHV, "cryptonight_haven"),
ALGO_ALIAS_AUTO(CN_HEAVY_TUBE), ALGO_ALIAS(CN_HEAVY_TUBE, "cryptonight-heavy/tube"),
ALGO_ALIAS(CN_HEAVY_TUBE, "cryptonight-bittube2"),
# endif
# ifdef XMRIG_ALGO_CN_PICO
{ "cryptonight-pico", "cn-pico", Algorithm::CN_PICO_0 },
{ "cryptonight-pico/trtl", "cn-pico/trtl", Algorithm::CN_PICO_0 },
{ "cryptonight-turtle", "cn-trtl", Algorithm::CN_PICO_0 },
{ "cryptonight-ultralite", "cn-ultralite", Algorithm::CN_PICO_0 },
{ "cryptonight_turtle", "cn_turtle", Algorithm::CN_PICO_0 },
{ "cryptonight-pico/tlo", "cn-pico/tlo", Algorithm::CN_PICO_TLO },
{ "cryptonight/ultra", "cn/ultra", Algorithm::CN_PICO_TLO },
{ "cryptonight-talleo", "cn-talleo", Algorithm::CN_PICO_TLO },
{ "cryptonight_talleo", "cn_talleo", Algorithm::CN_PICO_TLO },
ALGO_ALIAS_AUTO(CN_PICO_0), ALGO_ALIAS(CN_PICO_0, "cryptonight-pico"),
ALGO_ALIAS(CN_PICO_0, "cn-pico/0"),
ALGO_ALIAS(CN_PICO_0, "cryptonight-pico/trtl"),
ALGO_ALIAS(CN_PICO_0, "cn-pico/trtl"),
ALGO_ALIAS(CN_PICO_0, "cryptonight-turtle"),
ALGO_ALIAS(CN_PICO_0, "cn-trtl"),
ALGO_ALIAS(CN_PICO_0, "cryptonight-ultralite"),
ALGO_ALIAS(CN_PICO_0, "cn-ultralite"),
ALGO_ALIAS(CN_PICO_0, "cryptonight_turtle"),
ALGO_ALIAS(CN_PICO_0, "cn_turtle"),
ALGO_ALIAS_AUTO(CN_PICO_TLO), ALGO_ALIAS(CN_PICO_TLO, "cryptonight-pico/tlo"),
ALGO_ALIAS(CN_PICO_TLO, "cryptonight/ultra"),
ALGO_ALIAS(CN_PICO_TLO, "cn/ultra"),
ALGO_ALIAS(CN_PICO_TLO, "cryptonight-talleo"),
ALGO_ALIAS(CN_PICO_TLO, "cn-talleo"),
ALGO_ALIAS(CN_PICO_TLO, "cryptonight_talleo"),
ALGO_ALIAS(CN_PICO_TLO, "cn_talleo"),
# endif
# ifdef XMRIG_ALGO_CN_FEMTO
ALGO_ALIAS_AUTO(CN_UPX2), ALGO_ALIAS(CN_UPX2, "cryptonight/upx2"),
ALGO_ALIAS(CN_UPX2, "cn-extremelite/upx2"),
ALGO_ALIAS(CN_UPX2, "cryptonight-upx/2"),
# endif
# ifdef XMRIG_ALGO_RANDOMX
{ "randomx/0", "rx/0", Algorithm::RX_0 },
{ "randomx/test", "rx/test", Algorithm::RX_0 },
{ "RandomX", "rx", Algorithm::RX_0 },
{ "randomx/wow", "rx/wow", Algorithm::RX_WOW },
{ "RandomWOW", nullptr, Algorithm::RX_WOW },
{ "randomx/arq", "rx/arq", Algorithm::RX_ARQ },
{ "RandomARQ", nullptr, Algorithm::RX_ARQ },
{ "randomx/sfx", "rx/sfx", Algorithm::RX_SFX },
{ "RandomSFX", nullptr, Algorithm::RX_SFX },
{ "randomx/keva", "rx/keva", Algorithm::RX_KEVA },
{ "RandomKEVA", nullptr, Algorithm::RX_KEVA },
ALGO_ALIAS_AUTO(RX_0), ALGO_ALIAS(RX_0, "randomx/0"),
ALGO_ALIAS(RX_0, "randomx/test"),
ALGO_ALIAS(RX_0, "rx/test"),
ALGO_ALIAS(RX_0, "randomx"),
ALGO_ALIAS(RX_0, "rx"),
ALGO_ALIAS_AUTO(RX_WOW), ALGO_ALIAS(RX_WOW, "randomx/wow"),
ALGO_ALIAS(RX_WOW, "randomwow"),
ALGO_ALIAS_AUTO(RX_ARQ), ALGO_ALIAS(RX_ARQ, "randomx/arq"),
ALGO_ALIAS(RX_ARQ, "randomarq"),
ALGO_ALIAS_AUTO(RX_GRAFT), ALGO_ALIAS(RX_GRAFT, "randomx/graft"),
ALGO_ALIAS(RX_GRAFT, "randomgraft"),
ALGO_ALIAS_AUTO(RX_SFX), ALGO_ALIAS(RX_SFX, "randomx/sfx"),
ALGO_ALIAS(RX_SFX, "randomsfx"),
ALGO_ALIAS_AUTO(RX_KEVA), ALGO_ALIAS(RX_KEVA, "randomx/keva"),
ALGO_ALIAS(RX_KEVA, "randomkeva"),
# endif
# ifdef XMRIG_ALGO_ARGON2
{ "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "argon2/chukwav2", nullptr, Algorithm::AR2_CHUKWA_V2 },
{ "chukwav2", nullptr, Algorithm::AR2_CHUKWA_V2 },
{ "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ },
ALGO_ALIAS_AUTO(AR2_CHUKWA), ALGO_ALIAS(AR2_CHUKWA, "chukwa"),
ALGO_ALIAS_AUTO(AR2_CHUKWA_V2), ALGO_ALIAS(AR2_CHUKWA, "chukwav2"),
ALGO_ALIAS_AUTO(AR2_WRKZ), ALGO_ALIAS(AR2_WRKZ, "argon2/wrkz"),
# endif
# ifdef XMRIG_ALGO_ASTROBWT
{ "astrobwt", nullptr, Algorithm::ASTROBWT_DERO },
{ "astrobwt/dero", nullptr, Algorithm::ASTROBWT_DERO },
ALGO_ALIAS_AUTO(ASTROBWT_DERO), ALGO_ALIAS(ASTROBWT_DERO, "astrobwt/dero"),
# endif
# ifdef XMRIG_ALGO_KAWPOW
{ "kawpow", nullptr, Algorithm::KAWPOW_RVN },
{ "kawpow/rvn", nullptr, Algorithm::KAWPOW_RVN },
ALGO_ALIAS_AUTO(KAWPOW_RVN), ALGO_ALIAS(KAWPOW_RVN, "kawpow/rvn"),
# endif
{ "cryptonight/ccx", "cn/ccx", Algorithm::CN_CCX },
{ "cryptonight/conceal", "cn/conceal", Algorithm::CN_CCX },
};
@@ -141,11 +290,30 @@ xmrig::Algorithm::Algorithm(const rapidjson::Value &value) :
}
xmrig::Algorithm::Algorithm(uint32_t id) :
m_id(kAlgorithmNames.count(id) ? static_cast<Id>(id) : INVALID)
{
}
const char *xmrig::Algorithm::name() const
{
if (!isValid()) {
return kINVALID;
}
assert(kAlgorithmNames.count(m_id));
const auto it = kAlgorithmNames.find(m_id);
return it != kAlgorithmNames.end() ? it->second : kINVALID;
}
rapidjson::Value xmrig::Algorithm::toJSON() const
{
using namespace rapidjson;
return isValid() ? Value(StringRef(shortName())) : Value(kNullType);
return isValid() ? Value(StringRef(name())) : Value(kNullType);
}
@@ -155,237 +323,46 @@ rapidjson::Value xmrig::Algorithm::toJSON(rapidjson::Document &) const
}
size_t xmrig::Algorithm::l2() const
{
# ifdef XMRIG_ALGO_RANDOMX
switch (m_id) {
case RX_0:
case RX_SFX:
return 0x40000;
case RX_WOW:
case RX_KEVA:
return 0x20000;
case RX_ARQ:
return 0x10000;
default:
break;
}
# endif
return 0;
}
size_t xmrig::Algorithm::l3() const
{
constexpr size_t oneMiB = 0x100000;
const auto f = family();
assert(f != UNKNOWN);
switch (f) {
case CN:
return oneMiB * 2;
case CN_LITE:
return oneMiB;
case CN_HEAVY:
return oneMiB * 4;
case CN_PICO:
return oneMiB / 4;
default:
break;
}
# ifdef XMRIG_ALGO_RANDOMX
if (f == RANDOM_X) {
switch (m_id) {
case RX_0:
case RX_SFX:
return oneMiB * 2;
case RX_WOW:
case RX_KEVA:
return oneMiB;
case RX_ARQ:
return oneMiB / 4;
default:
break;
}
}
# endif
# ifdef XMRIG_ALGO_ARGON2
if (f == ARGON2) {
switch (m_id) {
case AR2_CHUKWA:
return oneMiB / 2;
case AR2_CHUKWA_V2:
return oneMiB;
case AR2_WRKZ:
return oneMiB / 4;
default:
break;
}
}
# endif
# ifdef XMRIG_ALGO_ASTROBWT
if (f == ASTROBWT) {
switch (m_id) {
case ASTROBWT_DERO:
return oneMiB * 20;
default:
break;
}
}
# endif
# ifdef XMRIG_ALGO_KAWPOW
if (f == KAWPOW) {
switch (m_id) {
case KAWPOW_RVN:
return 32768;
default:
break;
}
}
# endif
return 0;
}
uint32_t xmrig::Algorithm::maxIntensity() const
{
# ifdef XMRIG_ALGO_RANDOMX
if (family() == RANDOM_X) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_ARGON2
if (family() == ARGON2) {
return 1;
}
# endif
# ifdef XMRIG_ALGO_ASTROBWT
if (family() == ASTROBWT) {
return 1;
}
# endif
return 5;
}
xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
{
switch (id) {
case CN_0:
case CN_1:
case CN_2:
case CN_R:
case CN_FAST:
case CN_HALF:
case CN_XAO:
case CN_RTO:
case CN_RWZ:
case CN_ZLS:
case CN_DOUBLE:
case CN_CCX:
return CN;
# ifdef XMRIG_ALGO_CN_LITE
case CN_LITE_0:
case CN_LITE_1:
return CN_LITE;
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
case CN_HEAVY_0:
case CN_HEAVY_TUBE:
case CN_HEAVY_XHV:
return CN_HEAVY;
# endif
# ifdef XMRIG_ALGO_CN_PICO
case CN_PICO_0:
case CN_PICO_TLO:
return CN_PICO;
# endif
# ifdef XMRIG_ALGO_RANDOMX
case RX_0:
case RX_WOW:
case RX_ARQ:
case RX_SFX:
case RX_KEVA:
return RANDOM_X;
# endif
# ifdef XMRIG_ALGO_ARGON2
case AR2_CHUKWA:
case AR2_CHUKWA_V2:
case AR2_WRKZ:
return ARGON2;
# endif
# ifdef XMRIG_ALGO_ASTROBWT
case ASTROBWT_DERO:
return ASTROBWT;
# endif
# ifdef XMRIG_ALGO_KAWPOW
case KAWPOW_RVN:
return KAWPOW;
# endif
default:
break;
}
return UNKNOWN;
}
xmrig::Algorithm::Id xmrig::Algorithm::parse(const char *name)
{
if (name == nullptr || strlen(name) < 1) {
return INVALID;
}
for (const AlgoName &item : algorithm_names) {
if ((strcasecmp(name, item.name) == 0) || (item.shortName != nullptr && strcasecmp(name, item.shortName) == 0)) {
return item.id;
}
}
const auto it = kAlgorithmAliases.find(name);
return INVALID;
return it != kAlgorithmAliases.end() ? it->second : INVALID;
}
const char *xmrig::Algorithm::name(bool shortName) const
size_t xmrig::Algorithm::count()
{
for (const AlgoName &item : algorithm_names) {
if (item.id == m_id) {
return (shortName && item.shortName) ? item.shortName : item.name;
return kAlgorithmNames.size();
}
std::vector<xmrig::Algorithm> xmrig::Algorithm::all(const std::function<bool(const Algorithm &algo)> &filter)
{
static const std::vector<Id> order = {
CN_0, CN_1, CN_2, CN_R, CN_FAST, CN_HALF, CN_XAO, CN_RTO, CN_RWZ, CN_ZLS, CN_DOUBLE, CN_CCX,
CN_LITE_0, CN_LITE_1,
CN_HEAVY_0, CN_HEAVY_TUBE, CN_HEAVY_XHV,
CN_PICO_0, CN_PICO_TLO,
CN_UPX2,
RX_0, RX_WOW, RX_ARQ, RX_GRAFT, RX_SFX, RX_KEVA,
AR2_CHUKWA, AR2_CHUKWA_V2, AR2_WRKZ,
ASTROBWT_DERO,
KAWPOW_RVN
};
Algorithms out;
out.reserve(count());
for (const Id algo : order) {
if (kAlgorithmNames.count(algo) && (!filter || filter(algo))) {
out.emplace_back(algo);
}
}
return "invalid";
return out;
}

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -27,6 +21,7 @@
#define XMRIG_ALGORITHM_H
#include <functional>
#include <vector>
@@ -39,87 +34,174 @@ namespace xmrig {
class Algorithm
{
public:
// Changes in following file is required if this enum changed:
// Changes in following file may required if this enum changed:
//
// src/backend/opencl/cl/cn/algorithm.cl
//
enum Id : int {
INVALID = -1,
CN_0, // "cn/0" CryptoNight (original).
CN_1, // "cn/1" CryptoNight variant 1 also known as Monero7 and CryptoNightV7.
CN_2, // "cn/2" CryptoNight variant 2.
CN_R, // "cn/r" CryptoNightR (Monero's variant 4).
CN_FAST, // "cn/fast" CryptoNight variant 1 with half iterations.
CN_HALF, // "cn/half" CryptoNight variant 2 with half iterations (Masari/Torque).
CN_XAO, // "cn/xao" CryptoNight variant 0 (modified, Alloy only).
CN_RTO, // "cn/rto" CryptoNight variant 1 (modified, Arto only).
CN_RWZ, // "cn/rwz" CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft).
CN_ZLS, // "cn/zls" CryptoNight variant 2 with 3/4 iterations (Zelerius).
CN_DOUBLE, // "cn/double" CryptoNight variant 2 with double iterations (X-CASH).
CN_LITE_0, // "cn-lite/0" CryptoNight-Lite variant 0.
CN_LITE_1, // "cn-lite/1" CryptoNight-Lite variant 1.
CN_HEAVY_0, // "cn-heavy/0" CryptoNight-Heavy (4 MB).
CN_HEAVY_TUBE, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only).
CN_HEAVY_XHV, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only).
CN_PICO_0, // "cn-pico" CryptoNight-Pico
CN_PICO_TLO, // "cn-pico/tlo" CryptoNight-Pico (TLO)
CN_CCX, // "cn/ccx" Conceal (CCX)
RX_0, // "rx/0" RandomX (reference configuration).
RX_WOW, // "rx/wow" RandomWOW (Wownero).
RX_ARQ, // "rx/arq" RandomARQ (Arqma).
RX_SFX, // "rx/sfx" RandomSFX (Safex Cash).
RX_KEVA, // "rx/keva" RandomKEVA (Keva).
AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
AR2_CHUKWA_V2, // "argon2/chukwav2" Argon2id (Chukwa v2).
AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
ASTROBWT_DERO, // "astrobwt" AstroBWT (Dero)
KAWPOW_RVN, // "kawpow/rvn" KawPow (RVN)
MAX
// Id encoding:
// 1 byte: family
// 1 byte: L3 memory as power of 2 (if applicable).
// 1 byte: L2 memory for RandomX algorithms as power of 2, base variant for CryptoNight algorithms or 0x00.
// 1 byte: extra variant (coin) id.
enum Id : uint32_t {
INVALID = 0,
CN_0 = 0x63150000, // "cn/0" CryptoNight (original).
CN_1 = 0x63150100, // "cn/1" CryptoNight variant 1 also known as Monero7 and CryptoNightV7.
CN_2 = 0x63150200, // "cn/2" CryptoNight variant 2.
CN_R = 0x63150272, // "cn/r" CryptoNightR (Monero's variant 4).
CN_FAST = 0x63150166, // "cn/fast" CryptoNight variant 1 with half iterations.
CN_HALF = 0x63150268, // "cn/half" CryptoNight variant 2 with half iterations (Masari/Torque).
CN_XAO = 0x63150078, // "cn/xao" CryptoNight variant 0 (modified, Alloy only).
CN_RTO = 0x63150172, // "cn/rto" CryptoNight variant 1 (modified, Arto only).
CN_RWZ = 0x63150277, // "cn/rwz" CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft).
CN_ZLS = 0x6315027a, // "cn/zls" CryptoNight variant 2 with 3/4 iterations (Zelerius).
CN_DOUBLE = 0x63150264, // "cn/double" CryptoNight variant 2 with double iterations (X-CASH).
CN_CCX = 0x63150063, // "cn/ccx" Conceal (CCX)
CN_LITE_0 = 0x63140000, // "cn-lite/0" CryptoNight-Lite variant 0.
CN_LITE_1 = 0x63140100, // "cn-lite/1" CryptoNight-Lite variant 1.
CN_HEAVY_0 = 0x63160000, // "cn-heavy/0" CryptoNight-Heavy (4 MB).
CN_HEAVY_TUBE = 0x63160172, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only).
CN_HEAVY_XHV = 0x63160068, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only).
CN_PICO_0 = 0x63120200, // "cn-pico" CryptoNight-Pico
CN_PICO_TLO = 0x63120274, // "cn-pico/tlo" CryptoNight-Pico (TLO)
CN_UPX2 = 0x63110200, // "cn/upx2" Uplexa (UPX2)
RX_0 = 0x72151200, // "rx/0" RandomX (reference configuration).
RX_WOW = 0x72141177, // "rx/wow" RandomWOW (Wownero).
RX_ARQ = 0x72121061, // "rx/arq" RandomARQ (Arqma).
RX_GRAFT = 0x72151267, // "rx/graft" RandomGRAFT (Graft).
RX_SFX = 0x72151273, // "rx/sfx" RandomSFX (Safex Cash).
RX_KEVA = 0x7214116b, // "rx/keva" RandomKEVA (Keva).
AR2_CHUKWA = 0x61130000, // "argon2/chukwa" Argon2id (Chukwa).
AR2_CHUKWA_V2 = 0x61140000, // "argon2/chukwav2" Argon2id (Chukwa v2).
AR2_WRKZ = 0x61120000, // "argon2/wrkz" Argon2id (WRKZ)
ASTROBWT_DERO = 0x41000000, // "astrobwt" AstroBWT (Dero)
KAWPOW_RVN = 0x6b0f0000, // "kawpow/rvn" KawPow (RVN)
};
enum Family : int {
UNKNOWN,
CN,
CN_LITE,
CN_HEAVY,
CN_PICO,
RANDOM_X,
ARGON2,
ASTROBWT,
KAWPOW
enum Family : uint32_t {
UNKNOWN = 0,
CN_ANY = 0x63000000,
CN = 0x63150000,
CN_LITE = 0x63140000,
CN_HEAVY = 0x63160000,
CN_PICO = 0x63120000,
CN_FEMTO = 0x63110000,
RANDOM_X = 0x72000000,
ARGON2 = 0x61000000,
ASTROBWT = 0x41000000,
KAWPOW = 0x6b000000
};
static const char *kINVALID;
static const char *kCN;
static const char *kCN_0;
static const char *kCN_1;
static const char *kCN_2;
static const char *kCN_R;
static const char *kCN_FAST;
static const char *kCN_HALF;
static const char *kCN_XAO;
static const char *kCN_RTO;
static const char *kCN_RWZ;
static const char *kCN_ZLS;
static const char *kCN_DOUBLE;
static const char *kCN_CCX;
# ifdef XMRIG_ALGO_CN_LITE
static const char *kCN_LITE;
static const char *kCN_LITE_0;
static const char *kCN_LITE_1;
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
static const char *kCN_HEAVY;
static const char *kCN_HEAVY_0;
static const char *kCN_HEAVY_TUBE;
static const char *kCN_HEAVY_XHV;
# endif
# ifdef XMRIG_ALGO_CN_PICO
static const char *kCN_PICO;
static const char *kCN_PICO_0;
static const char *kCN_PICO_TLO;
# endif
# ifdef XMRIG_ALGO_CN_FEMTO
static const char *kCN_UPX2;
# endif
# ifdef XMRIG_ALGO_RANDOMX
static const char *kRX;
static const char *kRX_0;
static const char *kRX_WOW;
static const char *kRX_ARQ;
static const char *kRX_GRAFT;
static const char *kRX_SFX;
static const char *kRX_KEVA;
# endif
# ifdef XMRIG_ALGO_ARGON2
static const char *kAR2;
static const char *kAR2_CHUKWA;
static const char *kAR2_CHUKWA_V2;
static const char *kAR2_WRKZ;
# endif
# ifdef XMRIG_ALGO_ASTROBWT
static const char *kASTROBWT;
static const char *kASTROBWT_DERO;
# endif
# ifdef XMRIG_ALGO_KAWPOW
static const char *kKAWPOW;
static const char *kKAWPOW_RVN;
# endif
inline Algorithm() = default;
inline Algorithm(const char *algo) : m_id(parse(algo)) {}
inline Algorithm(Id id) : m_id(id) {}
inline Algorithm(const char *algo) : m_id(parse(algo)) {}
inline Algorithm(Id id) : m_id(id) {}
Algorithm(const rapidjson::Value &value);
Algorithm(uint32_t id);
inline bool isCN() const { auto f = family(); return f == CN || f == CN_LITE || f == CN_HEAVY || f == CN_PICO; }
inline bool isEqual(const Algorithm &other) const { return m_id == other.m_id; }
inline bool isValid() const { return m_id != INVALID && family() != UNKNOWN; }
inline const char *name() const { return name(false); }
inline const char *shortName() const { return name(true); }
inline Family family() const { return family(m_id); }
inline Id id() const { return m_id; }
static inline constexpr bool isCN(Id id) { return (id & 0xff000000) == CN_ANY; }
static inline constexpr Id base(Id id) { return isCN(id) ? static_cast<Id>(CN_0 | (id & 0xff00)) : INVALID; }
static inline constexpr size_t l2(Id id) { return family(id) == RANDOM_X ? (1U << ((id >> 8) & 0xff)) : 0U; }
static inline constexpr size_t l3(Id id) { return 1ULL << ((id >> 16) & 0xff); }
static inline constexpr uint32_t family(Id id) { return id & (isCN(id) ? 0xffff0000 : 0xff000000); }
inline bool operator!=(Algorithm::Id id) const { return m_id != id; }
inline bool operator!=(const Algorithm &other) const { return !isEqual(other); }
inline bool operator==(Algorithm::Id id) const { return m_id == id; }
inline bool operator==(const Algorithm &other) const { return isEqual(other); }
inline operator Algorithm::Id() const { return m_id; }
inline bool isCN() const { return isCN(m_id); }
inline bool isEqual(const Algorithm &other) const { return m_id == other.m_id; }
inline bool isValid() const { return m_id != INVALID && family() > UNKNOWN; }
inline Id base() const { return base(m_id); }
inline Id id() const { return m_id; }
inline size_t l2() const { return l2(m_id); }
inline uint32_t family() const { return family(m_id); }
inline uint32_t maxIntensity() const { return isCN() ? 5 : 1; };
inline size_t l3() const
{
# ifdef XMRIG_ALGO_ASTROBWT
return m_id != ASTROBWT_DERO ? l3(m_id) : 0x100000 * 20;
# else
return l3(m_id);
# endif
}
inline bool operator!=(Algorithm::Id id) const { return m_id != id; }
inline bool operator!=(const Algorithm &other) const { return !isEqual(other); }
inline bool operator==(Algorithm::Id id) const { return m_id == id; }
inline bool operator==(const Algorithm &other) const { return isEqual(other); }
inline operator Algorithm::Id() const { return m_id; }
const char *name() const;
rapidjson::Value toJSON() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t l2() const;
size_t l3() const;
uint32_t maxIntensity() const;
static Family family(Id id);
static Id parse(const char *name);
static size_t count();
static std::vector<Algorithm> all(const std::function<bool(const Algorithm &algo)> &filter = nullptr);
private:
const char *name(bool shortName) const;
Id m_id = INVALID;
};

View File

@@ -1,13 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,9 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/crypto/Coin.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
#include "base/io/log/Log.h"
#include <cstring>
@@ -39,70 +33,67 @@
namespace xmrig {
struct CoinName
struct CoinInfo
{
const Algorithm::Id algorithm;
const char *code;
const char *name;
const Coin::Id id;
const uint64_t target;
const uint64_t units;
const char *tag;
};
static CoinName const coin_names[] = {
{ "monero", Coin::MONERO },
{ "xmr", Coin::MONERO },
{ "arqma", Coin::ARQMA },
{ "arq", Coin::ARQMA },
{ "dero", Coin::DERO },
{ "keva", Coin::KEVA },
{ "ravencoin", Coin::RAVEN },
{ "raven", Coin::RAVEN },
{ "rvn", Coin::RAVEN },
{ "conceal", Coin::CONCEAL }
static const CoinInfo coinInfo[] = {
{ Algorithm::INVALID, nullptr, nullptr, 0, 0, nullptr },
{ Algorithm::RX_0, "XMR", "Monero", 120, 1000000000000, YELLOW_BG_BOLD( WHITE_BOLD_S " monero ") },
{ Algorithm::CN_R, "SUMO", "Sumokoin", 240, 1000000000, BLUE_BG_BOLD( WHITE_BOLD_S " sumo ") },
{ Algorithm::RX_ARQ, "ARQ", "ArQmA", 120, 1000000000, BLUE_BG_BOLD( WHITE_BOLD_S " arqma ") },
{ Algorithm::ASTROBWT_DERO, "DERO", "DERO", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " dero ") },
{ Algorithm::RX_GRAFT, "GRFT", "Graft", 120, 10000000000, BLUE_BG_BOLD( WHITE_BOLD_S " graft ") },
{ Algorithm::RX_KEVA, "KVA", "Kevacoin", 0, 0, MAGENTA_BG_BOLD(WHITE_BOLD_S " keva ") },
{ Algorithm::KAWPOW_RVN, "RVN", "Ravencoin", 0, 0, BLUE_BG_BOLD( WHITE_BOLD_S " raven ") },
{ Algorithm::RX_WOW, "WOW", "Wownero", 300, 100000000000, MAGENTA_BG_BOLD(WHITE_BOLD_S " wownero ") },
};
static_assert(Coin::MAX == sizeof(coinInfo) / sizeof(coinInfo[0]), "size mismatch");
const char *Coin::kDisabled = "DISABLED_COIN";
const char *Coin::kField = "coin";
const char *Coin::kUnknown = "UNKNOWN_COIN";
} /* namespace xmrig */
xmrig::Algorithm::Id xmrig::Coin::algorithm(uint8_t blobVersion) const
xmrig::Coin::Coin(const rapidjson::Value &value)
{
switch (id()) {
case MONERO:
return (blobVersion >= 12) ? Algorithm::RX_0 : Algorithm::CN_R;
case ARQMA:
return (blobVersion >= 15) ? Algorithm::RX_ARQ : Algorithm::CN_PICO_0;
case DERO:
return (blobVersion >= 4) ? Algorithm::ASTROBWT_DERO : Algorithm::CN_0;
case KEVA:
return (blobVersion >= 11) ? Algorithm::RX_KEVA : Algorithm::CN_R;
case RAVEN:
return Algorithm::KAWPOW_RVN;
case CONCEAL:
return Algorithm::CN_CCX;
case INVALID:
break;
if (value.IsString()) {
m_id = parse(value.GetString());
}
else if (value.IsObject() && !value.ObjectEmpty()) {
m_id = parse(Json::getString(value, kField));
}
return Algorithm::INVALID;
}
xmrig::Algorithm xmrig::Coin::algorithm(uint8_t) const
{
return coinInfo[m_id].algorithm;
}
const char *xmrig::Coin::code() const
{
return coinInfo[m_id].code;
}
const char *xmrig::Coin::name() const
{
for (const auto &i : coin_names) {
if (i.id == m_id) {
return i.name;
}
}
return nullptr;
return coinInfo[m_id].name;
}
@@ -110,7 +101,19 @@ rapidjson::Value xmrig::Coin::toJSON() const
{
using namespace rapidjson;
return isValid() ? Value(StringRef(name())) : Value(kNullType);
return isValid() ? Value(StringRef(code())) : Value(kNullType);
}
uint64_t xmrig::Coin::target(uint8_t) const
{
return coinInfo[m_id].target;
}
uint64_t xmrig::Coin::units() const
{
return coinInfo[m_id].units;
}
@@ -120,11 +123,17 @@ xmrig::Coin::Id xmrig::Coin::parse(const char *name)
return INVALID;
}
for (const auto &i : coin_names) {
if (strcasecmp(name, i.name) == 0) {
return i.id;
for (uint32_t i = 1; i < MAX; ++i) {
if (strcasecmp(name, coinInfo[i].code) == 0 || strcasecmp(name, coinInfo[i].name) == 0) {
return static_cast<Id>(i);
}
}
return INVALID;
}
const char *xmrig::Coin::tag(Id id)
{
return coinInfo[id].tag;
}

View File

@@ -1,13 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -37,37 +30,53 @@ namespace xmrig {
class Coin
{
public:
enum Id : int {
INVALID = -1,
enum Id : uint32_t {
INVALID,
MONERO,
SUMO,
ARQMA,
DERO,
GRAFT,
KEVA,
RAVEN,
CONCEAL
WOWNERO,
MAX
};
static const char *kDisabled;
static const char *kField;
static const char *kUnknown;
Coin() = default;
inline Coin(const char *name) : m_id(parse(name)) {}
inline Coin(Id id) : m_id(id) {}
Coin(const rapidjson::Value &value);
inline Coin(const char *name) : m_id(parse(name)) {}
inline Coin(Id id) : m_id(id) {}
inline Coin(uint32_t id) : m_id(id < MAX ? static_cast<Id>(id) : INVALID) {}
inline bool isEqual(const Coin &other) const { return m_id == other.m_id; }
inline bool isValid() const { return m_id != INVALID; }
inline Id id() const { return m_id; }
inline bool isEqual(const Coin &other) const { return m_id == other.m_id; }
inline bool isValid() const { return m_id != INVALID; }
inline Id id() const { return m_id; }
inline const char *tag() const { return tag(m_id); }
inline double decimal(uint64_t amount) const { return static_cast<double>(amount) / units(); }
Algorithm::Id algorithm(uint8_t blobVersion = 255) const;
Algorithm algorithm(uint8_t blobVersion = 255) const;
const char *code() const;
const char *name() const;
rapidjson::Value toJSON() const;
uint64_t target(uint8_t blobVersion = 255) const;
uint64_t units() const;
inline bool operator!=(Coin::Id id) const { return m_id != id; }
inline bool operator!=(const Coin &other) const { return !isEqual(other); }
inline bool operator==(Coin::Id id) const { return m_id == id; }
inline bool operator==(const Coin &other) const { return isEqual(other); }
inline operator Coin::Id() const { return m_id; }
inline bool operator!=(Id id) const { return m_id != id; }
inline bool operator!=(const Coin &other) const { return !isEqual(other); }
inline bool operator<(Id id) const { return m_id < id; }
inline bool operator<(const Coin &other) const { return m_id < other.m_id; }
inline bool operator==(Id id) const { return m_id == id; }
inline bool operator==(const Coin &other) const { return isEqual(other); }
inline operator Id() const { return m_id; }
static Id parse(const char *name);
static const char *tag(Id id);
private:
Id m_id = INVALID;

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/Console.h"
#include "base/kernel/interfaces/IConsoleListener.h"
#include "base/tools/Handle.h"
@@ -50,7 +49,7 @@ xmrig::Console::~Console()
}
bool xmrig::Console::isSupported() const
bool xmrig::Console::isSupported()
{
const uv_handle_type type = uv_guess_handle(0);
return type == UV_TTY || type == UV_NAMED_PIPE;

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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,7 +50,7 @@ public:
~Console();
private:
bool isSupported() const;
static bool isSupported();
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/Env.h"
#include "base/kernel/Process.h"
#include "version.h"
@@ -61,7 +60,7 @@ static void createVariables()
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
String hostname = "HOSTNAME";
if (!getenv(hostname)) {
if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe)
variables.insert({ std::move(hostname), Env::hostname() });
}
}
@@ -137,24 +136,17 @@ xmrig::String xmrig::Env::get(const String &name, const std::map<String, String>
}
# endif
return static_cast<const char *>(getenv(name));
return static_cast<const char *>(getenv(name)); // NOLINT(concurrency-mt-unsafe)
}
xmrig::String xmrig::Env::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
size_t size = sizeof(buf);
# if UV_VERSION_HEX >= 0x010c00
if (uv_os_gethostname(buf, &size) == 0) {
if (gethostname(buf, sizeof(buf)) == 0) {
return static_cast<const char *>(buf);
}
# else
if (gethostname(buf, size) == 0) {
return static_cast<const char *>(buf);
}
# endif
return {};
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/json/Json.h"
#include "3rdparty/rapidjson/document.h"
@@ -30,7 +29,7 @@ namespace xmrig {
static const rapidjson::Value kNullValue;
}
} // namespace xmrig
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/json/JsonChain.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
@@ -27,7 +26,7 @@ namespace xmrig {
static const rapidjson::Value kNullValue;
}
} // namespace xmrig
xmrig::JsonChain::JsonChain() = default;
@@ -58,8 +57,8 @@ bool xmrig::JsonChain::addFile(const char *fileName)
if (doc.HasParseError()) {
const size_t offset = doc.GetErrorOffset();
size_t line;
size_t pos;
size_t line = 0;
size_t pos = 0;
std::vector<std::string> s;
if (Json::convertOffset(fileName, offset, line, pos, s)) {
@@ -175,7 +174,6 @@ const rapidjson::Value &xmrig::JsonChain::getValue(const char *key) const
}
const rapidjson::Value &xmrig::JsonChain::object() const
{
assert(false);

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/json/JsonRequest.h"
#include "3rdparty/rapidjson/document.h"

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fstream>

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -37,9 +37,6 @@ static void fsWriteCallback(uv_fs_t *req)
}
static const char *kNewLine = "\n";
} // namespace xmrig
@@ -50,11 +47,24 @@ bool xmrig::FileLogWriter::open(const char *fileName)
return false;
}
uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, Env::expand(fileName), O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
uv_fs_t req{};
const auto path = Env::expand(fileName);
m_file = uv_fs_open(uv_default_loop(), &req, path, O_CREAT | O_WRONLY, 0644, nullptr);
if (req.result < 0 || !isOpen()) {
uv_fs_req_cleanup(&req);
m_file = -1;
return false;
}
uv_fs_req_cleanup(&req);
return isOpen();
uv_fs_stat(uv_default_loop(), &req, path, nullptr);
m_pos = req.statbuf.st_size;
uv_fs_req_cleanup(&req);
return true;
}
@@ -70,7 +80,8 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
auto req = new uv_fs_t;
req->data = buf.base;
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, fsWriteCallback);
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, m_pos, fsWriteCallback);
m_pos += size;
return true;
}
@@ -78,9 +89,9 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
{
uv_buf_t buf[2] = {
const uv_buf_t buf[2] = {
uv_buf_init(new char[size], size),
uv_buf_init(const_cast<char *>(kNewLine), 1)
uv_buf_init(const_cast<char *>(m_endl), sizeof(m_endl) - 1)
};
memcpy(buf[0].base, data, size);
@@ -88,7 +99,8 @@ bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
auto req = new uv_fs_t;
req->data = buf[0].base;
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, -1, fsWriteCallback);
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, m_pos, fsWriteCallback);
m_pos += (buf[0].len + buf[1].len);
return true;
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -21,6 +21,7 @@
#include <cstddef>
#include <cstdint>
namespace xmrig {
@@ -33,13 +34,21 @@ public:
FileLogWriter(const char *fileName) { open(fileName); }
inline bool isOpen() const { return m_file >= 0; }
inline int64_t pos() const { return m_pos; }
bool open(const char *fileName);
bool write(const char *data, size_t size);
bool writeLine(const char *data, size_t size);
private:
int m_file = -1;
# ifdef XMRIG_OS_WIN
const char m_endl[3] = {'\r', '\n', 0};
# else
const char m_endl[2] = {'\n', 0};
# endif
int m_file = -1;
int64_t m_pos = 0;
};

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef WIN32
# include <winsock2.h>
# include <windows.h>
@@ -103,7 +102,7 @@ public:
endl(size);
std::string txt(m_buf);
size_t i;
size_t i = 0;
while ((i = txt.find(CSI)) != std::string::npos) {
txt.erase(i, txt.find('m', i) - i + 1);
}
@@ -232,7 +231,7 @@ void xmrig::Log::print(const char *fmt, ...)
return;
}
va_list args;
va_list args{};
va_start(args, fmt);
d->print(NONE, fmt, args);
@@ -247,7 +246,7 @@ void xmrig::Log::print(Level level, const char *fmt, ...)
return;
}
va_list args;
va_list args{};
va_start(args, fmt);
d->print(level, fmt, args);

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/log/backends/ConsoleLog.h"
#include "base/io/log/Log.h"
#include "base/kernel/config/Title.h"
@@ -47,7 +46,7 @@ xmrig::ConsoleLog::ConsoleLog(const Title &title)
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
if (handle != INVALID_HANDLE_VALUE) {
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
DWORD mode = 0;
if (GetConsoleMode(handle, &mode)) {
mode &= ~ENABLE_QUICK_EDIT_MODE;
@@ -91,7 +90,7 @@ void xmrig::ConsoleLog::print(uint64_t, int, const char *line, size_t, size_t si
}
bool xmrig::ConsoleLog::isSupported() const
bool xmrig::ConsoleLog::isSupported()
{
const uv_handle_type type = uv_guess_handle(1);
return type == UV_TTY || type == UV_NAMED_PIPE;

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -47,7 +47,7 @@ protected:
void print(uint64_t timestamp, int level, const char *line, size_t offset, size_t size, bool colors) override;
private:
bool isSupported() const;
static bool isSupported();
uv_tty_t *m_tty = nullptr;

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <memory>
@@ -76,7 +69,7 @@ public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(BasePrivate)
inline BasePrivate(Process *process)
inline explicit BasePrivate(Process *process)
{
Log::init();
@@ -97,7 +90,7 @@ public:
}
inline bool read(const JsonChain &chain, std::unique_ptr<Config> &config)
inline static bool read(const JsonChain &chain, std::unique_ptr<Config> &config)
{
config = std::unique_ptr<Config>(new Config());
@@ -125,7 +118,7 @@ public:
private:
inline Config *load(Process *process)
inline static Config *load(Process *process)
{
JsonChain chain;
ConfigTransform transform;

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -109,7 +109,7 @@ static int exportTopology(const Process &)
{
const String path = Process::location(Process::ExeLocation, "topology.xml");
hwloc_topology_t topology;
hwloc_topology_t topology = nullptr;
hwloc_topology_init(&topology);
hwloc_topology_load(topology);
@@ -141,7 +141,7 @@ xmrig::Entry::Id xmrig::Entry::get(const Process &process)
return Usage;
}
if (args.hasArg("-V") || args.hasArg("--version")) {
if (args.hasArg("-V") || args.hasArg("--version") || args.hasArg("--versions")) {
return Version;
}

View File

@@ -30,7 +30,7 @@
static inline OSVERSIONINFOEX winOsVersion()
{
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); // NOLINT(modernize-use-using)
OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0};
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
@@ -61,9 +61,9 @@ char *xmrig::Platform::createUserAgent()
# endif
# ifdef __GNUC__
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif _MSC_VER
length += snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
# endif
return buf;

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ctime>
#include <string>
#include <uv.h>
@@ -80,7 +79,7 @@ static std::string getPath(Process::Location location)
return {};
}
const auto path = std::string(pathBuf, size);
auto path = std::string(pathBuf, size);
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
if (pos != std::string::npos) {
@@ -153,7 +152,7 @@ xmrig::String xmrig::Process::exepath()
{
size_t size = sizeof(pathBuf);
return uv_exepath(pathBuf, &size) < 0 ? "" : String(pathBuf, size);
return uv_exepath(pathBuf, &size) < 0 ? String("") : String(pathBuf, size);
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -23,6 +23,7 @@
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "base/net/dns/Dns.h"
#include "version.h"
@@ -105,6 +106,8 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_http.load(reader.getObject(kHttp));
m_pools.load(reader);
Dns::set(reader.getObject(DnsConfig::kField));
return m_pools.active() > 0;
}

View File

@@ -86,7 +86,7 @@ public:
bool read(const IJsonReader &reader, const char *fileName) override;
bool save() override;
void printVersions();
static void printVersions();
protected:
bool m_autoSave = true;
@@ -110,7 +110,7 @@ protected:
# endif
private:
void setVerbose(const rapidjson::Value &value);
static void setVerbose(const rapidjson::Value &value);
};

View File

@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdio>
@@ -33,6 +32,7 @@
#include "base/kernel/config/BaseConfig.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/kernel/Process.h"
#include "base/net/dns/DnsConfig.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/Config_platform.h"
@@ -47,14 +47,14 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans
{
using namespace rapidjson;
int key;
int key = 0;
int argc = process->arguments().argc();
char **argv = process->arguments().argv();
Document doc(kObjectType);
while (true) {
key = getopt_long(argc, argv, short_options, options, nullptr);
key = getopt_long(argc, argv, short_options, options, nullptr); // NOLINT(concurrency-mt-unsafe)
if (key < 0) {
break;
}
@@ -180,6 +180,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::PasswordKey: /* --pass */
return add(doc, Pools::kPools, Pool::kPass, arg);
case IConfig::SpendSecretKey: /* --spend-secret-key */
return add(doc, Pools::kPools, Pool::kSpendSecretKey, arg);
case IConfig::RigIdKey: /* --rig-id */
return add(doc, Pools::kPools, Pool::kRigId, arg);
@@ -238,12 +241,14 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
return set(doc, BaseConfig::kTls, TlsConfig::kGen, arg);
# endif
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
case IConfig::PrintTimeKey: /* --print-time */
case IConfig::HttpPort: /* --http-port */
case IConfig::DonateLevelKey: /* --donate-level */
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
case IConfig::PrintTimeKey: /* --print-time */
case IConfig::HttpPort: /* --http-port */
case IConfig::DonateLevelKey: /* --donate-level */
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
case IConfig::DnsTtlKey: /* --dns-ttl */
case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return transformUint64(doc, key, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::BackgroundKey: /* --background */
@@ -256,6 +261,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::DaemonKey: /* --daemon */
case IConfig::SubmitToOriginKey: /* --submit-to-origin */
case IConfig::VerboseKey: /* --verbose */
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
return transformBoolean(doc, key, true);
case IConfig::ColorKey: /* --no-color */
@@ -316,6 +322,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::NoTitleKey: /* --no-title */
return set(doc, BaseConfig::kTitle, enable);
case IConfig::DnsIPv6Key: /* --dns-ipv6 */
return set(doc, DnsConfig::kField, DnsConfig::kIPv6, enable);
default:
break;
}
@@ -344,9 +353,15 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
case IConfig::PrintTimeKey: /* --print-time */
return set(doc, BaseConfig::kPrintTime, arg);
case IConfig::DnsTtlKey: /* --dns-ttl */
return set(doc, DnsConfig::kField, DnsConfig::kTTL, arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);
case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return add(doc, Pools::kPools, Pool::kDaemonZMQPort, arg);
# endif
default:

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -27,6 +21,7 @@
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/Object.h"
#include <functional>
@@ -46,6 +41,8 @@ class String;
class IClient
{
public:
XMRIG_DISABLE_COPY_MOVE(IClient)
enum Extension {
EXT_ALGO,
EXT_NICEHASH,
@@ -57,7 +54,8 @@ public:
using Callback = std::function<void(const rapidjson::Value &result, bool success, uint64_t elapsed)>;
virtual ~IClient() = default;
IClient() = default;
virtual ~IClient() = default;
virtual bool disconnect() = 0;
virtual bool hasExtension(Extension extension) const noexcept = 0;

View File

@@ -82,6 +82,11 @@ public:
HugePageSizeKey = 1050,
PauseOnActiveKey = 1051,
SubmitToOriginKey = 1052,
DnsIPv6Key = 1053,
DnsTtlKey = 1054,
SpendSecretKey = 1055,
DaemonZMQPortKey = 1056,
HugePagesJitKey = 1057,
// xmrig common
CPUPriorityKey = 1021,

View File

@@ -0,0 +1,54 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_IDNSBACKEND_H
#define XMRIG_IDNSBACKEND_H
#include "base/tools/Object.h"
#include <memory>
namespace xmrig {
class DnsRecords;
class DnsRequest;
class IDnsListener;
class String;
class IDnsBackend
{
public:
XMRIG_DISABLE_COPY_MOVE(IDnsBackend)
IDnsBackend() = default;
virtual ~IDnsBackend() = default;
virtual const DnsRecords &records() const = 0;
virtual std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl) = 0;
};
} /* namespace xmrig */
#endif // XMRIG_IDNSBACKEND_H

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -26,7 +26,7 @@
namespace xmrig {
class Dns;
class DnsRecords;
class IDnsListener
@@ -37,7 +37,7 @@ public:
IDnsListener() = default;
virtual ~IDnsListener() = default;
virtual void onResolved(const Dns &dns, int status) = 0;
virtual void onResolved(const DnsRecords &records, int status, const char *error) = 0;
};

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -18,136 +18,24 @@
#include "base/net/dns/Dns.h"
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/dns/DnsUvBackend.h"
namespace xmrig {
Storage<Dns> Dns::m_storage;
static const DnsRecord defaultRecord;
}
xmrig::Dns::Dns(IDnsListener *listener) :
m_listener(listener)
DnsConfig Dns::m_config;
std::map<String, std::shared_ptr<IDnsBackend> > Dns::m_backends;
} // namespace xmrig
std::shared_ptr<xmrig::DnsRequest> xmrig::Dns::resolve(const String &host, IDnsListener *listener, uint64_t ttl)
{
m_key = m_storage.add(this);
if (m_backends.find(host) == m_backends.end()) {
m_backends.insert({ host, std::make_shared<DnsUvBackend>() });
}
m_resolver = new uv_getaddrinfo_t;
m_resolver->data = m_storage.ptr(m_key);
m_hints.ai_family = AF_UNSPEC;
m_hints.ai_socktype = SOCK_STREAM;
m_hints.ai_protocol = IPPROTO_TCP;
}
xmrig::Dns::~Dns()
{
m_storage.release(m_key);
delete m_resolver;
}
bool xmrig::Dns::resolve(const String &host)
{
if (m_host != host) {
m_host = host;
clear();
}
m_status = uv_getaddrinfo(uv_default_loop(), m_resolver, Dns::onResolved, m_host.data(), nullptr, &m_hints);
return m_status == 0;
}
const char *xmrig::Dns::error() const
{
return uv_strerror(m_status);
}
const xmrig::DnsRecord &xmrig::Dns::get(DnsRecord::Type prefered) const
{
if (count() == 0) {
return defaultRecord;
}
const size_t ipv4 = m_ipv4.size();
const size_t ipv6 = m_ipv6.size();
if (ipv6 && (prefered == DnsRecord::AAAA || !ipv4)) {
return m_ipv6[ipv6 == 1 ? 0 : static_cast<size_t>(rand()) % ipv6];
}
if (ipv4) {
return m_ipv4[ipv4 == 1 ? 0 : static_cast<size_t>(rand()) % ipv4];
}
return defaultRecord;
}
size_t xmrig::Dns::count(DnsRecord::Type type) const
{
if (type == DnsRecord::A) {
return m_ipv4.size();
}
if (type == DnsRecord::AAAA) {
return m_ipv6.size();
}
return m_ipv4.size() + m_ipv6.size();
}
void xmrig::Dns::clear()
{
m_ipv4.clear();
m_ipv6.clear();
}
void xmrig::Dns::onResolved(int status, addrinfo *res)
{
m_status = status;
if (m_status < 0) {
return m_listener->onResolved(*this, status);
}
clear();
addrinfo *ptr = res;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
m_ipv4.emplace_back(ptr);
}
if (ptr->ai_family == AF_INET6) {
m_ipv6.emplace_back(ptr);
}
ptr = ptr->ai_next;
}
if (isEmpty()) {
m_status = UV_EAI_NONAME;
}
m_listener->onResolved(*this, m_status);
}
void xmrig::Dns::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
{
Dns *dns = m_storage.get(req->data);
if (dns) {
dns->onResolved(status, res);
}
uv_freeaddrinfo(res);
return m_backends.at(host)->resolve(host, listener, ttl == 0 ? m_config.ttl() : ttl);
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -20,55 +20,34 @@
#define XMRIG_DNS_H
#include <vector>
#include <uv.h>
#include "base/net/dns/DnsRecord.h"
#include "base/net/tools/Storage.h"
#include "base/tools/Object.h"
#include "base/net/dns/DnsConfig.h"
#include "base/tools/String.h"
#include <map>
#include <memory>
namespace xmrig {
class DnsConfig;
class DnsRequest;
class IDnsBackend;
class IDnsListener;
class Dns
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns)
inline static const DnsConfig &config() { return m_config; }
inline static void set(const DnsConfig &config) { m_config = config; }
Dns(IDnsListener *listener);
~Dns();
inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); }
inline const String &host() const { return m_host; }
inline int status() const { return m_status; }
bool resolve(const String &host);
const char *error() const;
const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::A) const;
size_t count(DnsRecord::Type type = DnsRecord::Unknown) const;
static std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl = 0);
private:
void clear();
void onResolved(int status, addrinfo *res);
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
addrinfo m_hints{};
IDnsListener *m_listener;
int m_status = 0;
std::vector<DnsRecord> m_ipv4;
std::vector<DnsRecord> m_ipv6;
String m_host;
uintptr_t m_key;
uv_getaddrinfo_t *m_resolver = nullptr;
static Storage<Dns> m_storage;
static DnsConfig m_config;
static std::map<String, std::shared_ptr<IDnsBackend> > m_backends;
};

View File

@@ -0,0 +1,56 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/dns/DnsConfig.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
#include <algorithm>
namespace xmrig {
const char *DnsConfig::kField = "dns";
const char *DnsConfig::kIPv6 = "ipv6";
const char *DnsConfig::kTTL = "ttl";
} // namespace xmrig
xmrig::DnsConfig::DnsConfig(const rapidjson::Value &value)
{
m_ipv6 = Json::getBool(value, kIPv6, m_ipv6);
m_ttl = std::max(Json::getUint(value, kTTL, m_ttl), 1U);
}
rapidjson::Value xmrig::DnsConfig::toJSON(rapidjson::Document &doc) const
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
Value obj(kObjectType);
obj.AddMember(StringRef(kIPv6), m_ipv6, allocator);
obj.AddMember(StringRef(kTTL), m_ttl, allocator);
return obj;
}

View File

@@ -0,0 +1,54 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNSCONFIG_H
#define XMRIG_DNSCONFIG_H
#include "3rdparty/rapidjson/fwd.h"
namespace xmrig {
class DnsConfig
{
public:
static const char *kField;
static const char *kIPv6;
static const char *kTTL;
DnsConfig() = default;
DnsConfig(const rapidjson::Value &value);
inline bool isIPv6() const { return m_ipv6; }
inline uint32_t ttl() const { return m_ttl * 1000U; }
rapidjson::Value toJSON(rapidjson::Document &doc) const;
private:
bool m_ipv6 = false;
uint32_t m_ttl = 30U;
};
} /* namespace xmrig */
#endif /* XMRIG_DNSCONFIG_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -24,38 +24,34 @@
xmrig::DnsRecord::DnsRecord(const addrinfo *addr) :
m_type(addr->ai_family == AF_INET6 ? AAAA : A)
m_type(addr->ai_family == AF_INET6 ? AAAA : (addr->ai_family == AF_INET ? A : Unknown))
{
static_assert(sizeof(m_data) >= sizeof(sockaddr_in6), "Not enough storage for IPv6 address.");
memcpy(m_data, addr->ai_addr, m_type == AAAA ? sizeof(sockaddr_in6) : sizeof(sockaddr_in));
}
const sockaddr *xmrig::DnsRecord::addr(uint16_t port) const
{
reinterpret_cast<sockaddr_in*>(m_data)->sin_port = htons(port);
return reinterpret_cast<const sockaddr *>(m_data);
}
xmrig::String xmrig::DnsRecord::ip() const
{
char *buf = nullptr;
if (m_type == AAAA) {
buf = new char[45]();
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(addr->ai_addr), buf, 45);
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(m_data), buf, 45);
}
else {
buf = new char[16]();
uv_ip4_name(reinterpret_cast<sockaddr_in*>(addr->ai_addr), buf, 16);
uv_ip4_name(reinterpret_cast<sockaddr_in*>(m_data), buf, 16);
}
m_ip = buf;
}
sockaddr *xmrig::DnsRecord::addr(uint16_t port) const
{
if (m_type == A) {
auto addr = new sockaddr_in();
uv_ip4_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);
}
if (m_type == AAAA) {
auto addr = new sockaddr_in6();
uv_ip6_addr(m_ip.data(), port, addr);
return reinterpret_cast<sockaddr *>(addr);
}
return nullptr;
return buf;
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -33,7 +33,7 @@ namespace xmrig {
class DnsRecord
{
public:
enum Type {
enum Type : uint32_t {
Unknown,
A,
AAAA
@@ -42,15 +42,15 @@ public:
DnsRecord() {}
DnsRecord(const addrinfo *addr);
sockaddr *addr(uint16_t port = 0) const;
const sockaddr *addr(uint16_t port = 0) const;
String ip() const;
inline bool isValid() const { return m_type != Unknown; }
inline const String &ip() const { return m_ip; }
inline Type type() const { return m_type; }
private:
Type m_type = Unknown;
String m_ip;
mutable uint8_t m_data[28]{};
const Type m_type = Unknown;
};

View File

@@ -0,0 +1,107 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/net/dns/DnsRecords.h"
#include "base/net/dns/Dns.h"
const xmrig::DnsRecord &xmrig::DnsRecords::get(DnsRecord::Type prefered) const
{
static const DnsRecord defaultRecord;
if (isEmpty()) {
return defaultRecord;
}
const size_t ipv4 = m_ipv4.size();
const size_t ipv6 = m_ipv6.size();
if (ipv6 && (prefered == DnsRecord::AAAA || Dns::config().isIPv6() || !ipv4)) {
return m_ipv6[ipv6 == 1 ? 0 : static_cast<size_t>(rand()) % ipv6]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp)
}
if (ipv4) {
return m_ipv4[ipv4 == 1 ? 0 : static_cast<size_t>(rand()) % ipv4]; // NOLINT(concurrency-mt-unsafe, cert-msc30-c, cert-msc50-cpp)
}
return defaultRecord;
}
size_t xmrig::DnsRecords::count(DnsRecord::Type type) const
{
if (type == DnsRecord::A) {
return m_ipv4.size();
}
if (type == DnsRecord::AAAA) {
return m_ipv6.size();
}
return m_ipv4.size() + m_ipv6.size();
}
void xmrig::DnsRecords::clear()
{
m_ipv4.clear();
m_ipv6.clear();
}
void xmrig::DnsRecords::parse(addrinfo *res)
{
clear();
addrinfo *ptr = res;
size_t ipv4 = 0;
size_t ipv6 = 0;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
++ipv4;
}
else if (ptr->ai_family == AF_INET6) {
++ipv6;
}
ptr = ptr->ai_next;
}
if (ipv4 == 0 && ipv6 == 0) {
return;
}
m_ipv4.reserve(ipv4);
m_ipv6.reserve(ipv6);
ptr = res;
while (ptr != nullptr) {
if (ptr->ai_family == AF_INET) {
m_ipv4.emplace_back(ptr);
}
else if (ptr->ai_family == AF_INET6) {
m_ipv6.emplace_back(ptr);
}
ptr = ptr->ai_next;
}
}

View File

@@ -0,0 +1,48 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNSRECORDS_H
#define XMRIG_DNSRECORDS_H
#include "base/net/dns/DnsRecord.h"
namespace xmrig {
class DnsRecords
{
public:
inline bool isEmpty() const { return m_ipv4.empty() && m_ipv6.empty(); }
const DnsRecord &get(DnsRecord::Type prefered = DnsRecord::Unknown) const;
size_t count(DnsRecord::Type type = DnsRecord::Unknown) const;
void clear();
void parse(addrinfo *res);
private:
std::vector<DnsRecord> m_ipv4;
std::vector<DnsRecord> m_ipv6;
};
} /* namespace xmrig */
#endif /* XMRIG_DNSRECORDS_H */

View File

@@ -0,0 +1,50 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNSREQUEST_H
#define XMRIG_DNSREQUEST_H
#include "base/tools/Object.h"
#include <cstdint>
namespace xmrig {
class IDnsListener;
class DnsRequest
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DnsRequest)
DnsRequest(IDnsListener *listener) : listener(listener) {}
~DnsRequest() = default;
IDnsListener *listener;
};
} /* namespace xmrig */
#endif /* XMRIG_DNSREQUEST_H */

View File

@@ -0,0 +1,141 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#include "base/net/dns/DnsUvBackend.h"
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/net/dns/DnsRequest.h"
#include "base/tools/Chrono.h"
namespace xmrig {
static Storage<DnsUvBackend>* storage = nullptr;
Storage<DnsUvBackend>& DnsUvBackend::getStorage()
{
if (storage == nullptr) storage = new Storage<DnsUvBackend>();
return *storage;
}
void DnsUvBackend::releaseStorage()
{
delete storage;
}
static addrinfo hints{};
} // namespace xmrig
xmrig::DnsUvBackend::DnsUvBackend()
{
if (!hints.ai_protocol) {
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
}
m_key = getStorage().add(this);
}
xmrig::DnsUvBackend::~DnsUvBackend()
{
getStorage().release(m_key);
releaseStorage();
}
std::shared_ptr<xmrig::DnsRequest> xmrig::DnsUvBackend::resolve(const String &host, IDnsListener *listener, uint64_t ttl)
{
auto req = std::make_shared<DnsRequest>(listener);
if (Chrono::currentMSecsSinceEpoch() - m_ts <= ttl && !m_records.isEmpty()) {
req->listener->onResolved(m_records, 0, nullptr);
} else {
m_queue.emplace(req);
}
if (m_queue.size() == 1 && !resolve(host)) {
done();
}
return req;
}
bool xmrig::DnsUvBackend::resolve(const String &host)
{
m_req = std::make_shared<uv_getaddrinfo_t>();
m_req->data = getStorage().ptr(m_key);
m_status = uv_getaddrinfo(uv_default_loop(), m_req.get(), DnsUvBackend::onResolved, host.data(), nullptr, &hints);
return m_status == 0;
}
void xmrig::DnsUvBackend::done()
{
const char *error = m_status < 0 ? uv_strerror(m_status) : nullptr;
while (!m_queue.empty()) {
auto req = std::move(m_queue.front()).lock();
if (req) {
req->listener->onResolved(m_records, m_status, error);
}
m_queue.pop();
}
m_req.reset();
}
void xmrig::DnsUvBackend::onResolved(int status, addrinfo *res)
{
m_ts = Chrono::currentMSecsSinceEpoch();
if ((m_status = status) < 0) {
return done();
}
m_records.parse(res);
if (m_records.isEmpty()) {
m_status = UV_EAI_NONAME;
}
done();
}
void xmrig::DnsUvBackend::onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res)
{
auto backend = getStorage().get(req->data);
if (backend) {
backend->onResolved(status, res);
}
uv_freeaddrinfo(res);
}

View File

@@ -0,0 +1,72 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_DNSUVBACKEND_H
#define XMRIG_DNSUVBACKEND_H
#include "base/kernel/interfaces/IDnsBackend.h"
#include "base/net/dns/DnsRecords.h"
#include "base/net/tools/Storage.h"
#include <queue>
using uv_getaddrinfo_t = struct uv_getaddrinfo_s;
namespace xmrig {
class DnsUvBackend : public IDnsBackend
{
public:
XMRIG_DISABLE_COPY_MOVE(DnsUvBackend)
DnsUvBackend();
~DnsUvBackend() override;
protected:
inline const DnsRecords &records() const override { return m_records; }
std::shared_ptr<DnsRequest> resolve(const String &host, IDnsListener *listener, uint64_t ttl) override;
private:
bool resolve(const String &host);
void done();
void onResolved(int status, addrinfo *res);
static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res);
DnsRecords m_records;
int m_status = 0;
std::queue<std::weak_ptr<DnsRequest> > m_queue;
std::shared_ptr<uv_getaddrinfo_t> m_req;
uint64_t m_ts = 0;
uintptr_t m_key;
static Storage<DnsUvBackend>& getStorage();
void releaseStorage();
};
} /* namespace xmrig */
#endif /* XMRIG_DNSUVBACKEND_H */

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/http/Fetch.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/stringbuffer.h"
@@ -30,7 +29,7 @@
#endif
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls, bool quiet, const char *data, size_t size, const char *contentType) :
quiet(quiet),
tls(tls),
method(method),
@@ -44,7 +43,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16
}
xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
xmrig::FetchRequest::FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) :
quiet(quiet),
tls(tls),
method(method),
@@ -99,14 +98,14 @@ void xmrig::fetch(const char *tag, FetchRequest &&req, const std::weak_ptr<IHttp
{
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\"") BLACK_BOLD(" body: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
req.tls ? "s" : "", req.host.data(), req.port, http_method_str(req.method), req.path.data(), req.body.size());
req.tls ? "s" : "", req.host.data(), req.port, llhttp_method_name(req.method), req.path.data(), req.body.size());
if (req.hasBody() && req.body.size() < (Log::kMaxBufferSize - 1024) && req.headers.count(HttpData::kContentType) && req.headers.at(HttpData::kContentType) == HttpData::kApplicationJson) {
Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", req.headers.at(HttpData::kContentType).c_str(), static_cast<int>(req.body.size()), req.body.c_str());
}
# endif
HttpClient *client;
HttpClient *client = nullptr;
# ifdef XMRIG_FEATURE_TLS
if (req.tls) {
client = new HttpsClient(tag, std::move(req), listener);

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -21,7 +21,7 @@
#define XMRIG_FETCH_H
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "3rdparty/rapidjson/fwd.h"
#include "base/tools/String.h"
@@ -41,24 +41,24 @@ class FetchRequest
{
public:
FetchRequest() = default;
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr);
FetchRequest(llhttp_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false);
void setBody(const char *data, size_t size, const char *contentType = nullptr);
void setBody(const rapidjson::Value &value);
inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); }
bool quiet = false;
bool tls = false;
http_method method = HTTP_GET;
bool quiet = false;
bool tls = false;
llhttp_method method = HTTP_GET;
std::map<const std::string, const std::string> headers;
std::string body;
String fingerprint;
String host;
String path;
uint16_t port = 0;
uint64_t timeout = 0;
uint16_t port = 0;
uint64_t timeout = 0;
};

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/http/Http.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
@@ -39,7 +32,7 @@ const char *Http::kRestricted = "restricted";
const char *Http::kToken = "access-token";
}
} // namespace xmrig
xmrig::Http::Http() :

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTP_H
#define XMRIG_HTTP_H

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -25,7 +19,6 @@
#include "base/net/http/HttpApiResponse.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/prettywriter.h"
#include "3rdparty/rapidjson/stringbuffer.h"
#include "base/net/http/HttpData.h"
@@ -68,7 +61,7 @@ void xmrig::HttpApiResponse::end()
}
if (!m_doc.HasMember(kError)) {
m_doc.AddMember(StringRef(kError), StringRef(http_status_str(static_cast<http_status>(statusCode()))), m_doc.GetAllocator());
m_doc.AddMember(StringRef(kError), StringRef(HttpData::statusName(statusCode())), m_doc.GetAllocator());
}
}

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTPAPIRESPONSE_H
#define XMRIG_HTTPAPIRESPONSE_H

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -19,15 +19,17 @@
#include "base/net/http/HttpClient.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/io/log/Log.h"
#include "base/kernel/Platform.h"
#include "base/net/dns/Dns.h"
#include "base/net/dns/DnsRecords.h"
#include "base/net/tools/NetBuffer.h"
#include "base/tools/Timer.h"
#include <sstream>
#include <uv.h>
namespace xmrig {
@@ -48,7 +50,6 @@ xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::we
url = std::move(m_req.path);
body = std::move(m_req.body);
headers = std::move(m_req.headers);
m_dns = std::make_shared<Dns>(this);
if (m_req.timeout) {
m_timer = std::make_shared<Timer>(this, m_req.timeout, 0);
@@ -58,30 +59,29 @@ xmrig::HttpClient::HttpClient(const char *tag, FetchRequest &&req, const std::we
bool xmrig::HttpClient::connect()
{
return m_dns->resolve(m_req.host);
m_dns = Dns::resolve(m_req.host, this);
return true;
}
void xmrig::HttpClient::onResolved(const Dns &dns, int status)
void xmrig::HttpClient::onResolved(const DnsRecords &records, int status, const char *error)
{
this->status = status;
m_dns.reset();
if (status < 0 && dns.isEmpty()) {
if (status < 0 && records.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), error);
}
return;
}
sockaddr *addr = dns.get().addr(port());
auto req = new uv_connect_t;
req->data = this;
uv_tcp_connect(req, m_tcp, addr, onConnect);
delete addr;
uv_tcp_connect(req, m_tcp, records.get().addr(port()), onConnect);
}
@@ -102,7 +102,7 @@ void xmrig::HttpClient::handshake()
}
std::stringstream ss;
ss << http_method_str(static_cast<http_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
ss << llhttp_method_name(static_cast<llhttp_method>(method)) << " " << url << " HTTP/1.1" << kCRLF;
for (auto &header : headers) {
ss << header.first << ": " << header.second << kCRLF;
@@ -119,7 +119,7 @@ void xmrig::HttpClient::handshake()
void xmrig::HttpClient::read(const char *data, size_t size)
{
if (parse(data, size) < size) {
if (!parse(data, size)) {
close(UV_EPROTO);
}
}

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -32,7 +32,7 @@
namespace xmrig {
class String;
class DnsRequest;
class HttpClient : public HttpContext, public IDnsListener, public ITimerListener
@@ -51,7 +51,7 @@ public:
bool connect();
protected:
void onResolved(const Dns &dns, int status) override;
void onResolved(const DnsRecords &records, int status, const char *error) override;
void onTimer(const Timer *timer) override;
virtual void handshake();
@@ -65,7 +65,7 @@ private:
const char *m_tag;
FetchRequest m_req;
std::shared_ptr<Dns> m_dns;
std::shared_ptr<DnsRequest> m_dns;
std::shared_ptr<Timer> m_timer;
};

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -19,7 +19,7 @@
#include "base/net/http/HttpContext.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/tools/Baton.h"
#include "base/tools/Chrono.h"
@@ -32,7 +32,7 @@
namespace xmrig {
static http_parser_settings http_settings;
static llhttp_settings_t http_settings;
static std::map<uint64_t, HttpContext *> storage;
static uint64_t SEQUENCE = 0;
@@ -78,13 +78,13 @@ xmrig::HttpContext::HttpContext(int parser_type, const std::weak_ptr<IHttpListen
{
storage[id()] = this;
m_parser = new http_parser;
m_parser = new llhttp_t;
m_tcp = new uv_tcp_t;
uv_tcp_init(uv_default_loop(), m_tcp);
uv_tcp_nodelay(m_tcp, 1);
http_parser_init(m_parser, static_cast<http_parser_type>(parser_type));
llhttp_init(m_parser, static_cast<llhttp_type_t>(parser_type), &http_settings);
m_parser->data = m_tcp->data = this;
@@ -118,13 +118,13 @@ bool xmrig::HttpContext::isRequest() const
}
size_t xmrig::HttpContext::parse(const char *data, size_t size)
bool xmrig::HttpContext::parse(const char *data, size_t size)
{
if (size == 0) {
return size;
return true;
}
return http_parser_execute(m_parser, &http_settings, data, size);
return llhttp_execute(m_parser, data, size) == HPE_OK;
}
@@ -175,11 +175,9 @@ void xmrig::HttpContext::close(int status)
xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id)
{
if (storage.count(id) == 0) {
return nullptr;
}
const auto it = storage.find(id);
return storage[id];
return it == storage.end() ? nullptr : it->second;
}
@@ -193,7 +191,7 @@ void xmrig::HttpContext::closeAll()
}
int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_t length)
int xmrig::HttpContext::onHeaderField(llhttp_t *parser, const char *at, size_t length)
{
auto ctx = static_cast<HttpContext*>(parser->data);
@@ -212,7 +210,7 @@ int xmrig::HttpContext::onHeaderField(http_parser *parser, const char *at, size_
}
int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_t length)
int xmrig::HttpContext::onHeaderValue(llhttp_t *parser, const char *at, size_t length)
{
auto ctx = static_cast<HttpContext*>(parser->data);
@@ -227,14 +225,14 @@ int xmrig::HttpContext::onHeaderValue(http_parser *parser, const char *at, size_
}
void xmrig::HttpContext::attach(http_parser_settings *settings)
void xmrig::HttpContext::attach(llhttp_settings_t *settings)
{
settings->on_message_begin = nullptr;
settings->on_status = nullptr;
settings->on_chunk_header = nullptr;
settings->on_chunk_complete = nullptr;
settings->on_url = [](http_parser *parser, const char *at, size_t length) -> int
settings->on_url = [](llhttp_t *parser, const char *at, size_t length) -> int
{
static_cast<HttpContext*>(parser->data)->url = std::string(at, length);
return 0;
@@ -243,7 +241,7 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
settings->on_header_field = onHeaderField;
settings->on_header_value = onHeaderValue;
settings->on_headers_complete = [](http_parser* parser) -> int {
settings->on_headers_complete = [](llhttp_t *parser) -> int {
auto ctx = static_cast<HttpContext*>(parser->data);
ctx->status = parser->status_code;
@@ -258,14 +256,14 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
return 0;
};
settings->on_body = [](http_parser *parser, const char *at, size_t len) -> int
settings->on_body = [](llhttp_t *parser, const char *at, size_t len) -> int
{
static_cast<HttpContext*>(parser->data)->body.append(at, len);
return 0;
};
settings->on_message_complete = [](http_parser *parser) -> int
settings->on_message_complete = [](llhttp_t *parser) -> int
{
auto ctx = static_cast<HttpContext*>(parser->data);
auto listener = ctx->httpListener();

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,8 +22,8 @@
#define XMRIG_HTTPCONTEXT_H
using http_parser = struct http_parser;
using http_parser_settings = struct http_parser_settings;
using llhttp_settings_t = struct llhttp_settings_s;
using llhttp_t = struct llhttp__internal_s;
using uv_connect_t = struct uv_connect_s;
using uv_handle_t = struct uv_handle_s;
using uv_stream_t = struct uv_stream_s;
@@ -62,7 +62,7 @@ public:
void write(std::string &&data, bool close) override;
bool isRequest() const override;
size_t parse(const char *data, size_t size);
bool parse(const char *data, size_t size);
std::string ip() const override;
uint64_t elapsed() const;
void close(int status = 0);
@@ -76,15 +76,15 @@ protected:
private:
inline IHttpListener *httpListener() const { return m_listener.expired() ? nullptr : m_listener.lock().get(); }
static int onHeaderField(http_parser *parser, const char *at, size_t length);
static int onHeaderValue(http_parser *parser, const char *at, size_t length);
static void attach(http_parser_settings *settings);
static int onHeaderField(llhttp_t *parser, const char *at, size_t length);
static int onHeaderValue(llhttp_t *parser, const char *at, size_t length);
static void attach(llhttp_settings_t *settings);
void setHeader();
bool m_wasHeaderValue = false;
const uint64_t m_timestamp;
http_parser *m_parser;
llhttp_t *m_parser;
std::string m_lastHeaderField;
std::string m_lastHeaderValue;
std::weak_ptr<IHttpListener> m_listener;

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -19,7 +19,7 @@
#include "base/net/http/HttpData.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
@@ -29,6 +29,76 @@
#include <stdexcept>
/* Status Codes */
#define HTTP_STATUS_MAP(XX) \
XX(100, CONTINUE, Continue) \
XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
XX(102, PROCESSING, Processing) \
XX(200, OK, OK) \
XX(201, CREATED, Created) \
XX(202, ACCEPTED, Accepted) \
XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
XX(204, NO_CONTENT, No Content) \
XX(205, RESET_CONTENT, Reset Content) \
XX(206, PARTIAL_CONTENT, Partial Content) \
XX(207, MULTI_STATUS, Multi-Status) \
XX(208, ALREADY_REPORTED, Already Reported) \
XX(226, IM_USED, IM Used) \
XX(300, MULTIPLE_CHOICES, Multiple Choices) \
XX(301, MOVED_PERMANENTLY, Moved Permanently) \
XX(302, FOUND, Found) \
XX(303, SEE_OTHER, See Other) \
XX(304, NOT_MODIFIED, Not Modified) \
XX(305, USE_PROXY, Use Proxy) \
XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
XX(400, BAD_REQUEST, Bad Request) \
XX(401, UNAUTHORIZED, Unauthorized) \
XX(402, PAYMENT_REQUIRED, Payment Required) \
XX(403, FORBIDDEN, Forbidden) \
XX(404, NOT_FOUND, Not Found) \
XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
XX(406, NOT_ACCEPTABLE, Not Acceptable) \
XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
XX(408, REQUEST_TIMEOUT, Request Timeout) \
XX(409, CONFLICT, Conflict) \
XX(410, GONE, Gone) \
XX(411, LENGTH_REQUIRED, Length Required) \
XX(412, PRECONDITION_FAILED, Precondition Failed) \
XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
XX(414, URI_TOO_LONG, URI Too Long) \
XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
XX(417, EXPECTATION_FAILED, Expectation Failed) \
XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
XX(423, LOCKED, Locked) \
XX(424, FAILED_DEPENDENCY, Failed Dependency) \
XX(426, UPGRADE_REQUIRED, Upgrade Required) \
XX(428, PRECONDITION_REQUIRED, Precondition Required) \
XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
XX(501, NOT_IMPLEMENTED, Not Implemented) \
XX(502, BAD_GATEWAY, Bad Gateway) \
XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
XX(508, LOOP_DETECTED, Loop Detected) \
XX(510, NOT_EXTENDED, Not Extended) \
XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
enum http_status
{
# define XX(num, name, string) HTTP_STATUS_##name = num,
HTTP_STATUS_MAP(XX)
# undef XX
};
namespace xmrig {
@@ -38,6 +108,17 @@ const std::string HttpData::kContentTypeL = "content-type";
const std::string HttpData::kTextPlain = "text/plain";
static const char *http_status_str(enum http_status s)
{
switch (s) {
# define XX(num, name, string) case HTTP_STATUS_##name: return #string;
HTTP_STATUS_MAP(XX)
# undef XX
default: return "<unknown>";
}
}
} // namespace xmrig
@@ -55,17 +136,7 @@ bool xmrig::HttpData::isJSON() const
const char *xmrig::HttpData::methodName() const
{
return http_method_str(static_cast<http_method>(method));
}
const char *xmrig::HttpData::statusName() const
{
if (status < 0) {
return uv_strerror(status);
}
return http_status_str(static_cast<http_status>(status));
return llhttp_method_name(static_cast<llhttp_method>(method));
}
@@ -94,3 +165,13 @@ rapidjson::Document xmrig::HttpData::json() const
return doc;
}
const char *xmrig::HttpData::statusName(int status)
{
if (status < 0) {
return uv_strerror(status);
}
return http_status_str(static_cast<http_status>(status));
}

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -47,7 +47,8 @@ public:
inline HttpData(uint64_t id) : m_id(id) {}
virtual ~HttpData() = default;
inline uint64_t id() const { return m_id; }
inline const char *statusName() const { return statusName(status); }
inline uint64_t id() const { return m_id; }
virtual bool isRequest() const = 0;
virtual const char *host() const = 0;
@@ -59,9 +60,10 @@ public:
bool isJSON() const;
const char *methodName() const;
const char *statusName() const;
rapidjson::Document json() const;
static const char *statusName(int status);
int method = 0;
int status = 0;
int userType = 0;

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -18,7 +18,7 @@
#include "base/net/http/HttpListener.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpData.h"
@@ -28,7 +28,7 @@ void xmrig::HttpListener::onHttpData(const HttpData &data)
# ifdef APP_DEBUG
if (!data.isRequest()) {
LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"),
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast<http_method>(data.method)), data.url.data(),
m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), llhttp_method_name(static_cast<llhttp_method>(data.method)), data.url.data(),
(data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size());
if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) {

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -25,7 +19,7 @@
#include "base/net/http/HttpResponse.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpContext.h"
@@ -78,7 +72,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
setHeader("Connection", "close");
std::stringstream ss;
ss << "HTTP/1.1 " << statusCode() << " " << http_status_str(static_cast<http_status>(statusCode())) << kCRLF;
ss << "HTTP/1.1 " << statusCode() << " " << HttpData::statusName(statusCode()) << kCRLF;
for (auto &header : m_headers) {
ss << header.first << ": " << header.second << kCRLF;
@@ -97,7 +91,7 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
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)),
llhttp_method_name(static_cast<llhttp_method>(ctx->method)),
ctx->url.c_str(),
err ? 31 : 32,
statusCode(),

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTPRESPONSE_H
#define XMRIG_HTTPRESPONSE_H

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -29,7 +23,7 @@
#include "base/net/http/HttpServer.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/net/http/HttpContext.h"
#include "base/net/tools/NetBuffer.h"
@@ -56,14 +50,7 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
{
auto ctx = static_cast<HttpContext*>(tcp->data);
if (nread >= 0) {
const auto size = static_cast<size_t>(nread);
const auto parsed = ctx->parse(buf->base, size);
if (parsed < size) {
ctx->close();
}
} else {
if (nread < 0 || !ctx->parse(buf->base, static_cast<size_t>(nread))) {
ctx->close();
}

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,15 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTPSERVER_H
#define XMRIG_HTTPSERVER_H
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"

View File

@@ -170,7 +170,7 @@ bool xmrig::HttpsClient::verifyFingerprint(X509 *cert)
}
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int dlen;
unsigned int dlen = 0;
if (X509_digest(cert, digest, md, &dlen) != 1) {
return false;
@@ -189,7 +189,7 @@ void xmrig::HttpsClient::flush(bool close)
}
char *data = nullptr;
const size_t size = BIO_get_mem_data(m_write, &data);
const size_t size = BIO_get_mem_data(m_write, &data); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
std::string body(data, size);
(void) BIO_reset(m_write);

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,9 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/https/HttpsContext.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/llhttp/llhttp.h"
#include "base/net/tls/TlsContext.h"
@@ -61,7 +60,7 @@ bool xmrig::HttpsContext::write(BIO *bio)
}
char *data = nullptr;
const size_t size = BIO_get_mem_data(bio, &data);
const size_t size = BIO_get_mem_data(bio, &data); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
std::string body(data, size);
(void) BIO_reset(bio);
@@ -74,7 +73,7 @@ bool xmrig::HttpsContext::write(BIO *bio)
void xmrig::HttpsContext::parse(char *data, size_t size)
{
if (HttpContext::parse(data, size) < size) {
if (!HttpContext::parse(data, size)) {
close();
}
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
@@ -53,7 +52,7 @@ void xmrig::HttpsServer::onConnection(uv_stream_t *stream, uint16_t)
auto ctx = new HttpsContext(m_tls, m_listener);
uv_accept(stream, ctx->stream());
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead);
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
}

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HTTPSSERVER_H
#define XMRIG_HTTPSSERVER_H

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/AutoClient.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
@@ -31,7 +30,7 @@ xmrig::AutoClient::AutoClient(int id, const char *agent, IClientListener *listen
bool xmrig::AutoClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
if (m_mode == DEFAULT_MODE) {
return Client::handleResponse(id, result, error);
return Client::handleResponse(id, result, error); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::handleResponse(id, result, error);
@@ -73,7 +72,7 @@ bool xmrig::AutoClient::parseLogin(const rapidjson::Value &result, int *code)
int64_t xmrig::AutoClient::submit(const JobResult &result)
{
if (m_mode == DEFAULT_MODE) {
return Client::submit(result);
return Client::submit(result); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::submit(result);
@@ -83,7 +82,7 @@ int64_t xmrig::AutoClient::submit(const JobResult &result)
void xmrig::AutoClient::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{
if (m_mode == DEFAULT_MODE) {
return Client::parseNotification(method, params, error);
return Client::parseNotification(method, params, error); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::parseNotification(method, params, error);

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/BaseClient.h"
#include "3rdparty/fmt/core.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/Env.h"
#include "base/io/log/Log.h"
@@ -58,7 +52,7 @@ void xmrig::BaseClient::setPool(const Pool &pool)
m_user = Env::expand(pool.user());
m_password = Env::expand(pool.password());
m_rigId = Env::expand(pool.rigId());
m_tag = std::string(Tags::network()) + " " CYAN_BOLD_S + m_pool.url().data() + CLEAR;
m_tag = fmt::format("{} " CYAN_BOLD("{}"), Tags::network(), m_pool.url().data());
}

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 jtgrassie <https://github.com/jtgrassie>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2019 jtgrassie <https://github.com/jtgrassie>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -48,10 +42,12 @@
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/dns/Dns.h"
#include "base/net/dns/DnsRecords.h"
#include "base/net/stratum/Socks5.h"
#include "base/net/tools/NetBuffer.h"
#include "base/tools/Cvt.h"
#include "base/tools/Chrono.h"
#include "base/tools/Cvt.h"
#include "base/tools/cryptonote/BlobReader.h"
#include "net/JobResult.h"
@@ -82,17 +78,16 @@ static const char *states[] = {
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
BaseClient(id, listener),
m_agent(agent),
m_sendBuf(1024)
m_sendBuf(1024),
m_tempBuf(256)
{
m_reader.setListener(this);
m_key = m_storage.add(this);
m_dns = new Dns(this);
}
xmrig::Client::~Client()
{
delete m_dns;
delete m_socket;
}
@@ -199,11 +194,16 @@ int64_t xmrig::Client::submit(const JobResult &result)
const char *nonce = result.nonce;
const char *data = result.result;
# else
char *nonce = m_sendBuf.data();
char *data = m_sendBuf.data() + 16;
char *nonce = m_tempBuf.data();
char *data = m_tempBuf.data() + 16;
char *signature = m_tempBuf.data() + 88;
Cvt::toHex(nonce, sizeof(uint32_t) * 2 + 1, reinterpret_cast<const uint8_t *>(&result.nonce), sizeof(uint32_t));
Cvt::toHex(data, 65, result.result(), 32);
if (result.minerSignature()) {
Cvt::toHex(signature, 129, result.minerSignature(), 64);
}
# endif
Document doc(kObjectType);
@@ -215,8 +215,18 @@ int64_t xmrig::Client::submit(const JobResult &result)
params.AddMember("nonce", StringRef(nonce), allocator);
params.AddMember("result", StringRef(data), allocator);
# ifndef XMRIG_PROXY_PROJECT
if (result.minerSignature()) {
params.AddMember("sig", StringRef(signature), allocator);
}
# else
if (result.sig) {
params.AddMember("sig", StringRef(result.sig), allocator);
}
# endif
if (has<EXT_ALGO>() && result.algorithm.isValid()) {
params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator);
params.AddMember("algo", StringRef(result.algorithm.name()), allocator);
}
JsonRequest::create(doc, m_sequence, "submit", params);
@@ -295,22 +305,24 @@ void xmrig::Client::tick(uint64_t now)
}
void xmrig::Client::onResolved(const Dns &dns, int status)
void xmrig::Client::onResolved(const DnsRecords &records, int status, const char *error)
{
m_dns.reset();
assert(m_listener != nullptr);
if (!m_listener) {
return reconnect();
}
if (status < 0 && dns.isEmpty()) {
if (status < 0 && records.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(status));
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), error);
}
return reconnect();
}
const auto &record = dns.get();
const auto &record = records.get();
m_ip = record.ip();
connect(record.addr(m_socks5 ? m_pool.proxy().port() : m_pool.port()));
@@ -337,32 +349,6 @@ bool xmrig::Client::close()
}
bool xmrig::Client::isCriticalError(const char *message)
{
if (!message) {
return false;
}
if (strncasecmp(message, "Unauthenticated", 15) == 0) {
return true;
}
if (strncasecmp(message, "your IP is banned", 17) == 0) {
return true;
}
if (strncasecmp(message, "IP Address currently banned", 27) == 0) {
return true;
}
if (strncasecmp(message, "Invalid job id", 14) == 0) {
return true;
}
return false;
}
bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
{
if (!params.IsObject()) {
@@ -377,6 +363,19 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
const char *algo = Json::getString(params, "algo");
const char *blobData = Json::getString(params, "blob");
if (algo) {
job.setAlgorithm(algo);
}
else if (m_pool.coin().isValid()) {
uint8_t blobVersion = 0;
if (blobData) {
Cvt::fromHex(&blobVersion, 1, blobData, 2);
}
job.setAlgorithm(m_pool.coin().algorithm(blobVersion));
}
# ifdef XMRIG_FEATURE_HTTP
if (m_pool.mode() == Pool::MODE_SELF_SELECT) {
job.setExtraNonce(Json::getString(params, "extra_nonce"));
@@ -390,7 +389,7 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
else
# endif
{
if (!job.setBlob(params["blob"].GetString())) {
if (!job.setBlob(blobData)) {
*code = 4;
return false;
}
@@ -401,14 +400,6 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
const char *algo = Json::getString(params, "algo");
if (algo) {
job.setAlgorithm(algo);
}
else if (m_pool.coin().isValid()) {
job.setAlgorithm(m_pool.coin().algorithm(job.blob()[0]));
}
job.setHeight(Json::getUint64(params, "height"));
if (!verifyAlgorithm(job.algorithm(), algo)) {
@@ -421,6 +412,8 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
job.setSigKey(Json::getString(params, "sig_key"));
m_job.setClientId(m_rpcId);
if (m_job != job) {
@@ -446,7 +439,7 @@ bool xmrig::Client::send(BIO *bio)
{
# ifdef XMRIG_FEATURE_TLS
uv_buf_t buf;
buf.len = BIO_get_mem_data(bio, &buf.base);
buf.len = BIO_get_mem_data(bio, &buf.base); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
if (buf.len == 0) {
return true;
@@ -490,7 +483,7 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo
m_listener->onVerifyAlgorithm(this, algorithm, &ok);
if (!ok && !isQuiet()) {
LOG_ERR("%s " RED("incompatible/disabled algorithm ") RED_BOLD("\"%s\" ") RED("detected, reconnect"), tag(), algorithm.shortName());
LOG_ERR("%s " RED("incompatible/disabled algorithm ") RED_BOLD("\"%s\" ") RED("detected, reconnect"), tag(), algorithm.name());
}
return ok;
@@ -524,13 +517,7 @@ int xmrig::Client::resolve(const String &host)
m_failures = 0;
}
if (!m_dns->resolve(host)) {
if (!isQuiet()) {
LOG_ERR("%s " RED("getaddrinfo error: ") RED_BOLD("\"%s\""), tag(), uv_strerror(m_dns->status()));
}
return 1;
}
m_dns = Dns::resolve(host, this);
return 0;
}
@@ -566,7 +553,7 @@ int64_t xmrig::Client::send(size_t size)
}
void xmrig::Client::connect(sockaddr *addr)
void xmrig::Client::connect(const sockaddr *addr)
{
setState(ConnectingState);
@@ -584,8 +571,6 @@ void xmrig::Client::connect(sockaddr *addr)
# endif
uv_tcp_connect(req, m_socket, addr, onConnect);
delete addr;
}
@@ -948,6 +933,32 @@ void xmrig::Client::startTimeout()
}
bool xmrig::Client::isCriticalError(const char *message)
{
if (!message) {
return false;
}
if (strncasecmp(message, "Unauthenticated", 15) == 0) {
return true;
}
if (strncasecmp(message, "your IP is banned", 17) == 0) {
return true;
}
if (strncasecmp(message, "IP Address currently banned", 27) == 0) {
return true;
}
if (strncasecmp(message, "Invalid job id", 14) == 0) {
return true;
}
return false;
}
void xmrig::Client::onClose(uv_handle_t *handle)
{
auto client = getClient(handle->data);

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 jtgrassie <https://github.com/jtgrassie>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2019 jtgrassie <https://github.com/jtgrassie>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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 +44,7 @@ using BIO = struct bio_st;
namespace xmrig {
class DnsRequest;
class IClientListener;
class JobResult;
@@ -79,7 +74,7 @@ protected:
void deleteLater() override;
void tick(uint64_t now) override;
void onResolved(const Dns &dns, int status) override;
void onResolved(const DnsRecords &records, int status, const char *error) override;
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
inline const char *mode() const override { return "pool"; }
@@ -101,14 +96,13 @@ private:
class Socks5;
class Tls;
bool isCriticalError(const char *message);
bool parseJob(const rapidjson::Value &params, int *code);
bool send(BIO *bio);
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
bool write(const uv_buf_t &buf);
int resolve(const String &host);
int64_t send(size_t size);
void connect(sockaddr *addr);
void connect(const sockaddr *addr);
void handshake();
void parse(char *line, size_t len);
void parseExtensions(const rapidjson::Value &result);
@@ -124,6 +118,7 @@ private:
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
static bool isCriticalError(const char *message);
static void onClose(uv_handle_t *handle);
static void onConnect(uv_connect_t *req, int status);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
@@ -131,11 +126,12 @@ private:
static inline Client *getClient(void *data) { return m_storage.get(data); }
const char *m_agent;
Dns *m_dns;
LineReader m_reader;
Socks5 *m_socks5 = nullptr;
std::bitset<EXT_MAX> m_extensions;
std::shared_ptr<DnsRequest> m_dns;
std::vector<char> m_sendBuf;
std::vector<char> m_tempBuf;
String m_rpcId;
Tls *m_tls = nullptr;
uint64_t m_expire = 0;

View File

@@ -24,20 +24,27 @@
*/
#include <uv.h>
#include "base/net/stratum/DaemonClient.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
#include "base/io/json/JsonRequest.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/dns/Dns.h"
#include "base/net/dns/DnsRecords.h"
#include "base/net/http/Fetch.h"
#include "base/net/http/HttpData.h"
#include "base/net/http/HttpListener.h"
#include "base/net/stratum/SubmitResult.h"
#include "base/net/tools/NetBuffer.h"
#include "base/tools/bswap_64.h"
#include "base/tools/Cvt.h"
#include "base/tools/Timer.h"
#include "base/tools/cryptonote/Signatures.h"
#include "net/JobResult.h"
@@ -47,7 +54,11 @@
namespace xmrig {
static const char *kBlocktemplateBlob = "blocktemplate_blob";
Storage<DaemonClient> DaemonClient::m_storage;
static const char* kBlocktemplateBlob = "blocktemplate_blob";
static const char *kGetHeight = "/getheight";
static const char *kGetInfo = "/getinfo";
static const char *kHash = "hash";
@@ -56,7 +67,13 @@ static const char *kJsonRPC = "/json_rpc";
static constexpr size_t kBlobReserveSize = 8;
}
static const char kZMQGreeting[64] = { static_cast<char>(-1), 0, 0, 0, 0, 0, 0, 0, 0, 127, 3, 0, 'N', 'U', 'L', 'L' };
static constexpr size_t kZMQGreetingSize1 = 11;
static const char kZMQHandshake[] = "\4\x19\5READY\xbSocket-Type\0\0\0\3SUB";
static const char kZMQSubscribe[] = "\0\x18\1json-minimal-chain_main";
} // namespace xmrig
xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) :
@@ -64,12 +81,25 @@ xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) :
{
m_httpListener = std::make_shared<HttpListener>(this);
m_timer = new Timer(this);
m_key = m_storage.add(this);
}
xmrig::DaemonClient::~DaemonClient()
{
delete m_timer;
delete m_ZMQSocket;
}
void xmrig::DaemonClient::deleteLater()
{
if (m_pool.zmq_port() >= 0) {
ZMQClose(true);
}
else {
delete this;
}
}
@@ -95,16 +125,36 @@ bool xmrig::DaemonClient::isTLS() const
int64_t xmrig::DaemonClient::submit(const JobResult &result)
{
if (result.jobId != (m_blocktemplate.data() + m_blocktemplate.size() - 32)) {
if (result.jobId != m_currentJobId) {
return -1;
}
char *data = (m_apiVersion == API_DERO) ? m_blockhashingblob.data() : m_blocktemplate.data();
char *data = (m_apiVersion == API_DERO) ? m_blockhashingblob.data() : m_blocktemplateStr.data();
const size_t sig_offset = m_job.nonceOffset() + m_job.nonceSize();
# ifdef XMRIG_PROXY_PROJECT
memcpy(data + 78, result.nonce, 8);
memcpy(data + m_job.nonceOffset() * 2, result.nonce, 8);
if (m_blocktemplate.hasMinerSignature() && result.sig) {
memcpy(data + sig_offset * 2, result.sig, 64 * 2);
memcpy(data + m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) * 2, result.sig_data, 32 * 2);
memcpy(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2, result.sig_data + 32 * 2, 32 * 2);
}
if (result.extra_nonce >= 0) {
Cvt::toHex(data + m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) * 2, 8, reinterpret_cast<const uint8_t*>(&result.extra_nonce), 4);
}
# else
Cvt::toHex(data + 78, 8, reinterpret_cast<const uint8_t *>(&result.nonce), 4);
Cvt::toHex(data + m_job.nonceOffset() * 2, 8, reinterpret_cast<const uint8_t*>(&result.nonce), 4);
if (m_blocktemplate.hasMinerSignature()) {
Cvt::toHex(data + sig_offset * 2, 128, result.minerSignature(), 64);
}
# endif
using namespace rapidjson;
@@ -112,11 +162,11 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
Value params(kArrayType);
if (m_apiVersion == API_DERO) {
params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator());
params.PushBack(m_blocktemplateStr.toJSON(), doc.GetAllocator());
params.PushBack(m_blockhashingblob.toJSON(), doc.GetAllocator());
}
else {
params.PushBack(m_blocktemplate.toJSON(), doc.GetAllocator());
params.PushBack(m_blocktemplateStr.toJSON(), doc.GetAllocator());
}
JsonRequest::create(doc, m_sequence, "submitblock", params);
@@ -133,12 +183,34 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
void xmrig::DaemonClient::connect()
{
if ((m_pool.algorithm() == Algorithm::ASTROBWT_DERO) || (m_pool.coin() == Coin::DERO)) {
auto connectError = [this](const char *message) {
if (!isQuiet()) {
LOG_ERR("%s " RED("connect error: ") RED_BOLD("\"%s\""), tag(), message);
}
retry();
};
setState(ConnectingState);
if (!m_walletAddress.isValid()) {
return connectError("Invalid wallet address.");
}
if (!m_coin.isValid() && !m_pool.algorithm().isValid()) {
return connectError("Invalid algorithm.");
}
if ((m_pool.algorithm() == Algorithm::ASTROBWT_DERO) || (m_coin == Coin::DERO)) {
m_apiVersion = API_DERO;
}
setState(ConnectingState);
getBlockTemplate();
if (m_pool.zmq_port() >= 0) {
m_dns = Dns::resolve(m_pool.host(), this);
}
else {
getBlockTemplate();
}
}
@@ -149,9 +221,23 @@ void xmrig::DaemonClient::connect(const Pool &pool)
}
void xmrig::DaemonClient::setPool(const Pool &pool)
{
BaseClient::setPool(pool);
m_walletAddress.decode(m_user);
m_coin = pool.coin().isValid() ? pool.coin() : m_walletAddress.coin();
if (!m_coin.isValid() && pool.algorithm() == Algorithm::RX_WOW) {
m_coin = Coin::WOWNERO;
}
}
void xmrig::DaemonClient::onHttpData(const HttpData &data)
{
if (data.status != HTTP_STATUS_OK) {
if (data.status != 200) {
return retry();
}
@@ -165,7 +251,7 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
rapidjson::Document doc;
if (doc.Parse(data.body.c_str()).HasParseError()) {
if (!isQuiet()) {
LOG_ERR("[%s:%d] JSON decode failed: \"%s\"", m_pool.host().data(), m_pool.port(), rapidjson::GetParseError_En(doc.GetParseError()));
LOG_ERR("%s " RED("JSON decode failed: ") RED_BOLD("\"%s\""), tag(), rapidjson::GetParseError_En(doc.GetParseError()));
}
return retry();
@@ -179,12 +265,30 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
return send(kGetInfo);
}
if (isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, kHash))) {
getBlockTemplate();
const uint64_t height = Json::getUint64(doc, kHeight);
const String hash = Json::getString(doc, kHash);
if (isOutdated(height, hash)) {
// Multiple /getheight responses can come at once resulting in multiple getBlockTemplate() calls
if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) {
m_blocktemplateRequestHeight = height;
m_blocktemplateRequestHash = hash;
getBlockTemplate();
}
}
}
else if (data.url == kGetInfo && isOutdated(Json::getUint64(doc, kHeight), Json::getString(doc, "top_block_hash"))) {
getBlockTemplate();
else if (data.url == kGetInfo) {
const uint64_t height = Json::getUint64(doc, kHeight);
const String hash = Json::getString(doc, "top_block_hash");
if (isOutdated(height, hash)) {
// Multiple /getinfo responses can come at once resulting in multiple getBlockTemplate() calls
if ((height != m_blocktemplateRequestHeight) || (hash != m_blocktemplateRequestHash)) {
m_blocktemplateRequestHeight = height;
m_blocktemplateRequestHash = hash;
getBlockTemplate();
}
}
}
return;
@@ -199,7 +303,7 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)
void xmrig::DaemonClient::onTimer(const Timer *)
{
if (m_state == ConnectingState) {
getBlockTemplate();
connect();
}
else if (m_state == ConnectedState) {
if (m_apiVersion == API_DERO) {
@@ -212,6 +316,43 @@ void xmrig::DaemonClient::onTimer(const Timer *)
}
void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, const char* error)
{
m_dns.reset();
if (status < 0 && records.isEmpty()) {
if (!isQuiet()) {
LOG_ERR("%s " RED("DNS error: ") RED_BOLD("\"%s\""), tag(), error);
}
retry();
return;
}
delete m_ZMQSocket;
const auto &record = records.get();
m_ip = record.ip();
auto req = new uv_connect_t;
req->data = m_storage.ptr(m_key);
m_ZMQSocket = new uv_tcp_t;
m_ZMQSocket->data = m_storage.ptr(m_key);
uv_tcp_init(uv_default_loop(), m_ZMQSocket);
uv_tcp_nodelay(m_ZMQSocket, 1);
# ifndef WIN32
uv_tcp_keepalive(m_ZMQSocket, 1, 60);
# endif
uv_tcp_connect(req, m_ZMQSocket, record.addr(m_pool.zmq_port()), onZMQConnect);
}
bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
{
return m_job.height() != height || m_prevHash != hash;
@@ -220,33 +361,121 @@ bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
{
auto jobError = [this, code](const char *message) {
if (!isQuiet()) {
LOG_ERR("%s " RED("job error: ") RED_BOLD("\"%s\""), tag(), message);
}
*code = 1;
return false;
};
Job job(false, m_pool.algorithm(), String());
String blocktemplate = Json::getString(params, kBlocktemplateBlob);
if (blocktemplate.isNull()) {
return jobError("Empty block template received from daemon."); // FIXME
}
if (!m_blocktemplate.parse(blocktemplate, m_coin)) {
return jobError("Invalid block template received from daemon.");
}
# ifdef XMRIG_PROXY_PROJECT
const size_t k = m_blocktemplate.offset(BlockTemplate::MINER_TX_PREFIX_OFFSET);
job.setMinerTx(
m_blocktemplate.blob() + k,
m_blocktemplate.blob() + m_blocktemplate.offset(BlockTemplate::MINER_TX_PREFIX_END_OFFSET),
m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) - k,
m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) - k,
m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) - k,
m_blocktemplate.txExtraNonce().size(),
m_blocktemplate.minerTxMerkleTreeBranch()
);
# endif
m_blockhashingblob = Json::getString(params, "blockhashing_blob");
if (m_blocktemplate.hasMinerSignature()) {
if (m_pool.spendSecretKey().isEmpty()) {
return jobError("Secret spend key is not set.");
}
if (m_pool.spendSecretKey().size() != 64) {
return jobError("Secret spend key has invalid length. It must be 64 hex characters.");
}
uint8_t secret_spendkey[32];
if (!Cvt::fromHex(secret_spendkey, 32, m_pool.spendSecretKey(), 64)) {
return jobError("Secret spend key is not a valid hex data.");
}
uint8_t public_spendkey[32];
if (!secret_key_to_public_key(secret_spendkey, public_spendkey)) {
return jobError("Secret spend key is invalid.");
}
# ifdef XMRIG_PROXY_PROJECT
job.setSpendSecretKey(secret_spendkey);
# else
uint8_t secret_viewkey[32];
derive_view_secret_key(secret_spendkey, secret_viewkey);
uint8_t public_viewkey[32];
if (!secret_key_to_public_key(secret_viewkey, public_viewkey)) {
return jobError("Secret view key is invalid.");
}
uint8_t derivation[32];
if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation)) {
return jobError("Failed to generate key derivation for miner signature.");
}
if (!m_walletAddress.decode(m_pool.user())) {
return jobError("Invalid wallet address.");
}
if (memcmp(m_walletAddress.spendKey(), public_spendkey, sizeof(public_spendkey)) != 0) {
return jobError("Wallet address and spend key don't match.");
}
if (memcmp(m_walletAddress.viewKey(), public_viewkey, sizeof(public_viewkey)) != 0) {
return jobError("Wallet address and view key don't match.");
}
uint8_t eph_secret_key[32];
derive_secret_key(derivation, 0, secret_spendkey, eph_secret_key);
job.setEphemeralKeys(m_blocktemplate.blob(BlockTemplate::EPH_PUBLIC_KEY_OFFSET), eph_secret_key);
# endif
}
if (m_apiVersion == API_DERO) {
const uint64_t offset = Json::getUint64(params, "reserved_offset");
Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize);
}
if (blocktemplate.isNull() || !job.setBlob(m_blockhashingblob)) {
*code = 4;
if (m_coin.isValid()) {
job.setAlgorithm(m_coin.algorithm(m_blocktemplate.majorVersion()));
}
if (!job.setBlob(m_blockhashingblob)) {
*code = 3;
return false;
}
job.setSeedHash(Json::getString(params, "seed_hash"));
job.setHeight(Json::getUint64(params, kHeight));
job.setDiff(Json::getUint64(params, "difficulty"));
job.setId(blocktemplate.data() + blocktemplate.size() - 32);
if (m_pool.coin().isValid()) {
job.setAlgorithm(m_pool.coin().algorithm(job.blob()[0]));
}
m_currentJobId = Cvt::toHex(Cvt::randomBytes(4));
job.setId(m_currentJobId);
m_job = std::move(job);
m_blocktemplate = std::move(blocktemplate);
m_prevHash = Json::getString(params, "prev_hash");
m_job = std::move(job);
m_blocktemplateStr = std::move(blocktemplate);
m_prevHash = Json::getString(params, "prev_hash");
if (m_apiVersion == API_DERO) {
// Truncate to 32 bytes to have the same data as in get_info RPC
@@ -296,8 +525,19 @@ bool xmrig::DaemonClient::parseResponse(int64_t id, const rapidjson::Value &resu
return true;
}
if (handleSubmitResponse(id)) {
getBlockTemplate();
const char* error_msg = nullptr;
if ((m_apiVersion == API_DERO) && result.HasMember("status")) {
error_msg = result["status"].GetString();
if (!error_msg || (strlen(error_msg) == 0) || (strcmp(error_msg, "OK") == 0)) {
error_msg = nullptr;
}
}
if (handleSubmitResponse(id, error_msg)) {
if (error_msg || (m_pool.zmq_port() < 0)) {
getBlockTemplate();
}
return true;
}
@@ -349,6 +589,10 @@ void xmrig::DaemonClient::retry()
setState(ConnectingState);
}
if ((m_ZMQConnectionState != ZMQ_NOT_CONNECTED) && (m_ZMQConnectionState != ZMQ_DISCONNECTING)) {
uv_close(reinterpret_cast<uv_handle_t*>(m_ZMQSocket), onZMQClose);
}
m_timer->stop();
m_timer->start(m_retryPause, 0);
}
@@ -363,7 +607,6 @@ void xmrig::DaemonClient::send(const char *path)
void xmrig::DaemonClient::setState(SocketState state)
{
assert(m_state != state);
if (m_state == state) {
return;
}
@@ -376,8 +619,10 @@ void xmrig::DaemonClient::setState(SocketState state)
m_failures = 0;
m_listener->onLoginSuccess(this);
const uint64_t interval = std::max<uint64_t>(20, m_pool.pollInterval());
m_timer->start(interval, interval);
if (m_pool.zmq_port() < 0) {
const uint64_t interval = std::max<uint64_t>(20, m_pool.pollInterval());
m_timer->start(interval, interval);
}
}
break;
@@ -390,3 +635,281 @@ void xmrig::DaemonClient::setState(SocketState state)
break;
}
}
void xmrig::DaemonClient::onZMQConnect(uv_connect_t* req, int status)
{
DaemonClient* client = getClient(req->data);
delete req;
if (!client) {
return;
}
if (status < 0) {
LOG_ERR("%s " RED("ZMQ connect error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(status));
client->retry();
return;
}
client->ZMQConnected();
}
void xmrig::DaemonClient::onZMQRead(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
{
DaemonClient* client = getClient(stream->data);
if (client) {
client->ZMQRead(nread, buf);
}
NetBuffer::release(buf);
}
void xmrig::DaemonClient::onZMQClose(uv_handle_t* handle)
{
DaemonClient* client = getClient(handle->data);
if (client) {
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" disconnected"), client->m_pool.host().data(), client->m_pool.zmq_port());
# endif
client->m_ZMQConnectionState = ZMQ_NOT_CONNECTED;
}
}
void xmrig::DaemonClient::onZMQShutdown(uv_handle_t* handle)
{
DaemonClient* client = getClient(handle->data);
if (client) {
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" shutdown"), client->m_pool.host().data(), client->m_pool.zmq_port());
# endif
client->m_ZMQConnectionState = ZMQ_NOT_CONNECTED;
m_storage.remove(client->m_key);
}
}
void xmrig::DaemonClient::ZMQConnected()
{
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" connected"), m_pool.host().data(), m_pool.zmq_port());
# endif
m_ZMQConnectionState = ZMQ_GREETING_1;
m_ZMQSendBuf.reserve(256);
m_ZMQRecvBuf.reserve(256);
if (ZMQWrite(kZMQGreeting, kZMQGreetingSize1)) {
uv_read_start(reinterpret_cast<uv_stream_t*>(m_ZMQSocket), NetBuffer::onAlloc, onZMQRead);
}
}
bool xmrig::DaemonClient::ZMQWrite(const char* data, size_t size)
{
m_ZMQSendBuf.assign(data, data + size);
uv_buf_t buf;
buf.base = m_ZMQSendBuf.data();
buf.len = static_cast<uint32_t>(m_ZMQSendBuf.size());
const int rc = uv_try_write(reinterpret_cast<uv_stream_t*>(m_ZMQSocket), &buf, 1);
if (static_cast<size_t>(rc) == buf.len) {
return true;
}
LOG_ERR("%s " RED("ZMQ write failed, rc = %d"), tag(), rc);
ZMQClose();
return false;
}
void xmrig::DaemonClient::ZMQRead(ssize_t nread, const uv_buf_t* buf)
{
if (nread <= 0) {
LOG_ERR("%s " RED("ZMQ read failed, nread = %" PRId64), tag(), nread);
ZMQClose();
return;
}
m_ZMQRecvBuf.insert(m_ZMQRecvBuf.end(), buf->base, buf->base + nread);
do {
switch (m_ZMQConnectionState) {
case ZMQ_GREETING_1:
if (m_ZMQRecvBuf.size() >= kZMQGreetingSize1) {
if ((m_ZMQRecvBuf[0] == static_cast<char>(-1)) && (m_ZMQRecvBuf[9] == 127) && (m_ZMQRecvBuf[10] == 3)) {
ZMQWrite(kZMQGreeting + kZMQGreetingSize1, sizeof(kZMQGreeting) - kZMQGreetingSize1);
m_ZMQConnectionState = ZMQ_GREETING_2;
break;
}
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format"), tag());
ZMQClose();
}
return;
case ZMQ_GREETING_2:
if (m_ZMQRecvBuf.size() >= sizeof(kZMQGreeting)) {
if (memcmp(m_ZMQRecvBuf.data() + 12, kZMQGreeting + 12, 20) == 0) {
m_ZMQConnectionState = ZMQ_HANDSHAKE;
m_ZMQRecvBuf.erase(m_ZMQRecvBuf.begin(), m_ZMQRecvBuf.begin() + sizeof(kZMQGreeting));
ZMQWrite(kZMQHandshake, sizeof(kZMQHandshake) - 1);
break;
}
LOG_ERR("%s " RED("ZMQ handshake failed: invalid greeting format 2"), tag());
ZMQClose();
}
return;
case ZMQ_HANDSHAKE:
if (m_ZMQRecvBuf.size() >= 2) {
if (m_ZMQRecvBuf[0] != 4) {
LOG_ERR("%s " RED("ZMQ handshake failed: invalid handshake format"), tag());
ZMQClose();
return;
}
const size_t size = static_cast<unsigned char>(m_ZMQRecvBuf[1]);
if (size < 18) {
LOG_ERR("%s " RED("ZMQ handshake failed: invalid handshake size"), tag());
ZMQClose();
return;
}
if (m_ZMQRecvBuf.size() < size + 2) {
return;
}
if (memcmp(m_ZMQRecvBuf.data() + 2, kZMQHandshake + 2, 18) != 0) {
LOG_ERR("%s " RED("ZMQ handshake failed: invalid handshake data"), tag());
ZMQClose();
return;
}
ZMQWrite(kZMQSubscribe, sizeof(kZMQSubscribe) - 1);
m_ZMQConnectionState = ZMQ_CONNECTED;
m_ZMQRecvBuf.erase(m_ZMQRecvBuf.begin(), m_ZMQRecvBuf.begin() + size + 2);
getBlockTemplate();
break;
}
return;
case ZMQ_CONNECTED:
ZMQParse();
return;
default:
return;
}
} while (true);
}
void xmrig::DaemonClient::ZMQParse()
{
# ifdef APP_DEBUG
std::vector<char> msg;
# endif
size_t msg_size = 0;
char *data = m_ZMQRecvBuf.data();
size_t avail = m_ZMQRecvBuf.size();
bool more = false;
do {
if (avail < 1) {
return;
}
more = (data[0] & 1) != 0;
const bool long_size = (data[0] & 2) != 0;
const bool command = (data[0] & 4) != 0;
++data;
--avail;
uint64_t size = 0;
if (long_size)
{
if (avail < sizeof(uint64_t)) {
return;
}
size = bswap_64(*((uint64_t*)data));
data += sizeof(uint64_t);
avail -= sizeof(uint64_t);
}
else
{
if (avail < sizeof(uint8_t)) {
return;
}
size = static_cast<uint8_t>(*data);
++data;
--avail;
}
if (size > 1024U - msg_size)
{
LOG_ERR("%s " RED("ZMQ message is too large, size = %" PRIu64 " bytes"), tag(), size);
ZMQClose();
return;
}
if (avail < size) {
return;
}
if (!command) {
# ifdef APP_DEBUG
msg.insert(msg.end(), data, data + size);
# endif
msg_size += size;
}
data += size;
avail -= size;
} while (more);
m_ZMQRecvBuf.erase(m_ZMQRecvBuf.begin(), m_ZMQRecvBuf.begin() + (data - m_ZMQRecvBuf.data()));
# ifdef APP_DEBUG
LOG_DEBUG(CYAN("tcp-zmq://%s:%u") BLACK_BOLD(" read ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes") " %s", m_pool.host().data(), m_pool.zmq_port(), msg.size(), msg.data());
# endif
getBlockTemplate();
}
bool xmrig::DaemonClient::ZMQClose(bool shutdown)
{
if ((m_ZMQConnectionState == ZMQ_NOT_CONNECTED) || (m_ZMQConnectionState == ZMQ_DISCONNECTING)) {
if (shutdown) {
m_storage.remove(m_key);
}
return false;
}
m_ZMQConnectionState = ZMQ_DISCONNECTING;
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_ZMQSocket)) == 0) {
uv_close(reinterpret_cast<uv_handle_t*>(m_ZMQSocket), shutdown ? onZMQShutdown : onZMQClose);
if (!shutdown) {
retry();
}
return true;
}
return false;
}

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -27,19 +21,32 @@
#define XMRIG_DAEMONCLIENT_H
#include "base/kernel/interfaces/IDnsListener.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/net/stratum/BaseClient.h"
#include "base/tools/Object.h"
#include "base/net/tools/Storage.h"
#include "base/tools/cryptonote/BlockTemplate.h"
#include "base/tools/cryptonote/WalletAddress.h"
#include <memory>
using uv_buf_t = struct uv_buf_t;
using uv_connect_t = struct uv_connect_s;
using uv_handle_t = struct uv_handle_s;
using uv_stream_t = struct uv_stream_s;
using uv_tcp_t = struct uv_tcp_s;
namespace xmrig {
class DaemonClient : public BaseClient, public ITimerListener, public IHttpListener
class DnsRequest;
class DaemonClient : public BaseClient, public IDnsListener, public ITimerListener, public IHttpListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DaemonClient)
@@ -53,9 +60,11 @@ protected:
int64_t submit(const JobResult &result) override;
void connect() override;
void connect(const Pool &pool) override;
void setPool(const Pool &pool) override;
void onHttpData(const HttpData &data) override;
void onTimer(const Timer *timer) override;
void onResolved(const DnsRecords &records, int status, const char* error) override;
inline bool hasExtension(Extension) const noexcept override { return false; }
inline const char *mode() const override { return "daemon"; }
@@ -63,7 +72,7 @@ protected:
inline const char *tlsVersion() const override { return m_tlsVersion; }
inline int64_t send(const rapidjson::Value &, Callback) override { return -1; }
inline int64_t send(const rapidjson::Value &) override { return -1; }
inline void deleteLater() override { delete this; }
void deleteLater() override;
inline void tick(uint64_t) override {}
private:
@@ -82,13 +91,51 @@ private:
API_DERO,
} m_apiVersion = API_MONERO;
BlockTemplate m_blocktemplate;
Coin m_coin;
std::shared_ptr<IHttpListener> m_httpListener;
String m_blocktemplate;
String m_blockhashingblob;
String m_blocktemplateRequestHash;
String m_blocktemplateStr;
String m_currentJobId;
String m_prevHash;
String m_tlsFingerprint;
String m_tlsVersion;
Timer *m_timer;
uint64_t m_blocktemplateRequestHeight = 0;
WalletAddress m_walletAddress;
private:
static inline DaemonClient* getClient(void* data) { return m_storage.get(data); }
uintptr_t m_key = 0;
static Storage<DaemonClient> m_storage;
static void onZMQConnect(uv_connect_t* req, int status);
static void onZMQRead(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
static void onZMQClose(uv_handle_t* handle);
static void onZMQShutdown(uv_handle_t* handle);
void ZMQConnected();
bool ZMQWrite(const char* data, size_t size);
void ZMQRead(ssize_t nread, const uv_buf_t* buf);
void ZMQParse();
bool ZMQClose(bool shutdown = false);
std::shared_ptr<DnsRequest> m_dns;
uv_tcp_t* m_ZMQSocket = nullptr;
enum {
ZMQ_NOT_CONNECTED,
ZMQ_GREETING_1,
ZMQ_GREETING_2,
ZMQ_HANDSHAKE,
ZMQ_CONNECTED,
ZMQ_DISCONNECTING,
} m_ZMQConnectionState = ZMQ_NOT_CONNECTED;
std::vector<char> m_ZMQSendBuf;
std::vector<char> m_ZMQRecvBuf;
};

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -213,7 +213,7 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
if (!ok) {
if (!isQuiet()) {
LOG_ERR("[%s] incompatible/disabled algorithm \"%s\" detected, reconnect", url(), algo.shortName());
LOG_ERR("[%s] incompatible/disabled algorithm \"%s\" detected, reconnect", url(), algo.name());
}
close();
return;
@@ -272,7 +272,7 @@ void xmrig::EthStratumClient::setExtraNonce(const rapidjson::Value &nonce)
}
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error) const
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error)
{
if (error.IsArray() && error.GetArray().Size() > 1) {
auto &value = error.GetArray()[1];

View File

@@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -48,7 +48,8 @@ protected:
void setExtraNonce(const rapidjson::Value &nonce);
private:
const char *errorMessage(const rapidjson::Value &error) const;
static const char *errorMessage(const rapidjson::Value &error);
void authorize();
void onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
void onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);

View File

@@ -7,8 +7,8 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 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
@@ -32,6 +32,9 @@
#include "base/net/stratum/Job.h"
#include "base/tools/Buffer.h"
#include "base/tools/Cvt.h"
#include "base/tools/cryptonote/BlockTemplate.h"
#include "base/tools/cryptonote/Signatures.h"
#include "base/crypto/keccak.h"
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
@@ -119,8 +122,10 @@ bool xmrig::Job::setTarget(const char *target)
}
# ifdef XMRIG_PROXY_PROJECT
assert(sizeof(m_rawTarget) > (size * 2));
memset(m_rawTarget, 0, sizeof(m_rawTarget));
memcpy(m_rawTarget, target, len);
memcpy(m_rawTarget, target, std::min(size * 2, sizeof(m_rawTarget)));
# endif
m_diff = toDiff(m_target);
@@ -134,12 +139,55 @@ void xmrig::Job::setDiff(uint64_t diff)
m_target = toDiff(diff);
# ifdef XMRIG_PROXY_PROJECT
Buffer::toHex(reinterpret_cast<uint8_t *>(&m_target), 8, m_rawTarget);
m_rawTarget[16] = '\0';
Cvt::toHex(m_rawTarget, sizeof(m_rawTarget), reinterpret_cast<uint8_t *>(&m_target), sizeof(m_target));
# endif
}
void xmrig::Job::setSigKey(const char *sig_key)
{
constexpr const size_t size = 64;
if (!sig_key || strlen(sig_key) != size * 2) {
return;
}
# ifndef XMRIG_PROXY_PROJECT
const auto buf = Cvt::fromHex(sig_key, size * 2);
if (buf.size() == size) {
setEphemeralKeys(buf.data(), buf.data() + 32);
}
# else
m_rawSigKey = sig_key;
# endif
}
uint32_t xmrig::Job::getNumTransactions() const
{
if (!(m_algorithm.isCN() || m_algorithm.family() == Algorithm::RANDOM_X)) {
return 0;
}
uint32_t num_transactions = 0;
// Monero (and some other coins) has the number of transactions encoded as varint in the end of hashing blob
const size_t expected_tx_offset = (m_algorithm == Algorithm::RX_WOW) ? 141 : 75;
if ((m_size > expected_tx_offset) && (m_size <= expected_tx_offset + 4)) {
for (size_t i = expected_tx_offset, k = 0; i < m_size; ++i, k += 7) {
const uint8_t b = m_blob[i];
num_transactions |= static_cast<uint32_t>(b & 0x7F) << k;
if ((b & 0x80) == 0) {
break;
}
}
}
return num_transactions;
}
void xmrig::Job::copy(const Job &other)
{
m_algorithm = other.m_algorithm;
@@ -160,6 +208,7 @@ void xmrig::Job::copy(const Job &other)
# ifdef XMRIG_PROXY_PROJECT
m_rawSeedHash = other.m_rawSeedHash;
m_rawSigKey = other.m_rawSigKey;
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
@@ -168,6 +217,24 @@ void xmrig::Job::copy(const Job &other)
# ifdef XMRIG_FEATURE_BENCHMARK
m_benchSize = other.m_benchSize;
# endif
# ifdef XMRIG_PROXY_PROJECT
memcpy(m_spendSecretKey, other.m_spendSecretKey, sizeof(m_spendSecretKey));
memcpy(m_viewSecretKey, other.m_viewSecretKey, sizeof(m_viewSecretKey));
memcpy(m_spendPublicKey, other.m_spendPublicKey, sizeof(m_spendPublicKey));
memcpy(m_viewPublicKey, other.m_viewPublicKey, sizeof(m_viewPublicKey));
m_minerTxPrefix = other.m_minerTxPrefix;
m_minerTxEphPubKeyOffset = other.m_minerTxEphPubKeyOffset;
m_minerTxPubKeyOffset = other.m_minerTxPubKeyOffset;
m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset;
m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize;
m_minerTxMerkleTreeBranch = other.m_minerTxMerkleTreeBranch;
# else
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey));
# endif
m_hasMinerSignature = other.m_hasMinerSignature;
}
@@ -195,6 +262,7 @@ void xmrig::Job::move(Job &&other)
# ifdef XMRIG_PROXY_PROJECT
m_rawSeedHash = std::move(other.m_rawSeedHash);
m_rawSigKey = std::move(other.m_rawSigKey);
memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob));
memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget));
@@ -203,4 +271,115 @@ void xmrig::Job::move(Job &&other)
# ifdef XMRIG_FEATURE_BENCHMARK
m_benchSize = other.m_benchSize;
# endif
# ifdef XMRIG_PROXY_PROJECT
memcpy(m_spendSecretKey, other.m_spendSecretKey, sizeof(m_spendSecretKey));
memcpy(m_viewSecretKey, other.m_viewSecretKey, sizeof(m_viewSecretKey));
memcpy(m_spendPublicKey, other.m_spendPublicKey, sizeof(m_spendPublicKey));
memcpy(m_viewPublicKey, other.m_viewPublicKey, sizeof(m_viewPublicKey));
m_minerTxPrefix = std::move(other.m_minerTxPrefix);
m_minerTxEphPubKeyOffset = other.m_minerTxEphPubKeyOffset;
m_minerTxPubKeyOffset = other.m_minerTxPubKeyOffset;
m_minerTxExtraNonceOffset = other.m_minerTxExtraNonceOffset;
m_minerTxExtraNonceSize = other.m_minerTxExtraNonceSize;
m_minerTxMerkleTreeBranch = std::move(other.m_minerTxMerkleTreeBranch);
# else
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey));
# endif
m_hasMinerSignature = other.m_hasMinerSignature;
}
#ifdef XMRIG_PROXY_PROJECT
void xmrig::Job::setSpendSecretKey(const uint8_t *key)
{
m_hasMinerSignature = true;
memcpy(m_spendSecretKey, key, sizeof(m_spendSecretKey));
derive_view_secret_key(m_spendSecretKey, m_viewSecretKey);
secret_key_to_public_key(m_spendSecretKey, m_spendPublicKey);
secret_key_to_public_key(m_viewSecretKey, m_viewPublicKey);
}
void xmrig::Job::setMinerTx(const uint8_t *begin, const uint8_t *end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer &minerTxMerkleTreeBranch)
{
m_minerTxPrefix.assign(begin, end);
m_minerTxEphPubKeyOffset = minerTxEphPubKeyOffset;
m_minerTxPubKeyOffset = minerTxPubKeyOffset;
m_minerTxExtraNonceOffset = minerTxExtraNonceOffset;
m_minerTxExtraNonceSize = minerTxExtraNonceSize;
m_minerTxMerkleTreeBranch = minerTxMerkleTreeBranch;
}
void xmrig::Job::setExtraNonceInMinerTx(uint32_t extra_nonce)
{
memcpy(m_minerTxPrefix.data() + m_minerTxExtraNonceOffset, &extra_nonce, std::min(m_minerTxExtraNonceSize, sizeof(uint32_t)));
}
void xmrig::Job::generateSignatureData(String &signatureData) const
{
uint8_t* eph_public_key = m_minerTxPrefix.data() + m_minerTxEphPubKeyOffset;
uint8_t* txkey_pub = m_minerTxPrefix.data() + m_minerTxPubKeyOffset;
uint8_t txkey_sec[32];
generate_keys(txkey_pub, txkey_sec);
uint8_t derivation[32];
generate_key_derivation(m_viewPublicKey, txkey_sec, derivation);
derive_public_key(derivation, 0, m_spendPublicKey, eph_public_key);
uint8_t buf[32 * 3] = {};
memcpy(buf, txkey_pub, 32);
memcpy(buf + 32, eph_public_key, 32);
generate_key_derivation(txkey_pub, m_viewSecretKey, derivation);
derive_secret_key(derivation, 0, m_spendSecretKey, buf + 64);
signatureData = Cvt::toHex(buf, sizeof(buf));
}
void xmrig::Job::generateHashingBlob(String &blob) const
{
uint8_t root_hash[32];
const uint8_t* p = m_minerTxPrefix.data();
BlockTemplate::calculateRootHash(p, p + m_minerTxPrefix.size(), m_minerTxMerkleTreeBranch, root_hash);
uint64_t root_hash_offset = nonceOffset() + nonceSize();
if (m_hasMinerSignature) {
root_hash_offset += BlockTemplate::kSignatureSize + 2 /* vote */;
}
blob = rawBlob();
Cvt::toHex(blob.data() + root_hash_offset * 2, 64, root_hash, BlockTemplate::kHashSize);
}
#else
void xmrig::Job::generateMinerSignature(const uint8_t* blob, size_t size, uint8_t* out_sig) const
{
uint8_t tmp[kMaxBlobSize];
memcpy(tmp, blob, size);
// Fill signature with zeros
memset(tmp + nonceOffset() + nonceSize(), 0, BlockTemplate::kSignatureSize);
uint8_t prefix_hash[32];
xmrig::keccak(tmp, static_cast<int>(size), prefix_hash, sizeof(prefix_hash));
xmrig::generate_signature(prefix_hash, m_ephPublicKey, m_ephSecretKey, out_sig);
}
#endif

View File

@@ -7,8 +7,8 @@
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 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
@@ -63,6 +63,7 @@ public:
bool setSeedHash(const char *hash);
bool setTarget(const char *target);
void setDiff(uint64_t diff);
void setSigKey(const char *sig_key);
inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return (m_size > 0 && m_diff > 0) || !m_poolWallet.isEmpty(); }
@@ -82,7 +83,7 @@ public:
inline uint32_t backend() const { return m_backend; }
inline uint64_t diff() const { return m_diff; }
inline uint64_t height() const { return m_height; }
inline uint64_t nonceMask() const { return isNicehash() ? 0xFFFFFFULL : (nonceSize() == sizeof(uint64_t) ? (-1ULL >> (extraNonce().size() * 4)): 0xFFFFFFFFULL); }
inline uint64_t nonceMask() const { return isNicehash() ? 0xFFFFFFULL : (nonceSize() == sizeof(uint64_t) ? (static_cast<uint64_t>(-1LL) >> (extraNonce().size() * 4)) : 0xFFFFFFFFULL); }
inline uint64_t target() const { return m_target; }
inline uint8_t *blob() { return m_blob; }
inline uint8_t fixedByte() const { return *(m_blob + 42); }
@@ -102,6 +103,7 @@ public:
inline const char *rawBlob() const { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; }
inline const String &rawSeedHash() const { return m_rawSeedHash; }
inline const String &rawSigKey() const { return m_rawSigKey; }
# endif
static inline uint64_t toDiff(uint64_t target) { return target ? (0xFFFFFFFFFFFFFFFFULL / target) : 0; }
@@ -116,6 +118,29 @@ public:
inline void setBenchSize(uint32_t size) { m_benchSize = size; }
# endif
# ifdef XMRIG_PROXY_PROJECT
void setSpendSecretKey(const uint8_t* key);
void setMinerTx(const uint8_t* begin, const uint8_t* end, size_t minerTxEphPubKeyOffset, size_t minerTxPubKeyOffset, size_t minerTxExtraNonceOffset, size_t minerTxExtraNonceSize, const Buffer& minerTxMerkleTreeBranch);
void setExtraNonceInMinerTx(uint32_t extra_nonce);
void generateSignatureData(String& signatureData) const;
void generateHashingBlob(String& blob) const;
# else
inline const uint8_t* ephSecretKey() const { return m_hasMinerSignature ? m_ephSecretKey : nullptr; }
inline void setEphemeralKeys(const uint8_t *pub_key, const uint8_t *sec_key)
{
m_hasMinerSignature = true;
memcpy(m_ephPublicKey, pub_key, sizeof(m_ephSecretKey));
memcpy(m_ephSecretKey, sec_key, sizeof(m_ephSecretKey));
}
void generateMinerSignature(const uint8_t* blob, size_t size, uint8_t* out_sig) const;
# endif
inline bool hasMinerSignature() const { return m_hasMinerSignature; }
uint32_t getNumTransactions() const;
private:
void copy(const Job &other);
void move(Job &&other);
@@ -139,8 +164,27 @@ private:
char m_rawBlob[kMaxBlobSize * 2 + 8]{};
char m_rawTarget[24]{};
String m_rawSeedHash;
String m_rawSigKey;
// Miner signatures
uint8_t m_spendSecretKey[32]{};
uint8_t m_viewSecretKey[32]{};
uint8_t m_spendPublicKey[32]{};
uint8_t m_viewPublicKey[32]{};
mutable Buffer m_minerTxPrefix;
size_t m_minerTxEphPubKeyOffset = 0;
size_t m_minerTxPubKeyOffset = 0;
size_t m_minerTxExtraNonceOffset = 0;
size_t m_minerTxExtraNonceSize = 0;
Buffer m_minerTxMerkleTreeBranch;
# else
// Miner signatures
uint8_t m_ephPublicKey[32]{};
uint8_t m_ephSecretKey[32]{};
# endif
bool m_hasMinerSignature = false;
# ifdef XMRIG_FEATURE_BENCHMARK
uint32_t m_benchSize = 0;
# endif

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -22,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/NetworkState.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/log/Log.h"
@@ -196,7 +189,7 @@ void xmrig::NetworkState::printConnection() const
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-17s") CYAN_BOLD("%s ") BLACK_BOLD("(%s) ") GREEN_BOLD("%s"),
"pool address", m_pool, m_ip.data(), m_tls.isNull() ? "" : m_tls.data());
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-17s") WHITE_BOLD("%s"), "algorithm", m_algorithm.shortName());
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-17s") WHITE_BOLD("%s"), "algorithm", m_algorithm.name());
printDiff(m_diff);
printLatency(latency());
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-17s") CYAN_BOLD("%" PRIu64 "s"), "connection time", connectionTime() / 1000);
@@ -206,7 +199,7 @@ void xmrig::NetworkState::printConnection() const
void xmrig::NetworkState::printResults() const
{
if (!m_hashes) {
LOG_NOTICE(YELLOW_BOLD_S "no any results yet");
LOG_NOTICE(YELLOW_BOLD_S "no results yet");
return;
}

View File

@@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <cstring>
#include <cstdlib>
@@ -66,6 +65,7 @@ const char *Pool::kAlgo = "algo";
const char *Pool::kCoin = "coin";
const char *Pool::kDaemon = "daemon";
const char *Pool::kDaemonPollInterval = "daemon-poll-interval";
const char *Pool::kDaemonZMQPort = "daemon-zmq-port";
const char *Pool::kEnabled = "enabled";
const char *Pool::kFingerprint = "tls-fingerprint";
const char *Pool::kKeepalive = "keepalive";
@@ -78,10 +78,11 @@ const char *Pool::kSubmitToOrigin = "submit-to-origin";
const char *Pool::kTls = "tls";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
const char *Pool::kSpendSecretKey = "spend-secret-key";
const char *Pool::kNicehashHost = "nicehash.com";
}
} // namespace xmrig
xmrig::Pool::Pool(const char *url) :
@@ -92,12 +93,13 @@ xmrig::Pool::Pool(const char *url) :
}
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls, Mode mode) :
xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, Mode mode) :
m_keepAlive(keepAlive),
m_mode(mode),
m_flags(1 << FLAG_ENABLED),
m_password(password),
m_user(user),
m_spendSecretKey(spendSecretKey),
m_pollInterval(kDefaultPollInterval),
m_url(host, port, tls)
{
@@ -115,15 +117,17 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
return;
}
m_user = Json::getString(object, kUser);
m_password = Json::getString(object, kPass);
m_rigId = Json::getString(object, kRigId);
m_fingerprint = Json::getString(object, kFingerprint);
m_pollInterval = Json::getUint64(object, kDaemonPollInterval, kDefaultPollInterval);
m_algorithm = Json::getString(object, kAlgo);
m_coin = Json::getString(object, kCoin);
m_daemon = Json::getString(object, kSelfSelect);
m_proxy = Json::getValue(object, kSOCKS5);
m_user = Json::getString(object, kUser);
m_spendSecretKey = Json::getString(object, kSpendSecretKey);
m_password = Json::getString(object, kPass);
m_rigId = Json::getString(object, kRigId);
m_fingerprint = Json::getString(object, kFingerprint);
m_pollInterval = Json::getUint64(object, kDaemonPollInterval, kDefaultPollInterval);
m_algorithm = Json::getString(object, kAlgo);
m_coin = Json::getString(object, kCoin);
m_daemon = Json::getString(object, kSelfSelect);
m_proxy = Json::getValue(object, kSOCKS5);
m_zmqPort = Json::getInt(object, kDaemonZMQPort, m_zmqPort);
m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true));
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
@@ -186,10 +190,6 @@ bool xmrig::Pool::isEnabled() const
}
# endif
if (m_mode == MODE_DAEMON && (!algorithm().isValid() && !coin().isValid())) {
return false;
}
return m_flags.test(FLAG_ENABLED) && isValid();
}
@@ -270,6 +270,10 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
obj.AddMember(StringRef(kUrl), url().toJSON(), allocator);
obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator);
if (!m_spendSecretKey.isEmpty()) {
obj.AddMember(StringRef(kSpendSecretKey), m_spendSecretKey.toJSON(), allocator);
}
if (m_mode != MODE_DAEMON) {
obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator);
obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator);
@@ -294,6 +298,7 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
if (m_mode == MODE_DAEMON) {
obj.AddMember(StringRef(kDaemonPollInterval), m_pollInterval, allocator);
obj.AddMember(StringRef(kDaemonZMQPort), m_zmqPort, allocator);
}
else {
obj.AddMember(StringRef(kSelfSelect), m_daemon.url().toJSON(), allocator);
@@ -312,7 +317,7 @@ std::string xmrig::Pool::printableName() const
out += std::string(" coin ") + WHITE_BOLD_S + m_coin.name() + CLEAR;
}
else {
out += std::string(" algo ") + WHITE_BOLD_S + (m_algorithm.isValid() ? m_algorithm.shortName() : "auto") + CLEAR;
out += std::string(" algo ") + WHITE_BOLD_S + (m_algorithm.isValid() ? m_algorithm.name() : "auto") + CLEAR;
}
if (m_mode == MODE_SELF_SELECT) {
@@ -329,6 +334,9 @@ void xmrig::Pool::print() const
LOG_NOTICE("url: %s", url().data());
LOG_DEBUG ("host: %s", host().data());
LOG_DEBUG ("port: %d", static_cast<int>(port()));
if (m_zmqPort >= 0) {
LOG_DEBUG("zmq-port: %d", m_zmqPort);
}
LOG_DEBUG ("user: %s", m_user.data());
LOG_DEBUG ("pass: %s", m_password.data());
LOG_DEBUG ("rig-id %s", m_rigId.data());

View File

@@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Howard Chu <https://github.com/hyc>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -71,6 +71,8 @@ public:
static const char *kTls;
static const char *kUrl;
static const char *kUser;
static const char* kSpendSecretKey;
static const char* kDaemonZMQPort;
static const char *kNicehashHost;
constexpr static int kKeepAliveTimeout = 60;
@@ -78,7 +80,7 @@ public:
constexpr static uint64_t kDefaultPollInterval = 1000;
Pool() = default;
Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls, Mode mode);
Pool(const char *host, uint16_t port, const char *user, const char *password, const char* spendSecretKey, int keepAlive, bool nicehash, bool tls, Mode mode);
Pool(const char *url);
Pool(const rapidjson::Value &object);
@@ -101,10 +103,12 @@ public:
inline const String &rigId() const { return m_rigId; }
inline const String &url() const { return m_url.url(); }
inline const String &user() const { return !m_user.isNull() ? m_user : kDefaultUser; }
inline const String &spendSecretKey() const { return m_spendSecretKey; }
inline const Url &daemon() const { return m_daemon; }
inline int keepAlive() const { return m_keepAlive; }
inline Mode mode() const { return m_mode; }
inline uint16_t port() const { return m_url.port(); }
inline int zmq_port() const { return m_zmqPort; }
inline uint64_t pollInterval() const { return m_pollInterval; }
inline void setAlgo(const Algorithm &algorithm) { m_algorithm = algorithm; }
inline void setPassword(const String &password) { m_password = password; }
@@ -149,9 +153,11 @@ private:
String m_password;
String m_rigId;
String m_user;
String m_spendSecretKey;
uint64_t m_pollInterval = kDefaultPollInterval;
Url m_daemon;
Url m_url;
int m_zmqPort = -1;
# ifdef XMRIG_FEATURE_BENCHMARK
std::shared_ptr<BenchConfig> m_benchmark;

View File

@@ -230,6 +230,9 @@ void xmrig::Pools::setProxyDonate(int value)
case PROXY_DONATE_AUTO:
case PROXY_DONATE_ALWAYS:
m_proxyDonate = static_cast<ProxyDonate>(value);
default:
break;
}
}

View File

@@ -57,6 +57,12 @@ public:
Pools();
# ifdef XMRIG_FEATURE_BENCHMARK
inline bool isBenchmark() const { return !!m_benchmark; }
# else
inline constexpr static bool isBenchmark() { return false; }
# endif
inline const std::vector<Pool> &data() const { return m_data; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }

View File

@@ -20,7 +20,6 @@
#include "base/net/stratum/SelfSelectClient.h"
#include "3rdparty/http-parser/http_parser.h"
#include "3rdparty/rapidjson/document.h"
#include "3rdparty/rapidjson/error/en.h"
#include "base/io/json/Json.h"
@@ -76,7 +75,14 @@ int64_t xmrig::SelfSelectClient::submit(const JobResult &result)
submitOriginDaemon(result);
}
return m_client->submit(result);
uint64_t submit_result = m_client->submit(result);
if (m_submitToOrigin) {
// Ensure that the latest block template is available after block submission
getBlockTemplate();
}
return submit_result;
}
@@ -148,12 +154,17 @@ bool xmrig::SelfSelectClient::parseResponse(int64_t id, rapidjson::Value &result
}
}
if (!m_job.setBlob(result[kBlockhashingBlob].GetString())) {
return false;
const char *blobData = Json::getString(result, kBlockhashingBlob);
if (pool().coin().isValid()) {
uint8_t blobVersion = 0;
if (blobData) {
Cvt::fromHex(&blobVersion, 1, blobData, 2);
}
m_job.setAlgorithm(pool().coin().algorithm(blobVersion));
}
if (pool().coin().isValid()) {
m_job.setAlgorithm(pool().coin().algorithm(m_job.blob()[0]));
if (!m_job.setBlob(blobData)) {
return false;
}
m_job.setHeight(Json::getUint64(result, kHeight));
@@ -302,12 +313,11 @@ void xmrig::SelfSelectClient::submitOriginDaemon(const JobResult& result)
LOG_INFO("%s " GREEN_BOLD("submitted to origin daemon") " (%" PRId64 "/%" PRId64 ") "
" diff " WHITE("%" PRIu64) " vs. " WHITE("%" PRIu64),
Tags::origin(), m_originSubmitted, m_originNotSubmitted, m_blockDiff, result.actualDiff(), result.diff);
}
void xmrig::SelfSelectClient::onHttpData(const HttpData &data)
{
if (data.status != HTTP_STATUS_OK) {
if (data.status != 200) {
return retry();
}

View File

@@ -59,13 +59,13 @@ void xmrig::Client::Socks5::handshake()
}
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr) const
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr)
{
return uv_ip4_addr(host.data(), 0, reinterpret_cast<sockaddr_in *>(addr)) == 0;
}
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr) const
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr)
{
return uv_ip6_addr(host.data(), 0, reinterpret_cast<sockaddr_in6 *>(addr)) == 0;
}

View File

@@ -44,8 +44,9 @@ private:
Ready
};
bool isIPv4(const String &host, sockaddr_storage *addr) const;
bool isIPv6(const String &host, sockaddr_storage *addr) const;
static bool isIPv4(const String &host, sockaddr_storage *addr);
static bool isIPv6(const String &host, sockaddr_storage *addr);
void connect();
Client *m_client;

View File

@@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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
@@ -23,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/Tls.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Client.h"
@@ -177,7 +170,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
}
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int dlen;
unsigned int dlen = 0;
if (X509_digest(cert, digest, md, &dlen) != 1) {
return false;

View File

@@ -1,12 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 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

Some files were not shown because too many files have changed in this diff Show More