Restored algo field in login request.

This commit is contained in:
XMRig 2019-07-18 22:35:15 +07:00
parent f590cf58fb
commit 0ab26a1619
14 changed files with 129 additions and 35 deletions

View file

@ -174,6 +174,10 @@ void xmrig::CpuWorker<N>::start()
const Job &job = m_job.currentJob();
if (job.algorithm().memory() != m_algorithm.memory()) {
break;
}
# ifdef XMRIG_ALGO_RANDOMX
if (job.algorithm().family() == Algorithm::RANDOM_X) {
randomx_calculate_hash(m_vm->get(), m_job.blob(), job.size(), m_hash);

View file

@ -26,7 +26,7 @@
#define XMRIG_ISTRATEGYLISTENER_H
#include <stdint.h>
#include "rapidjson/fwd.h"
namespace xmrig {
@ -45,6 +45,7 @@ public:
virtual void onActive(IStrategy *strategy, IClient *client) = 0;
virtual void onJob(IStrategy *strategy, IClient *client, const Job &job) = 0;
virtual void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value &params) = 0;
virtual void onPause(IStrategy *strategy) = 0;
virtual void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) = 0;
};

View file

@ -575,19 +575,6 @@ void xmrig::Client::login()
params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
}
//# ifdef XMRIG_PROXY_PROJECT FIXME
// if (m_pool.algorithm().variant() != xmrig::VARIANT_AUTO)
//# endif
// {
// Value algo(kArrayType);
// for (const auto &a : m_pool.algorithms()) {
// algo.PushBack(StringRef(a.shortName()), allocator);
// }
// params.AddMember("algo", algo, allocator);
// }
m_listener->onLogin(this, doc, params);
JsonRequest::create(doc, 1, "login", params);

View file

@ -113,7 +113,7 @@ void xmrig::FailoverStrategy::resume()
}
void xmrig::FailoverStrategy::setAlgo(const xmrig::Algorithm &algo)
void xmrig::FailoverStrategy::setAlgo(const Algorithm &algo)
{
for (IClient *client : m_pools) {
client->setAlgo(algo);
@ -163,6 +163,12 @@ void xmrig::FailoverStrategy::onClose(IClient *client, int failures)
}
void xmrig::FailoverStrategy::onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params)
{
m_listener->onLogin(this, client, doc, params);
}
void xmrig::FailoverStrategy::onJobReceived(IClient *client, const Job &job, const rapidjson::Value &)
{
if (m_active == client->id()) {

View file

@ -53,7 +53,6 @@ public:
protected:
inline bool isActive() const override { return m_active >= 0; }
inline IClient *client() const override { return isActive() ? active() : m_pools[m_index]; }
inline void onLogin(IClient *, rapidjson::Document &, rapidjson::Value &) override {}
int64_t submit(const JobResult &result) override;
void connect() override;
@ -64,6 +63,7 @@ protected:
void onClose(IClient *client, int failures) override;
void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &params) override;
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onLoginSuccess(IClient *client) override;
void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override;

View file

@ -84,7 +84,7 @@ void xmrig::SinglePoolStrategy::resume()
}
void xmrig::SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo)
void xmrig::SinglePoolStrategy::setAlgo(const Algorithm &algo)
{
m_client->setAlgo(algo);
}
@ -119,6 +119,12 @@ void xmrig::SinglePoolStrategy::onJobReceived(IClient *client, const Job &job, c
}
void xmrig::SinglePoolStrategy::onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params)
{
m_listener->onLogin(this, client, doc, params);
}
void xmrig::SinglePoolStrategy::onLoginSuccess(IClient *client)
{
m_active = true;

View file

@ -47,7 +47,6 @@ public:
protected:
inline bool isActive() const override { return m_active; }
inline IClient *client() const override { return m_client; }
inline void onLogin(IClient *, rapidjson::Document &, rapidjson::Value &) override {}
int64_t submit(const JobResult &result) override;
void connect() override;
@ -58,6 +57,7 @@ protected:
void onClose(IClient *client, int failures) override;
void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &params) override;
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onLoginSuccess(IClient *client) override;
void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override;

