From 69903246812919f12ad1fa6f5fdae888da74c62b Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 16 Jun 2019 03:50:22 +0700 Subject: [PATCH] Allow null algorithm for pools. --- src/base/net/stratum/Client.cpp | 36 ++++++++++++++++----------------- src/base/net/stratum/Pool.cpp | 36 +++++++++++++++++++++------------ src/base/net/stratum/Pools.cpp | 2 +- src/crypto/common/Algorithm.cpp | 9 +++++++++ src/crypto/common/Algorithm.h | 5 +++++ 5 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 05e53c784..4234407ca 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -421,28 +421,28 @@ bool xmrig::Client::send(BIO *bio) bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const { -# ifdef XMRIG_PROXY_PROJECT - if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) { - return true; - } -# endif +//# ifdef XMRIG_PROXY_PROJECT +// if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) { +// return true; +// } +//# endif - if (m_pool.algorithm() == algorithm) { // FIXME - return true; - } +// if (m_pool.algorithm() == algorithm) { // FIXME +// return true; +// } - if (isQuiet()) { - return false; - } +// if (isQuiet()) { +// return false; +// } - if (algorithm.isValid()) { - LOG_ERR("Incompatible algorithm \"%s\" detected, reconnect", algorithm.name()); - } - else { - LOG_ERR("Unknown/unsupported algorithm detected, reconnect"); - } +// if (algorithm.isValid()) { +// LOG_ERR("Incompatible algorithm \"%s\" detected, reconnect", algorithm.name()); +// } +// else { +// LOG_ERR("Unknown/unsupported algorithm detected, reconnect"); +// } - return false; + return true; } diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index bb3fab72c..b11e1159e 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -172,7 +172,11 @@ bool xmrig::Pool::isEnabled() const } # endif - return m_flags.test(FLAG_ENABLED) && isValid() && algorithm().isValid(); + if (isDaemon() && !algorithm().isValid()) { + return false; + } + + return m_flags.test(FLAG_ENABLED) && isValid(); } @@ -259,28 +263,34 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const Value obj(kObjectType); - obj.AddMember(StringRef(kAlgo), StringRef(m_algorithm.shortName()), allocator); + obj.AddMember(StringRef(kAlgo), m_algorithm.toJSON(), allocator); obj.AddMember(StringRef(kUrl), m_url.toJSON(), allocator); obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator); - obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator); - obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator); -# ifndef XMRIG_PROXY_PROJECT - obj.AddMember(StringRef(kNicehash), isNicehash(), allocator); -# endif + if (!isDaemon()) { + obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator); + obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator); - if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) { - obj.AddMember(StringRef(kKeepalive), m_keepAlive > 0, allocator); - } - else { - obj.AddMember(StringRef(kKeepalive), m_keepAlive, allocator); +# ifndef XMRIG_PROXY_PROJECT + obj.AddMember(StringRef(kNicehash), isNicehash(), allocator); +# endif + + if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) { + obj.AddMember(StringRef(kKeepalive), m_keepAlive > 0, allocator); + } + else { + obj.AddMember(StringRef(kKeepalive), m_keepAlive, allocator); + } } obj.AddMember(StringRef(kEnabled), m_flags.test(FLAG_ENABLED), allocator); obj.AddMember(StringRef(kTls), isTLS(), allocator); obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator); obj.AddMember(StringRef(kDaemon), m_flags.test(FLAG_DAEMON), allocator); - obj.AddMember(StringRef(kDaemonPollInterval), m_pollInterval, allocator); + + if (isDaemon()) { + obj.AddMember(StringRef(kDaemonPollInterval), m_pollInterval, allocator); + } return obj; } diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index 985e5d4ec..4641ecd4f 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -139,7 +139,7 @@ void xmrig::Pools::print() const i, (pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31), pool.url().data(), - pool.algorithm().shortName() + pool.algorithm().isValid() ? pool.algorithm().shortName() : "auto" ); i++; diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 78272f796..b2f938961 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -31,6 +31,7 @@ #include "crypto/common/Algorithm.h" +#include "rapidjson/document.h" #ifdef _MSC_VER @@ -111,6 +112,14 @@ static AlgoName const algorithm_names[] = { } /* namespace xmrig */ +rapidjson::Value xmrig::Algorithm::toJSON() const +{ + using namespace rapidjson; + + return isValid() ? Value(StringRef(shortName())) : Value(kNullType); +} + + xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) { switch (id) { diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index c9388dee2..690814e7f 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -30,6 +30,9 @@ #include +#include "rapidjson/fwd.h" + + namespace xmrig { @@ -91,6 +94,8 @@ public: inline bool operator==(const Algorithm &other) const { return isEqual(other); } inline operator Algorithm::Id() const { return m_id; } + rapidjson::Value toJSON() const; + static Family family(Id id); static Id parse(const char *name);