#1202 Fixed algorithm verification in donate strategy.
This commit is contained in:
parent
e66eeefb14
commit
680081b93b
5 changed files with 41 additions and 34 deletions
|
@ -97,7 +97,7 @@ public:
|
||||||
bool isEnabled(const Algorithm &algorithm) const
|
bool isEnabled(const Algorithm &algorithm) const
|
||||||
{
|
{
|
||||||
for (IBackend *backend : backends) {
|
for (IBackend *backend : backends) {
|
||||||
if (backend->isEnabled(algorithm)) {
|
if (backend->isEnabled() && backend->isEnabled(algorithm)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <inttypes.h>
|
#include <cinttypes>
|
||||||
|
#include <ctime>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
|
@ -83,11 +83,7 @@ xmrig::Network::~Network()
|
||||||
JobResults::stop();
|
JobResults::stop();
|
||||||
|
|
||||||
delete m_timer;
|
delete m_timer;
|
||||||
|
|
||||||
if (m_donate) {
|
|
||||||
delete m_donate;
|
delete m_donate;
|
||||||
}
|
|
||||||
|
|
||||||
delete m_strategy;
|
delete m_strategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,8 +300,8 @@ void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &do
|
||||||
results.AddMember("hashes_total", m_state.total, allocator);
|
results.AddMember("hashes_total", m_state.total, allocator);
|
||||||
|
|
||||||
Value best(kArrayType);
|
Value best(kArrayType);
|
||||||
for (size_t i = 0; i < m_state.topDiff.size(); ++i) {
|
for (uint64_t i : m_state.topDiff) {
|
||||||
best.PushBack(m_state.topDiff[i], allocator);
|
best.PushBack(i, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.AddMember("best", best, allocator);
|
results.AddMember("best", best, allocator);
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "base/kernel/interfaces/IBaseListener.h"
|
#include "base/kernel/interfaces/IBaseListener.h"
|
||||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||||
#include "base/kernel/interfaces/ITimerListener.h"
|
#include "base/kernel/interfaces/ITimerListener.h"
|
||||||
|
#include "base/tools/Object.h"
|
||||||
#include "interfaces/IJobResultListener.h"
|
#include "interfaces/IJobResultListener.h"
|
||||||
#include "net/NetworkState.h"
|
#include "net/NetworkState.h"
|
||||||
#include "rapidjson/fwd.h"
|
#include "rapidjson/fwd.h"
|
||||||
|
@ -49,6 +50,8 @@ class IStrategy;
|
||||||
class Network : public IJobResultListener, public IStrategyListener, public IBaseListener, public ITimerListener, public IApiListener
|
class Network : public IJobResultListener, public IStrategyListener, public IBaseListener, public ITimerListener, public IApiListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Network)
|
||||||
|
|
||||||
Network(Controller *controller);
|
Network(Controller *controller);
|
||||||
~Network() override;
|
~Network() override;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,17 +58,10 @@ static const char *kDonateHostTls = "donate.ssl.xmrig.com";
|
||||||
|
|
||||||
|
|
||||||
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) :
|
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) :
|
||||||
m_tls(false),
|
|
||||||
m_userId(),
|
|
||||||
m_donateTime(static_cast<uint64_t>(controller->config()->pools().donateLevel()) * 60 * 1000),
|
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_idleTime((100 - static_cast<uint64_t>(controller->config()->pools().donateLevel())) * 60 * 1000),
|
||||||
m_controller(controller),
|
m_controller(controller),
|
||||||
m_proxy(nullptr),
|
m_listener(listener)
|
||||||
m_strategy(nullptr),
|
|
||||||
m_listener(listener),
|
|
||||||
m_state(STATE_NEW),
|
|
||||||
m_now(0),
|
|
||||||
m_timestamp(0)
|
|
||||||
{
|
{
|
||||||
uint8_t hash[200];
|
uint8_t hash[200];
|
||||||
|
|
||||||
|
@ -77,15 +70,15 @@ xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener
|
||||||
Buffer::toHex(hash, 32, m_userId);
|
Buffer::toHex(hash, 32, m_userId);
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_TLS
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
m_pools.push_back(Pool(kDonateHostTls, 443, m_userId, nullptr, 0, true, true));
|
m_pools.emplace_back(kDonateHostTls, 443, m_userId, nullptr, 0, true, true);
|
||||||
# endif
|
# endif
|
||||||
m_pools.push_back(Pool(kDonateHost, 3333, m_userId, nullptr, 0, true));
|
m_pools.emplace_back(kDonateHost, 3333, m_userId, nullptr, 0, true);
|
||||||
|
|
||||||
if (m_pools.size() > 1) {
|
if (m_pools.size() > 1) {
|
||||||
m_strategy = new FailoverStrategy(m_pools, 1, 2, this, true);
|
m_strategy = new FailoverStrategy(m_pools, 10, 2, this, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true);
|
m_strategy = new SinglePoolStrategy(m_pools.front(), 10, 2, this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_timer = new Timer(this);
|
m_timer = new Timer(this);
|
||||||
|
@ -223,6 +216,18 @@ void xmrig::DonateStrategy::onLoginSuccess(IClient *client)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::DonateStrategy::onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok)
|
||||||
|
{
|
||||||
|
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::DonateStrategy::onVerifyAlgorithm(IStrategy *, const IClient *client, const Algorithm &algorithm, bool *ok)
|
||||||
|
{
|
||||||
|
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::DonateStrategy::onTimer(const Timer *)
|
void xmrig::DonateStrategy::onTimer(const Timer *)
|
||||||
{
|
{
|
||||||
setState(isActive() ? STATE_WAIT : STATE_CONNECT);
|
setState(isActive() ? STATE_WAIT : STATE_CONNECT);
|
||||||
|
@ -246,7 +251,7 @@ xmrig::Client *xmrig::DonateStrategy::createProxy()
|
||||||
Pool pool(client->ip(), client->pool().port(), m_userId, client->pool().password(), 0, true, client->isTLS());
|
Pool pool(client->ip(), client->pool().port(), m_userId, client->pool().password(), 0, true, client->isTLS());
|
||||||
pool.setAlgo(client->pool().algorithm());
|
pool.setAlgo(client->pool().algorithm());
|
||||||
|
|
||||||
Client *proxy = new Client(-1, Platform::userAgent(), this);
|
auto proxy = new Client(-1, Platform::userAgent(), this);
|
||||||
proxy->setPool(pool);
|
proxy->setPool(pool);
|
||||||
proxy->setQuiet(true);
|
proxy->setQuiet(true);
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||||
#include "base/kernel/interfaces/ITimerListener.h"
|
#include "base/kernel/interfaces/ITimerListener.h"
|
||||||
#include "base/net/stratum/Pool.h"
|
#include "base/net/stratum/Pool.h"
|
||||||
|
#include "base/tools/Object.h"
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
@ -47,6 +48,8 @@ class IStrategyListener;
|
||||||
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener
|
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener, public IClientListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE_DEFAULT(DonateStrategy)
|
||||||
|
|
||||||
DonateStrategy(Controller *controller, IStrategyListener *listener);
|
DonateStrategy(Controller *controller, IStrategyListener *listener);
|
||||||
~DonateStrategy() override;
|
~DonateStrategy() override;
|
||||||
|
|
||||||
|
@ -57,8 +60,6 @@ protected:
|
||||||
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); }
|
inline void onJobReceived(IClient *client, const Job &job, const rapidjson::Value &) override { setJob(client, job); }
|
||||||
inline void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
inline void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||||
inline void onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
inline void onResultAccepted(IStrategy *, IClient *client, const SubmitResult &result, const char *error) override { setResult(client, result, error); }
|
||||||
inline void onVerifyAlgorithm(const IClient *, const Algorithm &, bool *) override {}
|
|
||||||
inline void onVerifyAlgorithm(IStrategy *, const IClient *, const Algorithm &, bool *) override {}
|
|
||||||
inline void resume() override {}
|
inline void resume() override {}
|
||||||
|
|
||||||
int64_t submit(const JobResult &result) override;
|
int64_t submit(const JobResult &result) override;
|
||||||
|
@ -74,6 +75,8 @@ protected:
|
||||||
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||||
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override;
|
||||||
void onLoginSuccess(IClient *client) override;
|
void onLoginSuccess(IClient *client) override;
|
||||||
|
void onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok) override;
|
||||||
|
void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) override;
|
||||||
|
|
||||||
void onTimer(const Timer *timer) override;
|
void onTimer(const Timer *timer) override;
|
||||||
|
|
||||||
|
@ -96,19 +99,19 @@ private:
|
||||||
void setState(State state);
|
void setState(State state);
|
||||||
|
|
||||||
Algorithm m_algorithm;
|
Algorithm m_algorithm;
|
||||||
bool m_tls;
|
bool m_tls = false;
|
||||||
char m_userId[65];
|
char m_userId[65] = { 0 };
|
||||||
const uint64_t m_donateTime;
|
const uint64_t m_donateTime;
|
||||||
const uint64_t m_idleTime;
|
const uint64_t m_idleTime;
|
||||||
Controller *m_controller;
|
Controller *m_controller;
|
||||||
IClient *m_proxy;
|
IClient *m_proxy = nullptr;
|
||||||
IStrategy *m_strategy;
|
IStrategy *m_strategy = nullptr;
|
||||||
IStrategyListener *m_listener;
|
IStrategyListener *m_listener;
|
||||||
State m_state;
|
State m_state = STATE_NEW;
|
||||||
std::vector<Pool> m_pools;
|
std::vector<Pool> m_pools;
|
||||||
Timer *m_timer;
|
Timer *m_timer = nullptr;
|
||||||
uint64_t m_now;
|
uint64_t m_now = 0;
|
||||||
uint64_t m_timestamp;
|
uint64_t m_timestamp = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue