Merge xmrig v6.4.0 into master

This commit is contained in:
MoneroOcean 2020-10-18 22:04:56 +00:00
commit 2cf2fcaf8c
109 changed files with 7365 additions and 6359 deletions

View file

@ -6,9 +6,9 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View file

@ -0,0 +1,62 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/NullClient.h"
#include "3rdparty/rapidjson/document.h"
#include "base/kernel/interfaces/IClientListener.h"
xmrig::NullClient::NullClient(IClientListener* listener) :
m_listener(listener)
{
m_job.setAlgorithm(Algorithm::RX_0);
std::vector<char> blob(112 * 2 + 1, '0');
blob.back() = '\0';
m_job.setBlob(blob.data());
blob[Job::kMaxSeedSize * 2] = '\0';
m_job.setSeedHash(blob.data());
m_job.setDiff(uint64_t(-1));
m_job.setHeight(1);
m_job.setId("00000000");
}
void xmrig::NullClient::connect()
{
m_listener->onLoginSuccess(this);
rapidjson::Value params;
m_listener->onJobReceived(this, m_job, params);
}
void xmrig::NullClient::setPool(const Pool& pool)
{
m_pool = pool;
if (!m_pool.algorithm().isValid()) {
m_pool.setAlgo(Algorithm::RX_0);
}
m_job.setAlgorithm(m_pool.algorithm().id());
}

View file

@ -0,0 +1,77 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_NULLCLIENT_H
#define XMRIG_NULLCLIENT_H
#include "base/net/stratum/Client.h"
namespace xmrig {
class NullClient : public IClient
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(NullClient)
NullClient(IClientListener* listener);
~NullClient() override = default;
inline bool disconnect() override { return true; }
inline bool hasExtension(Extension extension) const noexcept override { return false; }
inline bool isEnabled() const override { return true; }
inline bool isTLS() const override { return false; }
inline const char *mode() const override { return "benchmark"; }
inline const char *tag() const override { return "null"; }
inline const char *tlsFingerprint() const override { return nullptr; }
inline const char *tlsVersion() const override { return nullptr; }
inline const Job &job() const override { return m_job; }
inline const Pool &pool() const override { return m_pool; }
inline const String &ip() const override { return m_ip; }
inline int id() const override { return 0; }
inline int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; }
inline int64_t send(const rapidjson::Value& obj) override { return 0; }
inline int64_t sequence() const override { return 0; }
inline int64_t submit(const JobResult& result) override { return 0; }
inline void connect(const Pool& pool) override { setPool(pool); }
inline void deleteLater() override {}
inline void setAlgo(const Algorithm& algo) override {}
inline void setEnabled(bool enabled) override {}
inline void setProxy(const ProxyUrl& proxy) override {}
inline void setQuiet(bool quiet) override {}
inline void setRetries(int retries) override {}
inline void setRetryPause(uint64_t ms) override {}
inline void tick(uint64_t now) override {}
void connect() override;
void setPool(const Pool& pool) override;
private:
IClientListener* m_listener;
Job m_job;
Pool m_pool;
String m_ip;
};
} /* namespace xmrig */
#endif /* XMRIG_NULLCLIENT_H */

View file

