From b719bbfefc0e747aedcecb737cac9f4f7f78765c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Jun 2018 16:08:08 +0700 Subject: [PATCH] Better variant detection for nicehash.com and minergate.com. --- src/common/net/Pool.cpp | 102 +++++++++++++++++++++++++++------------ src/common/net/Pool.h | 1 + src/common/utils/c_str.h | 6 +++ 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 58be044e..83dbc290 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -225,42 +225,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const void Pool::adjust(const xmrig::Algorithm &algorithm) { - using namespace xmrig; - if (!isValid()) { return; } if (!m_algorithm.isValid()) { m_algorithm.setAlgo(algorithm.algo()); - -# ifndef XMRIG_PROXY_PROJECT - if (m_algorithm.variant() == VARIANT_AUTO) { - if (algorithm.variant() != VARIANT_AUTO) { - m_algorithm.setVariant(algorithm.variant()); - } - else if (algorithm.algo() == CRYPTONIGHT_HEAVY) { - m_algorithm.setVariant(VARIANT_0); - } - else { - m_algorithm.setVariant(VARIANT_1); - } - } -# endif - } - - if (strstr(m_host.data(), ".nicehash.com")) { - m_keepAlive = false; - m_nicehash = true; - - if (strstr(m_host.data(), "cryptonightv7.")) { - m_algorithm.setVariant(VARIANT_1); - } - } - - if (strstr(m_host.data(), ".minergate.com")) { - m_keepAlive = false; - m_algorithm.setVariant(VARIANT_1); + adjustVariant(algorithm.variant()); } rebuild(); @@ -325,9 +296,80 @@ void Pool::addVariant(xmrig::Variant variant) } +void Pool::adjustVariant(const xmrig::Variant variantHint) +{ +# ifndef XMRIG_PROXY_PROJECT + using namespace xmrig; + + if (m_host.contains(".nicehash.com")) { + m_keepAlive = false; + m_nicehash = true; + bool valid = true; + + if (m_host.contains("cryptonight.") && m_port == 3355) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(VARIANT_0); + } + else if (m_host.contains("cryptonightv7.") && m_port == 3363) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(VARIANT_1); + } + else if (m_host.contains("cryptonightheavy.") && m_port == 3364) { + valid = m_algorithm.algo() == CRYPTONIGHT_HEAVY; + m_algorithm.setVariant(VARIANT_0); + } + + if (!valid) { + m_algorithm.setAlgo(INVALID_ALGO); + } + + return; + } + + if (m_host.contains(".minergate.com")) { + m_keepAlive = false; + bool valid = true; + m_algorithm.setVariant(VARIANT_1); + + if (m_host.contains("xmr.pool.")) { + valid = m_algorithm.algo() == CRYPTONIGHT; + m_algorithm.setVariant(m_port == 45700 ? VARIANT_1 : VARIANT_0); + } + else if (m_host.contains("aeon.pool.") && m_port == 45690) { + valid = m_algorithm.algo() == CRYPTONIGHT_LITE; + m_algorithm.setVariant(VARIANT_1); + } + + if (!valid) { + m_algorithm.setAlgo(INVALID_ALGO); + } + + return; + } + + if (variantHint != VARIANT_AUTO) { + m_algorithm.setVariant(variantHint); + return; + } + + if (m_algorithm.algo() == CRYPTONIGHT_HEAVY) { + m_algorithm.setVariant(VARIANT_0); + } + else { + m_algorithm.setVariant(VARIANT_1); + } +# endif +} + + void Pool::rebuild() { m_algorithms.clear(); + + if (!m_algorithm.isValid()) { + return; + } + m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index e6ecef4a..57a30d1e 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -87,6 +87,7 @@ public: private: bool parseIPv6(const char *addr); void addVariant(xmrig::Variant variant); + void adjustVariant(const xmrig::Variant variantHint); void rebuild(); bool m_nicehash; diff --git a/src/common/utils/c_str.h b/src/common/utils/c_str.h index 3cc4d326..7ce63754 100644 --- a/src/common/utils/c_str.h +++ b/src/common/utils/c_str.h @@ -72,6 +72,12 @@ public: } + inline bool contains(const char *str) const + { + return strstr(m_data, str) != nullptr; + } + + inline bool isNull() const { return m_data == nullptr; } inline const char *data() const { return m_data; } inline size_t size() const { return m_data == nullptr ? 0 : strlen(m_data); }