mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
Restored algorithm verification.
This commit is contained in:
parent
88edde804f
commit
691b2fabbf
13 changed files with 56 additions and 23 deletions
|
@ -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 ¶ms) = 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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 ¶ms) = 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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -330,14 +330,15 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ private:
|
|||
bool parseJob(const rapidjson::Value ¶ms, 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ protected:
|
|||
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) 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)]; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ protected:
|
|||
void onLogin(IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue