Implemented dynamic pool reload.

This commit is contained in:
XMRig 2019-02-17 19:29:33 +07:00
parent 7c789a0d3c
commit 9c088eabc2
5 changed files with 59 additions and 24 deletions

View file

@ -51,6 +51,16 @@ xmrig::Pool &xmrig::Pools::current()
} }
bool xmrig::Pools::isEqual(const Pools &other) const
{
if (m_data.size() != other.m_data.size() || m_retries != other.m_retries || m_retryPause != other.m_retryPause) {
return false;
}
return std::equal(m_data.begin(), m_data.end(), other.m_data.begin());
}
bool xmrig::Pools::setUrl(const char *url) bool xmrig::Pools::setUrl(const char *url)
{ {
if (m_data.empty() || m_data.back().isValid()) { if (m_data.empty() || m_data.back().isValid()) {
@ -144,7 +154,7 @@ void xmrig::Pools::load(const rapidjson::Value &pools)
} }
void xmrig::Pools::print() void xmrig::Pools::print() const
{ {
size_t i = 1; size_t i = 1;
for (const Pool &pool : m_data) { for (const Pool &pool : m_data) {

View file

@ -59,13 +59,17 @@ public:
inline void setVariant(const char *variant) { current().algorithm().parseVariant(variant); } inline void setVariant(const char *variant) { current().algorithm().parseVariant(variant); }
inline void setVariant(int variant) { current().algorithm().parseVariant(variant); } inline void setVariant(int variant) { current().algorithm().parseVariant(variant); }
inline bool operator!=(const Pools &other) const { return !isEqual(other); }
inline bool operator==(const Pools &other) const { return isEqual(other); }
bool isEqual(const Pools &other) const;
bool setUrl(const char *url); bool setUrl(const char *url);
IStrategy *createStrategy(IStrategyListener *listener) const; IStrategy *createStrategy(IStrategyListener *listener) const;
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t active() const; size_t active() const;
void adjust(const Algorithm &algorithm); void adjust(const Algorithm &algorithm);
void load(const rapidjson::Value &pools); void load(const rapidjson::Value &pools);
void print(); void print() const;
void setRetries(int retries); void setRetries(int retries);
void setRetryPause(int retryPause); void setRetryPause(int retryPause);

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -34,7 +35,7 @@ class Config;
class IControllerListener class IControllerListener
{ {
public: public:
virtual ~IControllerListener() {} virtual ~IControllerListener() = default;
virtual void onConfigChanged(Config *config, Config *previousConfig) = 0; virtual void onConfigChanged(Config *config, Config *previousConfig) = 0;
}; };

View file

@ -47,6 +47,7 @@ xmrig::Network::Network(Controller *controller) :
m_donate(nullptr) m_donate(nullptr)
{ {
Workers::setListener(this); Workers::setListener(this);
controller->addListener(this);
const Pools &pools = controller->config()->pools(); const Pools &pools = controller->config()->pools();
m_strategy = pools.createStrategy(this); m_strategy = pools.createStrategy(this);
@ -64,6 +65,7 @@ xmrig::Network::Network(Controller *controller) :
xmrig::Network::~Network() xmrig::Network::~Network()
{ {
delete m_strategy;
} }
@ -104,6 +106,22 @@ void xmrig::Network::onActive(IStrategy *strategy, Client *client)
} }
void xmrig::Network::onConfigChanged(Config *config, Config *previousConfig)
{
if (config->pools() == previousConfig->pools() || !config->pools().active()) {
return;
}
m_strategy->stop();
config->pools().print();
delete m_strategy;
m_strategy = config->pools().createStrategy(this);
connect();
}
void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job) void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job)
{ {
if (m_donate && m_donate->isActive() && m_donate != strategy) { if (m_donate && m_donate->isActive() && m_donate != strategy) {

View file

@ -31,6 +31,7 @@
#include "api/NetworkState.h" #include "api/NetworkState.h"
#include "common/interfaces/IControllerListener.h"
#include "common/interfaces/IStrategyListener.h" #include "common/interfaces/IStrategyListener.h"
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
@ -42,7 +43,7 @@ class Controller;
class IStrategy; class IStrategy;
class Network : public IJobResultListener, public IStrategyListener class Network : public IJobResultListener, public IStrategyListener, public IControllerListener
{ {
public: public:
Network(Controller *controller); Network(Controller *controller);
@ -53,6 +54,7 @@ public:
protected: protected:
void onActive(IStrategy *strategy, Client *client) override; void onActive(IStrategy *strategy, Client *client) override;
void onConfigChanged(Config *config, Config *previousConfig) override;
void onJob(IStrategy *strategy, Client *client, const Job &job) override; void onJob(IStrategy *strategy, Client *client, const Job &job) override;
void onJobResult(const JobResult &result) override; void onJobResult(const JobResult &result) override;
void onPause(IStrategy *strategy) override; void onPause(IStrategy *strategy) override;