@ -50,6 +50,16 @@
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
# include "base/net/stratum/NullClient.h"
#endif
#ifdef _MSC_VER
# define strcasecmp _stricmp
#endif
namespace xmrig {
@ -72,9 +82,11 @@ const char *Pool::kSOCKS5 = "socks5";
const char *Pool::kTls = "tls";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
const char *Pool::kNicehashHost = "nicehash.com";
const char *Pool::kNicehashHost = "nicehash.com";
#ifdef XMRIG_FEATURE_BENCHMARK
const char *Pool::kBenchmark = "benchmark";
#endif
}
@ -125,20 +137,22 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS());
setKeepAlive(Json::getValue(object, kKeepalive));
# ifdef XMRIG_FEATURE_BENCHMARK
if (setBenchSize(Json::getString(object, kBenchmark, nullptr))) {
m_mode = MODE_BENCHMARK;
return;
}
# endif
if (m_daemon.isValid()) {
m_mode = MODE_SELF_SELECT;
}
else if (Json::getBool(object, kDaemon)) {
m_mode = MODE_DAEMON;
}
const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive);
if (keepalive.IsInt()) {
setKeepAlive(keepalive.GetInt());
}
else if (keepalive.IsBool()) {
setKeepAlive(keepalive.GetBool());
}
}
@ -217,6 +231,11 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
client = new AutoClient(id, Platform::userAgent(), listener);
}
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
else if (m_mode == MODE_BENCHMARK) {
client = new NullClient(listener);
}
# endif
assert(client != nullptr);
@ -307,3 +326,34 @@ void xmrig::Pool::print() const
LOG_DEBUG ("keepAlive: %d", m_keepAlive);
}
#endif
void xmrig::Pool::setKeepAlive(const rapidjson::Value &value)
{
if (value.IsInt()) {
setKeepAlive(value.GetInt());
}
else if (value.IsBool()) {
setKeepAlive(value.GetBool());
}
}
#ifdef XMRIG_FEATURE_BENCHMARK
bool xmrig::Pool::setBenchSize(const char *benchmark)
{
if (!benchmark) {
return false;
}
const auto size = strtoul(benchmark, nullptr, 10);
if (size < 1 || size > 10) {
return false;
}
const std::string s = std::to_string(size) + "M";
m_benchSize = strcasecmp(benchmark, s.c_str()) == 0 ? size * 1000000 : 0;
return m_benchSize > 0;
}
#endif

View file

@ -50,7 +50,10 @@ public:
MODE_POOL,
MODE_DAEMON,
MODE_SELF_SELECT,
MODE_AUTO_ETH
MODE_AUTO_ETH,
# ifdef XMRIG_FEATURE_BENCHMARK
MODE_BENCHMARK,
# endif
};
static const String kDefaultPassword;
@ -73,6 +76,10 @@ public:
static const char *kUser;
static const char *kNicehashHost;
# ifdef XMRIG_FEATURE_BENCHMARK
static const char *kBenchmark;
# endif
constexpr static int kKeepAliveTimeout = 60;
constexpr static uint16_t kDefaultPort = 3333;
constexpr static uint64_t kDefaultPollInterval = 1000;
@ -105,6 +112,10 @@ public:
inline void setRigId(const String &rigId) { m_rigId = rigId; }
inline void setUser(const String &user) { m_user = user; }
# ifdef XMRIG_FEATURE_BENCHMARK
inline uint32_t benchSize() const { return m_benchSize; }
# endif
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
inline bool operator==(const Pool &other) const { return isEqual(other); }
@ -129,6 +140,8 @@ private:
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); }
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
void setKeepAlive(const rapidjson::Value &value);
Algorithm m_algorithm;
Coin m_coin;
int m_keepAlive = 0;
@ -142,6 +155,12 @@ private:
uint64_t m_pollInterval = kDefaultPollInterval;
Url m_daemon;
Url m_url;
# ifdef XMRIG_FEATURE_BENCHMARK
bool setBenchSize(const char *benchmark);
uint32_t m_benchSize = 0;
# endif
};

View file

@ -144,6 +144,18 @@ void xmrig::Pools::load(const IJsonReader &reader)
}
uint32_t xmrig::Pools::benchSize() const
{
# ifdef XMRIG_FEATURE_BENCHMARK
if (m_data.size() == 1 && m_data.front().mode() == Pool::MODE_BENCHMARK) {
return m_data.front().benchSize();
}
# endif
return 0;
}
void xmrig::Pools::print() const
{
size_t i = 1;

View file

@ -58,7 +58,7 @@ public:
Pools();
inline const std::vector<Pool> &data() const { return m_data; }
inline int donateLevel() const { return m_donateLevel; }
inline int donateLevel() const { return benchSize() ? 0 : m_donateLevel; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
@ -70,6 +70,7 @@ public:
IStrategy *createStrategy(IStrategyListener *listener) const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t active() const;
uint32_t benchSize() const;
void load(const IJsonReader &reader);
void print() const;