diff --git a/CMakeLists.txt b/CMakeLists.txt index 188f595ce..f83045890 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ set(HEADERS src/base/kernel/Process.h src/base/kernel/Signals.h src/base/net/stratum/Client.h - src/base/net/stratum/Id.h src/base/net/stratum/Job.h src/base/net/stratum/Pool.h src/base/net/stratum/Pools.h diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 1dfbc7fd5..cffbe5432 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -397,7 +397,8 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) { - if (!m_rpcId.setId(result["id"].GetString())) { + m_rpcId = result["id"].GetString(); + if (m_rpcId.isNull()) { *code = 1; return false; } @@ -498,7 +499,7 @@ int64_t xmrig::Client::send(const rapidjson::Document &doc) { using namespace rapidjson; - StringBuffer buffer(0, 512); + StringBuffer buffer(nullptr, 512); Writer writer(buffer); doc.Accept(writer); diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 977a3681f..ed433ff95 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -32,7 +32,6 @@ #include -#include "base/net/stratum/Id.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/Pool.h" #include "base/net/stratum/SubmitResult.h" @@ -155,7 +154,6 @@ private: char m_sendBuf[2048]; const char *m_agent; IClientListener *m_listener; - Id m_rpcId; int m_id; int m_retries; int m_retryPause; @@ -166,6 +164,7 @@ private: SocketState m_state; std::bitset m_extensions; std::map m_results; + String m_rpcId; Tls *m_tls; uint64_t m_expire; uint64_t m_jobs; diff --git a/src/base/net/stratum/Id.h b/src/base/net/stratum/Id.h deleted file mode 100644 index 999e7837a..000000000 --- a/src/base/net/stratum/Id.h +++ /dev/null @@ -1,98 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2019 XMRig , - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef XMRIG_ID_H -#define XMRIG_ID_H - - -#include - - -namespace xmrig { - - -class Id -{ -public: - inline Id() : - m_data() - { - } - - - inline Id(const char *id, size_t sizeFix = 0) - { - setId(id, sizeFix); - } - - - inline bool operator==(const Id &other) const - { - return memcmp(m_data, other.m_data, sizeof(m_data)) == 0; - } - - - inline bool operator!=(const Id &other) const - { - return memcmp(m_data, other.m_data, sizeof(m_data)) != 0; - } - - - Id &operator=(const Id &other) - { - memcpy(m_data, other.m_data, sizeof(m_data)); - - return *this; - } - - - inline bool setId(const char *id, size_t sizeFix = 0) - { - memset(m_data, 0, sizeof(m_data)); - if (!id) { - return false; - } - - const size_t size = strlen(id); - if (size >= sizeof(m_data)) { - return false; - } - - memcpy(m_data, id, size - sizeFix); - return true; - } - - - inline const char *data() const { return m_data; } - inline bool isValid() const { return *m_data != '\0'; } - - -private: - char m_data[64]; -}; - - -} /* namespace xmrig */ - - -#endif /* XMRIG_ID_H */ diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 3fb691ced..c9902f49d 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -65,25 +65,25 @@ xmrig::Job::Job() : m_threadId(-1), m_size(0), m_diff(0), + m_height(0), m_target(0), - m_blob(), - m_height(0) + m_blob() { } -xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId) : +xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId) : + m_algorithm(algorithm), m_autoVariant(algorithm.variant() == VARIANT_AUTO), m_nicehash(nicehash), m_poolId(poolId), m_threadId(-1), m_size(0), + m_clientId(clientId), m_diff(0), - m_target(0), - m_blob(), m_height(0), - m_algorithm(algorithm), - m_clientId(clientId) + m_target(0), + m_blob() { } diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 426a64ded..878274e8c 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -31,8 +31,8 @@ #include +#include "base/tools/String.h" #include "common/crypto/Algorithm.h" -#include "base/net/stratum/Id.h" namespace xmrig { @@ -46,7 +46,7 @@ public: static constexpr const size_t kMaxBlobSize = 128; Job(); - Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId); + Job(int poolId, bool nicehash, const Algorithm &algorithm, const String &clientId); ~Job(); bool isEqual(const Job &other) const; @@ -57,10 +57,10 @@ public: inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } - inline bool setId(const char *id) { return m_id.setId(id); } + inline bool setId(const char *id) { return m_id = id; } inline const Algorithm &algorithm() const { return m_algorithm; } - inline const Id &clientId() const { return m_clientId; } - inline const Id &id() const { return m_id; } + inline const String &clientId() const { return m_clientId; } + inline const String &id() const { return m_id; } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } @@ -72,7 +72,7 @@ public: inline uint64_t target() const { return m_target; } inline uint8_t fixedByte() const { return *(m_blob + 42); } inline void reset() { m_size = 0; m_diff = 0; } - inline void setClientId(const Id &id) { m_clientId = id; } + inline void setClientId(const String &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } @@ -99,18 +99,18 @@ public: private: Variant variant() const; + Algorithm m_algorithm; bool m_autoVariant; bool m_nicehash; int m_poolId; int m_threadId; size_t m_size; + String m_clientId; + String m_id; uint64_t m_diff; + uint64_t m_height; uint64_t m_target; uint8_t m_blob[kMaxBlobSize]; - uint64_t m_height; - xmrig::Algorithm m_algorithm; - xmrig::Id m_clientId; - xmrig::Id m_id; # ifdef XMRIG_PROXY_PROJECT char m_rawBlob[kMaxBlobSize * 2 + 8]; diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 2e5b08688..9d2300b57 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -31,6 +31,7 @@ #include +#include "base/tools/String.h" #include "base/net/stratum/Job.h" @@ -41,11 +42,11 @@ class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const Id &jobId, const Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : + inline JobResult(int poolId, const String &jobId, const String &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : algorithm(algorithm), + poolId(poolId), clientId(clientId), jobId(jobId), - poolId(poolId), diff(diff), nonce(nonce) { @@ -71,9 +72,9 @@ public: Algorithm algorithm; - Id clientId; - Id jobId; int poolId; + String clientId; + String jobId; uint32_t diff; uint32_t nonce; uint8_t result[32];