From 1ebaf677e0f056400b9c0ce951abd4456f2302e3 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 11 Apr 2018 06:39:24 +0700 Subject: [PATCH] Move static algo name conversions to Pool class. --- src/core/CommonConfig.cpp | 43 +-------------------------------------- src/core/CommonConfig.h | 6 ++---- src/net/Pool.cpp | 42 ++++++++++++++++++++++++++++++++++++++ src/net/Pool.h | 3 +++ src/workers/CpuThread.cpp | 2 +- 5 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/core/CommonConfig.cpp b/src/core/CommonConfig.cpp index b8af451b..b1758921 100644 --- a/src/core/CommonConfig.cpp +++ b/src/core/CommonConfig.cpp @@ -39,25 +39,6 @@ #include "xmrig.h" -static const char *algoNames[] = { - "cryptonight", - "cryptonight-lite", - "cryptonight-heavy" -}; - - -static const char *algoNamesShort[] = { - "cn", - "cn-lite", - "cn-heavy" -}; - - -#if defined(_WIN32) && !defined(strcasecmp) -# define strcasecmp _stricmp -#endif - - xmrig::CommonConfig::CommonConfig() : m_algorithm(CRYPTONIGHT), m_adjusted(false), @@ -93,12 +74,6 @@ xmrig::CommonConfig::~CommonConfig() } -const char *xmrig::CommonConfig::algoName(Algo algorithm) -{ - return algoNames[algorithm]; -} - - bool xmrig::CommonConfig::adjust() { if (m_adjusted) { @@ -353,21 +328,5 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) void xmrig::CommonConfig::setAlgo(const char *algo) { - if (strcasecmp(algo, "cryptonight-light") == 0) { - fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n"); - - m_algorithm = CRYPTONIGHT_LITE; - return; - } - - const size_t size = sizeof(algoNames) / sizeof(algoNames[0]); - - assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0]))); - - for (size_t i = 0; i < size; i++) { - if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) { - m_algorithm = static_cast(i); - break; - } - } + m_algorithm = Pool::algorithm(algo); } diff --git a/src/core/CommonConfig.h b/src/core/CommonConfig.h index 89dbc7ed..0b72b7e1 100644 --- a/src/core/CommonConfig.h +++ b/src/core/CommonConfig.h @@ -30,8 +30,8 @@ #include "core/utils/c_str.h" #include "interfaces/IConfig.h" -#include "xmrig.h" #include "net/Pool.h" +#include "xmrig.h" namespace xmrig { @@ -43,15 +43,13 @@ public: CommonConfig(); ~CommonConfig(); - static const char *algoName(Algo algorithm); - inline Algo algorithm() const { return m_algorithm; } inline bool isApiIPv6() const { return m_apiIPv6; } inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isSyslog() const { return m_syslog; } - inline const char *algoName() const { return algoName(m_algorithm); } + inline const char *algoName() const { return Pool::algoName(m_algorithm); } inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } diff --git a/src/net/Pool.cpp b/src/net/Pool.cpp index ff7d461a..f6816567 100644 --- a/src/net/Pool.cpp +++ b/src/net/Pool.cpp @@ -36,6 +36,20 @@ #endif +static const char *algoNames[] = { + "cryptonight", + "cryptonight-lite", + "cryptonight-heavy" +}; + + +static const char *algoNamesShort[] = { + "cn", + "cn-lite", + "cn-heavy" +}; + + Pool::Pool() : m_nicehash(false), m_keepAlive(0), @@ -89,6 +103,34 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo } +const char *Pool::algoName(xmrig::Algo algorithm) +{ + return algoNames[algorithm]; +} + + +xmrig::Algo Pool::algorithm(const char *algo) +{ + if (strcasecmp(algo, "cryptonight-light") == 0) { + fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n"); + + return xmrig::CRYPTONIGHT_LITE; + } + + const size_t size = sizeof(algoNames) / sizeof(algoNames[0]); + + assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0]))); + + for (size_t i = 0; i < size; i++) { + if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) { + return static_cast(i); + } + } + + return xmrig::CRYPTONIGHT; +} + + bool Pool::parse(const char *url) { assert(url != nullptr); diff --git a/src/net/Pool.h b/src/net/Pool.h index 5a2c3529..efa3e3a7 100644 --- a/src/net/Pool.h +++ b/src/net/Pool.h @@ -51,6 +51,9 @@ public: xmrig::Variant variant = xmrig::VARIANT_AUTO ); + static const char *algoName(xmrig::Algo algorithm); + static xmrig::Algo algorithm(const char *algo); + inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return !m_host.isNull() && m_port > 0; } inline const char *host() const { return m_host.data(); } diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 7e68a990..482b4305 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -204,7 +204,7 @@ rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const auto &allocator = doc.GetAllocator(); obj.AddMember("type", "cpu", allocator); - obj.AddMember("algo", rapidjson::StringRef(CommonConfig::algoName(algorithm())), allocator); + obj.AddMember("algo", rapidjson::StringRef(Pool::algoName(algorithm())), allocator); obj.AddMember("av", m_av, allocator); obj.AddMember("low_power_mode", multiway(), allocator); obj.AddMember("affine_to_cpu", affinity(), allocator);