View file

@ -62,17 +62,46 @@ public:
}
bool isEnabled(const Algorithm &algorithm) const
{
for (IBackend *backend : backends) {
if (backend->isEnabled(algorithm)) {
return true;
}
}
return false;
}
inline void rebuild()
{
algorithms.clear();
for (int i = 0; i < Algorithm::MAX; ++i) {
const Algorithm algo(static_cast<Algorithm::Id>(i));
if (isEnabled(algo)) {
algorithms.push_back(algo);
}
}
}
inline void handleJobChange()
{
active = true;
if (enabled) {
Nonce::pause(false);;
}
for (IBackend *backend : backends) {
backend->setJob(job);
}
if (enabled) {
Nonce::pause(false);;
}
Nonce::reset(job.index());
if (ticks == 0) {
ticks++;
timer->start(500, 500);
@ -80,6 +109,7 @@ public:
}
Algorithms algorithms;
bool active = false;
bool enabled = true;
Controller *controller;
@ -104,6 +134,8 @@ xmrig::Miner::Miner(Controller *controller)
d_ptr->timer = new Timer(this);
d_ptr->backends.push_back(new CpuBackend(controller));
d_ptr->rebuild();
}
@ -119,6 +151,12 @@ bool xmrig::Miner::isEnabled() const
}
const xmrig::Algorithms &xmrig::Miner::algorithms() const
{
return d_ptr->algorithms;
}
const std::vector<xmrig::IBackend *> &xmrig::Miner::backends() const
{
return d_ptr->backends;
@ -202,8 +240,6 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
d_ptr->job = job;
d_ptr->job.setIndex(index);
Nonce::reset(index);
uv_rwlock_wrunlock(&d_ptr->rwlock);
d_ptr->handleJobChange();
@ -222,6 +258,8 @@ void xmrig::Miner::stop()
void xmrig::Miner::onConfigChanged(Config *config, Config *previousConfig)
{
d_ptr->rebuild();
if (config->pools() != previousConfig->pools() && config->pools().active() > 0) {
return;
}

View file

@ -31,6 +31,7 @@
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "crypto/common/Algorithm.h"
namespace xmrig {
@ -49,6 +50,7 @@ public:
~Miner() override;
bool isEnabled() const;
const Algorithms &algorithms() const;
const std::vector<IBackend *> &backends() const;
Job job() const;
void pause();

View file

@ -115,7 +115,7 @@ private:
};
typedef std::vector<xmrig::Algorithm> Algorithms;
typedef std::vector<Algorithm> Algorithms;
} /* namespace xmrig */

View file

@ -154,6 +154,21 @@ void xmrig::Network::onJobResult(const JobResult &result)
}
void xmrig::Network::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value &params)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
Value algo(kArrayType);
for (const auto &a : m_controller->miner()->algorithms()) {
algo.PushBack(StringRef(a.shortName()), allocator);
}
params.AddMember("algo", algo, allocator);
}
void xmrig::Network::onPause(IStrategy *strategy)
{
if (m_donate && m_donate == strategy) {

View file

@ -63,6 +63,7 @@ protected:
void onConfigChanged(Config *config, Config *previousConfig) override;
void onJob(IStrategy *strategy, IClient *client, const Job &job) override;
void onJobResult(const JobResult &result) override;
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onPause(IStrategy *strategy) override;
void onRequest(IApiRequest &request) override;
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;

View file

@ -23,7 +23,9 @@
*/
#include <algorithm>
#include <assert.h>
#include <iterator>
#include "base/kernel/Platform.h"
@ -35,6 +37,7 @@
#include "base/tools/Timer.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "core/Miner.h"
#include "crypto/common/keccak.h"
#include "net/Network.h"
#include "net/strategies/DonateStrategy.h"
@ -57,10 +60,10 @@ static const char *kDonateHostTls = "donate.ssl.xmrig.com";
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) :
m_tls(false),
m_userId(),
m_proxy(nullptr),
m_donateTime(static_cast<uint64_t>(controller->config()->pools().donateLevel()) * 60 * 1000),
m_idleTime((100 - static_cast<uint64_t>(controller->config()->pools().donateLevel())) * 60 * 1000),
m_controller(controller),
m_proxy(nullptr),
m_strategy(nullptr),
m_listener(listener),
m_state(STATE_NEW),
@ -78,10 +81,6 @@ xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener
# endif
m_pools.push_back(Pool(kDonateHost, 3333, m_userId, nullptr, 0, true));
// for (Pool &pool : m_pools) {
// pool.adjust(Algorithm()); // FIXME
// }
if (m_pools.size() > 1) {
m_strategy = new FailoverStrategy(m_pools, 1, 2, this, true);
}
@ -129,6 +128,8 @@ void xmrig::DonateStrategy::connect()
void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo)
{
m_algorithm = algo;
m_strategy->setAlgo(algo);
}
@ -185,13 +186,14 @@ void xmrig::DonateStrategy::onClose(IClient *, int failures)
void xmrig::DonateStrategy::onLogin(IClient *, rapidjson::Document &doc, rapidjson::Value &params)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
# ifdef XMRIG_FEATURE_TLS
if (m_tls) {
char buf[40] = { 0 };
snprintf(buf, sizeof(buf), "stratum+ssl://%s", m_pools[0].url().data());
params.AddMember("url", rapidjson::Value(buf, allocator), allocator);
params.AddMember("url", Value(buf, allocator), allocator);
}
else {
params.AddMember("url", m_pools[1].url().toJSON(), allocator);
@ -199,6 +201,14 @@ void xmrig::DonateStrategy::onLogin(IClient *, rapidjson::Document &doc, rapidjs
# else
params.AddMember("url", m_pools[0].url().toJSON(), allocator);
# endif
setAlgorithms(doc, params);
}
void xmrig::DonateStrategy::onLogin(IStrategy *, IClient *, rapidjson::Document &doc, rapidjson::Value &params)
{
setAlgorithms(doc, params);
}
@ -250,6 +260,27 @@ void xmrig::DonateStrategy::idle(double min, double max)
}
void xmrig::DonateStrategy::setAlgorithms(rapidjson::Document &doc, rapidjson::Value &params)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
Algorithms algorithms = m_controller->miner()->algorithms();
const size_t index = static_cast<size_t>(std::distance(algorithms.begin(), std::find(algorithms.begin(), algorithms.end(), m_algorithm)));
if (index > 0 && index < algorithms.size()) {
std::swap(algorithms[0], algorithms[index]);
}
Value algo(kArrayType);
for (const auto &a : algorithms) {
algo.PushBack(StringRef(a.shortName()), allocator);
}
params.AddMember("algo", algo, allocator);
}
void xmrig::DonateStrategy::setJob(IClient *client, const Job &job)
{
if (isActive()) {

View file

@ -70,6 +70,7 @@ protected:
void onClose(IClient *client, int failures) override;
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value &params) override;
void onLoginSuccess(IClient *client) override;
void onTimer(const Timer *timer) override;
@ -87,16 +88,18 @@ private:
Client *createProxy();
void idle(double min, double max);
void setAlgorithms(rapidjson::Document &doc, rapidjson::Value &params);
void setJob(IClient *client, const Job &job);
void setResult(IClient *client, const SubmitResult &result, const char *error);
void setState(State state);
Algorithm m_algorithm;
bool m_tls;
char m_userId[65];
IClient *m_proxy;
const uint64_t m_donateTime;
const uint64_t m_idleTime;
Controller *m_controller;
IClient *m_proxy;
IStrategy *m_strategy;
IStrategyListener *m_listener;
State m_state;