mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-31 16:09:46 +00:00
Merge pull request #2848 from Spudz76/dev-addClientReconnect
Add support for client.reconnect method
This commit is contained in:
commit
7bde3ed5f7
3 changed files with 40 additions and 1 deletions
|
@ -23,6 +23,7 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
|
@ -683,12 +684,48 @@ void xmrig::Client::parse(char *line, size_t len)
|
|||
|
||||
const auto &id = Json::getValue(doc, "id");
|
||||
const auto &error = Json::getValue(doc, "error");
|
||||
const char *method = Json::getString(doc, "method");
|
||||
|
||||
if (method && strcmp(method, "client.reconnect") == 0) {
|
||||
const auto ¶ms = Json::getValue(doc, "params");
|
||||
if (!params.IsArray()) {
|
||||
LOG_ERR("%s " RED("invalid client.reconnect notification: params is not an array"), tag());
|
||||
return;
|
||||
}
|
||||
|
||||
auto arr = params.GetArray();
|
||||
|
||||
if (arr.Empty()) {
|
||||
LOG_ERR("%s " RED("invalid client.reconnect notification: params array is empty"), tag());
|
||||
return;
|
||||
}
|
||||
|
||||
if (arr.Size() != 2) {
|
||||
LOG_ERR("%s " RED("invalid client.reconnect notification: params array has wrong size"), tag());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!arr[0].IsString()) {
|
||||
LOG_ERR("%s " RED("invalid client.reconnect notification: host is not a string"), tag());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!arr[1].IsString()) {
|
||||
LOG_ERR("%s " RED("invalid client.reconnect notification: port is not a string"), tag());
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream s;
|
||||
s << arr[0].GetString() << ":" << arr[1].GetString();
|
||||
LOG_WARN("%s " YELLOW("client.reconnect to %s"), tag(), s.str().c_str());
|
||||
setPoolUrl(s.str().c_str());
|
||||
return reconnect();
|
||||
}
|
||||
|
||||
if (id.IsInt64()) {
|
||||
return parseResponse(id.GetInt64(), Json::getValue(doc, "result"), error);
|
||||
}
|
||||
|
||||
const char *method = Json::getString(doc, "method");
|
||||
if (!method) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ protected:
|
|||
inline const char *url() const { return m_pool.url(); }
|
||||
inline const String &rpcId() const { return m_rpcId; }
|
||||
inline void setRpcId(const char *id) { m_rpcId = id; }
|
||||
inline void setPoolUrl(const char *url) { m_pool.setUrl(url); }
|
||||
|
||||
virtual bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
virtual void login();
|
||||
|
|
|
@ -111,6 +111,7 @@ public:
|
|||
inline int zmq_port() const { return m_zmqPort; }
|
||||
inline uint64_t pollInterval() const { return m_pollInterval; }
|
||||
inline void setAlgo(const Algorithm &algorithm) { m_algorithm = algorithm; }
|
||||
inline void setUrl(const char *url) { m_url = Url(url); }
|
||||
inline void setPassword(const String &password) { m_password = password; }
|
||||
inline void setProxy(const ProxyUrl &proxy) { m_proxy = proxy; }
|
||||
inline void setRigId(const String &rigId) { m_rigId = rigId; }
|
||||
|
|
Loading…
Reference in a new issue