mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 20:19:23 +00:00
Implemented dynamic pool reload.
This commit is contained in:
parent
7c789a0d3c
commit
9c088eabc2
5 changed files with 59 additions and 24 deletions
|
@ -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)
|
||||
{
|
||||
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;
|
||||
for (const Pool &pool : m_data) {
|
||||
|
|
|
@ -59,13 +59,17 @@ public:
|
|||
inline void setVariant(const char *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);
|
||||
IStrategy *createStrategy(IStrategyListener *listener) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
size_t active() const;
|
||||
void adjust(const Algorithm &algorithm);
|
||||
void load(const rapidjson::Value &pools);
|
||||
void print();
|
||||
void print() const;
|
||||
void setRetries(int retries);
|
||||
void setRetryPause(int retryPause);
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -34,7 +35,7 @@ class Config;
|
|||
class IControllerListener
|
||||
{
|
||||
public:
|
||||
virtual ~IControllerListener() {}
|
||||
virtual ~IControllerListener() = default;
|
||||
|
||||
virtual void onConfigChanged(Config *config, Config *previousConfig) = 0;
|
||||
};
|
||||
|
|
|
@ -47,6 +47,7 @@ xmrig::Network::Network(Controller *controller) :
|
|||
m_donate(nullptr)
|
||||
{
|
||||
Workers::setListener(this);
|
||||
controller->addListener(this);
|
||||
|
||||
const Pools &pools = controller->config()->pools();
|
||||
m_strategy = pools.createStrategy(this);
|
||||
|
@ -64,6 +65,7 @@ xmrig::Network::Network(Controller *controller) :
|
|||
|
||||
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)
|
||||
{
|
||||
if (m_donate && m_donate->isActive() && m_donate != strategy) {
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
|
||||
#include "api/NetworkState.h"
|
||||
#include "common/interfaces/IControllerListener.h"
|
||||
#include "common/interfaces/IStrategyListener.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
|
||||
|
@ -42,36 +43,37 @@ class Controller;
|
|||
class IStrategy;
|
||||
|
||||
|
||||
class Network : public IJobResultListener, public IStrategyListener
|
||||
class Network : public IJobResultListener, public IStrategyListener, public IControllerListener
|
||||
{
|
||||
public:
|
||||
Network(Controller *controller);
|
||||
~Network() override;
|
||||
Network(Controller *controller);
|
||||
~Network() override;
|
||||
|
||||
void connect();
|
||||
void stop();
|
||||
void connect();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
void onActive(IStrategy *strategy, Client *client) override;
|
||||
void onJob(IStrategy *strategy, Client *client, const Job &job) override;
|
||||
void onJobResult(const JobResult &result) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) 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 onJobResult(const JobResult &result) override;
|
||||
void onPause(IStrategy *strategy) override;
|
||||
void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
|
||||
|
||||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
bool isColors() const;
|
||||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
bool isColors() const;
|
||||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
|
||||
static void onTick(uv_timer_t *handle);
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
||||
Controller *m_controller;
|
||||
IStrategy *m_donate;
|
||||
IStrategy *m_strategy;
|
||||
NetworkState m_state;
|
||||
uv_timer_t m_timer;
|
||||
Controller *m_controller;
|
||||
IStrategy *m_donate;
|
||||
IStrategy *m_strategy;
|
||||
NetworkState m_state;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue