diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 75906621..431eff1d 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -141,7 +141,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) { switch (key) { case AlgorithmKey: /* --algo */ - setAlgo(arg); + m_algorithm = Pool::algorithm(arg); break; case UserpassKey: /* --userpass */ @@ -204,7 +204,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) case SyslogKey: /* --syslog */ case KeepAliveKey: /* --keepalive */ case NicehashKey: /* --nicehash */ - case ApiIPv6Key: /* --api-ipv6 */ + case ApiIPv6Key: /* --api-ipv6 */ return parseBoolean(key, true); case ColorKey: /* --no-color */ @@ -322,9 +322,3 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) return true; } - - -void xmrig::CommonConfig::setAlgo(const char *algo) -{ - m_algorithm = Pool::algorithm(algo); -} diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 015ba04e..ebeb41fe 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -96,7 +96,6 @@ protected: private: bool parseInt(int key, int arg); - void setAlgo(const char *algo); }; diff --git a/src/common/log/Log.h b/src/common/log/Log.h index f8c6a401..8434d779 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -80,6 +80,12 @@ private: }; +#define MAGENTA_BOLD(x) "\e[1;35m" x "\e[0m" +#define MAGENTA(x) "\e[0;35m" x "\e[0m" +#define WHITE_BOLD(x) "\e[1;37m" x "\e[0m" +#define WHITE(x) "\e[0;37m" x "\e[0m" + + #define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) #define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index a110b2ce..d7e88cbf 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -232,7 +232,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) return false; } - Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant(), m_rpcId); + Job job(m_id, m_nicehash, m_pool.algorithm(), m_pool.variant(), m_rpcId); if (!job.setId(params["job_id"].GetString())) { *code = 3; diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index c5f9902c..ec5279bf 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -65,7 +65,7 @@ Job::Job() : m_diff(0), m_target(0), m_blob(), - m_algo(xmrig::INVALID_ALGO), + m_algorithm(xmrig::INVALID_ALGO), m_variant(xmrig::VARIANT_AUTO) { } @@ -79,7 +79,7 @@ Job::Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, co m_diff(0), m_target(0), m_blob(), - m_algo(algo), + m_algorithm(algo), m_clientId(clientId), m_variant(variant) { @@ -170,7 +170,7 @@ void Job::setVariant(int variant) { switch (variant) { case xmrig::VARIANT_AUTO: - case xmrig::VARIANT_NONE: + case xmrig::VARIANT_V0: case xmrig::VARIANT_V1: m_variant = static_cast(variant); break; diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 4eb7018e..0e2951f3 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -61,7 +61,8 @@ public: inline void setClientId(const xmrig::Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } - inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_NONE) : m_variant); } + inline xmrig::Algo algorithm() const { return m_algorithm; } + inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_V0) : m_variant); } # ifdef XMRIG_PROXY_PROJECT inline char *rawBlob() { return m_rawBlob; } @@ -88,7 +89,7 @@ private: uint64_t m_diff; uint64_t m_target; uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. - xmrig::Algo m_algo; + xmrig::Algo m_algorithm; xmrig::Id m_clientId; xmrig::Id m_id; xmrig::Variant m_variant; diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 22f2a647..f1dd1352 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -81,7 +81,7 @@ Pool::Pool() : m_nicehash(false), m_keepAlive(0), m_port(kDefaultPort), - m_algo(xmrig::CRYPTONIGHT), + m_algorithm(xmrig::INVALID_ALGO), m_variant(xmrig::VARIANT_AUTO) { } @@ -102,7 +102,7 @@ Pool::Pool(const char *url) : m_nicehash(false), m_keepAlive(0), m_port(kDefaultPort), - m_algo(xmrig::CRYPTONIGHT), + m_algorithm(xmrig::INVALID_ALGO), m_variant(xmrig::VARIANT_AUTO) { parse(url); @@ -113,11 +113,11 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo m_nicehash(nicehash), m_keepAlive(keepAlive), m_port(port), - m_algo(xmrig::CRYPTONIGHT), + m_algorithm(xmrig::INVALID_ALGO), m_host(host), m_password(password), m_user(user), - m_variant(variant) + m_variant(variant) { const size_t size = m_host.size() + 8; assert(size > 8); @@ -131,6 +131,10 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo const char *Pool::algoName(xmrig::Algo algorithm, bool shortName) { + if (algorithm == xmrig::INVALID_ALGO) { + return "invalid"; + } + return (shortName ? algoNamesShort : algoNames)[algorithm]; } @@ -160,6 +164,20 @@ xmrig::Algo Pool::algorithm(const char *algo) } +bool Pool::isEqual(const Pool &other) const +{ + return (m_nicehash == other.m_nicehash + && m_keepAlive == other.m_keepAlive + && m_port == other.m_port + && m_algorithm == other.m_algorithm + && m_host == other.m_host + && m_password == other.m_password + && m_url == other.m_url + && m_user == other.m_user + && m_variant == other.m_variant); +} + + bool Pool::parse(const char *url) { assert(url != nullptr); @@ -218,13 +236,15 @@ bool Pool::setUserpass(const char *userpass) } -void Pool::adjust(xmrig::Algo algo) +void Pool::adjust(xmrig::Algo algorithm) { if (!isValid()) { return; } - m_algo = algo; + if (m_algorithm == xmrig::INVALID_ALGO) { + m_algorithm = algorithm; + } if (strstr(m_host.data(), ".nicehash.com")) { m_keepAlive = false; @@ -241,7 +261,7 @@ void Pool::setVariant(int variant) { switch (variant) { case xmrig::VARIANT_AUTO: - case xmrig::VARIANT_NONE: + case xmrig::VARIANT_V0: case xmrig::VARIANT_V1: m_variant = static_cast(variant); break; @@ -253,17 +273,20 @@ void Pool::setVariant(int variant) } -bool Pool::isEqual(const Pool &other) const +xmrig::Variant Pool::variant() const { - return (m_nicehash == other.m_nicehash - && m_keepAlive == other.m_keepAlive - && m_port == other.m_port - && m_algo == other.m_algo - && m_host == other.m_host - && m_password == other.m_password - && m_url == other.m_url - && m_user == other.m_user - && m_variant == other.m_variant); + switch (m_algorithm) { + case xmrig::CRYPTONIGHT_HEAVY: + return xmrig::VARIANT_V0; + + case xmrig::CRYPTONIGHT_IPBC: + return xmrig::VARIANT_V1; + + default: + break; + } + + return m_variant; } diff --git a/src/common/net/Pool.h b/src/common/net/Pool.h index 62c80185..a7e1ca8b 100644 --- a/src/common/net/Pool.h +++ b/src/common/net/Pool.h @@ -62,22 +62,23 @@ public: inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } inline int keepAlive() const { return m_keepAlive; } inline uint16_t port() const { return m_port; } + inline void setAlgo(const char *algo) { m_algorithm = algorithm(algo); } + inline void setAlgo(xmrig::Algo algorithm) { m_algorithm = algorithm; } 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 setUser(const char *user) { m_user = user; } - inline xmrig::Algo algo() const { return m_algo; } - inline xmrig::Variant variant() const { return m_variant; } + inline xmrig::Algo algorithm() const { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } + bool isEqual(const Pool &other) const; bool parse(const char *url); bool setUserpass(const char *userpass); - void adjust(xmrig::Algo algo); + void adjust(xmrig::Algo algorithm); void setVariant(int variant); - - bool isEqual(const Pool &other) const; + xmrig::Variant variant() const; private: bool parseIPv6(const char *addr); @@ -85,7 +86,7 @@ private: bool m_nicehash; int m_keepAlive; uint16_t m_port; - xmrig::Algo m_algo; + xmrig::Algo m_algorithm; xmrig::c_str m_host; xmrig::c_str m_password; xmrig::c_str m_url; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index 6bef4186..2de1a798 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -60,7 +60,7 @@ enum AlgoVariant { enum Variant { VARIANT_AUTO = -1, // Autodetect - VARIANT_NONE = 0, // Original CryptoNight + VARIANT_V0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_V1 = 1 // Monero v7 PoW }; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 5f6d73ee..4101245e 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -166,12 +166,9 @@ bool Network::isColors() const void Network::setJob(Client *client, const Job &job, bool donate) { - if (isColors()) { - LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff()); - } - else { - LOG_INFO("new job from %s:%d diff %d", client->host(), client->port(), job.diff()); - } + LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s/%d") + : "new job from %s:%d diff %d algo %s/%d", + client->host(), client->port(), job.diff(), Pool::algoName(job.algorithm(), true), static_cast(job.variant())); m_state.diff = job.diff(); Workers::setJob(job, donate); diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 2efe4977..ad8e88c0 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -26,6 +26,7 @@ #include "common/net/Client.h" #include "common/net/Job.h" #include "common/net/strategies/FailoverStrategy.h" +#include "common/net/strategies/SinglePoolStrategy.h" #include "common/Platform.h" #include "common/xmrig.h" #include "interfaces/IStrategyListener.h" @@ -41,7 +42,7 @@ static inline float randomf(float min, float max) { } -DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener) : +DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener) : m_active(false), m_donateTime(level * 60 * 1000), m_idleTime((100 - level) * 60 * 1000), @@ -61,14 +62,24 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL } else if (algo == xmrig::CRYPTONIGHT_HEAVY) { m_pools.push_back(Pool(kDonatePool1, 8888, userId, nullptr, false, true)); - m_pools.push_back(Pool(kDonatePool1, 8889, userId, nullptr, false, true)); + } + else if (algo == xmrig::CRYPTONIGHT_IPBC) { + m_pools.push_back(Pool(kDonatePool1, 13333, userId, nullptr, false, true)); } else { m_pools.push_back(Pool(kDonatePool1, 5555, userId, nullptr, false, true)); - m_pools.push_back(Pool(kDonatePool1, 7777, userId, nullptr, false, true)); } - m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true); + for (Pool &pool : m_pools) { + pool.setAlgo(algo); + } + + if (m_pools.size() > 1) { + m_strategy = new FailoverStrategy(m_pools, 1, 2, this, true); + } + else { + m_strategy = new SinglePoolStrategy(m_pools.front(), 1, this, true); + } m_timer.data = this; uv_timer_init(uv_default_loop(), &m_timer); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index edb15c8f..66c0375c 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -43,7 +43,7 @@ class Url; class DonateStrategy : public IStrategy, public IStrategyListener { public: - DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener); + DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); ~DonateStrategy(); public: diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index be24b2d5..5c0e8c0b 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -62,19 +62,19 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) { - assert(variant == VARIANT_NONE || variant == VARIANT_V1); + assert(variant == VARIANT_V0 || variant == VARIANT_V1); static const cn_hash_fun func_table[50] = { - 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, cryptonight_single_hash, cryptonight_double_hash, @@ -88,16 +88,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_penta_hash, # ifndef XMRIG_NO_AEON - 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, cryptonight_single_hash, cryptonight_double_hash, @@ -115,16 +115,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a # endif # ifndef XMRIG_NO_SUMO - 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, # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, # endif @@ -132,7 +132,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a # ifndef XMRIG_NO_SUMO if (algorithm == CRYPTONIGHT_HEAVY) { - variant = VARIANT_NONE; + variant = VARIANT_V0; } # endif diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 09dd568f..33f5864d 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -50,11 +50,11 @@ MultiWorker::~MultiWorker() template bool MultiWorker::selfTest() { - if (m_thread->fn(xmrig::VARIANT_NONE) == nullptr) { + if (m_thread->fn(xmrig::VARIANT_V0) == nullptr) { return false; } - m_thread->fn(xmrig::VARIANT_NONE)(test_input, 76, m_hash, m_ctx); + m_thread->fn(xmrig::VARIANT_V0)(test_input, 76, m_hash, m_ctx); if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, sizeof m_hash) == 0) { m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_hash, m_ctx);