Silence primary pool errors if failover active.

This commit is contained in:
XMRig 2018-04-26 15:28:33 +07:00
parent 41e8c4f887
commit 2ddac1ce68
7 changed files with 22 additions and 15 deletions

View file

@ -55,6 +55,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
m_agent(agent),
m_listener(listener),
m_id(id),
m_retries(5),
m_retryPause(5000),
m_failures(0),
m_recvBufPos(0),
@ -267,7 +268,7 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
if (!m_quiet) {
if (!isQuiet()) {
LOG_WARN("[%s] duplicate job received, reconnect", m_pool.url());
}
@ -311,7 +312,7 @@ int Client::resolve(const char *host)
const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints);
if (r) {
if (!m_quiet) {
if (!isQuiet()) {
LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_pool.port(), uv_strerror(r));
}
return 1;
@ -453,7 +454,7 @@ void Client::parse(char *line, size_t len)
LOG_DEBUG("[%s] received (%d bytes): \"%s\"", m_pool.url(), len, line);
if (len < 32 || line[0] != '{') {
if (!m_quiet) {
if (!isQuiet()) {
LOG_ERR("[%s] JSON decode failed", m_pool.url());
}
@ -462,7 +463,7 @@ void Client::parse(char *line, size_t len)
rapidjson::Document doc;
if (doc.ParseInsitu(line).HasParseError()) {
if (!m_quiet) {
if (!isQuiet()) {
LOG_ERR("[%s] JSON decode failed: \"%s\"", m_pool.url(), rapidjson::GetParseError_En(doc.GetParseError()));
}
@ -504,7 +505,7 @@ void Client::parseExtensions(const rapidjson::Value &value)
void Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{
if (error.IsObject()) {
if (!m_quiet) {
if (!isQuiet()) {
LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), error["message"].GetString(), error["code"].GetInt());
}
return;
@ -538,7 +539,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
m_listener->onResultAccepted(this, it->second, message);
m_results.erase(it);
}
else if (!m_quiet) {
else if (!isQuiet()) {
LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), message, error["code"].GetInt());
}
@ -556,7 +557,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
if (id == 1) {
int code = -1;
if (!parseLogin(result, &code)) {
if (!m_quiet) {
if (!isQuiet()) {
LOG_ERR("[%s] login error code: %d", m_pool.url(), code);
}
@ -661,7 +662,7 @@ void Client::onConnect(uv_connect_t *req, int status)
}
if (status < 0) {
if (!client->m_quiet) {
if (!client->isQuiet()) {
LOG_ERR("[%s] connect error: \"%s\"", client->m_pool.url(), uv_strerror(status));
}
@ -689,7 +690,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
}
if (nread < 0) {
if (nread != UV_EOF && !client->m_quiet) {
if (nread != UV_EOF && !client->isQuiet()) {
LOG_ERR("[%s] read error: \"%s\"", client->m_pool.url(), uv_strerror((int) nread));
}
@ -749,7 +750,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
}
if (status < 0) {
if (!client->m_quiet) {
if (!client->isQuiet()) {
LOG_ERR("[%s] DNS error: \"%s\"", client->m_pool.url(), uv_strerror(status));
}
@ -773,7 +774,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
}
if (ipv4.empty() && ipv6.empty()) {
if (!client->m_quiet) {
if (!client->isQuiet()) {
LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_pool.url());
}

View file

@ -74,6 +74,7 @@ public:
inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_pool.port(); }
inline void setQuiet(bool quiet) { m_quiet = quiet; }
inline void setRetries(int retries) { m_retries = retries; }
inline void setRetryPause(int ms) { m_retryPause = ms; }
private:
@ -96,6 +97,8 @@ private:
void setState(SocketState state);
void startTimeout();
inline bool isQuiet() const { return m_quiet || m_failures >= m_retries; }
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
static void onClose(uv_handle_t *handle);
static void onConnect(uv_connect_t *req, int status);
@ -114,6 +117,7 @@ private:
const char *m_agent;
IClientListener *m_listener;
int m_id;
int m_retries;
int m_retryPause;
int64_t m_failures;
Job m_job;

View file

@ -157,6 +157,7 @@ void FailoverStrategy::add(const Pool &pool)
{
Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
client->setPool(pool);
client->setRetries(m_retries);
client->setRetryPause(m_retryPause * 1000);
client->setQuiet(m_quiet);

View file

@ -28,12 +28,13 @@
#include "interfaces/IStrategyListener.h"
SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet) :
SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_active(false),
m_listener(listener)
{
m_client = new Client(0, Platform::userAgent(), this);
m_client->setPool(pool);
m_client->setRetries(retries);
m_client->setRetryPause(retryPause * 1000);
m_client->setQuiet(quiet);
}

View file

@ -37,7 +37,7 @@ class Url;
class SinglePoolStrategy : public IStrategy, public IClientListener
{
public:
SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet = false);
SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~SinglePoolStrategy();
public:

View file

@ -57,7 +57,7 @@ Network::Network(xmrig::Controller *controller) :
m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this);
}
else {
m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), this);
m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), controller->config()->retries(), this);
}
if (controller->config()->donateLevel() > 0) {

View file

@ -75,7 +75,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS
m_strategy = new FailoverStrategy(m_pools, 1, 2, this, true);
}
else {
m_strategy = new SinglePoolStrategy(m_pools.front(), 1, this, true);
m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true);
}
m_timer.data = this;