Basic failover support.

This commit is contained in:
XMRig 2017-06-07 09:07:31 +03:00
parent 387524e1c5
commit c31ea00399
6 changed files with 41 additions and 7 deletions

View file

@ -36,7 +36,7 @@
Network::Network(const Options *options) :
m_donate(false),
m_options(options),
m_pool(1)
m_pool(0)
{
m_pools.reserve(2);
m_agent = userAgent();
@ -61,13 +61,25 @@ Network::~Network()
void Network::connect()
{
m_pools.at(m_pool)->connect();
m_pools.at(1)->connect();
}
void Network::onClose(Client *client, int failures)
{
LOG_DEBUG("CLOSE %d %d", client->id(), failures);
const int id = client->id();
if (id == 0 && failures == -1) {
m_donate = false;
return;
}
if (m_pool == id) {
m_pool = 0;
}
if (id == 1 && m_pools.size() > 2 && failures == m_options->retries()) {
m_pools.at(2)->connect();
}
}
@ -85,6 +97,23 @@ void Network::onLoginCredentialsRequired(Client *client)
void Network::onLoginSuccess(Client *client)
{
const int id = client->id();
if (id == 0) {
m_donate = true;
return;
}
if (id == 2 && m_pool) { // primary pool is already active
m_pools.at(2)->disconnect();
return;
}
LOG_NOTICE("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.at(2)->disconnect();
}
}