Restored algorithm verification.

This commit is contained in:
XMRig 2019-07-19 00:39:27 +07:00
parent 88edde804f
commit 691b2fabbf
13 changed files with 56 additions and 23 deletions

View file

@ -35,6 +35,7 @@
namespace xmrig {
class Algorithm;
class IClient;
class Job;
class SubmitResult;
@ -50,6 +51,7 @@ public:
virtual void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value &params) = 0;
virtual void onLoginSuccess(IClient *client) = 0;
virtual void onResultAccepted(IClient *client, const SubmitResult &result, const char *error) = 0;
virtual void onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok) = 0;
};

View file

@ -32,6 +32,7 @@
namespace xmrig {
class Algorithm;
class IClient;
class IStrategy;
class Job;
@ -48,6 +49,7 @@ public:
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;
virtual void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) = 0;
};

View file

@ -330,14 +330,15 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
if (params.HasMember("algo")) {
job.setAlgorithm(params["algo"].GetString());
const char *algo = Json::getString(params, "algo");
if (algo) {
job.setAlgorithm(algo);
}
job.setSeedHash(Json::getString(params, "seed_hash"));
job.setHeight(Json::getUint64(params, "height"));
if (!verifyAlgorithm(job.algorithm())) {
if (!verifyAlgorithm(job.algorithm(), algo)) {
*code = 6;
close();
@ -415,30 +416,24 @@ bool xmrig::Client::send(BIO *bio)
}
bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const
bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo) const
{
//# ifdef XMRIG_PROXY_PROJECT
// if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) {
// return true;
// }
//# endif
if (!algorithm.isValid()) {
if (!isQuiet()) {
LOG_ERR("[%s] Unknown/unsupported algorithm \"%s\" detected, reconnect", url(), algo);
}
// if (m_pool.algorithm() == algorithm) { // FIXME
// return true;
// }
return false;
}
// if (isQuiet()) {
// return false;
// }
bool ok = true;
m_listener->onVerifyAlgorithm(this, algorithm, &ok);
// if (algorithm.isValid()) {
// LOG_ERR("Incompatible algorithm \"%s\" detected, reconnect", algorithm.name());
// }
// else {
// LOG_ERR("Unknown/unsupported algorithm detected, reconnect");
// }
if (!ok && !isQuiet()) {
LOG_ERR("[%s] Incompatible/disabled algorithm \"%s\" detected, reconnect", url(), algorithm.shortName());
}
return true;
return ok;
}

View file

@ -92,7 +92,7 @@ private:
bool parseJob(const rapidjson::Value &params, int *code);
bool parseLogin(const rapidjson::Value &result, int *code);
bool send(BIO *bio);
bool verifyAlgorithm(const Algorithm &algorithm) const;
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
int resolve(const String &host);
int64_t send(const rapidjson::Document &doc);
int64_t send(size_t size);

View file

@ -202,3 +202,9 @@ void xmrig::FailoverStrategy::onResultAccepted(IClient *client, const SubmitResu
{
m_listener->onResultAccepted(this, client, result, error);
}
void xmrig::FailoverStrategy::onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok)
{
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
}

View file

@ -66,6 +66,7 @@ protected:
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;
void onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok) override;
private:
inline IClient *active() const { return m_pools[static_cast<size_t>(m_active)]; }

View file

@ -136,3 +136,9 @@ void xmrig::SinglePoolStrategy::onResultAccepted(IClient *client, const SubmitRe
{
m_listener->onResultAccepted(this, client, result, error);
}
void xmrig::SinglePoolStrategy::onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok)
{
m_listener->onVerifyAlgorithm(this, client, algorithm, ok);
}

View file

@ -60,6 +60,7 @@ protected:
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;
void onVerifyAlgorithm(const IClient *client, const Algorithm &algorithm, bool *ok) override;
private:
bool m_active;

View file

@ -157,6 +157,12 @@ bool xmrig::Miner::isEnabled() const
}
bool xmrig::Miner::isEnabled(const Algorithm &algorithm) const
{
return std::find(d_ptr->algorithms.begin(), d_ptr->algorithms.end(), algorithm) != d_ptr->algorithms.end();
}
const xmrig::Algorithms &xmrig::Miner::algorithms() const
{
return d_ptr->algorithms;

View file

@ -50,6 +50,7 @@ public:
~Miner() override;
bool isEnabled() const;
bool isEnabled(const Algorithm &algorithm) const;
const Algorithms &algorithms() const;
const std::vector<IBackend *> &backends() const;
Job job() const;

View file

@ -213,6 +213,16 @@ void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult
}
void xmrig::Network::onVerifyAlgorithm(IStrategy *, const IClient *, const Algorithm &algorithm, bool *ok)
{
if (!m_controller->miner()->isEnabled(algorithm)) {
*ok = false;
return;
}
}
void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
{
if (job.height()) {

View file

@ -67,6 +67,7 @@ protected:
void onPause(IStrategy *strategy) override;
void onRequest(IApiRequest &request) override;
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) override;
private:
constexpr static int kTickInterval = 1 * 1000;

View file

@ -57,6 +57,8 @@ protected:
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(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 {}
int64_t submit(const JobResult &result) override;