Add FailoverStrategy.

This commit is contained in:
XMRig 2017-07-01 20:53:42 +03:00
parent 7536663caf
commit 970b5d1964
6 changed files with 205 additions and 88 deletions

View file

@ -29,6 +29,7 @@
#include "net/Client.h"
#include "net/Network.h"
#include "net/strategies/DonateStrategy.h"
#include "net/strategies/FailoverStrategy.h"
#include "net/strategies/SinglePoolStrategy.h"
#include "net/Url.h"
#include "Options.h"
@ -45,7 +46,12 @@ Network::Network(const Options *options) :
const std::vector<Url*> &pools = options->pools();
m_strategy = new SinglePoolStrategy(pools.front(), m_agent, this);
if (pools.size() > 1) {
m_strategy = new FailoverStrategy(pools, m_agent, this);
}
else {
m_strategy = new SinglePoolStrategy(pools.front(), m_agent, this);
}
if (m_options->donateLevel() > 0) {
m_donate = new DonateStrategy(m_agent, this);
@ -55,10 +61,6 @@ Network::Network(const Options *options) :
Network::~Network()
{
// for (auto client : m_pools) {
// delete client;
// }
free(m_agent);
}
@ -80,28 +82,6 @@ void Network::onActive(Client *client)
}
//void Network::onClose(Client *client, int failures)
//{
// const int id = client->id();
// if (id == 0) {
// if (failures == -1) {
// stopDonate();
// }
// return;
// }
// if (m_pool == id) {
// m_pool = 0;
// Workers::pause();
// }
// if (id == 1 && m_pools.size() > 2 && failures == m_options->retries()) {
// m_pools[2]->connect();
// }
//}
void Network::onJob(Client *client, const Job &job)
{
if (m_donate && m_donate->isActive() && client->id() != -1) {
@ -124,27 +104,6 @@ void Network::onJobResult(const JobResult &result)
}
//void Network::onLoginSuccess(Client *client)
//{
// const int id = client->id();
// if (id == 0) {
// return startDonate();
// }
// if (id == 2 && m_pool) { // primary pool is already active
// m_pools[2]->disconnect();
// return;
// }
// LOG_INFO(m_options->colors() ? "\x1B[01;37muse pool: \x1B[01;36m%s:%d" : "use pool: %s:%d", client->host(), client->port());
// m_pool = id;
// if (m_pool == 1 && m_pools.size() > 2) { // try disconnect from backup pool
// m_pools[2]->disconnect();
// }
//}
void Network::onPause(IStrategy *strategy)
{
if (m_donate && m_donate == strategy) {
@ -171,40 +130,3 @@ void Network::setJob(Client *client, const Job &job)
Workers::setJob(job);
}
void Network::stopDonate()
{
// if (!m_donateActive) {
// return;
// }
// LOG_NOTICE("dev donate finished");
// m_donateActive = false;
// if (!m_pool) {
// return;
// }
// Client *client = m_pools[m_pool];
// if (client->isReady()) {
// setJob(client, client->job());
// }
}
//void Network::onTimer(uv_timer_t *handle)
//{
// auto net = static_cast<Network*>(handle->data);
// if (!net->m_donateActive) {
// auto url = std::make_unique<Url>("donate.xmrig.com", net->m_options->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443);
// net->m_pools[0]->connect(url.get());
// uv_timer_start(&net->m_timer, Network::onTimer, net->m_options->donateLevel() * 60 * 1000, 0);
// return;
// }
// net->m_pools[0]->disconnect();
// uv_timer_start(&net->m_timer, Network::onTimer, (100 - net->m_options->donateLevel()) * 60 * 1000, 0);
//}