mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-22 10:45:06 +00:00
Basic failover support.
This commit is contained in:
parent
387524e1c5
commit
c31ea00399
6 changed files with 41 additions and 7 deletions
|
@ -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__ */
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue