From 9cb7d727c2699df7d06501e62e08c853bc2bd66b Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 15:14:21 +0300 Subject: [PATCH] Force close connection if IP address banned. --- src/net/Client.cpp | 24 +++++++++++++++++++++++- src/net/Client.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/net/Client.cpp b/src/net/Client.cpp index fde7f4802..c2518be93 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -199,6 +199,28 @@ int64_t Client::submit(const JobResult &result) } +bool Client::isCriticalError(const char *message) +{ + if (!message) { + return false; + } + + if (strncasecmp(message, "Unauthenticated", 15) == 0) { + return true; + } + + if (strncasecmp(message, "your IP is banned", 17) == 0) { + return true; + } + + if (strncasecmp(message, "IP Address currently banned", 27) == 0) { + return true; + } + + return false; +} + + bool Client::parseJob(const json_t *params, int *code) { if (!json_is_object(params)) { @@ -405,7 +427,7 @@ void Client::parseResponse(int64_t id, const json_t *result, const json_t *error LOG_ERR("[%s:%u] error: \"%s\", code: %" PRId64, m_url.host(), m_url.port(), message, json_integer_value(json_object_get(error, "code"))); } - if (id == 1 || (message && strncasecmp(message, "Unauthenticated", 15) == 0)) { + if (id == 1 || isCriticalError(message)) { close(); } diff --git a/src/net/Client.h b/src/net/Client.h index b7eda3257..f554e3417 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -77,6 +77,7 @@ public: private: constexpr static size_t kRecvBufSize = 4096; + bool isCriticalError(const char *message); bool parseJob(const json_t *params, int *code); bool parseLogin(const json_t *result, int *code); int resolve(const char *host);