From d57b41c67303b39e390a2a4d657d51dc22a8b9cc Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Mar 2019 18:42:27 +0700 Subject: [PATCH] Sync changes. --- CMakeLists.txt | 1 + src/base/net/Pool.cpp | 2 +- src/base/tools/Chrono.h | 60 +++++++++++++++++++ src/common/interfaces/IClientListener.h | 6 +- src/common/interfaces/IConfig.h | 2 + src/common/net/Client.cpp | 8 ++- src/common/net/Job.h | 8 ++- .../net/strategies/FailoverStrategy.cpp | 2 +- src/common/net/strategies/FailoverStrategy.h | 4 +- .../net/strategies/SinglePoolStrategy.cpp | 2 +- .../net/strategies/SinglePoolStrategy.h | 4 +- src/crypto/CryptoNight_constants.h | 26 ++++++++ 12 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 src/base/tools/Chrono.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 14dcc931a..94bf61b63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ set(HEADERS src/base/net/Pool.h src/base/net/Pools.h src/base/tools/Arguments.h + src/base/tools/Chrono.h src/base/tools/Handle.h src/base/tools/String.h src/common/config/CommonConfig.h diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index 9d4f2bde6..de02be92c 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -165,7 +165,7 @@ bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const # ifdef XMRIG_PROXY_PROJECT if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT) { - return m_algorithm.variant() == xmrig::VARIANT_XTL || m_algorithm.variant() == xmrig::VARIANT_MSR; + return m_algorithm.variant() == xmrig::VARIANT_RWZ || m_algorithm.variant() == xmrig::VARIANT_ZLS; } # endif diff --git a/src/base/tools/Chrono.h b/src/base/tools/Chrono.h new file mode 100644 index 000000000..d3c146028 --- /dev/null +++ b/src/base/tools/Chrono.h @@ -0,0 +1,60 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_CHRONO_H +#define XMRIG_CHRONO_H + + +#include + + +namespace xmrig { + + +class Chrono +{ +public: + static inline uint64_t steadyMSecs() + { + using namespace std::chrono; + if (high_resolution_clock::is_steady) { + return static_cast(time_point_cast(high_resolution_clock::now()).time_since_epoch().count()); + } + + return static_cast(time_point_cast(steady_clock::now()).time_since_epoch().count()); + } + + + static inline uint64_t currentMSecsSinceEpoch() + { + using namespace std::chrono; + + return static_cast(time_point_cast(system_clock::now()).time_since_epoch().count()); + } +}; + + +} /* namespace xmrig */ + +#endif /* XMRIG_CHRONO_H */ diff --git a/src/common/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h index 70a3d1d0f..753847eef 100644 --- a/src/common/interfaces/IClientListener.h +++ b/src/common/interfaces/IClientListener.h @@ -29,6 +29,9 @@ #include +#include "rapidjson/fwd.h" + + namespace xmrig { @@ -43,7 +46,8 @@ public: virtual ~IClientListener() = default; virtual void onClose(Client *client, int failures) = 0; - virtual void onJobReceived(Client *client, const Job &job) = 0; + virtual void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) = 0; + virtual void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value ¶ms) = 0; virtual void onLoginSuccess(Client *client) = 0; virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; }; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 7e6931a89..41a2f01c5 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -117,6 +117,8 @@ public: TlsCiphersKey = 1112, TlsCipherSuitesKey = 1113, TlsProtocolsKey = 1114, + AlgoExtKey = 1115, + ProxyPasswordKey = 1116, // xmrig nvidia CudaMaxThreadsKey = 1200, diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 7cd09d46b..c08109275 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -252,7 +252,7 @@ int64_t xmrig::Client::submit(const JobResult &result) params.AddMember("nonce", StringRef(nonce), allocator); params.AddMember("result", StringRef(data), allocator); - if (m_extensions & AlgoExt) { + if ((m_extensions & AlgoExt) && result.algorithm.isValid()) { params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator); } @@ -643,6 +643,8 @@ void xmrig::Client::login() params.AddMember("algo", algo, allocator); } + m_listener->onLogin(this, doc, params); + doc.AddMember("params", params, allocator); send(doc); @@ -750,7 +752,7 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value if (strcmp(method, "job") == 0) { int code = -1; if (parseJob(params, &code)) { - m_listener->onJobReceived(this, m_job); + m_listener->onJobReceived(this, m_job, params); } return; @@ -799,7 +801,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co m_failures = 0; m_listener->onLoginSuccess(this); - m_listener->onJobReceived(this, m_job); + m_listener->onJobReceived(this, m_job, result["job"]); return; } diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 49ddc7da3..a6e1ec257 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -58,18 +58,19 @@ public: inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool setId(const char *id) { return m_id.setId(id); } - inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } - inline const uint8_t *blob() const { return m_blob; } inline const Algorithm &algorithm() const { return m_algorithm; } inline const Id &clientId() const { return m_clientId; } inline const Id &id() const { return m_id; } + inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } + inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } inline uint32_t diff() const { return static_cast(m_diff); } - inline uint64_t target() const { return m_target; } inline uint64_t height() const { return m_height; } + inline uint64_t target() const { return m_target; } + inline uint8_t fixedByte() const { return *(m_blob + 42); } inline void reset() { m_size = 0; m_diff = 0; } inline void setClientId(const Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } @@ -79,6 +80,7 @@ public: # ifdef XMRIG_PROXY_PROJECT inline char *rawBlob() { return m_rawBlob; } + inline const char *rawBlob() const { return m_rawBlob; } inline const char *rawTarget() const { return m_rawTarget; } # endif diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index c833f6e6e..1ec7449f9 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -150,7 +150,7 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures) } -void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &) { if (m_active == client->id()) { m_listener->onJob(this, client, job); diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index d2231a30b..a02b590e4 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -61,8 +61,10 @@ public: void tick(uint64_t now) override; protected: + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} + void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; + void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index d17a43da1..ca5d45f73 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -98,7 +98,7 @@ void xmrig::SinglePoolStrategy::onClose(Client *, int) } -void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &) { m_listener->onJob(this, client, job); } diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index eeb6903e8..7d864263e 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -55,8 +55,10 @@ public: void tick(uint64_t now) override; protected: + inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {} + void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; + void onJobReceived(Client *client, const Job &job, const rapidjson::Value ¶ms) override; void onLoginSuccess(Client *client) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 58a3915fc..1bc06a3bb 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -215,6 +215,32 @@ template<> inline constexpr Variant cn_base_variant() { return V template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +inline Variant cn_base_variant(Variant variant) +{ + switch (variant) { + case VARIANT_0: + case VARIANT_XHV: + case VARIANT_XAO: + return VARIANT_0; + + case VARIANT_1: + case VARIANT_TUBE: + case VARIANT_XTL: + case VARIANT_MSR: + case VARIANT_RTO: + return VARIANT_1; + + case VARIANT_GPU: + return VARIANT_GPU; + + default: + break; + } + + return VARIANT_2; +} + + template inline constexpr bool cn_is_cryptonight_r() { return false; } template<> inline constexpr bool cn_is_cryptonight_r() { return true; } template<> inline constexpr bool cn_is_cryptonight_r() { return true; }