mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-24 12:39:28 +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)
|
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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,36 +43,37 @@ 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);
|
||||||
~Network() override;
|
~Network() override;
|
||||||
|
|
||||||
void connect();
|
void connect();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onActive(IStrategy *strategy, Client *client) override;
|
void onActive(IStrategy *strategy, Client *client) override;
|
||||||
void onJob(IStrategy *strategy, Client *client, const Job &job) override;
|
void onConfigChanged(Config *config, Config *previousConfig) override;
|
||||||
void onJobResult(const JobResult &result) override;
|
void onJob(IStrategy *strategy, Client *client, const Job &job) override;
|
||||||
void onPause(IStrategy *strategy) override;
|
void onJobResult(const JobResult &result) override;
|
||||||
void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
|
void onPause(IStrategy *strategy) override;
|
||||||
|
void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr static int kTickInterval = 1 * 1000;
|
constexpr static int kTickInterval = 1 * 1000;
|
||||||
|
|
||||||
bool isColors() const;
|
bool isColors() const;
|
||||||
void setJob(Client *client, const Job &job, bool donate);
|
void setJob(Client *client, const Job &job, bool donate);
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
static void onTick(uv_timer_t *handle);
|
static void onTick(uv_timer_t *handle);
|
||||||
|
|
||||||
Controller *m_controller;
|
Controller *m_controller;
|
||||||
IStrategy *m_donate;
|
IStrategy *m_donate;
|
||||||
IStrategy *m_strategy;
|
IStrategy *m_strategy;
|
||||||
NetworkState m_state;
|
NetworkState m_state;
|
||||||
uv_timer_t m_timer;
|
uv_timer_t m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue