From 41e8c4f887be3c0c1d4fae0faf80230a472238a7 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 26 Apr 2018 15:02:01 +0700 Subject: [PATCH] Send supported algorithms to pool in login request. --- src/common/crypto/Algorithm.cpp | 2 +- src/common/crypto/Algorithm.h | 6 ++++++ src/common/net/Client.cpp | 24 ++++++++++++++-------- src/common/net/Pool.cpp | 30 +++++++++++++++++++++++++++ src/common/net/Pool.h | 36 +++++++++++++++++---------------- src/common/xmrig.h | 2 +- src/crypto/CryptoNight_x86.h | 8 ++++---- src/workers/CpuThread.cpp | 22 ++++++++++---------- src/workers/MultiWorker.cpp | 2 +- 9 files changed, 89 insertions(+), 43 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 8d95acde..3123c361 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -62,7 +62,7 @@ static AlgoData const algorithms[] = { { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, - { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IBPC }, + { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, # endif # ifndef XMRIG_NO_SUMO diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index aff7a8c8..a34d5c07 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -26,6 +26,9 @@ #define __ALGORITHM_H__ +#include + + #include "common/xmrig.h" @@ -71,6 +74,9 @@ private: }; +typedef std::vector Algorithms; + + } /* namespace xmrig */ #endif /* __ALGORITHM_H__ */ diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 9a2b8b1b..c7cdd358 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -385,9 +385,10 @@ void Client::connect(sockaddr *addr) void Client::login() { + using namespace rapidjson; m_results.clear(); - rapidjson::Document doc; + Document doc; doc.SetObject(); auto &allocator = doc.GetAllocator(); @@ -396,19 +397,26 @@ void Client::login() doc.AddMember("jsonrpc", "2.0", allocator); doc.AddMember("method", "login", allocator); - rapidjson::Value params(rapidjson::kObjectType); - params.AddMember("login", rapidjson::StringRef(m_pool.user()), allocator); - params.AddMember("pass", rapidjson::StringRef(m_pool.password()), allocator); - params.AddMember("agent", rapidjson::StringRef(m_agent), allocator); + Value params(kObjectType); + params.AddMember("login", StringRef(m_pool.user()), allocator); + params.AddMember("pass", StringRef(m_pool.password()), allocator); + params.AddMember("agent", StringRef(m_agent), allocator); if (m_pool.rigId()) { - params.AddMember("rigid", rapidjson::StringRef(m_pool.rigId()), allocator); + params.AddMember("rigid", StringRef(m_pool.rigId()), allocator); } + Value algo(kArrayType); + + for (const auto &a : m_pool.algorithms()) { + algo.PushBack(StringRef(a.shortName()), allocator); + } + + params.AddMember("algo", algo, allocator); doc.AddMember("params", params, allocator); - rapidjson::StringBuffer buffer(0, 512); - rapidjson::Writer writer(buffer); + StringBuffer buffer(0, 512); + Writer writer(buffer); doc.Accept(writer); const size_t size = buffer.GetSize(); diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index d3c15056..aa1fa651 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -37,6 +37,9 @@ #endif +#define ADD_VARIANT(variant) m_algorithms.push_back(xmrig::Algorithm(m_algorithm.algo(), variant)); + + #ifdef _MSC_VER # define strncasecmp _strnicmp # define strcasecmp _stricmp @@ -224,6 +227,33 @@ void Pool::adjust(xmrig::Algo algorithm) m_keepAlive = false; m_algorithm.setVariant(xmrig::VARIANT_1); } + +# ifndef XMRIG_PROXY_PROJECT + switch (m_algorithm.algo()) { + case xmrig::CRYPTONIGHT: + ADD_VARIANT(xmrig::VARIANT_AUTO); + ADD_VARIANT(xmrig::VARIANT_0); + ADD_VARIANT(xmrig::VARIANT_1); + ADD_VARIANT(xmrig::VARIANT_XTL); + break; + + case xmrig::CRYPTONIGHT_LITE: + ADD_VARIANT(xmrig::VARIANT_AUTO); + ADD_VARIANT(xmrig::VARIANT_0); + ADD_VARIANT(xmrig::VARIANT_1); + ADD_VARIANT(xmrig::VARIANT_IPBC); + break; + + case xmrig::CRYPTONIGHT_HEAVY: + ADD_VARIANT(xmrig::VARIANT_0); + break; + + default: + break; + } +# else + m_algorithms.push_back(m_algorithm); +# endif } diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index 670924f2..eb926b3b 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -25,7 +25,7 @@ #define __POOL_H__ -#include +#include #include "common/crypto/Algorithm.h" @@ -51,22 +51,23 @@ public: bool nicehash = false ); - 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(); } - inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } - inline const char *rigId() const { return m_rigId.data(); } - inline const char *url() const { return m_url.data(); } - inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline int keepAlive() const { return m_keepAlive; } - inline uint16_t port() const { return m_port; } - inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } - inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } - inline void setPassword(const char *password) { m_password = password; } - inline void setRigId(const char *rigId) { m_rigId = rigId; } - inline void setUser(const char *user) { m_user = user; } - inline xmrig::Algorithm &algorithm() { return m_algorithm; } + 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(); } + inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; } + inline const char *rigId() const { return m_rigId.data(); } + inline const char *url() const { return m_url.data(); } + inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } + inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } + inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } + inline int keepAlive() const { return m_keepAlive; } + inline uint16_t port() const { return m_port; } + inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } + inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setPassword(const char *password) { m_password = password; } + inline void setRigId(const char *rigId) { m_rigId = rigId; } + inline void setUser(const char *user) { m_user = user; } + inline xmrig::Algorithm &algorithm() { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } @@ -88,6 +89,7 @@ private: int m_keepAlive; uint16_t m_port; xmrig::Algorithm m_algorithm; + xmrig::Algorithms m_algorithms; xmrig::c_str m_host; xmrig::c_str m_password; xmrig::c_str m_rigId; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 3349d3b6..a6fda9fc 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -61,7 +61,7 @@ enum Variant { VARIANT_AUTO = -1, // Autodetect VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 - VARIANT_IBPC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) + VARIANT_IPBC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) VARIANT_XTL = 3 // CryptoNight variant 1 (Stellite only) }; diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 75246b6e..75778053 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -460,7 +460,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (VARIANT > 0) { - if (VARIANT == xmrig::VARIANT_IBPC) { + if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -568,7 +568,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l0[idx0 & MASK])[0] = al0; if (VARIANT > 0) { - if (VARIANT == xmrig::VARIANT_IBPC) { + if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; } else { @@ -602,7 +602,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ((uint64_t*)&l1[idx1 & MASK])[0] = al1; if (VARIANT > 0) { - if (VARIANT == xmrig::VARIANT_IBPC) { + if (VARIANT == xmrig::VARIANT_IPBC) { ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; } else { @@ -672,7 +672,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si if (VARIANT > 0) { \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ \ - if (VARIANT == xmrig::VARIANT_IBPC) { \ + if (VARIANT == xmrig::VARIANT_IPBC) { \ ((uint64_t*)ptr)[1] ^= ((uint64_t*)ptr)[0]; \ } \ } else { \ diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 86699afc..e42139c0 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,7 +62,7 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IBPC || variant == VARIANT_XTL); + assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IPBC || variant == VARIANT_XTL); static const cn_hash_fun func_table[90] = { cryptonight_single_hash, @@ -123,16 +123,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, - cryptonight_single_hash, - cryptonight_double_hash, - cryptonight_single_hash, - cryptonight_double_hash, - cryptonight_triple_hash, - cryptonight_quad_hash, - cryptonight_penta_hash, - cryptonight_triple_hash, - cryptonight_quad_hash, - cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # else diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 012876a3..b3b384f6 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -69,7 +69,7 @@ bool MultiWorker::selfTest() return false; } - m_thread->fn(xmrig::VARIANT_IBPC)(test_input, 76, m_hash, m_ctx); + m_thread->fn(xmrig::VARIANT_IPBC)(test_input, 76, m_hash, m_ctx); return memcmp(m_hash, test_output_ipbc_lite, sizeof m_hash) == 0; } # endif