diff --git a/src/App.h b/src/App.h index 9ec8edcc5..3a1777979 100644 --- a/src/App.h +++ b/src/App.h @@ -33,13 +33,13 @@ class Console; class Httpd; -class Network; namespace xmrig { class Controller; +class Network; class Process; class Signals; @@ -62,9 +62,9 @@ private: void release(); Console *m_console; + Controller *m_controller; Httpd *m_httpd; Signals *m_signals; - xmrig::Controller *m_controller; }; diff --git a/src/api/Api.cpp b/src/api/Api.cpp index 3fff45b52..2abdf4be0 100644 --- a/src/api/Api.cpp +++ b/src/api/Api.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -62,7 +63,7 @@ void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) } -void Api::tick(const NetworkState &network) +void Api::tick(const xmrig::NetworkState &network) { if (!m_router) { return; diff --git a/src/api/Api.h b/src/api/Api.h index 316bb0fa2..caee887a6 100644 --- a/src/api/Api.h +++ b/src/api/Api.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __API_H__ -#define __API_H__ +#ifndef XMRIG_API_H +#define XMRIG_API_H #include @@ -30,13 +31,13 @@ class ApiRouter; class Hashrate; -class NetworkState; namespace xmrig { class Controller; class HttpReply; class HttpRequest; + class NetworkState; } @@ -47,10 +48,10 @@ public: static void release(); static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); - static void tick(const NetworkState &results); + static void tick(const xmrig::NetworkState &results); private: static ApiRouter *m_router; }; -#endif /* __API_H__ */ +#endif /* XMRIG_API_H */ diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index dd7accf69..69fa15949 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -119,7 +120,7 @@ void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) } -void ApiRouter::tick(const NetworkState &network) +void ApiRouter::tick(const xmrig::NetworkState &network) { m_network = network; } @@ -133,7 +134,7 @@ void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousCo void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const { - rapidjson::StringBuffer buffer(0, 4096); + rapidjson::StringBuffer buffer(nullptr, 4096); rapidjson::PrettyWriter writer(buffer); writer.SetMaxDecimalPlaces(10); doc.Accept(writer); @@ -173,7 +174,7 @@ void ApiRouter::genId(const char *id) memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); xmrig::keccak(input, inSize, hash); - Job::toHex(hash, 8, m_id); + xmrig::Job::toHex(hash, 8, m_id); delete [] input; break; diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index b781d5a28..a92173ce4 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __APIROUTER_H__ -#define __APIROUTER_H__ +#ifndef XMRIG_APIROUTER_H +#define XMRIG_APIROUTER_H #include "api/NetworkState.h" @@ -44,12 +45,12 @@ class ApiRouter : public xmrig::IControllerListener { public: ApiRouter(xmrig::Controller *controller); - ~ApiRouter(); + ~ApiRouter() override; void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const; void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); - void tick(const NetworkState &results); + void tick(const xmrig::NetworkState &results); protected: void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override; @@ -68,8 +69,8 @@ private: char m_id[32]; char m_workerId[128]; - NetworkState m_network; + xmrig::NetworkState m_network; xmrig::Controller *m_controller; }; -#endif /* __APIROUTER_H__ */ +#endif /* XMRIG_APIROUTER_H */ diff --git a/src/api/NetworkState.cpp b/src/api/NetworkState.cpp index 0ab800935..0d60cbd2e 100644 --- a/src/api/NetworkState.cpp +++ b/src/api/NetworkState.cpp @@ -32,7 +32,7 @@ #include "common/net/SubmitResult.h" -NetworkState::NetworkState() : +xmrig::NetworkState::NetworkState() : diff(0), accepted(0), failures(0), @@ -44,13 +44,13 @@ NetworkState::NetworkState() : } -int NetworkState::connectionTime() const +int xmrig::NetworkState::connectionTime() const { return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0; } -uint32_t NetworkState::avgTime() const +uint32_t xmrig::NetworkState::avgTime() const { if (m_latency.empty()) { return 0; @@ -60,7 +60,7 @@ uint32_t NetworkState::avgTime() const } -uint32_t NetworkState::latency() const +uint32_t xmrig::NetworkState::latency() const { const size_t calls = m_latency.size(); if (calls == 0) { @@ -74,7 +74,7 @@ uint32_t NetworkState::latency() const } -void NetworkState::add(const SubmitResult &result, const char *error) +void xmrig::NetworkState::add(const SubmitResult &result, const char *error) { if (error) { rejected++; @@ -94,7 +94,7 @@ void NetworkState::add(const SubmitResult &result, const char *error) } -void NetworkState::setPool(const char *host, int port, const char *ip) +void xmrig::NetworkState::setPool(const char *host, int port, const char *ip) { snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port); @@ -103,7 +103,7 @@ void NetworkState::setPool(const char *host, int port, const char *ip) } -void NetworkState::stop() +void xmrig::NetworkState::stop() { m_active = false; diff = 0; diff --git a/src/api/NetworkState.h b/src/api/NetworkState.h index d09980741..c45761fb2 100644 --- a/src/api/NetworkState.h +++ b/src/api/NetworkState.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,14 +22,17 @@ * along with this program. If not, see . */ -#ifndef __NETWORKSTATE_H__ -#define __NETWORKSTATE_H__ +#ifndef XMRIG_NETWORKSTATE_H +#define XMRIG_NETWORKSTATE_H #include #include +namespace xmrig { + + class SubmitResult; @@ -58,4 +62,8 @@ private: uint64_t m_connectionTime; }; -#endif /* __NETWORKSTATE_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_NETWORKSTATE_H */ diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index c53377e8a..b81593b40 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -44,7 +44,7 @@ #endif -Pool::Pool() : +xmrig::Pool::Pool() : m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -64,7 +64,7 @@ Pool::Pool() : * * @param url */ -Pool::Pool(const char *url) : +xmrig::Pool::Pool(const char *url) : m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -74,14 +74,54 @@ Pool::Pool(const char *url) : } -Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : +xmrig::Pool::Pool(const rapidjson::Value &object) : + m_nicehash(false), + m_tls(false), + m_keepAlive(0), + m_port(kDefaultPort) +{ + if (!parse(object["url"].GetString())) { + return; + } + + setUser(object["user"].GetString()); + setPassword(object["pass"].GetString()); + setRigId(object["rig-id"].GetString()); + setNicehash(object["nicehash"].GetBool()); + + const rapidjson::Value &keepalive = object["keepalive"]; + if (keepalive.IsInt()) { + setKeepAlive(keepalive.GetInt()); + } + else if (keepalive.IsBool()) { + setKeepAlive(keepalive.IsTrue() ? kKeepAliveTimeout : 0); + } + + const rapidjson::Value &variant = object["variant"]; + if (variant.IsString()) { + algorithm().parseVariant(variant.GetString()); + } + else if (variant.IsInt()) { + algorithm().parseVariant(variant.GetInt()); + } + + const rapidjson::Value &tls = object["tls"]; + if (tls.IsBool()) { + m_tls = tls.IsTrue(); + } + + m_fingerprint = object["tls-fingerprint"].GetString(); +} + + +xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : m_nicehash(nicehash), m_tls(tls), m_keepAlive(keepAlive), - m_port(port), m_host(host), m_password(password), - m_user(user) + m_user(user), + m_port(port) { const size_t size = m_host.size() + 8; assert(size > 8); @@ -93,7 +133,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo } -bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const +bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const { if (m_algorithms.empty()) { return true; @@ -115,7 +155,7 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const } -bool Pool::isEqual(const Pool &other) const +bool xmrig::Pool::isEqual(const Pool &other) const { return (m_nicehash == other.m_nicehash && m_tls == other.m_tls @@ -131,7 +171,7 @@ bool Pool::isEqual(const Pool &other) const } -bool Pool::parse(const char *url) +bool xmrig::Pool::parse(const char *url) { assert(url != nullptr); @@ -178,7 +218,7 @@ bool Pool::parse(const char *url) } -bool Pool::setUserpass(const char *userpass) +bool xmrig::Pool::setUserpass(const char *userpass) { const char *p = strchr(userpass, ':'); if (!p) { @@ -195,7 +235,7 @@ bool Pool::setUserpass(const char *userpass) } -rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const +rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const { using namespace rapidjson; @@ -220,13 +260,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const } switch (m_algorithm.variant()) { - case xmrig::VARIANT_AUTO: - case xmrig::VARIANT_0: - case xmrig::VARIANT_1: + case VARIANT_AUTO: + case VARIANT_0: + case VARIANT_1: obj.AddMember("variant", m_algorithm.variant(), allocator); break; - case xmrig::VARIANT_2: + case VARIANT_2: obj.AddMember("variant", 2, allocator); break; @@ -242,7 +282,7 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const } -void Pool::adjust(const xmrig::Algorithm &algorithm) +void xmrig::Pool::adjust(const Algorithm &algorithm) { if (!isValid()) { return; @@ -257,7 +297,7 @@ void Pool::adjust(const xmrig::Algorithm &algorithm) } -void Pool::setAlgo(const xmrig::Algorithm &algorithm) +void xmrig::Pool::setAlgo(const xmrig::Algorithm &algorithm) { m_algorithm = algorithm; @@ -266,7 +306,7 @@ void Pool::setAlgo(const xmrig::Algorithm &algorithm) #ifdef APP_DEBUG -void Pool::print() const +void xmrig::Pool::print() const { LOG_NOTICE("url: %s", m_url.data()); LOG_DEBUG ("host: %s", m_host.data()); @@ -281,7 +321,7 @@ void Pool::print() const #endif -bool Pool::parseIPv6(const char *addr) +bool xmrig::Pool::parseIPv6(const char *addr) { const char *end = strchr(addr, ']'); if (!end) { @@ -304,7 +344,7 @@ bool Pool::parseIPv6(const char *addr) } -void Pool::addVariant(xmrig::Variant variant) +void xmrig::Pool::addVariant(xmrig::Variant variant) { const xmrig::Algorithm algorithm(m_algorithm.algo(), variant); if (!algorithm.isValid() || m_algorithm == algorithm) { @@ -315,7 +355,7 @@ void Pool::addVariant(xmrig::Variant variant) } -void Pool::adjustVariant(const xmrig::Variant variantHint) +void xmrig::Pool::adjustVariant(const xmrig::Variant variantHint) { # ifndef XMRIG_PROXY_PROJECT using namespace xmrig; @@ -401,7 +441,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint) } -void Pool::rebuild() +void xmrig::Pool::rebuild() { m_algorithms.clear(); @@ -412,18 +452,18 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - addVariant(xmrig::VARIANT_WOW); - addVariant(xmrig::VARIANT_2); - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_HALF); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_TUBE); - addVariant(xmrig::VARIANT_MSR); - addVariant(xmrig::VARIANT_XHV); - addVariant(xmrig::VARIANT_XAO); - addVariant(xmrig::VARIANT_RTO); - addVariant(xmrig::VARIANT_GPU); - addVariant(xmrig::VARIANT_AUTO); + addVariant(VARIANT_WOW); + addVariant(VARIANT_2); + addVariant(VARIANT_1); + addVariant(VARIANT_0); + addVariant(VARIANT_HALF); + addVariant(VARIANT_XTL); + addVariant(VARIANT_TUBE); + addVariant(VARIANT_MSR); + addVariant(VARIANT_XHV); + addVariant(VARIANT_XAO); + addVariant(VARIANT_RTO); + addVariant(VARIANT_GPU); + addVariant(VARIANT_AUTO); # endif } diff --git a/src/base/net/Pool.h b/src/base/net/Pool.h index 59bc9eb89..06ccf2bc9 100644 --- a/src/base/net/Pool.h +++ b/src/base/net/Pool.h @@ -5,7 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -29,11 +29,14 @@ #include +#include "base/tools/String.h" #include "common/crypto/Algorithm.h" -#include "common/utils/c_str.h" #include "rapidjson/fwd.h" +namespace xmrig { + + class Pool { public: @@ -44,6 +47,7 @@ public: Pool(); Pool(const char *url); + Pool(const rapidjson::Value &object); Pool(const char *host, uint16_t port, const char *user = nullptr, @@ -62,8 +66,8 @@ public: inline const char *rigId() const { return m_rigId.data(); } inline const char *url() const { return m_url.data(); } inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } + inline const Algorithm &algorithm() const { return m_algorithm; } + inline const Algorithms &algorithms() const { return m_algorithms; } inline int keepAlive() const { return m_keepAlive; } inline uint16_t port() const { return m_port; } inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } @@ -73,18 +77,18 @@ public: inline void setRigId(const char *rigId) { m_rigId = rigId; } inline void setTLS(bool tls) { m_tls = tls; } inline void setUser(const char *user) { m_user = user; } - inline xmrig::Algorithm &algorithm() { return m_algorithm; } + inline Algorithm &algorithm() { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } - bool isCompatible(const xmrig::Algorithm &algorithm) const; + bool isCompatible(const Algorithm &algorithm) const; bool isEqual(const Pool &other) const; bool parse(const char *url); bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; - void adjust(const xmrig::Algorithm &algorithm); - void setAlgo(const xmrig::Algorithm &algorithm); + void adjust(const Algorithm &algorithm); + void setAlgo(const Algorithm &algorithm); # ifdef APP_DEBUG void print() const; @@ -92,25 +96,26 @@ public: private: bool parseIPv6(const char *addr); - void addVariant(xmrig::Variant variant); - void adjustVariant(const xmrig::Variant variantHint); + void addVariant(Variant variant); + void adjustVariant(const Variant variantHint); void rebuild(); + Algorithm m_algorithm; + Algorithms m_algorithms; bool m_nicehash; bool m_tls; int m_keepAlive; + String m_fingerprint; + String m_host; + String m_password; + String m_rigId; + String m_url; + String m_user; uint16_t m_port; - xmrig::Algorithm m_algorithm; - xmrig::Algorithms m_algorithms; - xmrig::c_str m_fingerprint; - xmrig::c_str m_host; - xmrig::c_str m_password; - xmrig::c_str m_rigId; - xmrig::c_str m_url; - xmrig::c_str m_user; }; -//typedef std::vector Pools; +} /* namespace xmrig */ + #endif /* XMRIG_POOL_H */ diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index ab5609fcc..49a1607c3 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -26,7 +26,7 @@ #include "base/net/Pools.h" -xmrig::Pools::Pools() +xmrig::Pools::Pools() : + m_index(0) { - } diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index 5d2aa0d48..1f8a8c771 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -41,6 +41,7 @@ public: Pools(); private: + size_t m_index; std::vector m_data; }; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 9a2f8c9e0..604ab0890 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -425,6 +425,12 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) } +void xmrig::CommonConfig::parseJSON(const rapidjson::Document &doc) +{ + +} + + void xmrig::CommonConfig::setFileName(const char *fileName) { m_fileName = fileName; @@ -480,7 +486,7 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) } -Pool &xmrig::CommonConfig::currentPool() +xmrig::Pool &xmrig::CommonConfig::currentPool() { fixup(); diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 058d6eddb..6316a078b 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -81,6 +81,7 @@ protected: bool parseBoolean(int key, bool enable) override; bool parseString(int key, const char *arg) override; bool parseUint64(int key, uint64_t arg) override; + void parseJSON(const rapidjson::Document &doc) override; void setFileName(const char *fileName) override; Algorithm m_algorithm; @@ -101,12 +102,12 @@ protected: State m_state; std::vector m_activePools; std::vector m_pools; - xmrig::String m_apiId; - xmrig::String m_apiToken; - xmrig::String m_apiWorkerId; - xmrig::String m_fileName; - xmrig::String m_logFile; - xmrig::String m_userAgent; + String m_apiId; + String m_apiToken; + String m_apiWorkerId; + String m_fileName; + String m_logFile; + String m_userAgent; private: bool parseInt(int key, int arg); diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index f4380d45f..664552aa5 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify diff --git a/src/common/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h index f6e7fd3c5..029d140d6 100644 --- a/src/common/interfaces/IClientListener.h +++ b/src/common/interfaces/IClientListener.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,22 +22,27 @@ * along with this program. If not, see . */ -#ifndef __ICLIENTLISTENER_H__ -#define __ICLIENTLISTENER_H__ +#ifndef XMRIG_ICLIENTLISTENER_H +#define XMRIG_ICLIENTLISTENER_H #include -class Client; class Job; class SubmitResult; +namespace xmrig { + + +class Client; + + class IClientListener { public: - virtual ~IClientListener() {} + virtual ~IClientListener() = default; virtual void onClose(Client *client, int failures) = 0; virtual void onJobReceived(Client *client, const Job &job) = 0; @@ -45,4 +51,7 @@ public: }; -#endif // __ICLIENTLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ICLIENTLISTENER_H diff --git a/src/common/interfaces/IStrategy.h b/src/common/interfaces/IStrategy.h index b3ac7f9cb..1e9c19bc4 100644 --- a/src/common/interfaces/IStrategy.h +++ b/src/common/interfaces/IStrategy.h @@ -33,23 +33,27 @@ class JobResult; namespace xmrig { - class Algorithm; -} + + +class Algorithm; class IStrategy { public: - virtual ~IStrategy() {} + virtual ~IStrategy() = default; virtual bool isActive() const = 0; virtual int64_t submit(const JobResult &result) = 0; virtual void connect() = 0; virtual void resume() = 0; - virtual void setAlgo(const xmrig::Algorithm &algo) = 0; + virtual void setAlgo(const Algorithm &algo) = 0; virtual void stop() = 0; virtual void tick(uint64_t now) = 0; }; +} /* namespace xmrig */ + + #endif // XMRIG_ISTRATEGY_H diff --git a/src/common/interfaces/IStrategyListener.h b/src/common/interfaces/IStrategyListener.h index 9f2c4487a..cbec7742e 100644 --- a/src/common/interfaces/IStrategyListener.h +++ b/src/common/interfaces/IStrategyListener.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,13 +22,16 @@ * along with this program. If not, see . */ -#ifndef __ISTRATEGYLISTENER_H__ -#define __ISTRATEGYLISTENER_H__ +#ifndef XMRIG_ISTRATEGYLISTENER_H +#define XMRIG_ISTRATEGYLISTENER_H #include +namespace xmrig { + + class Client; class IStrategy; class Job; @@ -37,7 +41,7 @@ class SubmitResult; class IStrategyListener { public: - virtual ~IStrategyListener() {} + virtual ~IStrategyListener() = default; virtual void onActive(IStrategy *strategy, Client *client) = 0; virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0; @@ -46,4 +50,7 @@ public: }; -#endif // __ISTRATEGYLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ISTRATEGYLISTENER_H diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 36ddba31b..d846175df 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -51,8 +52,12 @@ #endif +namespace xmrig { + int64_t Client::m_sequence = 1; -xmrig::Storage Client::m_storage; +Storage Client::m_storage; + +} /* namespace xmrig */ #ifdef APP_DEBUG @@ -66,7 +71,7 @@ static const char *states[] = { #endif -Client::Client(int id, const char *agent, IClientListener *listener) : +xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : m_ipv6(false), m_nicehash(false), m_quiet(false), @@ -103,13 +108,13 @@ Client::Client(int id, const char *agent, IClientListener *listener) : } -Client::~Client() +xmrig::Client::~Client() { delete m_socket; } -void Client::connect() +void xmrig::Client::connect() { # ifndef XMRIG_NO_TLS if (m_pool.isTLS()) { @@ -126,14 +131,14 @@ void Client::connect() * * @param url */ -void Client::connect(const Pool &url) +void xmrig::Client::connect(const Pool &url) { setPool(url); connect(); } -void Client::deleteLater() +void xmrig::Client::deleteLater() { if (!m_listener) { return; @@ -148,7 +153,7 @@ void Client::deleteLater() -void Client::setPool(const Pool &pool) +void xmrig::Client::setPool(const Pool &pool) { if (!pool.isValid()) { return; @@ -158,7 +163,7 @@ void Client::setPool(const Pool &pool) } -void Client::tick(uint64_t now) +void xmrig::Client::tick(uint64_t now) { if (m_state == ConnectedState) { if (m_expire && now > m_expire) { @@ -176,7 +181,7 @@ void Client::tick(uint64_t now) } -bool Client::disconnect() +bool xmrig::Client::disconnect() { m_keepAlive = 0; m_expire = 0; @@ -186,7 +191,7 @@ bool Client::disconnect() } -const char *Client::tlsFingerprint() const +const char *xmrig::Client::tlsFingerprint() const { # ifndef XMRIG_NO_TLS if (isTLS() && m_pool.fingerprint() == nullptr) { @@ -198,7 +203,7 @@ const char *Client::tlsFingerprint() const } -const char *Client::tlsVersion() const +const char *xmrig::Client::tlsVersion() const { # ifndef XMRIG_NO_TLS if (isTLS()) { @@ -210,7 +215,7 @@ const char *Client::tlsVersion() const } -int64_t Client::submit(const JobResult &result) +int64_t xmrig::Client::submit(const JobResult &result) { # ifndef XMRIG_PROXY_PROJECT if (result.clientId != m_rpcId) { @@ -218,7 +223,7 @@ int64_t Client::submit(const JobResult &result) } # endif - if (m_job.algorithm().variant() == xmrig::VARIANT_WOW && m_job.id() != result.jobId) { + if (m_job.algorithm().variant() == VARIANT_WOW && m_job.id() != result.jobId) { return -1; } @@ -267,7 +272,7 @@ int64_t Client::submit(const JobResult &result) } -bool Client::close() +bool xmrig::Client::close() { if (m_state == ClosingState) { return m_socket != nullptr; @@ -287,7 +292,7 @@ bool Client::close() } -bool Client::isCriticalError(const char *message) +bool xmrig::Client::isCriticalError(const char *message) { if (!message) { return false; @@ -309,7 +314,7 @@ bool Client::isCriticalError(const char *message) } -bool Client::isTLS() const +bool xmrig::Client::isTLS() const { # ifndef XMRIG_NO_TLS return m_pool.isTLS() && m_tls; @@ -319,7 +324,7 @@ bool Client::isTLS() const } -bool Client::parseJob(const rapidjson::Value ¶ms, int *code) +bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) { if (!params.IsObject()) { *code = 2; @@ -394,7 +399,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } -bool Client::parseLogin(const rapidjson::Value &result, int *code) +bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) { if (!m_rpcId.setId(result["id"].GetString())) { *code = 1; @@ -414,7 +419,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) } -bool Client::send(BIO *bio) +bool xmrig::Client::send(BIO *bio) { # ifndef XMRIG_NO_TLS uv_buf_t buf; @@ -447,10 +452,10 @@ bool Client::send(BIO *bio) } -bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const +bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const { # ifdef XMRIG_PROXY_PROJECT - if (m_pool.algorithm().variant() == xmrig::VARIANT_AUTO || m_id == -1) { + if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) { return true; } # endif @@ -474,7 +479,7 @@ bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const } -int Client::resolve(const char *host) +int xmrig::Client::resolve(const char *host) { setState(HostLookupState); @@ -497,7 +502,7 @@ int Client::resolve(const char *host) } -int64_t Client::send(const rapidjson::Document &doc) +int64_t xmrig::Client::send(const rapidjson::Document &doc) { using namespace rapidjson; @@ -520,7 +525,7 @@ int64_t Client::send(const rapidjson::Document &doc) } -int64_t Client::send(size_t size) +int64_t xmrig::Client::send(size_t size) { LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); @@ -551,7 +556,7 @@ int64_t Client::send(size_t size) } -void Client::connect(const std::vector &ipv4, const std::vector &ipv6) +void xmrig::Client::connect(const std::vector &ipv4, const std::vector &ipv6) { addrinfo *addr = nullptr; m_ipv6 = ipv4.empty() && !ipv6.empty(); @@ -569,7 +574,7 @@ void Client::connect(const std::vector &ipv4, const std::vectordata); if (!client) { @@ -903,7 +908,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t } -void Client::onClose(uv_handle_t *handle) +void xmrig::Client::onClose(uv_handle_t *handle) { auto client = getClient(handle->data); if (!client) { @@ -914,7 +919,7 @@ void Client::onClose(uv_handle_t *handle) } -void Client::onConnect(uv_connect_t *req, int status) +void xmrig::Client::onConnect(uv_connect_t *req, int status) { auto client = getClient(req->data); if (!client) { @@ -943,7 +948,7 @@ void Client::onConnect(uv_connect_t *req, int status) } -void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) +void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { auto client = getClient(stream->data); if (!client) { @@ -986,7 +991,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) } -void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) +void xmrig::Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) { auto client = getClient(req->data); if (!client) { diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 4594a90fa..9314739a2 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -39,13 +40,16 @@ #include "rapidjson/fwd.h" +typedef struct bio_st BIO; + + +namespace xmrig { + + class IClientListener; class JobResult; -typedef struct bio_st BIO; - - class Client { public: @@ -85,7 +89,7 @@ public: inline int id() const { return m_id; } inline SocketState state() const { return m_state; } inline uint16_t port() const { return m_pool.port(); } - inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } + inline void setAlgo(const Algorithm &algo) { m_pool.setAlgo(algo); } inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setRetries(int retries) { m_retries = retries; } inline void setRetryPause(int ms) { m_retryPause = ms; } @@ -105,7 +109,7 @@ private: bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); - bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const; + bool verifyAlgorithm(const Algorithm &algorithm) const; int resolve(const char *host); int64_t send(const rapidjson::Document &doc); int64_t send(size_t size); @@ -162,11 +166,14 @@ private: uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; - xmrig::Id m_rpcId; + Id m_rpcId; static int64_t m_sequence; - static xmrig::Storage m_storage; + static Storage m_storage; }; +} /* namespace xmrig */ + + #endif /* XMRIG_CLIENT_H */ diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index ee76f732b..2bca5af62 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -58,7 +58,7 @@ char hf_bin2hex(unsigned char c) } -Job::Job() : +xmrig::Job::Job() : m_autoVariant(false), m_nicehash(false), m_poolId(-2), @@ -72,8 +72,8 @@ Job::Job() : } -Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) : - m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO), +xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId) : + m_autoVariant(algorithm.variant() == VARIANT_AUTO), m_nicehash(nicehash), m_poolId(poolId), m_threadId(-1), @@ -88,18 +88,18 @@ Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmr } -Job::~Job() +xmrig::Job::~Job() { } -bool Job::isEqual(const Job &other) const +bool xmrig::Job::isEqual(const Job &other) const { return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; } -bool Job::setBlob(const char *blob) +bool xmrig::Job::setBlob(const char *blob) { if (!blob) { return false; @@ -128,14 +128,14 @@ bool Job::setBlob(const char *blob) } if (!m_algorithm.isForced()) { - if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] >= 9) { - m_algorithm.setVariant(xmrig::VARIANT_HALF); + if (m_algorithm.variant() == VARIANT_XTL && m_blob[0] >= 9) { + m_algorithm.setVariant(VARIANT_HALF); } - else if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] >= 8) { - m_algorithm.setVariant(xmrig::VARIANT_HALF); + else if (m_algorithm.variant() == VARIANT_MSR && m_blob[0] >= 8) { + m_algorithm.setVariant(VARIANT_HALF); } - else if (m_algorithm.variant() == xmrig::VARIANT_WOW && m_blob[0] < 11) { - m_algorithm.setVariant(xmrig::VARIANT_2); + else if (m_algorithm.variant() == VARIANT_WOW && m_blob[0] < 11) { + m_algorithm.setVariant(VARIANT_2); } } @@ -148,7 +148,7 @@ bool Job::setBlob(const char *blob) } -bool Job::setTarget(const char *target) +bool xmrig::Job::setTarget(const char *target) { if (!target) { return false; @@ -190,7 +190,7 @@ bool Job::setTarget(const char *target) } -void Job::setAlgorithm(const char *algo) +void xmrig::Job::setAlgorithm(const char *algo) { m_algorithm.parseAlgorithm(algo); @@ -200,13 +200,13 @@ void Job::setAlgorithm(const char *algo) } -void Job::setHeight(uint64_t height) +void xmrig::Job::setHeight(uint64_t height) { m_height = height; } -bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) +bool xmrig::Job::fromHex(const char* in, unsigned int len, unsigned char* out) { bool error = false; for (unsigned int i = 0; i < len; i += 2) { @@ -220,7 +220,7 @@ bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) } -void Job::toHex(const unsigned char* in, unsigned int len, char* out) +void xmrig::Job::toHex(const unsigned char* in, unsigned int len, char* out) { for (unsigned int i = 0; i < len; i++) { out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4); @@ -230,7 +230,7 @@ void Job::toHex(const unsigned char* in, unsigned int len, char* out) #ifdef APP_DEBUG -char *Job::toHex(const unsigned char* in, unsigned int len) +char *xmrig::Job::toHex(const unsigned char* in, unsigned int len) { char *out = new char[len * 2 + 1](); toHex(in, len, out); @@ -240,10 +240,8 @@ char *Job::toHex(const unsigned char* in, unsigned int len) #endif -xmrig::Variant Job::variant() const +xmrig::Variant xmrig::Job::variant() const { - using namespace xmrig; - switch (m_algorithm.algo()) { case CRYPTONIGHT: return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 4fdac3ada..49ddc7da3 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -35,6 +35,9 @@ #include "common/net/Id.h" +namespace xmrig { + + class Job { public: @@ -43,7 +46,7 @@ public: static constexpr const size_t kMaxBlobSize = 128; Job(); - Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); + Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId); ~Job(); bool isEqual(const Job &other) const; @@ -57,9 +60,9 @@ public: inline bool setId(const char *id) { return m_id.setId(id); } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline const xmrig::Id &clientId() const { return m_clientId; } - inline const xmrig::Id &id() const { return m_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 int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } @@ -68,7 +71,7 @@ public: inline uint64_t target() const { return m_target; } inline uint64_t height() const { return m_height; } inline void reset() { m_size = 0; m_diff = 0; } - inline void setClientId(const xmrig::Id &id) { m_clientId = id; } + inline void setClientId(const Id &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); } @@ -92,7 +95,7 @@ public: inline bool operator!=(const Job &other) const { return !isEqual(other); } private: - xmrig::Variant variant() const; + Variant variant() const; bool m_autoVariant; bool m_nicehash; @@ -113,4 +116,8 @@ private: # endif }; + +} /* namespace xmrig */ + + #endif /* XMRIG_JOB_H */ diff --git a/src/common/net/SubmitResult.cpp b/src/common/net/SubmitResult.cpp index 251b2bf16..d14bbb408 100644 --- a/src/common/net/SubmitResult.cpp +++ b/src/common/net/SubmitResult.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -28,7 +29,7 @@ #include "common/net/SubmitResult.h" -SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : +xmrig::SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : reqId(reqId), seq(seq), diff(diff), @@ -39,7 +40,7 @@ SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int6 } -void SubmitResult::done() +void xmrig::SubmitResult::done() { elapsed = (uv_hrtime() - start) / 1000000; } diff --git a/src/common/net/SubmitResult.h b/src/common/net/SubmitResult.h index e812cbf8a..db97ac38a 100644 --- a/src/common/net/SubmitResult.h +++ b/src/common/net/SubmitResult.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,13 +22,16 @@ * along with this program. If not, see . */ -#ifndef __SUBMITRESULT_H__ -#define __SUBMITRESULT_H__ +#ifndef XMRIG_SUBMITRESULT_H +#define XMRIG_SUBMITRESULT_H #include +namespace xmrig { + + class SubmitResult { public: @@ -46,4 +50,8 @@ private: uint64_t start; }; -#endif /* __SUBMITRESULT_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_SUBMITRESULT_H */ diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp index 182d86ff5..a9b3fa7de 100644 --- a/src/common/net/Tls.cpp +++ b/src/common/net/Tls.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -37,7 +37,7 @@ #endif -Client::Tls::Tls(Client *client) : +xmrig::Client::Tls::Tls(Client *client) : m_ready(false), m_buf(), m_fingerprint(), @@ -57,7 +57,7 @@ Client::Tls::Tls(Client *client) : } -Client::Tls::~Tls() +xmrig::Client::Tls::~Tls() { if (m_ctx) { SSL_CTX_free(m_ctx); @@ -69,7 +69,7 @@ Client::Tls::~Tls() } -bool Client::Tls::handshake() +bool xmrig::Client::Tls::handshake() { m_ssl = SSL_new(m_ctx); assert(m_ssl != nullptr); @@ -86,7 +86,7 @@ bool Client::Tls::handshake() } -bool Client::Tls::send(const char *data, size_t size) +bool xmrig::Client::Tls::send(const char *data, size_t size) { SSL_write(m_ssl, data, size); @@ -94,19 +94,19 @@ bool Client::Tls::send(const char *data, size_t size) } -const char *Client::Tls::fingerprint() const +const char *xmrig::Client::Tls::fingerprint() const { return m_ready ? m_fingerprint : nullptr; } -const char *Client::Tls::version() const +const char *xmrig::Client::Tls::version() const { return m_ready ? SSL_get_version(m_ssl) : nullptr; } -void Client::Tls::read(const char *data, size_t size) +void xmrig::Client::Tls::read(const char *data, size_t size) { BIO_write(m_readBio, data, size); @@ -139,13 +139,13 @@ void Client::Tls::read(const char *data, size_t size) } -bool Client::Tls::send() +bool xmrig::Client::Tls::send() { return m_client->send(m_writeBio); } -bool Client::Tls::verify(X509 *cert) +bool xmrig::Client::Tls::verify(X509 *cert) { if (cert == nullptr) { LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); @@ -169,7 +169,7 @@ bool Client::Tls::verify(X509 *cert) } -bool Client::Tls::verifyFingerprint(X509 *cert) +bool xmrig::Client::Tls::verifyFingerprint(X509 *cert) { const EVP_MD *digest = EVP_get_digestbyname("sha256"); if (digest == nullptr) { diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index 083adfc45..937d255c2 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * 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 @@ -31,7 +32,7 @@ #include "common/net/Client.h" -class Client::Tls +class xmrig::Client::Tls { public: Tls(Client *client); diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index 3be3687d6..95883f701 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -29,7 +29,7 @@ #include "common/Platform.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +xmrig::FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_quiet(quiet), m_retries(retries), m_retryPause(retryPause), @@ -43,7 +43,7 @@ FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause } -FailoverStrategy::~FailoverStrategy() +xmrig::FailoverStrategy::~FailoverStrategy() { for (Client *client : m_pools) { client->deleteLater(); @@ -51,7 +51,7 @@ FailoverStrategy::~FailoverStrategy() } -int64_t FailoverStrategy::submit(const JobResult &result) +int64_t xmrig::FailoverStrategy::submit(const JobResult &result) { if (m_active == -1) { return -1; @@ -61,13 +61,13 @@ int64_t FailoverStrategy::submit(const JobResult &result) } -void FailoverStrategy::connect() +void xmrig::FailoverStrategy::connect() { m_pools[m_index]->connect(); } -void FailoverStrategy::resume() +void xmrig::FailoverStrategy::resume() { if (!isActive()) { return; @@ -77,7 +77,7 @@ void FailoverStrategy::resume() } -void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) { for (Client *client : m_pools) { client->setAlgo(algo); @@ -85,7 +85,7 @@ void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) } -void FailoverStrategy::stop() +void xmrig::FailoverStrategy::stop() { for (size_t i = 0; i < m_pools.size(); ++i) { m_pools[i]->disconnect(); @@ -98,7 +98,7 @@ void FailoverStrategy::stop() } -void FailoverStrategy::tick(uint64_t now) +void xmrig::FailoverStrategy::tick(uint64_t now) { for (Client *client : m_pools) { client->tick(now); @@ -106,7 +106,7 @@ void FailoverStrategy::tick(uint64_t now) } -void FailoverStrategy::onClose(Client *client, int failures) +void xmrig::FailoverStrategy::onClose(Client *client, int failures) { if (failures == -1) { return; @@ -127,7 +127,7 @@ void FailoverStrategy::onClose(Client *client, int failures) } -void FailoverStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job) { if (m_active == client->id()) { m_listener->onJob(this, client, job); @@ -135,7 +135,7 @@ void FailoverStrategy::onJobReceived(Client *client, const Job &job) } -void FailoverStrategy::onLoginSuccess(Client *client) +void xmrig::FailoverStrategy::onLoginSuccess(Client *client) { int active = m_active; @@ -156,13 +156,13 @@ void FailoverStrategy::onLoginSuccess(Client *client) } -void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) +void xmrig::FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } -void FailoverStrategy::add(const Pool &pool) +void xmrig::FailoverStrategy::add(const Pool &pool) { Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); client->setPool(pool); diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index cfc8e92ae..0bff0e0ab 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -34,9 +34,11 @@ #include "common/interfaces/IStrategy.h" +namespace xmrig { + + class Client; class IStrategyListener; -class Url; class FailoverStrategy : public IStrategy, public IClientListener @@ -51,7 +53,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -73,4 +75,7 @@ private: std::vector m_pools; }; + +} /* namespace xmrig */ + #endif /* XMRIG_FAILOVERSTRATEGY_H */ diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index 354bf6d6a..f0a51a493 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -29,7 +29,7 @@ #include "common/Platform.h" -SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +xmrig::SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_active(false), m_listener(listener) { @@ -41,25 +41,25 @@ SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int ret } -SinglePoolStrategy::~SinglePoolStrategy() +xmrig::SinglePoolStrategy::~SinglePoolStrategy() { m_client->deleteLater(); } -int64_t SinglePoolStrategy::submit(const JobResult &result) +int64_t xmrig::SinglePoolStrategy::submit(const JobResult &result) { return m_client->submit(result); } -void SinglePoolStrategy::connect() +void xmrig::SinglePoolStrategy::connect() { m_client->connect(); } -void SinglePoolStrategy::resume() +void xmrig::SinglePoolStrategy::resume() { if (!isActive()) { return; @@ -69,25 +69,25 @@ void SinglePoolStrategy::resume() } -void SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo) { m_client->setAlgo(algo); } -void SinglePoolStrategy::stop() +void xmrig::SinglePoolStrategy::stop() { m_client->disconnect(); } -void SinglePoolStrategy::tick(uint64_t now) +void xmrig::SinglePoolStrategy::tick(uint64_t now) { m_client->tick(now); } -void SinglePoolStrategy::onClose(Client *client, int failures) +void xmrig::SinglePoolStrategy::onClose(Client *client, int failures) { if (!isActive()) { return; @@ -98,20 +98,20 @@ void SinglePoolStrategy::onClose(Client *client, int failures) } -void SinglePoolStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job) { m_listener->onJob(this, client, job); } -void SinglePoolStrategy::onLoginSuccess(Client *client) +void xmrig::SinglePoolStrategy::onLoginSuccess(Client *client) { m_active = true; m_listener->onActive(this, client); } -void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) +void xmrig::SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index f258d9cd3..eeb6903e8 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -30,6 +30,9 @@ #include "common/interfaces/IStrategy.h" +namespace xmrig { + + class Client; class IStrategyListener; class Pool; @@ -47,7 +50,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -63,4 +66,8 @@ private: IStrategyListener *m_listener; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_SINGLEPOOLSTRATEGY_H */ diff --git a/src/core/Config.cpp b/src/core/Config.cpp index f54f092b7..f3487b15b 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -292,6 +292,8 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) void xmrig::Config::parseJSON(const rapidjson::Document &doc) { + CommonConfig::parseJSON(doc); + const rapidjson::Value &threads = doc["threads"]; if (threads.IsArray()) { diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index abe6d46d9..766ddbab6 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -62,8 +62,8 @@ public: Network *network; Process *process; - std::vector listeners; - xmrig::Config *config; + std::vector listeners; + Config *config; }; @@ -127,7 +127,7 @@ int xmrig::Controller::init() } -Network *xmrig::Controller::network() const +xmrig::Network *xmrig::Controller::network() const { assert(d_ptr->network != nullptr); diff --git a/src/core/Controller.h b/src/core/Controller.h index 89a462f9c..8d2f26745 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -29,7 +29,6 @@ #include "base/kernel/interfaces/IConfigListener.h" -class Network; class StatsData; @@ -39,6 +38,7 @@ namespace xmrig { class Config; class ControllerPrivate; class IControllerListener; +class Network; class Process; @@ -62,6 +62,8 @@ private: ControllerPrivate *d_ptr; }; + } /* namespace xmrig */ + #endif /* XMRIG_CONTROLLER_H */ diff --git a/src/interfaces/IJobResultListener.h b/src/interfaces/IJobResultListener.h index 483a2062d..e99db502a 100644 --- a/src/interfaces/IJobResultListener.h +++ b/src/interfaces/IJobResultListener.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * 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 @@ -21,8 +22,11 @@ * along with this program. If not, see . */ -#ifndef __IJOBRESULTLISTENER_H__ -#define __IJOBRESULTLISTENER_H__ +#ifndef XMRIG_IJOBRESULTLISTENER_H +#define XMRIG_IJOBRESULTLISTENER_H + + +namespace xmrig { class Client; @@ -32,10 +36,13 @@ class JobResult; class IJobResultListener { public: - virtual ~IJobResultListener() {} + virtual ~IJobResultListener() = default; virtual void onJobResult(const JobResult &result) = 0; }; -#endif // __IJOBRESULTLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_IJOBRESULTLISTENER_H diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 071cbb8b1..5ab4d2942 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -5,7 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * 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 @@ -32,17 +34,20 @@ #include "common/net/Job.h" +namespace xmrig { + + class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const xmrig::Id &jobId, const xmrig::Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : - poolId(poolId), - diff(diff), - nonce(nonce), + inline JobResult(int poolId, const Id &jobId, const Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : algorithm(algorithm), clientId(clientId), - jobId(jobId) + jobId(jobId), + poolId(poolId), + diff(diff), + nonce(nonce) { memcpy(this->result, result, sizeof(this->result)); } @@ -65,13 +70,17 @@ public: } + Algorithm algorithm; + Id clientId; + Id jobId; int poolId; uint32_t diff; uint32_t nonce; uint8_t result[32]; - xmrig::Algorithm algorithm; - xmrig::Id clientId; - xmrig::Id jobId; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_JOBRESULT_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 08e96d1d6..78ace87c3 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -44,12 +44,10 @@ #include "workers/Workers.h" -Network::Network(xmrig::Controller *controller) : - m_donate(nullptr), - m_controller(controller) +xmrig::Network::Network(Controller *controller) : + m_controller(controller), + m_donate(nullptr) { - srand(time(0) ^ (uintptr_t) this); - Workers::setListener(this); const std::vector &pools = controller->config()->pools(); @@ -72,18 +70,18 @@ Network::Network(xmrig::Controller *controller) : } -Network::~Network() +xmrig::Network::~Network() { } -void Network::connect() +void xmrig::Network::connect() { m_strategy->connect(); } -void Network::stop() +void xmrig::Network::stop() { if (m_donate) { m_donate->stop(); @@ -93,7 +91,7 @@ void Network::stop() } -void Network::onActive(IStrategy *strategy, Client *client) +void xmrig::Network::onActive(IStrategy *strategy, Client *client) { if (m_donate && m_donate == strategy) { LOG_NOTICE("dev donate started"); @@ -114,7 +112,7 @@ void Network::onActive(IStrategy *strategy, Client *client) } -void Network::onJob(IStrategy *strategy, Client *client, const Job &job) +void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job) { if (m_donate && m_donate->isActive() && m_donate != strategy) { return; @@ -124,7 +122,7 @@ void Network::onJob(IStrategy *strategy, Client *client, const Job &job) } -void Network::onJobResult(const JobResult &result) +void xmrig::Network::onJobResult(const JobResult &result) { if (result.poolId == -1 && m_donate) { m_donate->submit(result); @@ -135,7 +133,7 @@ void Network::onJobResult(const JobResult &result) } -void Network::onPause(IStrategy *strategy) +void xmrig::Network::onPause(IStrategy *strategy) { if (m_donate && m_donate == strategy) { LOG_NOTICE("dev donate finished"); @@ -150,7 +148,7 @@ void Network::onPause(IStrategy *strategy) } -void Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) { m_state.add(result, error); @@ -167,13 +165,13 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit } -bool Network::isColors() const +bool xmrig::Network::isColors() const { return m_controller->config()->isColors(); } -void Network::setJob(Client *client, const Job &job, bool donate) +void xmrig::Network::setJob(Client *client, const Job &job, bool donate) { if (job.height()) { LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64) @@ -195,7 +193,7 @@ void Network::setJob(Client *client, const Job &job, bool donate) } -void Network::tick() +void xmrig::Network::tick() { const uint64_t now = uv_now(uv_default_loop()); @@ -211,7 +209,7 @@ void Network::tick() } -void Network::onTick(uv_timer_t *handle) +void xmrig::Network::onTick(uv_timer_t *handle) { static_cast(handle->data)->tick(); } diff --git a/src/net/Network.h b/src/net/Network.h index aac4010bd..e9b073ae9 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -35,19 +35,17 @@ #include "interfaces/IJobResultListener.h" -class IStrategy; -class Url; - - namespace xmrig { - class Controller; -} + + +class Controller; +class IStrategy; class Network : public IJobResultListener, public IStrategyListener { public: - Network(xmrig::Controller *controller); + Network(Controller *controller); ~Network() override; void connect(); @@ -69,12 +67,15 @@ private: static void onTick(uv_timer_t *handle); + Controller *m_controller; IStrategy *m_donate; IStrategy *m_strategy; NetworkState m_state; uv_timer_t m_timer; - xmrig::Controller *m_controller; }; +} /* namespace xmrig */ + + #endif /* XMRIG_NETWORK_H */ diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 417a31fbf..9593dc9a8 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -39,7 +39,7 @@ static inline float randomf(float min, float max) { } -DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener) : +xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener) : m_active(false), m_donateTime(level * 60 * 1000), m_idleTime((100 - level) * 60 * 1000), @@ -51,7 +51,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS uint8_t hash[200]; char userId[65] = { 0 }; - xmrig::keccak(reinterpret_cast(user), strlen(user), hash); + keccak(reinterpret_cast(user), strlen(user), hash); Job::toHex(hash, 32, userId); # ifndef XMRIG_NO_TLS @@ -61,7 +61,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true)); for (Pool &pool : m_pools) { - pool.adjust(xmrig::Algorithm(algo, xmrig::VARIANT_AUTO)); + pool.adjust(Algorithm(algo, VARIANT_AUTO)); } if (m_pools.size() > 1) { @@ -78,38 +78,38 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS } -DonateStrategy::~DonateStrategy() +xmrig::DonateStrategy::~DonateStrategy() { delete m_strategy; } -int64_t DonateStrategy::submit(const JobResult &result) +int64_t xmrig::DonateStrategy::submit(const JobResult &result) { return m_strategy->submit(result); } -void DonateStrategy::connect() +void xmrig::DonateStrategy::connect() { m_strategy->connect(); } -void DonateStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo) { m_strategy->setAlgo(algo); } -void DonateStrategy::stop() +void xmrig::DonateStrategy::stop() { uv_timer_stop(&m_timer); m_strategy->stop(); } -void DonateStrategy::tick(uint64_t now) +void xmrig::DonateStrategy::tick(uint64_t now) { m_now = now; @@ -122,7 +122,7 @@ void DonateStrategy::tick(uint64_t now) } -void DonateStrategy::onActive(IStrategy *strategy, Client *client) +void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); @@ -133,7 +133,7 @@ void DonateStrategy::onActive(IStrategy *strategy, Client *client) } -void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) +void xmrig::DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) { if (isActive()) { m_listener->onJob(this, client, job); @@ -141,24 +141,24 @@ void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) } -void DonateStrategy::onPause(IStrategy *strategy) +void xmrig::DonateStrategy::onPause(IStrategy *strategy) { } -void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } -void DonateStrategy::idle(uint64_t timeout) +void xmrig::DonateStrategy::idle(uint64_t timeout) { uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); } -void DonateStrategy::suspend() +void xmrig::DonateStrategy::suspend() { # if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT) m_stop = m_now + 5000; @@ -173,7 +173,7 @@ void DonateStrategy::suspend() } -void DonateStrategy::onTimer(uv_timer_t *handle) +void xmrig::DonateStrategy::onTimer(uv_timer_t *handle) { auto strategy = static_cast(handle->data); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index eab01370e..76702ef32 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -36,15 +36,17 @@ #include "common/interfaces/IStrategyListener.h" +namespace xmrig { + + class Client; class IStrategyListener; -class Url; class DonateStrategy : public IStrategy, public IStrategyListener { public: - DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); + DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener); ~DonateStrategy() override; public: @@ -53,7 +55,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -80,4 +82,8 @@ private: uv_timer_t m_timer; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_DONATESTRATEGY_H */ diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 2a6153d5b..1b166d0dc 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -132,7 +132,7 @@ void MultiWorker::start() for (size_t i = 0; i < N; ++i) { if (*reinterpret_cast(m_hash + (i * 32) + 24) < m_state.job.target()) { - Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); + Workers::submit(xmrig::JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); } *nonce(i) += 1; @@ -149,7 +149,7 @@ void MultiWorker::start() template -bool MultiWorker::resume(const Job &job) +bool MultiWorker::resume(const xmrig::Job &job) { if (m_state.job.poolId() == -1 && job.poolId() >= 0 && job.id() == m_pausedState.job.id()) { m_state = m_pausedState; @@ -237,7 +237,7 @@ bool MultiWorker::verify2(xmrig::Variant variant, const char *test_data) template void MultiWorker::consumeJob() { - Job job = Workers::job(); + xmrig::Job job = Workers::job(); m_sequence = Workers::sequence(); if (m_state.job == job) { return; @@ -272,7 +272,7 @@ void MultiWorker::consumeJob() template -void MultiWorker::save(const Job &job) +void MultiWorker::save(const xmrig::Job &job) { if (job.poolId() == -1 && m_state.job.poolId() >= 0) { m_pausedState = m_state; diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 1db6a2bf2..8560b510a 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -48,11 +48,11 @@ protected: void start() override; private: - bool resume(const Job &job); + bool resume(const xmrig::Job &job); bool verify(xmrig::Variant variant, const uint8_t *referenceValue); bool verify2(xmrig::Variant variant, const char *test_data); void consumeJob(); - void save(const Job &job); + void save(const xmrig::Job &job); inline uint32_t *nonce(size_t index) { @@ -61,8 +61,8 @@ private: struct State { - alignas(16) uint8_t blob[Job::kMaxBlobSize * N]; - Job job; + alignas(16) uint8_t blob[xmrig::Job::kMaxBlobSize * N]; + xmrig::Job job; }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f6a584544..f718a52c5 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -45,12 +45,12 @@ bool Workers::m_active = false; bool Workers::m_enabled = true; Hashrate *Workers::m_hashrate = nullptr; -IJobResultListener *Workers::m_listener = nullptr; -Job Workers::m_job; +xmrig::IJobResultListener *Workers::m_listener = nullptr; +xmrig::Job Workers::m_job; Workers::LaunchStatus Workers::m_status; std::atomic Workers::m_paused; std::atomic Workers::m_sequence; -std::list Workers::m_queue; +std::list Workers::m_queue; std::vector Workers::m_workers; uint64_t Workers::m_ticks = 0; uv_async_t Workers::m_async; @@ -60,10 +60,10 @@ uv_timer_t Workers::m_timer; xmrig::Controller *Workers::m_controller = nullptr; -Job Workers::job() +xmrig::Job Workers::job() { uv_rwlock_rdlock(&m_rwlock); - Job job = m_job; + xmrig::Job job = m_job; uv_rwlock_rdunlock(&m_rwlock); return job; @@ -139,7 +139,7 @@ void Workers::setEnabled(bool enabled) } -void Workers::setJob(const Job &job, bool donate) +void Workers::setJob(const xmrig::Job &job, bool donate) { uv_rwlock_wrlock(&m_rwlock); m_job = job; @@ -225,7 +225,7 @@ void Workers::stop() } -void Workers::submit(const JobResult &result) +void Workers::submit(const xmrig::JobResult &result) { uv_mutex_lock(&m_mutex); m_queue.push_back(result); @@ -300,7 +300,7 @@ void Workers::onReady(void *arg) void Workers::onResult(uv_async_t *handle) { - std::list results; + std::list results; uv_mutex_lock(&m_mutex); while (!m_queue.empty()) { diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 61868819f..a9b8e6958 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -38,35 +38,35 @@ class Handle; class Hashrate; -class IJobResultListener; class IWorker; namespace xmrig { class Controller; + class IJobResultListener; } class Workers { public: - static Job job(); + static xmrig::Job job(); static size_t hugePages(); static size_t threads(); static void printHashrate(bool detail); static void setEnabled(bool enabled); - static void setJob(const Job &job, bool donate); + static void setJob(const xmrig::Job &job, bool donate); static void start(xmrig::Controller *controller); static void stop(); - static void submit(const JobResult &result); + static void submit(const xmrig::JobResult &result); - static inline bool isEnabled() { return m_enabled; } - static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; } - static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; } - static inline Hashrate *hashrate() { return m_hashrate; } - static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); } - static inline void pause() { m_active = false; m_paused = 1; m_sequence++; } - static inline void setListener(IJobResultListener *listener) { m_listener = listener; } + static inline bool isEnabled() { return m_enabled; } + static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; } + static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; } + static inline Hashrate *hashrate() { return m_hashrate; } + static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); } + static inline void pause() { m_active = false; m_paused = 1; m_sequence++; } + static inline void setListener(xmrig::IJobResultListener *listener) { m_listener = listener; } # ifndef XMRIG_NO_API static void threadsSummary(rapidjson::Document &doc); @@ -103,12 +103,12 @@ private: static bool m_active; static bool m_enabled; static Hashrate *m_hashrate; - static IJobResultListener *m_listener; - static Job m_job; + static xmrig::IJobResultListener *m_listener; + static xmrig::Job m_job; static LaunchStatus m_status; static std::atomic m_paused; static std::atomic m_sequence; - static std::list m_queue; + static std::list m_queue; static std::vector m_workers; static uint64_t m_ticks; static uv_async_t m_async;