diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ba8c6c6c..ae62c29f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v5.4.0 +- [#1434](https://github.com/xmrig/xmrig/pull/1434) Added RandomSFX (`rx/sfx`) algorithm for Safex Cash. +- [#1445](https://github.com/xmrig/xmrig/pull/1445) Added RandomV (`rx/v`) algorithm for *new* MoneroV. +- [#367](https://github.com/xmrig/xmrig-proxy/issues/367) Added "cert-key" alias, fixed --tls-cert-key command line option. + # v5.0.1 - **Fixed memory leak.** - Fixed crash if no valid configuration found. diff --git a/src/Summary.cpp b/src/Summary.cpp index 14c350a19..4795346a9 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -23,7 +23,7 @@ */ -#include +#include #include @@ -35,18 +35,21 @@ #include "version.h" +namespace xmrig { + + static void print_mode(xmrig::Controller *controller) { - xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName()); + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName()); } static void print_bind(xmrig::Controller *controller) { - const xmrig::BindHosts &bind = controller->config()->bind(); + const BindHosts &bind = controller->config()->bind(); for (size_t i = 0; i < bind.size(); ++i) { - xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m", + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m", i + 1, bind[i].isIPv6() ? "[" : "", bind[i].host(), @@ -59,18 +62,21 @@ static void print_bind(xmrig::Controller *controller) static void print_commands(xmrig::Controller *) { - if (xmrig::Log::colors) { - xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + if (Log::isColors()) { + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") MAGENTA_BOLD("c") WHITE_BOLD("onnections, ") MAGENTA_BOLD("v") WHITE_BOLD("erbose, ") MAGENTA_BOLD("w") WHITE_BOLD("orkers")); } else { - xmrig::Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers"); + Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers"); } } +} // namespace xmrig + + void Summary::print(xmrig::Controller *controller) { controller->config()->printVersions(); diff --git a/src/api/v1/ApiRouter.cpp b/src/api/v1/ApiRouter.cpp index e73d77fbe..212ef10bb 100644 --- a/src/api/v1/ApiRouter.cpp +++ b/src/api/v1/ApiRouter.cpp @@ -22,14 +22,8 @@ * along with this program. If not, see . */ -#include -#include -#include -#include - - -#include "base/api/interfaces/IApiRequest.h" #include "api/v1/ApiRouter.h" +#include "base/api/interfaces/IApiRequest.h" #include "base/kernel/Platform.h" #include "base/tools/Buffer.h" #include "core/config/Config.h" @@ -41,6 +35,11 @@ #include "version.h" +#include +#include +#include + + static inline double normalize(double d) { if (!std::isnormal(d)) { @@ -57,9 +56,7 @@ xmrig::ApiRouter::ApiRouter(Base *base) : } -xmrig::ApiRouter::~ApiRouter() -{ -} +xmrig::ApiRouter::~ApiRouter() = default; void xmrig::ApiRouter::onRequest(IApiRequest &request) @@ -69,7 +66,6 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request) request.accept(); getMiner(request.reply(), request.doc()); getHashrate(request.reply(), request.doc()); - getResourcesSummary(request.reply(), request.doc()); getMinersSummary(request.reply(), request.doc()); getResults(request.reply(), request.doc()); } @@ -196,36 +192,6 @@ void xmrig::ApiRouter::getMinersSummary(rapidjson::Value &reply, rapidjson::Docu } - -void xmrig::ApiRouter::getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const -{ - using namespace rapidjson; - auto &allocator = doc.GetAllocator(); - - size_t rss = 0; - uv_resident_set_memory(&rss); - - Value resources(kObjectType); - Value memory(kObjectType); - Value load_average(kArrayType); - - memory.AddMember("total", uv_get_total_memory(), allocator); - memory.AddMember("resident_set_memory", static_cast(rss), allocator); - - double loadavg[3] = { 1.0 }; - uv_loadavg(loadavg); - load_average.PushBack(loadavg[0], allocator); - load_average.PushBack(loadavg[1], allocator); - load_average.PushBack(loadavg[2], allocator); - - resources.AddMember("memory", memory, allocator); - resources.AddMember("load_average", load_average, allocator); - resources.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator); - - reply.AddMember("resources", resources, allocator); -} - - void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &doc) const { auto &allocator = doc.GetAllocator(); @@ -243,8 +209,8 @@ void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document & results.AddMember("hashes_donate", stats.donateHashes, allocator); rapidjson::Value best(rapidjson::kArrayType); - for (size_t i = 0; i < stats.topDiff.size(); ++i) { - best.PushBack(stats.topDiff[i], allocator); + for (uint64_t i : stats.topDiff) { + best.PushBack(i, allocator); } results.AddMember("best", best, allocator); diff --git a/src/api/v1/ApiRouter.h b/src/api/v1/ApiRouter.h index 60560dc9b..f121849f2 100644 --- a/src/api/v1/ApiRouter.h +++ b/src/api/v1/ApiRouter.h @@ -27,6 +27,7 @@ #include "base/api/interfaces/IApiListener.h" +#include "base/tools/Object.h" #include "proxy/StatsData.h" #include "rapidjson/fwd.h" @@ -40,6 +41,8 @@ class Base; class ApiRouter : public xmrig::IApiListener { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRouter) + ApiRouter(Base *base); ~ApiRouter() override; @@ -52,7 +55,6 @@ class ApiRouter : public xmrig::IApiListener void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const; void getMiners(rapidjson::Value &reply, rapidjson::Document &doc) const; void getMinersSummary(rapidjson::Value &reply, rapidjson::Document &doc) const; - void getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const; void getResults(rapidjson::Value &reply, rapidjson::Document &doc) const; void getWorkers(rapidjson::Value &reply, rapidjson::Document &doc) const; diff --git a/src/base/api/Api.cpp b/src/base/api/Api.cpp index ad44bbb31..c4b2c5a7d 100644 --- a/src/base/api/Api.cpp +++ b/src/base/api/Api.cpp @@ -31,10 +31,11 @@ #endif -#include "3rdparty/http-parser/http_parser.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/io/json/Json.h" #include "base/kernel/Base.h" #include "base/tools/Buffer.h" #include "base/tools/Chrono.h" @@ -49,12 +50,49 @@ #endif +#include + + +namespace xmrig { + + +static rapidjson::Value getResources(rapidjson::Document &doc) +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + size_t rss = 0; + uv_resident_set_memory(&rss); + + Value out(kObjectType); + Value memory(kObjectType); + Value load_average(kArrayType); + + memory.AddMember("free", uv_get_free_memory(), allocator); + memory.AddMember("total", uv_get_total_memory(), allocator); + memory.AddMember("resident_set_memory", static_cast(rss), allocator); + + double loadavg[3] = { 0.0 }; + uv_loadavg(loadavg); + + for (double value : loadavg) { + load_average.PushBack(Json::normalize(value, true), allocator); + } + + out.AddMember("memory", memory, allocator); + out.AddMember("load_average", load_average, allocator); + out.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator); + + return out; +} + + +} // namespace xmrig + + xmrig::Api::Api(Base *base) : m_base(base), - m_id(), - m_workerId(), - m_timestamp(Chrono::currentMSecsSinceEpoch()), - m_httpd(nullptr) + m_timestamp(Chrono::currentMSecsSinceEpoch()) { base->addListener(this); @@ -117,10 +155,13 @@ void xmrig::Api::exec(IApiRequest &request) auto &allocator = request.doc().GetAllocator(); request.accept(); - request.reply().AddMember("id", StringRef(m_id), allocator); - request.reply().AddMember("worker_id", StringRef(m_workerId), allocator); - request.reply().AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator); - request.reply().AddMember("restricted", request.isRestricted(), allocator); + + auto &reply = request.reply(); + reply.AddMember("id", StringRef(m_id), allocator); + reply.AddMember("worker_id", StringRef(m_workerId), allocator); + reply.AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator); + reply.AddMember("restricted", request.isRestricted(), allocator); + reply.AddMember("resources", getResources(request.doc()), allocator); Value features(kArrayType); # ifdef XMRIG_FEATURE_API @@ -144,7 +185,10 @@ void xmrig::Api::exec(IApiRequest &request) # ifdef XMRIG_FEATURE_OPENCL features.PushBack("opencl", allocator); # endif - request.reply().AddMember("features", features, allocator); +# ifdef XMRIG_FEATURE_CUDA + features.PushBack("cuda", allocator); +# endif + reply.AddMember("features", features, allocator); } for (IApiListener *listener : m_listeners) { @@ -180,9 +224,9 @@ void xmrig::Api::genId(const String &id) uint8_t hash[200]; const size_t addrSize = sizeof(interfaces[i].phys_addr); const size_t inSize = (sizeof(APP_KIND) - 1) + addrSize + sizeof(uint16_t); - const uint16_t port = static_cast(m_base->config()->http().port()); + const auto port = static_cast(m_base->config()->http().port()); - uint8_t *input = new uint8_t[inSize](); + auto*input = new uint8_t[inSize](); memcpy(input, &port, sizeof(uint16_t)); memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize); memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, (sizeof(APP_KIND) - 1)); diff --git a/src/base/api/Api.h b/src/base/api/Api.h index 0c1a728db..130ce78ef 100644 --- a/src/base/api/Api.h +++ b/src/base/api/Api.h @@ -70,10 +70,10 @@ class Api : public IBaseListener void genWorkerId(const String &id); Base *m_base; - char m_id[32]; - char m_workerId[128]; + char m_id[32]{}; + char m_workerId[128]{}; const uint64_t m_timestamp; - Httpd *m_httpd; + Httpd *m_httpd = nullptr; std::vector m_listeners; }; diff --git a/src/base/api/Httpd.cpp b/src/base/api/Httpd.cpp index e61e66f1c..27e7dc448 100644 --- a/src/base/api/Httpd.cpp +++ b/src/base/api/Httpd.cpp @@ -23,9 +23,9 @@ */ +#include "base/api/Httpd.h" #include "3rdparty/http-parser/http_parser.h" #include "base/api/Api.h" -#include "base/api/Httpd.h" #include "base/io/log/Log.h" #include "base/net/http/HttpApiResponse.h" #include "base/net/http/HttpData.h" @@ -58,9 +58,7 @@ xmrig::Httpd::Httpd(Base *base) : } -xmrig::Httpd::~Httpd() -{ -} +xmrig::Httpd::~Httpd() = default; bool xmrig::Httpd::start() diff --git a/src/base/api/Httpd.h b/src/base/api/Httpd.h index 220bb7f5a..ebfbcbf7e 100644 --- a/src/base/api/Httpd.h +++ b/src/base/api/Httpd.h @@ -26,11 +26,12 @@ #define XMRIG_HTTPD_H -#include +#include #include "base/kernel/interfaces/IBaseListener.h" #include "base/kernel/interfaces/IHttpListener.h" +#include "base/tools/Object.h" namespace xmrig { @@ -44,6 +45,8 @@ class TcpServer; class Httpd : public IBaseListener, public IHttpListener { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd) + Httpd(Base *base); ~Httpd() override; diff --git a/src/base/api/requests/ApiRequest.cpp b/src/base/api/requests/ApiRequest.cpp index da73adee4..4f0bd0443 100644 --- a/src/base/api/requests/ApiRequest.cpp +++ b/src/base/api/requests/ApiRequest.cpp @@ -33,6 +33,4 @@ xmrig::ApiRequest::ApiRequest(Source source, bool restricted) : } -xmrig::ApiRequest::~ApiRequest() -{ -} +xmrig::ApiRequest::~ApiRequest() = default; diff --git a/src/base/api/requests/ApiRequest.h b/src/base/api/requests/ApiRequest.h index ad4b0c350..c87e822c0 100644 --- a/src/base/api/requests/ApiRequest.h +++ b/src/base/api/requests/ApiRequest.h @@ -29,6 +29,7 @@ #include "base/api/interfaces/IApiRequest.h" #include "base/tools/String.h" +#include "base/tools/Object.h" namespace xmrig { @@ -37,6 +38,8 @@ namespace xmrig { class ApiRequest : public IApiRequest { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRequest) + ApiRequest(Source source, bool restricted); ~ApiRequest() override; @@ -63,8 +66,8 @@ class ApiRequest : public IApiRequest String m_rpcMethod; private: - bool m_restricted; - Source m_source; + const bool m_restricted; + const Source m_source; }; diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index 9a5782933..738621448 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -28,6 +28,7 @@ #include +#include namespace xmrig { @@ -154,6 +155,18 @@ unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsi } +rapidjson::Value xmrig::Json::normalize(double value, bool zero) +{ + using namespace rapidjson; + + if (!std::isnormal(value)) { + return zero ? Value(0.0) : Value(kNullType); + } + + return Value(floor(value * 100.0) / 100.0); +} + + bool xmrig::JsonReader::isEmpty() const { return !m_obj.IsObject() || m_obj.ObjectEmpty(); diff --git a/src/base/io/json/Json.h b/src/base/io/json/Json.h index 80fe5dc26..b5e2a3c8a 100644 --- a/src/base/io/json/Json.h +++ b/src/base/io/json/Json.h @@ -48,6 +48,8 @@ class Json static bool get(const char *fileName, rapidjson::Document &doc); static bool save(const char *fileName, const rapidjson::Document &doc); + + static rapidjson::Value normalize(double value, bool zero); }; diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 2cd372423..a091f923f 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -92,7 +92,7 @@ class LogPrivate std::lock_guard lock(m_mutex); - if (Log::background && m_backends.empty()) { + if (Log::isBackground() && m_backends.empty()) { return; } @@ -195,9 +195,10 @@ class LogPrivate }; -bool Log::background = false; -bool Log::colors = true; -LogPrivate *Log::d = new LogPrivate(); +bool Log::m_background = false; +bool Log::m_colors = true; +LogPrivate *Log::d = new LogPrivate(); +uint32_t Log::m_verbose = 0; } /* namespace xmrig */ diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index cfd3c3a33..3181f9342 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -27,6 +27,9 @@ #define XMRIG_LOG_H +#include + + namespace xmrig { @@ -54,10 +57,19 @@ class Log static void print(const char *fmt, ...); static void print(Level level, const char *fmt, ...); - static bool background; - static bool colors; + static inline bool isBackground() { return m_background; } + static inline bool isColors() { return m_colors; } + static inline bool isVerbose() { return m_verbose > 0; } + static inline uint32_t verbose() { return m_verbose; } + static inline void setBackground(bool background) { m_background = background; } + static inline void setColors(bool colors) { m_colors = colors; } + static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; } private: + static bool m_background; + static bool m_colors; + static uint32_t m_verbose; + static LogPrivate *d; }; @@ -83,6 +95,7 @@ class Log #define WHITE_BOLD_S CSI "1;37m" // actually white #define GREEN_BG_BOLD_S CSI "42;1m" +#define YELLOW_BG_BOLD_S CSI "43;1m" #define BLUE_BG_S CSI "44m" #define BLUE_BG_BOLD_S CSI "44;1m" #define MAGENTA_BG_S CSI "45m" @@ -109,6 +122,7 @@ class Log #define WHITE_BOLD(x) WHITE_BOLD_S x CLEAR #define GREEN_BG_BOLD(x) GREEN_BG_BOLD_S x CLEAR +#define YELLOW_BG_BOLD(x) YELLOW_BG_BOLD_S x CLEAR #define BLUE_BG(x) BLUE_BG_S x CLEAR #define BLUE_BG_BOLD(x) BLUE_BG_BOLD_S x CLEAR #define MAGENTA_BG(x) MAGENTA_BG_S x CLEAR @@ -117,13 +131,14 @@ class Log #define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR -#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) -#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) -#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) -#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) -#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) -#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) -#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__) +#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__) +#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__) +#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__) +#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) +#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) +#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) +#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) diff --git a/src/base/io/log/backends/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp index de907318f..4d3c532a0 100644 --- a/src/base/io/log/backends/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -35,14 +35,14 @@ xmrig::ConsoleLog::ConsoleLog() { if (!isSupported()) { - Log::colors = false; + Log::setColors(false); return; } m_tty = new uv_tty_t; if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) { - Log::colors = false; + Log::setColors(false); return; } @@ -71,7 +71,7 @@ xmrig::ConsoleLog::~ConsoleLog() void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors) { - if (!m_tty || Log::colors != colors) { + if (!m_tty || Log::isColors() != colors) { return; } diff --git a/src/base/io/log/backends/FileLog.cpp b/src/base/io/log/backends/FileLog.cpp index 1ff016371..c581b880d 100644 --- a/src/base/io/log/backends/FileLog.cpp +++ b/src/base/io/log/backends/FileLog.cpp @@ -24,11 +24,12 @@ */ -#include -#include +#include "base/io/log/backends/FileLog.h" -#include "base/io/log/backends/FileLog.h" +#include +#include +#include xmrig::FileLog::FileLog(const char *fileName) @@ -45,13 +46,12 @@ void xmrig::FileLog::print(int, const char *line, size_t, size_t size, bool colo return; } -# ifdef _WIN32 - uv_buf_t buf = uv_buf_init(strdup(line), static_cast(size)); -# else - uv_buf_t buf = uv_buf_init(strdup(line), size); -# endif + assert(strlen(line) == size); + + uv_buf_t buf = uv_buf_init(new char[size], size); + memcpy(buf.base, line, size); - uv_fs_t *req = new uv_fs_t; + auto req = new uv_fs_t; req->data = buf.base; uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, FileLog::onWrite); diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 90c7cb57c..03aaaca5f 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -176,12 +176,8 @@ int xmrig::Base::init() Platform::init(config()->userAgent()); -# ifndef XMRIG_PROXY_PROJECT - Platform::setProcessPriority(config()->cpu().priority()); -# endif - if (isBackground()) { - Log::background = true; + Log::setBackground(true); } else { Log::add(new ConsoleLog()); diff --git a/src/base/kernel/Platform.h b/src/base/kernel/Platform.h index 3f026f8bd..fe39a69ea 100644 --- a/src/base/kernel/Platform.h +++ b/src/base/kernel/Platform.h @@ -51,7 +51,6 @@ class Platform static uint32_t setTimerResolution(uint32_t resolution); static void init(const char *userAgent); static void restoreTimerResolution(); - static void setProcessPriority(int priority); static void setThreadPriority(int priority); static inline const char *userAgent() { return m_userAgent; } diff --git a/src/base/kernel/Platform_mac.cpp b/src/base/kernel/Platform_mac.cpp index 146dd52d7..8d9bac3b8 100644 --- a/src/base/kernel/Platform_mac.cpp +++ b/src/base/kernel/Platform_mac.cpp @@ -83,11 +83,6 @@ void xmrig::Platform::restoreTimerResolution() } -void xmrig::Platform::setProcessPriority(int priority) -{ -} - - void xmrig::Platform::setThreadPriority(int priority) { if (priority == -1) { diff --git a/src/base/kernel/Platform_unix.cpp b/src/base/kernel/Platform_unix.cpp index bbba39f90..b6ca17e4a 100644 --- a/src/base/kernel/Platform_unix.cpp +++ b/src/base/kernel/Platform_unix.cpp @@ -111,11 +111,6 @@ void xmrig::Platform::restoreTimerResolution() } -void xmrig::Platform::setProcessPriority(int priority) -{ -} - - void xmrig::Platform::setThreadPriority(int priority) { if (priority == -1) { diff --git a/src/base/kernel/Platform_win.cpp b/src/base/kernel/Platform_win.cpp index 064c8352f..ad93cb6a7 100644 --- a/src/base/kernel/Platform_win.cpp +++ b/src/base/kernel/Platform_win.cpp @@ -131,43 +131,6 @@ void xmrig::Platform::restoreTimerResolution() } -void xmrig::Platform::setProcessPriority(int priority) -{ - if (priority == -1) { - return; - } - - DWORD prio = IDLE_PRIORITY_CLASS; - switch (priority) - { - case 1: - prio = BELOW_NORMAL_PRIORITY_CLASS; - break; - - case 2: - prio = NORMAL_PRIORITY_CLASS; - break; - - case 3: - prio = ABOVE_NORMAL_PRIORITY_CLASS; - break; - - case 4: - prio = HIGH_PRIORITY_CLASS; - break; - - case 5: - prio = REALTIME_PRIORITY_CLASS; - break; - - default: - break; - } - - SetPriorityClass(GetCurrentProcess(), prio); -} - - void xmrig::Platform::setThreadPriority(int priority) { if (priority == -1) { diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 3da06b57a..7b647ed0e 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -23,99 +23,28 @@ */ -#include -#include -#include -#include -#include - - -#ifdef XMRIG_FEATURE_TLS -# include -#endif - -#ifdef XMRIG_FEATURE_HWLOC -# include "backend/cpu/Cpu.h" -#endif - -#ifdef XMRIG_AMD_PROJECT -# if defined(__APPLE__) -# include -# else -# include "3rdparty/CL/cl.h" -# endif -#endif - - -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - - +#include "base/kernel/config/BaseConfig.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" -#include "base/kernel/config/BaseConfig.h" #include "base/kernel/interfaces/IJsonReader.h" -#include "donate.h" #include "rapidjson/document.h" -#include "rapidjson/filewritestream.h" -#include "rapidjson/prettywriter.h" #include "version.h" -xmrig::BaseConfig::BaseConfig() -{ -} - - -void xmrig::BaseConfig::printVersions() -{ - char buf[256] = { 0 }; - -# if defined(__clang__) - snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif defined(_MSC_VER) - snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); -# endif - - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); - -# if defined(XMRIG_AMD_PROJECT) -# if CL_VERSION_2_0 - const char *ocl = "2.0"; -# elif CL_VERSION_1_2 - const char *ocl = "1.2"; -# elif CL_VERSION_1_1 - const char *ocl = "1.1"; -# elif CL_VERSION_1_0 - const char *ocl = "1.0"; -# else - const char *ocl = "0.0"; -# endif - int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl); -# elif defined(XMRIG_NVIDIA_PROJECT) - const int cudaVersion = cuda_get_runtime_version(); - int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100); -# endif - - std::string libs; +#include +#include +#include +#include +#include -# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) - { - constexpr const char *v = OPENSSL_VERSION_TEXT + 8; - snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); - libs += buf; - } -# endif -# if defined(XMRIG_FEATURE_HWLOC) - libs += Cpu::info()->backend(); -# endif +#ifdef XMRIG_FEATURE_TLS +# include +#endif - Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); -} +#ifdef XMRIG_FEATURE_HWLOC +# include "backend/cpu/Cpu.h" +#endif bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) @@ -131,12 +60,13 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_dryRun = reader.getBool("dry-run", m_dryRun); m_syslog = reader.getBool("syslog", m_syslog); m_watch = reader.getBool("watch", m_watch); - Log::colors = reader.getBool("colors", Log::colors); m_logFile = reader.getString("log-file"); m_userAgent = reader.getString("user-agent"); m_version = reader.getUint("version"); + Log::setColors(reader.getBool("colors", Log::isColors())); setPrintTime(reader.getUint("print-time", 60)); + setVerbose(reader.getValue("verbose")); const rapidjson::Value &api = reader.getObject("api"); if (api.IsObject()) { @@ -167,3 +97,46 @@ bool xmrig::BaseConfig::save() return false; } + + +void xmrig::BaseConfig::printVersions() +{ + char buf[256] = { 0 }; + +# if defined(__clang__) + snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) + snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf); + + std::string libs; + +# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast(strchr(v, ' ') - v), v); + libs += buf; + } +# endif + +# if defined(XMRIG_FEATURE_HWLOC) + libs += Cpu::info()->backend(); +# endif + + Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str()); +} + + +void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value) +{ + if (value.IsBool()) { + Log::setVerbose(value.GetBool() ? 1 : 0); + } + else if (value.IsUint()) { + Log::setVerbose(value.GetUint()); + } +} diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index 2e10c3ff8..7be81828c 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -31,9 +31,6 @@ #include "base/net/stratum/Pools.h" -struct option; - - namespace xmrig { @@ -43,7 +40,7 @@ class IJsonReader; class BaseConfig : public IConfig { public: - BaseConfig(); + BaseConfig() = default; inline bool isAutoSave() const { return m_autoSave; } inline bool isBackground() const { return m_background; } @@ -85,6 +82,8 @@ class BaseConfig : public IConfig private: inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } + + void setVerbose(const rapidjson::Value &value); }; diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index ccf5ccf11..8a3a140ec 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -222,6 +222,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch case IConfig::DryRunKey: /* --dry-run */ case IConfig::HttpEnabledKey: /* --http-enabled */ case IConfig::DaemonKey: /* --daemon */ + case IConfig::VerboseKey: /* --verbose */ return transformBoolean(doc, key, true); case IConfig::ColorKey: /* --no-color */ @@ -273,6 +274,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b case IConfig::DryRunKey: /* --dry-run */ return set(doc, "dry-run", enable); + case IConfig::VerboseKey: /* --verbose */ + return set(doc, "verbose", enable); + default: break; } diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 7167e0bb7..fe1a24b53 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -89,8 +89,12 @@ class IConfig AssemblyKey = 1015, RandomXInitKey = 1022, RandomXNumaKey = 1023, + RandomXModeKey = 1029, + RandomX1GbPagesKey = 1031, + RandomXWrmsrKey = 1032, CPUMaxThreadsKey = 1026, MemoryPoolKey = 1027, + YieldKey = 1030, // xmrig amd OclPlatformKey = 1400, @@ -125,6 +129,7 @@ class IConfig TlsProtocolsKey = 1114, AlgoExtKey = 1115, ProxyPasswordKey = 1116, + LoginFileKey = 'L', // xmrig nvidia CudaMaxThreadsKey = 1200, diff --git a/src/base/kernel/interfaces/IStrategy.h b/src/base/kernel/interfaces/IStrategy.h index f2e584083..a0a249879 100644 --- a/src/base/kernel/interfaces/IStrategy.h +++ b/src/base/kernel/interfaces/IStrategy.h @@ -26,7 +26,7 @@ #define XMRIG_ISTRATEGY_H -#include +#include namespace xmrig { diff --git a/src/base/net/http/Http.cpp b/src/base/net/http/Http.cpp index 3c275824d..c58080e6b 100644 --- a/src/base/net/http/Http.cpp +++ b/src/base/net/http/Http.cpp @@ -23,9 +23,9 @@ */ +#include "base/net/http/Http.h" #include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "base/net/http/Http.h" namespace xmrig { @@ -41,10 +41,7 @@ static const char *kToken = "access-token"; xmrig::Http::Http() : - m_enabled(false), - m_restricted(true), - m_host(kLocalhost), - m_port(0) + m_host(kLocalhost) { } diff --git a/src/base/net/http/Http.h b/src/base/net/http/Http.h index 21eb581a0..0e8e4fbb6 100644 --- a/src/base/net/http/Http.h +++ b/src/base/net/http/Http.h @@ -38,7 +38,7 @@ class Http public: Http(); - inline bool isAuthRequired() const { return m_restricted == false || !m_token.isNull(); } + inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); } inline bool isEnabled() const { return m_enabled; } inline bool isRestricted() const { return m_restricted; } inline const String &host() const { return m_host; } @@ -58,11 +58,11 @@ class Http void setPort(int port); private: - bool m_enabled; - bool m_restricted; + bool m_enabled = false; + bool m_restricted = true; String m_host; String m_token; - uint16_t m_port; + uint16_t m_port = 0; }; diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index 2699e6631..9db1e8093 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -66,7 +66,7 @@ class ClientWriteBaton : public Baton inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast(req->data); } - uv_buf_t bufs[2]; + uv_buf_t bufs[2]{}; private: std::string m_body; diff --git a/src/base/net/http/HttpContext.cpp b/src/base/net/http/HttpContext.cpp index 1130d12c5..af5762578 100644 --- a/src/base/net/http/HttpContext.cpp +++ b/src/base/net/http/HttpContext.cpp @@ -24,27 +24,30 @@ */ -#include -#include - - +#include "base/net/http/HttpContext.h" #include "3rdparty/http-parser/http_parser.h" #include "base/kernel/interfaces/IHttpListener.h" -#include "base/net/http/HttpContext.h" +#include "base/tools/Chrono.h" + + +#include +#include namespace xmrig { + static http_parser_settings http_settings; static std::map storage; static uint64_t SEQUENCE = 0; + } // namespace xmrig xmrig::HttpContext::HttpContext(int parser_type, IHttpListener *listener) : HttpData(SEQUENCE++), - m_wasHeaderValue(false), + m_timestamp(Chrono::steadyMSecs()), m_listener(listener) { storage[id()] = this; @@ -96,6 +99,12 @@ std::string xmrig::HttpContext::ip() const } +uint64_t xmrig::HttpContext::elapsed() const +{ + return Chrono::steadyMSecs() - m_timestamp; +} + + void xmrig::HttpContext::close(int status) { if (status < 0 && m_listener) { diff --git a/src/base/net/http/HttpContext.h b/src/base/net/http/HttpContext.h index ba4418b61..9c304139a 100644 --- a/src/base/net/http/HttpContext.h +++ b/src/base/net/http/HttpContext.h @@ -59,6 +59,7 @@ class HttpContext : public HttpData size_t parse(const char *data, size_t size); std::string ip() const; + uint64_t elapsed() const; void close(int status = 0); static HttpContext *get(uint64_t id); @@ -74,7 +75,8 @@ class HttpContext : public HttpData void setHeader(); - bool m_wasHeaderValue; + bool m_wasHeaderValue = false; + const uint64_t m_timestamp; http_parser *m_parser; IHttpListener *m_listener; std::string m_lastHeaderField; diff --git a/src/base/net/http/HttpData.h b/src/base/net/http/HttpData.h index ceb19b8e4..1705e8816 100644 --- a/src/base/net/http/HttpData.h +++ b/src/base/net/http/HttpData.h @@ -38,12 +38,12 @@ namespace xmrig { class HttpData { public: - inline HttpData(uint64_t id) : method(0), status(0), m_id(id) {} + inline HttpData(uint64_t id) : m_id(id) {} inline uint64_t id() const { return m_id; } - int method; - int status; + int method = 0; + int status = 0; std::map headers; std::string body; std::string url; diff --git a/src/base/net/http/HttpResponse.cpp b/src/base/net/http/HttpResponse.cpp index 7a4af8387..ebd0bcf98 100644 --- a/src/base/net/http/HttpResponse.cpp +++ b/src/base/net/http/HttpResponse.cpp @@ -24,20 +24,23 @@ */ -#include -#include -#include - - +#include "base/net/http/HttpResponse.h" #include "3rdparty/http-parser/http_parser.h" #include "base/io/log/Log.h" #include "base/net/http/HttpContext.h" -#include "base/net/http/HttpResponse.h" #include "base/tools/Baton.h" +#include "base/tools/Object.h" + + +#include +#include +#include +#include namespace xmrig { + static const char *kCRLF = "\r\n"; static const char *kUserAgent = "user-agent"; @@ -45,6 +48,8 @@ static const char *kUserAgent = "user-agent"; class WriteBaton : public Baton { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(WriteBaton) + inline WriteBaton(const std::stringstream &ss, const char *data, size_t size, HttpContext *ctx) : m_ctx(ctx), m_header(ss.str()) @@ -79,7 +84,7 @@ class WriteBaton : public Baton inline static void onWrite(uv_write_t *req, int) { delete reinterpret_cast(req->data); } - uv_buf_t bufs[2]; + uv_buf_t bufs[2]{}; private: HttpContext *m_ctx; @@ -98,7 +103,7 @@ xmrig::HttpResponse::HttpResponse(uint64_t id, int statusCode) : bool xmrig::HttpResponse::isAlive() const { - HttpContext *ctx = HttpContext::get(m_id); + auto ctx = HttpContext::get(m_id); return ctx && uv_is_writable(ctx->stream()); } @@ -129,8 +134,8 @@ void xmrig::HttpResponse::end(const char *data, size_t size) ss << kCRLF; - HttpContext *ctx = HttpContext::get(m_id); - WriteBaton *baton = new WriteBaton(ss, data, size, ctx); + auto ctx = HttpContext::get(m_id); + auto baton = new WriteBaton(ss, data, size, ctx); # ifndef APP_DEBUG if (statusCode() >= 400) @@ -138,13 +143,14 @@ void xmrig::HttpResponse::end(const char *data, size_t size) { const bool err = statusCode() >= 400; - Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") BLACK_BOLD("\"%s\""), + Log::print(err ? Log::ERR : Log::INFO, CYAN("%s ") CLEAR MAGENTA_BOLD("%s") WHITE_BOLD(" %s ") CSI "1;%dm%d " CLEAR WHITE_BOLD("%zu ") CYAN_BOLD("%" PRIu64 "ms ") BLACK_BOLD("\"%s\""), ctx->ip().c_str(), http_method_str(static_cast(ctx->method)), ctx->url.c_str(), err ? 31 : 32, statusCode(), baton->size(), + ctx->elapsed(), ctx->headers.count(kUserAgent) ? ctx->headers.at(kUserAgent).c_str() : nullptr ); } diff --git a/src/base/net/http/HttpServer.cpp b/src/base/net/http/HttpServer.cpp index 60db31f62..5aae1b6f2 100644 --- a/src/base/net/http/HttpServer.cpp +++ b/src/base/net/http/HttpServer.cpp @@ -49,7 +49,7 @@ xmrig::HttpServer::~HttpServer() void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t) { - HttpContext *ctx = new HttpContext(HTTP_REQUEST, m_listener); + auto ctx = new HttpContext(HTTP_REQUEST, m_listener); uv_accept(stream, ctx->stream()); uv_read_start(ctx->stream(), @@ -65,11 +65,11 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t) }, [](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf) { - HttpContext *ctx = static_cast(tcp->data); + auto ctx = static_cast(tcp->data); if (nread >= 0) { - const size_t size = static_cast(nread); - const size_t parsed = ctx->parse(buf->base, size); + const auto size = static_cast(nread); + const auto parsed = ctx->parse(buf->base, size); if (parsed < size) { ctx->close(); diff --git a/src/base/net/http/HttpServer.h b/src/base/net/http/HttpServer.h index 45f3843d1..74e846b91 100644 --- a/src/base/net/http/HttpServer.h +++ b/src/base/net/http/HttpServer.h @@ -28,11 +28,12 @@ #define XMRIG_HTTPSERVER_H -typedef struct http_parser http_parser; -typedef struct http_parser_settings http_parser_settings; +using http_parser = struct http_parser; +using http_parser_settings = struct http_parser_settings; #include "base/kernel/interfaces/ITcpServerListener.h" +#include "base/tools/Object.h" namespace xmrig { @@ -44,6 +45,8 @@ class IHttpListener; class HttpServer : public ITcpServerListener { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(HttpServer) + HttpServer(IHttpListener *listener); ~HttpServer() override; diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 9729f3fbc..30ef20ead 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -79,7 +79,8 @@ static const char *states[] = { xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : BaseClient(id, listener), - m_agent(agent) + m_agent(agent), + m_sendBuf(1024) { m_key = m_storage.add(this); m_dns = new Dns(this); @@ -158,13 +159,18 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) obj.Accept(writer); const size_t size = buffer.GetSize(); - if (size > (sizeof(m_sendBuf) - 2)) { - LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2)); + if (size > kMaxSendBufferSize) { + LOG_ERR("[%s] send failed: \"max send buffer size exceeded: %zu\"", url(), size); close(); + return -1; } - memcpy(m_sendBuf, buffer.GetString(), size); + if (size > (m_sendBuf.size() - 2)) { + m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024); + } + + memcpy(m_sendBuf.data(), buffer.GetString(), size); m_sendBuf[size] = '\n'; m_sendBuf[size + 1] = '\0'; @@ -186,8 +192,8 @@ int64_t xmrig::Client::submit(const JobResult &result) const char *nonce = result.nonce; const char *data = result.result; # else - char *nonce = m_sendBuf; - char *data = m_sendBuf + 16; + char *nonce = m_sendBuf.data(); + char *data = m_sendBuf.data() + 16; Buffer::toHex(reinterpret_cast(&result.nonce), 4, nonce); nonce[8] = '\0'; @@ -338,6 +344,10 @@ bool xmrig::Client::isCriticalError(const char *message) return true; } + if (strncasecmp(message, "Invalid job id", 14) == 0) { + return true; + } + return false; } @@ -456,11 +466,7 @@ bool xmrig::Client::send(BIO *bio) bool result = false; if (state() == ConnectedState && uv_is_writable(m_stream)) { - result = uv_try_write(m_stream, &buf, 1) > 0; - - if (!result) { - close(); - } + result = write(buf); } else { LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state); @@ -501,6 +507,23 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo } +bool xmrig::Client::write(const uv_buf_t &buf) +{ + const int rc = uv_try_write(m_stream, &buf, 1); + if (static_cast(rc) == buf.len) { + return true; + } + + if (!isQuiet()) { + LOG_ERR("[%s] write error: \"%s\"", url(), uv_strerror(rc)); + } + + close(); + + return false; +} + + int xmrig::Client::resolve(const String &host) { setState(HostLookupState); @@ -525,11 +548,11 @@ int xmrig::Client::resolve(const String &host) int64_t xmrig::Client::send(size_t size) { - LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf); + LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf.data()); # ifdef XMRIG_FEATURE_TLS if (isTLS()) { - if (!m_tls->send(m_sendBuf, size)) { + if (!m_tls->send(m_sendBuf.data(), size)) { return -1; } } @@ -541,10 +564,9 @@ int64_t xmrig::Client::send(size_t size) return -1; } - uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size); + uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size); - if (uv_try_write(m_stream, &buf, 1) < 0) { - close(); + if (!write(buf)) { return -1; } } @@ -558,7 +580,7 @@ void xmrig::Client::connect(sockaddr *addr) { setState(ConnectingState); - uv_connect_t *req = new uv_connect_t; + auto req = new uv_connect_t; req->data = m_storage.ptr(m_key); m_socket = new uv_tcp_t; @@ -791,7 +813,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co void xmrig::Client::ping() { - send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); + send(snprintf(m_sendBuf.data(), m_sendBuf.size(), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); m_keepAlive = 0; } @@ -799,7 +821,7 @@ void xmrig::Client::ping() void xmrig::Client::read(ssize_t nread) { - const size_t size = static_cast(nread); + const auto size = static_cast(nread); if (nread > 0 && size > m_recvBuf.available()) { nread = UV_ENOBUFS; @@ -859,7 +881,7 @@ void xmrig::Client::reconnect() void xmrig::Client::setState(SocketState state) { - LOG_DEBUG("[%s] state: \"%s\"", url(), states[state]); + LOG_DEBUG("[%s] state: \"%s\" -> \"%s\"", url(), states[m_state], states[state]); if (m_state == state) { return; @@ -956,6 +978,12 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status) return; } + if (client->state() == ConnectedState) { + LOG_ERR("[%s] already connected"); + + return; + } + client->m_stream = static_cast(req->handle); client->m_stream->data = req->data; client->setState(ConnectedState); diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index da4234845..ec90dd857 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -60,14 +60,10 @@ class Client : public BaseClient, public IDnsListener, public ILineListener public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client) - constexpr static uint64_t kConnectTimeout = 20 * 1000; - constexpr static uint64_t kResponseTimeout = 20 * 1000; - -# ifdef XMRIG_FEATURE_TLS - constexpr static size_t kInputBufferSize = 1024 * 16; -# else - constexpr static size_t kInputBufferSize = 1024 * 2; -# endif + constexpr static uint64_t kConnectTimeout = 20 * 1000; + constexpr static uint64_t kResponseTimeout = 20 * 1000; + constexpr static size_t kInputBufferSize = 1024 * 16; + constexpr static size_t kMaxSendBufferSize = 1024 * 16; Client(int id, const char *agent, IClientListener *listener); ~Client() override; @@ -100,6 +96,7 @@ class Client : public BaseClient, public IDnsListener, public ILineListener bool parseLogin(const rapidjson::Value &result, 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); @@ -128,11 +125,11 @@ class Client : public BaseClient, public IDnsListener, public ILineListener static inline Client *getClient(void *data) { return m_storage.get(data); } - char m_sendBuf[2048] = { 0 }; const char *m_agent; Dns *m_dns; RecvBuf m_recvBuf; std::bitset m_extensions; + std::vector m_sendBuf; String m_rpcId; Tls *m_tls = nullptr; uint64_t m_expire = 0; diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 9e1f3bc98..ed369a163 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -99,7 +99,7 @@ class Job # endif static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast(blob + 39); } - static inline uint64_t toDiff(uint64_t target) { return 0xFFFFFFFFFFFFFFFFULL / target; } + static inline uint64_t toDiff(uint64_t target) { return target ? (0xFFFFFFFFFFFFFFFFULL / target) : 0; } inline bool operator!=(const Job &other) const { return !isEqual(other); } inline bool operator==(const Job &other) const { return isEqual(other); } diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index ec26cd0c4..2749f5ca8 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -22,9 +22,9 @@ * along with this program. If not, see . */ -#include -#include -#include +#include +#include +#include #include @@ -46,16 +46,7 @@ static const char *modeNames[] = { #endif -xmrig::Config::Config() : - m_algoExt(true), - m_debug(false), - m_verbose(false), - m_mode(NICEHASH_MODE), - m_reuseTimeout(0), - m_diff(0), - m_workersMode(Workers::RigID) -{ -} +xmrig::Config::Config() = default; bool xmrig::Config::isTLS() const @@ -78,13 +69,18 @@ const char *xmrig::Config::modeName() const } +bool xmrig::Config::isVerbose() const +{ + return Log::isVerbose(); +} + + bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) { if (!BaseConfig::read(reader, fileName)) { return false; } - m_verbose = reader.getBool("verbose", m_verbose); m_debug = reader.getBool("debug", m_debug); m_algoExt = reader.getBool("algo-ext", m_algoExt); m_reuseTimeout = reader.getInt("reuse-timeout", m_reuseTimeout); @@ -98,7 +94,7 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) # ifdef XMRIG_FEATURE_TLS const rapidjson::Value &tls = reader.getObject("tls"); if (tls.IsObject()) { - m_tls = std::move(TlsConfig(tls)); + m_tls = TlsConfig(tls); } # endif @@ -150,12 +146,12 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("background", isBackground(), allocator); Value bind(kArrayType); - for (const xmrig::BindHost &host : m_bind) { + for (const auto &host : m_bind) { bind.PushBack(host.toJSON(doc), allocator); } doc.AddMember("bind", bind, allocator); - doc.AddMember("colors", Log::colors, allocator); + doc.AddMember("colors", Log::isColors(), allocator); doc.AddMember("custom-diff", diff(), allocator); doc.AddMember("donate-level", m_pools.donateLevel(), allocator); doc.AddMember("log-file", m_logFile.toJSON(), allocator); @@ -177,6 +173,12 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const } +void xmrig::Config::toggleVerbose() +{ + Log::setVerbose(Log::isVerbose() ? 0 : 1); +} + + void xmrig::Config::setCustomDiff(uint64_t diff) { if (diff >= 100 && diff < INT_MAX) { diff --git a/src/core/config/Config.h b/src/core/config/Config.h index 655032b56..d53ee1e0b 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -26,7 +26,7 @@ #define XMRIG_CONFIG_H -#include +#include #include @@ -74,27 +74,26 @@ class Config : public BaseConfig bool isTLS() const; const char *modeName() const; + bool isVerbose() const; bool read(const IJsonReader &reader, const char *fileName) override; void getJSON(rapidjson::Document &doc) const override; + void toggleVerbose(); inline bool hasAlgoExt() const { return isDonateOverProxy() ? m_algoExt : true; } inline bool isDebug() const { return m_debug; } inline bool isDonateOverProxy() const { return m_pools.donateLevel() == 0 || m_mode == SIMPLE_MODE; } inline bool isShouldSave() const { return m_upgrade && isAutoSave(); } - inline bool isVerbose() const { return m_verbose; } + inline const BindHosts &bind() const { return m_bind; } inline const String &accessLog() const { return m_accessLog; } inline const String &password() const { return m_password; } - inline const xmrig::BindHosts &bind() const { return m_bind; } inline int mode() const { return m_mode; } inline int reuseTimeout() const { return m_reuseTimeout; } inline static IConfig *create() { return new Config(); } inline uint64_t diff() const { return m_diff; } - inline void setVerbose(bool verbose) { m_verbose = verbose; } - inline void toggleVerbose() { m_verbose = !m_verbose; } inline Workers::Mode workersMode() const { return m_workersMode; } # ifdef XMRIG_FEATURE_TLS - inline const xmrig::TlsConfig &tls() const { return m_tls; } + inline const TlsConfig &tls() const { return m_tls; } # endif private: @@ -103,15 +102,14 @@ class Config : public BaseConfig void setWorkersMode(const rapidjson::Value &value); BindHosts m_bind; - bool m_algoExt; - bool m_debug; - bool m_verbose; - int m_mode; - int m_reuseTimeout; + bool m_algoExt = true; + bool m_debug = false; + int m_mode = NICEHASH_MODE; + int m_reuseTimeout = 0; String m_accessLog; String m_password; - uint64_t m_diff; - Workers::Mode m_workersMode; + uint64_t m_diff = 0; + Workers::Mode m_workersMode = Workers::RigID; # ifdef XMRIG_FEATURE_TLS TlsConfig m_tls; diff --git a/src/core/config/ConfigTransform.cpp b/src/core/config/ConfigTransform.cpp index 9303441bc..a3ca9d8f8 100644 --- a/src/core/config/ConfigTransform.cpp +++ b/src/core/config/ConfigTransform.cpp @@ -37,9 +37,7 @@ static const char *kTls = "tls"; } -xmrig::ConfigTransform::ConfigTransform() -{ -} +xmrig::ConfigTransform::ConfigTransform() = default; void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const char *arg) @@ -68,7 +66,6 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const case IConfig::ProxyPasswordKey: /* --access-password */ return set(doc, "access-password", arg); - case IConfig::VerboseKey: /* --verbose */ case IConfig::DebugKey: /* --debug */ return transformBoolean(doc, key, true); @@ -112,9 +109,6 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key, bool enable) { switch (key) { - case IConfig::VerboseKey: /* --verbose */ - return set(doc, "verbose", enable); - case IConfig::DebugKey: /* --debug */ return set(doc, "debug", enable); diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index bf04911c4..a725890f8 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -112,6 +112,10 @@ static AlgoName const algorithm_names[] = { { "RandomXL", nullptr, Algorithm::RX_LOKI }, { "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/v", "rx/v", Algorithm::RX_V }, + { "RandomV", nullptr, Algorithm::RX_V }, # endif # ifdef XMRIG_ALGO_ARGON2 { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, @@ -138,6 +142,8 @@ size_t xmrig::Algorithm::l2() const switch (m_id) { case RX_0: case RX_LOKI: + case RX_SFX: + case RX_V: return 0x40000; case RX_WOW: @@ -157,7 +163,9 @@ size_t xmrig::Algorithm::l2() const size_t xmrig::Algorithm::l3() const { +# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_ARGON2) constexpr size_t oneMiB = 0x100000; +# endif const Family f = family(); assert(f != UNKNOWN); @@ -171,6 +179,8 @@ size_t xmrig::Algorithm::l3() const switch (m_id) { case RX_0: case RX_LOKI: + case RX_SFX: + case RX_V: return oneMiB * 2; case RX_WOW: @@ -270,6 +280,8 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) case RX_WOW: case RX_LOKI: case RX_ARQ: + case RX_SFX: + case RX_V: return RANDOM_X; # endif diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index 0c6f2649a..c72b4e6aa 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -67,6 +67,8 @@ class Algorithm RX_WOW, // "rx/wow" RandomWOW (Wownero). RX_LOKI, // "rx/loki" RandomXL (Loki). RX_ARQ, // "rx/arq" RandomARQ (Arqma). + RX_SFX, // "rx/sfx" RandomSFX (Safex Cash). + RX_V, // "rx/v" RandomV (Monerov). AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa). AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ) MAX diff --git a/src/proxy/tls/TlsConfig.cpp b/src/proxy/tls/TlsConfig.cpp index 52370c1da..e9b81f284 100644 --- a/src/proxy/tls/TlsConfig.cpp +++ b/src/proxy/tls/TlsConfig.cpp @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2016-2019 XMRig , * * 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 @@ -49,12 +49,14 @@ xmrig::TlsConfig::TlsConfig(const rapidjson::Value &object) : setCiphers(object["ciphers"].GetString()); setCipherSuites(object["ciphersuites"].GetString()); setDH(object["dhparam"].GetString()); + + if (m_key.isNull()) { + setKey(object["cert-key"].GetString()); + } } -xmrig::TlsConfig::~TlsConfig() -{ -} +xmrig::TlsConfig::~TlsConfig() = default; rapidjson::Value xmrig::TlsConfig::toJSON(rapidjson::Document &doc) const diff --git a/src/proxy/tls/TlsConfig.h b/src/proxy/tls/TlsConfig.h index 461abd5b3..c18af275d 100644 --- a/src/proxy/tls/TlsConfig.h +++ b/src/proxy/tls/TlsConfig.h @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2016-2019 XMRig , * * 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 diff --git a/src/version.h b/src/version.h index c9736d8dd..43f105404 100644 --- a/src/version.h +++ b/src/version.h @@ -28,15 +28,15 @@ #define APP_ID "xmrig-proxy" #define APP_NAME "xmrig-proxy" #define APP_DESC "XMRig Stratum proxy" -#define APP_VERSION "5.0.1" +#define APP_VERSION "5.4.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_KIND "proxy" #define APP_VER_MAJOR 5 -#define APP_VER_MINOR 0 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 4 +#define APP_VER_PATCH 0 #ifdef _MSC_VER # if (_MSC_VER >= 1920)