Browse Source

Basic failover support.

pull/409/head
XMRig 7 years ago
parent
commit
c31ea00399
  1. 6
      src/Console.h
  2. 2
      src/Options.cpp
  3. 1
      src/Options.h
  4. 2
      src/net/Client.cpp
  5. 2
      src/net/Client.h
  6. 35
      src/net/Network.cpp

6
src/Console.h

@ -71,11 +71,13 @@ private:
#define LOG_INFO(x, ...) Console::i()->message(Console::INFO, x, ##__VA_ARGS__)
#ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) Console::i()->message(Console::DEBUG, x, ##__VA_ARGS__)
# define LOG_DEBUG_ERR(x, ...) Console::i()->message(Console::ERR, x, ##__VA_ARGS__)
# define LOG_DEBUG(x, ...) Console::i()->message(Console::DEBUG, x, ##__VA_ARGS__)
# define LOG_DEBUG_ERR(x, ...) Console::i()->message(Console::ERR, x, ##__VA_ARGS__)
# define LOG_DEBUG_WARN(x, ...) Console::i()->message(Console::WARNING, x, ##__VA_ARGS__)
#else
# define LOG_DEBUG(x, ...)
# define LOG_DEBUG_ERR(x, ...)
# define LOG_DEBUG_WARN(x, ...)
#endif
#endif /* __CONSOLE_H__ */

2
src/Options.cpp

@ -131,7 +131,7 @@ Options::Options(int argc, char **argv) :
m_donateLevel(kDonateLevel),
m_maxCpuUsage(75),
m_retries(5),
m_retryPause(2),
m_retryPause(5),
m_threads(0),
m_affinity(-1L),
m_backupUrl(nullptr),

1
src/Options.h

@ -57,6 +57,7 @@ public:
inline const char *user() const { return m_user; }
inline const Url *backupUrl() const { return m_backupUrl; }
inline const Url *url() const { return m_url; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
private:

2
src/net/Client.cpp

@ -33,7 +33,7 @@ Client::Client(int id, IClientListener *listener) :
m_host(nullptr),
m_listener(listener),
m_id(id),
m_retryPause(2000),
m_retryPause(5000),
m_failures(0),
m_sequence(1),
m_recvBufPos(0),

2
src/net/Client.h

@ -60,8 +60,10 @@ public:
void send(char *data);
void setUrl(const Url *url);
inline const char *host() const { return m_host; }
inline int id() const { return m_id; }
inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_port; }
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
inline void setRetryPause(int ms) { m_retryPause = ms; }

35
src/net/Network.cpp

@ -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();
}
}

Loading…
Cancel
Save