Code cleanup based on Clang-Tidy.

This commit is contained in:
XMRig 2021-08-25 18:45:15 +07:00
parent 3215403815
commit c7ac314110
No known key found for this signature in database
GPG key ID: 446A53638BE94409
133 changed files with 437 additions and 833 deletions

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/AutoClient.h"
#include "3rdparty/rapidjson/document.h"
#include "base/io/json/Json.h"
@ -31,7 +30,7 @@ xmrig::AutoClient::AutoClient(int id, const char *agent, IClientListener *listen
bool xmrig::AutoClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
if (m_mode == DEFAULT_MODE) {
return Client::handleResponse(id, result, error);
return Client::handleResponse(id, result, error); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::handleResponse(id, result, error);
@ -73,7 +72,7 @@ bool xmrig::AutoClient::parseLogin(const rapidjson::Value &result, int *code)
int64_t xmrig::AutoClient::submit(const JobResult &result)
{
if (m_mode == DEFAULT_MODE) {
return Client::submit(result);
return Client::submit(result); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::submit(result);
@ -83,7 +82,7 @@ int64_t xmrig::AutoClient::submit(const JobResult &result)
void xmrig::AutoClient::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{
if (m_mode == DEFAULT_MODE) {
return Client::parseNotification(method, params, error);
return Client::parseNotification(method, params, error); // NOLINT(bugprone-parent-virtual-call)
}
return EthStratumClient::parseNotification(method, params, error);

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View file

@ -349,32 +349,6 @@ bool xmrig::Client::close()
}
bool xmrig::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;
}
if (strncasecmp(message, "Invalid job id", 14) == 0) {
return true;
}
return false;
}
bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
{
if (!params.IsObject()) {
@ -465,7 +439,7 @@ bool xmrig::Client::send(BIO *bio)
{
# ifdef XMRIG_FEATURE_TLS
uv_buf_t buf;
buf.len = BIO_get_mem_data(bio, &buf.base);
buf.len = BIO_get_mem_data(bio, &buf.base); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
if (buf.len == 0) {
return true;
@ -959,6 +933,32 @@ void xmrig::Client::startTimeout()
}
bool xmrig::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;
}
if (strncasecmp(message, "Invalid job id", 14) == 0) {
return true;
}
return false;
}
void xmrig::Client::onClose(uv_handle_t *handle)
{
auto client = getClient(handle->data);

View file

@ -96,7 +96,6 @@ private:
class Socks5;
class Tls;
bool isCriticalError(const char *message);
bool parseJob(const rapidjson::Value &params, int *code);
bool send(BIO *bio);
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
@ -119,6 +118,7 @@ private:
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
static bool isCriticalError(const char *message);
static void onClose(uv_handle_t *handle);
static void onConnect(uv_connect_t *req, int status);
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);

View file

@ -73,7 +73,7 @@ static constexpr size_t kZMQGreetingSize1 = 11;
static const char kZMQHandshake[] = "\4\x19\5READY\xbSocket-Type\0\0\0\3SUB";
static const char kZMQSubscribe[] = "\0\x18\1json-minimal-chain_main";
}
} // namespace xmrig
xmrig::DaemonClient::DaemonClient(int id, IClientListener *listener) :
@ -823,9 +823,9 @@ void xmrig::DaemonClient::ZMQParse()
size_t msg_size = 0;
char* data = m_ZMQRecvBuf.data();
char *data = m_ZMQRecvBuf.data();
size_t avail = m_ZMQRecvBuf.size();
bool more;
bool more = false;
do {
if (avail < 1) {

View file

@ -272,7 +272,7 @@ void xmrig::EthStratumClient::setExtraNonce(const rapidjson::Value &nonce)
}
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error) const
const char *xmrig::EthStratumClient::errorMessage(const rapidjson::Value &error)
{
if (error.IsArray() && error.GetArray().Size() > 1) {
auto &value = error.GetArray()[1];

View file

@ -48,7 +48,8 @@ protected:
void setExtraNonce(const rapidjson::Value &nonce);
private:
const char *errorMessage(const rapidjson::Value &error) const;
static const char *errorMessage(const rapidjson::Value &error);
void authorize();
void onAuthorizeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);
void onSubscribeResponse(const rapidjson::Value &result, bool success, uint64_t elapsed);

View file

@ -82,7 +82,7 @@ const char *Pool::kSpendSecretKey = "spend-secret-key";
const char *Pool::kNicehashHost = "nicehash.com";
}
} // namespace xmrig
xmrig::Pool::Pool(const char *url) :

View file

@ -230,6 +230,9 @@ void xmrig::Pools::setProxyDonate(int value)
case PROXY_DONATE_AUTO:
case PROXY_DONATE_ALWAYS:
m_proxyDonate = static_cast<ProxyDonate>(value);
default:
break;
}
}

View file

@ -59,13 +59,13 @@ void xmrig::Client::Socks5::handshake()
}
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr) const
bool xmrig::Client::Socks5::isIPv4(const String &host, sockaddr_storage *addr)
{
return uv_ip4_addr(host.data(), 0, reinterpret_cast<sockaddr_in *>(addr)) == 0;
}
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr) const
bool xmrig::Client::Socks5::isIPv6(const String &host, sockaddr_storage *addr)
{
return uv_ip6_addr(host.data(), 0, reinterpret_cast<sockaddr_in6 *>(addr)) == 0;
}

View file

@ -44,8 +44,9 @@ private:
Ready
};
bool isIPv4(const String &host, sockaddr_storage *addr) const;
bool isIPv6(const String &host, sockaddr_storage *addr) const;
static bool isIPv4(const String &host, sockaddr_storage *addr);
static bool isIPv6(const String &host, sockaddr_storage *addr);
void connect();
Client *m_client;

View file

@ -1,13 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@ -23,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/Tls.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Client.h"
@ -177,7 +170,7 @@ bool xmrig::Client::Tls::verifyFingerprint(X509 *cert)
}
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int dlen;
unsigned int dlen = 0;
if (X509_digest(cert, digest, md, &dlen) != 1) {
return false;

View file

@ -1,12 +1,7 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View file

@ -1,13 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@ -23,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/Url.h"
@ -49,7 +41,7 @@ static const char kDaemonHttp[] = "daemon+http://";
static const char kDaemonHttps[] = "daemon+https://";
#endif
}
} // namespace xmrig
xmrig::Url::Url(const char *url)

View file

@ -1,13 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View file

@ -249,7 +249,7 @@ uint64_t xmrig::BenchClient::referenceHash() const
}
void xmrig::BenchClient::printExit()
void xmrig::BenchClient::printExit() const
{
LOG_INFO("%s " WHITE_BOLD("press ") MAGENTA_BOLD("Ctrl+C") WHITE_BOLD(" to exit"), tag());
}

View file

@ -90,7 +90,7 @@ private:
bool setSeed(const char *seed);
uint64_t referenceHash() const;
void printExit();
void printExit() const;
void start();
# ifdef XMRIG_FEATURE_HTTP