From de5016dda82b48a755177bbf9ff6be15147c75ba Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 17 Mar 2018 16:30:41 +0700 Subject: [PATCH] #459 Fix issue with xmr.f2pool.com --- src/net/Client.cpp | 34 ++++++++++++++++++++++++---------- src/net/Client.h | 1 + src/net/Job.cpp | 6 ++++++ src/net/Job.h | 1 + 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/net/Client.cpp b/src/net/Client.cpp index cb1a53f82..5d8c59195 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -65,6 +65,7 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_recvBufPos(0), m_state(UnconnectedState), m_expire(0), + m_jobs(0), m_stream(nullptr), m_socket(nullptr) { @@ -245,17 +246,22 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) job.setVariant(params["variant"].GetInt()); } - if (m_job == job) { - if (!m_quiet) { - LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); - } + if (m_job != job) { + m_jobs++; + m_job = std::move(job); + return true; + } - close(); + if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459 return false; } - m_job = std::move(job); - return true; + if (!m_quiet) { + LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); + } + + close(); + return false; } @@ -272,7 +278,10 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) parseExtensions(result["extensions"]); } - return parseJob(result["job"], code); + const bool rc = parseJob(result["job"], code); + m_jobs = 0; + + return rc; } @@ -683,7 +692,10 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) { auto client = getClient(req->data); if (status < 0) { - LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); + if (!client->m_quiet) { + LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); + } + return client->reconnect(); } @@ -704,7 +716,9 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) } if (ipv4.empty() && ipv6.empty()) { - LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port()); + if (!client->m_quiet) { + LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port()); + } uv_freeaddrinfo(res); return client->reconnect(); diff --git a/src/net/Client.h b/src/net/Client.h index a927bd19d..ec68ab05c 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -120,6 +120,7 @@ private: static int64_t m_sequence; std::map m_results; uint64_t m_expire; + uint64_t m_jobs; Url m_url; uv_buf_t m_recvBuf; uv_getaddrinfo_t m_resolver; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 48e73a52c..7d137fac9 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -210,3 +210,9 @@ bool Job::operator==(const Job &other) const { return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; } + + +bool Job::operator!=(const Job &other) const +{ + return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0; +} diff --git a/src/net/Job.h b/src/net/Job.h index d981ed378..4f9c472e2 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -69,6 +69,7 @@ public: static void toHex(const unsigned char* in, unsigned int len, char* out); bool operator==(const Job &other) const; + bool operator!=(const Job &other) const; private: bool m_nicehash;