diff --git a/src/base/kernel/interfaces/IClientListener.h b/src/base/kernel/interfaces/IClientListener.h index de4dd81d5..3583be5ad 100644 --- a/src/base/kernel/interfaces/IClientListener.h +++ b/src/base/kernel/interfaces/IClientListener.h @@ -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; }; diff --git a/src/base/kernel/interfaces/IStrategyListener.h b/src/base/kernel/interfaces/IStrategyListener.h index 01e668d40..8b88b5068 100644 --- a/src/base/kernel/interfaces/IStrategyListener.h +++ b/src/base/kernel/interfaces/IStrategyListener.h @@ -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; }; diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 0be86ecae..618e132cd 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -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; } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 841e0e0b9..46030abaf 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -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); diff --git a/src/base/net/stratum/strategies/FailoverStrategy.cpp b/src/base/net/stratum/strategies/FailoverStrategy.cpp index 4a35f3a54..48be2ba35 100644 --- a/src/base/net/stratum/strategies/FailoverStrategy.cpp +++ b/src/base/net/stratum/strategies/FailoverStrategy.cpp @@ -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); +} diff --git a/src/base/net/stratum/strategies/FailoverStrategy.h b/src/base/net/stratum/strategies/FailoverStrategy.h index 5336a634b..283d49165 100644 --- a/src/base/net/stratum/strategies/FailoverStrategy.h +++ b/src/base/net/stratum/strategies/FailoverStrategy.h @@ -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(m_active)]; } diff --git a/src/base/net/stratum/strategies/SinglePoolStrategy.cpp b/src/base/net/stratum/strategies/SinglePoolStrategy.cpp index 5f09d174f..c923e1c2c 100644 --- a/src/base/net/stratum/strategies/SinglePoolStrategy.cpp +++ b/src/base/net/stratum/strategies/SinglePoolStrategy.cpp @@ -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); +} diff --git a/src/base/net/stratum/strategies/SinglePoolStrategy.h b/src/base/net/stratum/strategies/SinglePoolStrategy.h index 04eef40ec..ea808193c 100644 --- a/src/base/net/stratum/strategies/SinglePoolStrategy.h +++ b/src/base/net/stratum/strategies/SinglePoolStrategy.h @@ -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; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 1f7f77e9a..b64d6b95e 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -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; diff --git a/src/core/Miner.h b/src/core/Miner.h index dd195e29c..333f9250c 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -50,6 +50,7 @@ public: ~Miner() override; bool isEnabled() const; + bool isEnabled(const Algorithm &algorithm) const; const Algorithms &algorithms() const; const std::vector &backends() const; Job job() const; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index a1c1ec8d0..eaff6748c 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -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()) { diff --git a/src/net/Network.h b/src/net/Network.h index bf61a9b67..689677135 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -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; diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 5350aefa3..134127bf6 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -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;