Move network classes into xmrig namespace.

This commit is contained in:
XMRig 2019-02-17 06:59:19 +07:00
parent dbdcc14672
commit ee667144e8
42 changed files with 481 additions and 332 deletions

View file

@ -33,13 +33,13 @@
class Console; class Console;
class Httpd; class Httpd;
class Network;
namespace xmrig { namespace xmrig {
class Controller; class Controller;
class Network;
class Process; class Process;
class Signals; class Signals;
@ -62,9 +62,9 @@ private:
void release(); void release();
Console *m_console; Console *m_console;
Controller *m_controller;
Httpd *m_httpd; Httpd *m_httpd;
Signals *m_signals; Signals *m_signals;
xmrig::Controller *m_controller;
}; };

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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) { if (!m_router) {
return; return;

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __API_H__ #ifndef XMRIG_API_H
#define __API_H__ #define XMRIG_API_H
#include <uv.h> #include <uv.h>
@ -30,13 +31,13 @@
class ApiRouter; class ApiRouter;
class Hashrate; class Hashrate;
class NetworkState;
namespace xmrig { namespace xmrig {
class Controller; class Controller;
class HttpReply; class HttpReply;
class HttpRequest; class HttpRequest;
class NetworkState;
} }
@ -47,10 +48,10 @@ public:
static void release(); static void release();
static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
static void tick(const NetworkState &results); static void tick(const xmrig::NetworkState &results);
private: private:
static ApiRouter *m_router; static ApiRouter *m_router;
}; };
#endif /* __API_H__ */ #endif /* XMRIG_API_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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; 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 void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const
{ {
rapidjson::StringBuffer buffer(0, 4096); rapidjson::StringBuffer buffer(nullptr, 4096);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer); rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
writer.SetMaxDecimalPlaces(10); writer.SetMaxDecimalPlaces(10);
doc.Accept(writer); doc.Accept(writer);
@ -173,7 +174,7 @@ void ApiRouter::genId(const char *id)
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND));
xmrig::keccak(input, inSize, hash); xmrig::keccak(input, inSize, hash);
Job::toHex(hash, 8, m_id); xmrig::Job::toHex(hash, 8, m_id);
delete [] input; delete [] input;
break; break;

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __APIROUTER_H__ #ifndef XMRIG_APIROUTER_H
#define __APIROUTER_H__ #define XMRIG_APIROUTER_H
#include "api/NetworkState.h" #include "api/NetworkState.h"
@ -44,12 +45,12 @@ class ApiRouter : public xmrig::IControllerListener
{ {
public: public:
ApiRouter(xmrig::Controller *controller); ApiRouter(xmrig::Controller *controller);
~ApiRouter(); ~ApiRouter() override;
void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const; void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const;
void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply);
void tick(const NetworkState &results); void tick(const xmrig::NetworkState &results);
protected: protected:
void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override; void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override;
@ -68,8 +69,8 @@ private:
char m_id[32]; char m_id[32];
char m_workerId[128]; char m_workerId[128];
NetworkState m_network; xmrig::NetworkState m_network;
xmrig::Controller *m_controller; xmrig::Controller *m_controller;
}; };
#endif /* __APIROUTER_H__ */ #endif /* XMRIG_APIROUTER_H */

View file

@ -32,7 +32,7 @@
#include "common/net/SubmitResult.h" #include "common/net/SubmitResult.h"
NetworkState::NetworkState() : xmrig::NetworkState::NetworkState() :
diff(0), diff(0),
accepted(0), accepted(0),
failures(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; 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()) { if (m_latency.empty()) {
return 0; 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(); const size_t calls = m_latency.size();
if (calls == 0) { 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) { if (error) {
rejected++; 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); 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; m_active = false;
diff = 0; diff = 0;

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,14 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __NETWORKSTATE_H__ #ifndef XMRIG_NETWORKSTATE_H
#define __NETWORKSTATE_H__ #define XMRIG_NETWORKSTATE_H
#include <array> #include <array>
#include <vector> #include <vector>
namespace xmrig {
class SubmitResult; class SubmitResult;
@ -58,4 +62,8 @@ private:
uint64_t m_connectionTime; uint64_t m_connectionTime;
}; };
#endif /* __NETWORKSTATE_H__ */
} /* namespace xmrig */
#endif /* XMRIG_NETWORKSTATE_H */

View file

@ -44,7 +44,7 @@
#endif #endif
Pool::Pool() : xmrig::Pool::Pool() :
m_nicehash(false), m_nicehash(false),
m_tls(false), m_tls(false),
m_keepAlive(0), m_keepAlive(0),
@ -64,7 +64,7 @@ Pool::Pool() :
* *
* @param url * @param url
*/ */
Pool::Pool(const char *url) : xmrig::Pool::Pool(const char *url) :
m_nicehash(false), m_nicehash(false),
m_tls(false), m_tls(false),
m_keepAlive(0), 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_nicehash(nicehash),
m_tls(tls), m_tls(tls),
m_keepAlive(keepAlive), m_keepAlive(keepAlive),
m_port(port),
m_host(host), m_host(host),
m_password(password), m_password(password),
m_user(user) m_user(user),
m_port(port)
{ {
const size_t size = m_host.size() + 8; const size_t size = m_host.size() + 8;
assert(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()) { if (m_algorithms.empty()) {
return true; 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 return (m_nicehash == other.m_nicehash
&& m_tls == other.m_tls && 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); 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, ':'); const char *p = strchr(userpass, ':');
if (!p) { 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; using namespace rapidjson;
@ -220,13 +260,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
} }
switch (m_algorithm.variant()) { switch (m_algorithm.variant()) {
case xmrig::VARIANT_AUTO: case VARIANT_AUTO:
case xmrig::VARIANT_0: case VARIANT_0:
case xmrig::VARIANT_1: case VARIANT_1:
obj.AddMember("variant", m_algorithm.variant(), allocator); obj.AddMember("variant", m_algorithm.variant(), allocator);
break; break;
case xmrig::VARIANT_2: case VARIANT_2:
obj.AddMember("variant", 2, allocator); obj.AddMember("variant", 2, allocator);
break; 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()) { if (!isValid()) {
return; 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; m_algorithm = algorithm;
@ -266,7 +306,7 @@ void Pool::setAlgo(const xmrig::Algorithm &algorithm)
#ifdef APP_DEBUG #ifdef APP_DEBUG
void Pool::print() const void xmrig::Pool::print() const
{ {
LOG_NOTICE("url: %s", m_url.data()); LOG_NOTICE("url: %s", m_url.data());
LOG_DEBUG ("host: %s", m_host.data()); LOG_DEBUG ("host: %s", m_host.data());
@ -281,7 +321,7 @@ void Pool::print() const
#endif #endif
bool Pool::parseIPv6(const char *addr) bool xmrig::Pool::parseIPv6(const char *addr)
{ {
const char *end = strchr(addr, ']'); const char *end = strchr(addr, ']');
if (!end) { 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); const xmrig::Algorithm algorithm(m_algorithm.algo(), variant);
if (!algorithm.isValid() || m_algorithm == algorithm) { 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 # ifndef XMRIG_PROXY_PROJECT
using namespace xmrig; using namespace xmrig;
@ -401,7 +441,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint)
} }
void Pool::rebuild() void xmrig::Pool::rebuild()
{ {
m_algorithms.clear(); m_algorithms.clear();
@ -412,18 +452,18 @@ void Pool::rebuild()
m_algorithms.push_back(m_algorithm); m_algorithms.push_back(m_algorithm);
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
addVariant(xmrig::VARIANT_WOW); addVariant(VARIANT_WOW);
addVariant(xmrig::VARIANT_2); addVariant(VARIANT_2);
addVariant(xmrig::VARIANT_1); addVariant(VARIANT_1);
addVariant(xmrig::VARIANT_0); addVariant(VARIANT_0);
addVariant(xmrig::VARIANT_HALF); addVariant(VARIANT_HALF);
addVariant(xmrig::VARIANT_XTL); addVariant(VARIANT_XTL);
addVariant(xmrig::VARIANT_TUBE); addVariant(VARIANT_TUBE);
addVariant(xmrig::VARIANT_MSR); addVariant(VARIANT_MSR);
addVariant(xmrig::VARIANT_XHV); addVariant(VARIANT_XHV);
addVariant(xmrig::VARIANT_XAO); addVariant(VARIANT_XAO);
addVariant(xmrig::VARIANT_RTO); addVariant(VARIANT_RTO);
addVariant(xmrig::VARIANT_GPU); addVariant(VARIANT_GPU);
addVariant(xmrig::VARIANT_AUTO); addVariant(VARIANT_AUTO);
# endif # endif
} }

View file

@ -5,7 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -29,11 +29,14 @@
#include <vector> #include <vector>
#include "base/tools/String.h"
#include "common/crypto/Algorithm.h" #include "common/crypto/Algorithm.h"
#include "common/utils/c_str.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
namespace xmrig {
class Pool class Pool
{ {
public: public:
@ -44,6 +47,7 @@ public:
Pool(); Pool();
Pool(const char *url); Pool(const char *url);
Pool(const rapidjson::Value &object);
Pool(const char *host, Pool(const char *host,
uint16_t port, uint16_t port,
const char *user = nullptr, const char *user = nullptr,
@ -62,8 +66,8 @@ public:
inline const char *rigId() const { return m_rigId.data(); } inline const char *rigId() const { return m_rigId.data(); }
inline const char *url() const { return m_url.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 char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } inline const Algorithm &algorithm() const { return m_algorithm; }
inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } inline const Algorithms &algorithms() const { return m_algorithms; }
inline int keepAlive() const { return m_keepAlive; } inline int keepAlive() const { return m_keepAlive; }
inline uint16_t port() const { return m_port; } inline uint16_t port() const { return m_port; }
inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } 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 setRigId(const char *rigId) { m_rigId = rigId; }
inline void setTLS(bool tls) { m_tls = tls; } inline void setTLS(bool tls) { m_tls = tls; }
inline void setUser(const char *user) { m_user = user; } 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); }
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 isEqual(const Pool &other) const;
bool parse(const char *url); bool parse(const char *url);
bool setUserpass(const char *userpass); bool setUserpass(const char *userpass);
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
void adjust(const xmrig::Algorithm &algorithm); void adjust(const Algorithm &algorithm);
void setAlgo(const xmrig::Algorithm &algorithm); void setAlgo(const Algorithm &algorithm);
# ifdef APP_DEBUG # ifdef APP_DEBUG
void print() const; void print() const;
@ -92,25 +96,26 @@ public:
private: private:
bool parseIPv6(const char *addr); bool parseIPv6(const char *addr);
void addVariant(xmrig::Variant variant); void addVariant(Variant variant);
void adjustVariant(const xmrig::Variant variantHint); void adjustVariant(const Variant variantHint);
void rebuild(); void rebuild();
Algorithm m_algorithm;
Algorithms m_algorithms;
bool m_nicehash; bool m_nicehash;
bool m_tls; bool m_tls;
int m_keepAlive; 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; 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<Pool> Pools; } /* namespace xmrig */
#endif /* XMRIG_POOL_H */ #endif /* XMRIG_POOL_H */

View file

@ -26,7 +26,7 @@
#include "base/net/Pools.h" #include "base/net/Pools.h"
xmrig::Pools::Pools() xmrig::Pools::Pools() :
m_index(0)
{ {
} }

View file

@ -41,6 +41,7 @@ public:
Pools(); Pools();
private: private:
size_t m_index;
std::vector<Pool> m_data; std::vector<Pool> m_data;
}; };

View file

@ -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) void xmrig::CommonConfig::setFileName(const char *fileName)
{ {
m_fileName = 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(); fixup();

View file

@ -81,6 +81,7 @@ protected:
bool parseBoolean(int key, bool enable) override; bool parseBoolean(int key, bool enable) override;
bool parseString(int key, const char *arg) override; bool parseString(int key, const char *arg) override;
bool parseUint64(int key, uint64_t arg) override; bool parseUint64(int key, uint64_t arg) override;
void parseJSON(const rapidjson::Document &doc) override;
void setFileName(const char *fileName) override; void setFileName(const char *fileName) override;
Algorithm m_algorithm; Algorithm m_algorithm;
@ -101,12 +102,12 @@ protected:
State m_state; State m_state;
std::vector<Pool> m_activePools; std::vector<Pool> m_activePools;
std::vector<Pool> m_pools; std::vector<Pool> m_pools;
xmrig::String m_apiId; String m_apiId;
xmrig::String m_apiToken; String m_apiToken;
xmrig::String m_apiWorkerId; String m_apiWorkerId;
xmrig::String m_fileName; String m_fileName;
xmrig::String m_logFile; String m_logFile;
xmrig::String m_userAgent; String m_userAgent;
private: private:
bool parseInt(int key, int arg); bool parseInt(int key, int arg);

View file

@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,22 +22,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ICLIENTLISTENER_H__ #ifndef XMRIG_ICLIENTLISTENER_H
#define __ICLIENTLISTENER_H__ #define XMRIG_ICLIENTLISTENER_H
#include <stdint.h> #include <stdint.h>
class Client;
class Job; class Job;
class SubmitResult; class SubmitResult;
namespace xmrig {
class Client;
class IClientListener class IClientListener
{ {
public: public:
virtual ~IClientListener() {} virtual ~IClientListener() = default;
virtual void onClose(Client *client, int failures) = 0; virtual void onClose(Client *client, int failures) = 0;
virtual void onJobReceived(Client *client, const Job &job) = 0; virtual void onJobReceived(Client *client, const Job &job) = 0;
@ -45,4 +51,7 @@ public:
}; };
#endif // __ICLIENTLISTENER_H__ } /* namespace xmrig */
#endif // XMRIG_ICLIENTLISTENER_H

View file

@ -33,23 +33,27 @@ class JobResult;
namespace xmrig { namespace xmrig {
class Algorithm;
}
class Algorithm;
class IStrategy class IStrategy
{ {
public: public:
virtual ~IStrategy() {} virtual ~IStrategy() = default;
virtual bool isActive() const = 0; virtual bool isActive() const = 0;
virtual int64_t submit(const JobResult &result) = 0; virtual int64_t submit(const JobResult &result) = 0;
virtual void connect() = 0; virtual void connect() = 0;
virtual void resume() = 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 stop() = 0;
virtual void tick(uint64_t now) = 0; virtual void tick(uint64_t now) = 0;
}; };
} /* namespace xmrig */
#endif // XMRIG_ISTRATEGY_H #endif // XMRIG_ISTRATEGY_H

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,13 +22,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ISTRATEGYLISTENER_H__ #ifndef XMRIG_ISTRATEGYLISTENER_H
#define __ISTRATEGYLISTENER_H__ #define XMRIG_ISTRATEGYLISTENER_H
#include <stdint.h> #include <stdint.h>
namespace xmrig {
class Client; class Client;
class IStrategy; class IStrategy;
class Job; class Job;
@ -37,7 +41,7 @@ class SubmitResult;
class IStrategyListener class IStrategyListener
{ {
public: public:
virtual ~IStrategyListener() {} virtual ~IStrategyListener() = default;
virtual void onActive(IStrategy *strategy, Client *client) = 0; virtual void onActive(IStrategy *strategy, Client *client) = 0;
virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 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

View file

@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -51,8 +52,12 @@
#endif #endif
namespace xmrig {
int64_t Client::m_sequence = 1; int64_t Client::m_sequence = 1;
xmrig::Storage<Client> Client::m_storage; Storage<Client> Client::m_storage;
} /* namespace xmrig */
#ifdef APP_DEBUG #ifdef APP_DEBUG
@ -66,7 +71,7 @@ static const char *states[] = {
#endif #endif
Client::Client(int id, const char *agent, IClientListener *listener) : xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
m_ipv6(false), m_ipv6(false),
m_nicehash(false), m_nicehash(false),
m_quiet(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; delete m_socket;
} }
void Client::connect() void xmrig::Client::connect()
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (m_pool.isTLS()) { if (m_pool.isTLS()) {
@ -126,14 +131,14 @@ void Client::connect()
* *
* @param url * @param url
*/ */
void Client::connect(const Pool &url) void xmrig::Client::connect(const Pool &url)
{ {
setPool(url); setPool(url);
connect(); connect();
} }
void Client::deleteLater() void xmrig::Client::deleteLater()
{ {
if (!m_listener) { if (!m_listener) {
return; return;
@ -148,7 +153,7 @@ void Client::deleteLater()
void Client::setPool(const Pool &pool) void xmrig::Client::setPool(const Pool &pool)
{ {
if (!pool.isValid()) { if (!pool.isValid()) {
return; 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_state == ConnectedState) {
if (m_expire && now > m_expire) { 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_keepAlive = 0;
m_expire = 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 # ifndef XMRIG_NO_TLS
if (isTLS() && m_pool.fingerprint() == nullptr) { 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 # ifndef XMRIG_NO_TLS
if (isTLS()) { 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 # ifndef XMRIG_PROXY_PROJECT
if (result.clientId != m_rpcId) { if (result.clientId != m_rpcId) {
@ -218,7 +223,7 @@ int64_t Client::submit(const JobResult &result)
} }
# endif # 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; return -1;
} }
@ -267,7 +272,7 @@ int64_t Client::submit(const JobResult &result)
} }
bool Client::close() bool xmrig::Client::close()
{ {
if (m_state == ClosingState) { if (m_state == ClosingState) {
return m_socket != nullptr; 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) { if (!message) {
return false; 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 # ifndef XMRIG_NO_TLS
return m_pool.isTLS() && m_tls; return m_pool.isTLS() && m_tls;
@ -319,7 +324,7 @@ bool Client::isTLS() const
} }
bool Client::parseJob(const rapidjson::Value &params, int *code) bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
{ {
if (!params.IsObject()) { if (!params.IsObject()) {
*code = 2; *code = 2;
@ -394,7 +399,7 @@ bool Client::parseJob(const rapidjson::Value &params, 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())) { if (!m_rpcId.setId(result["id"].GetString())) {
*code = 1; *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 # ifndef XMRIG_NO_TLS
uv_buf_t buf; 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 # 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; return true;
} }
# endif # 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); 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; 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); 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<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6) void xmrig::Client::connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6)
{ {
addrinfo *addr = nullptr; addrinfo *addr = nullptr;
m_ipv6 = ipv4.empty() && !ipv6.empty(); m_ipv6 = ipv4.empty() && !ipv6.empty();
@ -569,7 +574,7 @@ void Client::connect(const std::vector<addrinfo*> &ipv4, const std::vector<addri
} }
void Client::connect(sockaddr *addr) void xmrig::Client::connect(sockaddr *addr)
{ {
setState(ConnectingState); setState(ConnectingState);
@ -592,7 +597,7 @@ void Client::connect(sockaddr *addr)
} }
void Client::handshake() void xmrig::Client::handshake()
{ {
# ifndef XMRIG_NO_TLS # ifndef XMRIG_NO_TLS
if (isTLS()) { if (isTLS()) {
@ -608,7 +613,7 @@ void Client::handshake()
} }
void Client::login() void xmrig::Client::login()
{ {
using namespace rapidjson; using namespace rapidjson;
m_results.clear(); m_results.clear();
@ -648,7 +653,7 @@ void Client::login()
} }
void Client::onClose() void xmrig::Client::onClose()
{ {
delete m_socket; delete m_socket;
@ -667,7 +672,7 @@ void Client::onClose()
} }
void Client::parse(char *line, size_t len) void xmrig::Client::parse(char *line, size_t len)
{ {
startTimeout(); startTimeout();
@ -706,7 +711,7 @@ void Client::parse(char *line, size_t len)
} }
void Client::parseExtensions(const rapidjson::Value &value) void xmrig::Client::parseExtensions(const rapidjson::Value &value)
{ {
m_extensions = 0; m_extensions = 0;
@ -733,7 +738,7 @@ void Client::parseExtensions(const rapidjson::Value &value)
} }
void Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error) void xmrig::Client::parseNotification(const char *method, const rapidjson::Value &params, const rapidjson::Value &error)
{ {
if (error.IsObject()) { if (error.IsObject()) {
if (!isQuiet()) { if (!isQuiet()) {
@ -759,7 +764,7 @@ void Client::parseNotification(const char *method, const rapidjson::Value &param
} }
void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error) void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{ {
if (error.IsObject()) { if (error.IsObject()) {
const char *message = error["message"].GetString(); const char *message = error["message"].GetString();
@ -811,13 +816,13 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
} }
void Client::ping() void xmrig::Client::ping()
{ {
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
} }
void Client::read() void xmrig::Client::read()
{ {
char* end; char* end;
char* start = m_recvBuf.base; char* start = m_recvBuf.base;
@ -846,7 +851,7 @@ void Client::read()
} }
void Client::reconnect() void xmrig::Client::reconnect()
{ {
if (!m_listener) { if (!m_listener) {
m_storage.remove(m_key); m_storage.remove(m_key);
@ -869,7 +874,7 @@ void Client::reconnect()
} }
void Client::setState(SocketState state) void xmrig::Client::setState(SocketState state)
{ {
LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]); LOG_DEBUG("[%s] state: \"%s\"", m_pool.url(), states[state]);
@ -881,7 +886,7 @@ void Client::setState(SocketState state)
} }
void Client::startTimeout() void xmrig::Client::startTimeout()
{ {
m_expire = 0; m_expire = 0;
@ -891,7 +896,7 @@ void Client::startTimeout()
} }
void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) void xmrig::Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
{ {
auto client = getClient(handle->data); auto client = getClient(handle->data);
if (!client) { 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); auto client = getClient(handle->data);
if (!client) { 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); auto client = getClient(req->data);
if (!client) { 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); auto client = getClient(stream->data);
if (!client) { 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); auto client = getClient(req->data);
if (!client) { if (!client) {

View file

@ -5,6 +5,7 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -39,13 +40,16 @@
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
typedef struct bio_st BIO;
namespace xmrig {
class IClientListener; class IClientListener;
class JobResult; class JobResult;
typedef struct bio_st BIO;
class Client class Client
{ {
public: public:
@ -85,7 +89,7 @@ public:
inline int id() const { return m_id; } inline int id() const { return m_id; }
inline SocketState state() const { return m_state; } inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_pool.port(); } 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 setQuiet(bool quiet) { m_quiet = quiet; }
inline void setRetries(int retries) { m_retries = retries; } inline void setRetries(int retries) { m_retries = retries; }
inline void setRetryPause(int ms) { m_retryPause = ms; } inline void setRetryPause(int ms) { m_retryPause = ms; }
@ -105,7 +109,7 @@ private:
bool parseJob(const rapidjson::Value &params, int *code); bool parseJob(const rapidjson::Value &params, int *code);
bool parseLogin(const rapidjson::Value &result, int *code); bool parseLogin(const rapidjson::Value &result, int *code);
bool send(BIO *bio); bool send(BIO *bio);
bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const; bool verifyAlgorithm(const Algorithm &algorithm) const;
int resolve(const char *host); int resolve(const char *host);
int64_t send(const rapidjson::Document &doc); int64_t send(const rapidjson::Document &doc);
int64_t send(size_t size); int64_t send(size_t size);
@ -162,11 +166,14 @@ private:
uv_getaddrinfo_t m_resolver; uv_getaddrinfo_t m_resolver;
uv_stream_t *m_stream; uv_stream_t *m_stream;
uv_tcp_t *m_socket; uv_tcp_t *m_socket;
xmrig::Id m_rpcId; Id m_rpcId;
static int64_t m_sequence; static int64_t m_sequence;
static xmrig::Storage<Client> m_storage; static Storage<Client> m_storage;
}; };
} /* namespace xmrig */
#endif /* XMRIG_CLIENT_H */ #endif /* XMRIG_CLIENT_H */

View file

@ -58,7 +58,7 @@ char hf_bin2hex(unsigned char c)
} }
Job::Job() : xmrig::Job::Job() :
m_autoVariant(false), m_autoVariant(false),
m_nicehash(false), m_nicehash(false),
m_poolId(-2), m_poolId(-2),
@ -72,8 +72,8 @@ Job::Job() :
} }
Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) : xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId) :
m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO), m_autoVariant(algorithm.variant() == VARIANT_AUTO),
m_nicehash(nicehash), m_nicehash(nicehash),
m_poolId(poolId), m_poolId(poolId),
m_threadId(-1), 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; 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) { if (!blob) {
return false; return false;
@ -128,14 +128,14 @@ bool Job::setBlob(const char *blob)
} }
if (!m_algorithm.isForced()) { if (!m_algorithm.isForced()) {
if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] >= 9) { if (m_algorithm.variant() == VARIANT_XTL && m_blob[0] >= 9) {
m_algorithm.setVariant(xmrig::VARIANT_HALF); m_algorithm.setVariant(VARIANT_HALF);
} }
else if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] >= 8) { else if (m_algorithm.variant() == VARIANT_MSR && m_blob[0] >= 8) {
m_algorithm.setVariant(xmrig::VARIANT_HALF); m_algorithm.setVariant(VARIANT_HALF);
} }
else if (m_algorithm.variant() == xmrig::VARIANT_WOW && m_blob[0] < 11) { else if (m_algorithm.variant() == VARIANT_WOW && m_blob[0] < 11) {
m_algorithm.setVariant(xmrig::VARIANT_2); 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) { if (!target) {
return false; 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); 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; 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; bool error = false;
for (unsigned int i = 0; i < len; i += 2) { 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++) { for (unsigned int i = 0; i < len; i++) {
out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4); 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 #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](); char *out = new char[len * 2 + 1]();
toHex(in, len, out); toHex(in, len, out);
@ -240,10 +240,8 @@ char *Job::toHex(const unsigned char* in, unsigned int len)
#endif #endif
xmrig::Variant Job::variant() const xmrig::Variant xmrig::Job::variant() const
{ {
using namespace xmrig;
switch (m_algorithm.algo()) { switch (m_algorithm.algo()) {
case CRYPTONIGHT: case CRYPTONIGHT:
return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1;

View file

@ -35,6 +35,9 @@
#include "common/net/Id.h" #include "common/net/Id.h"
namespace xmrig {
class Job class Job
{ {
public: public:
@ -43,7 +46,7 @@ public:
static constexpr const size_t kMaxBlobSize = 128; static constexpr const size_t kMaxBlobSize = 128;
Job(); 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(); ~Job();
bool isEqual(const Job &other) const; bool isEqual(const Job &other) const;
@ -57,9 +60,9 @@ public:
inline bool setId(const char *id) { return m_id.setId(id); } inline bool setId(const char *id) { return m_id.setId(id); }
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); } inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
inline const uint8_t *blob() const { return m_blob; } inline const uint8_t *blob() const { return m_blob; }
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } inline const Algorithm &algorithm() const { return m_algorithm; }
inline const xmrig::Id &clientId() const { return m_clientId; } inline const Id &clientId() const { return m_clientId; }
inline const xmrig::Id &id() const { return m_id; } inline const Id &id() const { return m_id; }
inline int poolId() const { return m_poolId; } inline int poolId() const { return m_poolId; }
inline int threadId() const { return m_threadId; } inline int threadId() const { return m_threadId; }
inline size_t size() const { return m_size; } inline size_t size() const { return m_size; }
@ -68,7 +71,7 @@ public:
inline uint64_t target() const { return m_target; } inline uint64_t target() const { return m_target; }
inline uint64_t height() const { return m_height; } inline uint64_t height() const { return m_height; }
inline void reset() { m_size = 0; m_diff = 0; } 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 setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setThreadId(int threadId) { m_threadId = threadId; }
inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } 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); } inline bool operator!=(const Job &other) const { return !isEqual(other); }
private: private:
xmrig::Variant variant() const; Variant variant() const;
bool m_autoVariant; bool m_autoVariant;
bool m_nicehash; bool m_nicehash;
@ -113,4 +116,8 @@ private:
# endif # endif
}; };
} /* namespace xmrig */
#endif /* XMRIG_JOB_H */ #endif /* XMRIG_JOB_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -28,7 +29,7 @@
#include "common/net/SubmitResult.h" #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), reqId(reqId),
seq(seq), seq(seq),
diff(diff), 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; elapsed = (uv_hrtime() - start) / 1000000;
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,13 +22,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SUBMITRESULT_H__ #ifndef XMRIG_SUBMITRESULT_H
#define __SUBMITRESULT_H__ #define XMRIG_SUBMITRESULT_H
#include <uv.h> #include <uv.h>
namespace xmrig {
class SubmitResult class SubmitResult
{ {
public: public:
@ -46,4 +50,8 @@ private:
uint64_t start; uint64_t start;
}; };
#endif /* __SUBMITRESULT_H__ */
} /* namespace xmrig */
#endif /* XMRIG_SUBMITRESULT_H */

View file

@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -37,7 +37,7 @@
#endif #endif
Client::Tls::Tls(Client *client) : xmrig::Client::Tls::Tls(Client *client) :
m_ready(false), m_ready(false),
m_buf(), m_buf(),
m_fingerprint(), m_fingerprint(),
@ -57,7 +57,7 @@ Client::Tls::Tls(Client *client) :
} }
Client::Tls::~Tls() xmrig::Client::Tls::~Tls()
{ {
if (m_ctx) { if (m_ctx) {
SSL_CTX_free(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); m_ssl = SSL_new(m_ctx);
assert(m_ssl != nullptr); 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); 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; 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; 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); 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); return m_client->send(m_writeBio);
} }
bool Client::Tls::verify(X509 *cert) bool xmrig::Client::Tls::verify(X509 *cert)
{ {
if (cert == nullptr) { if (cert == nullptr) {
LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); 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"); const EVP_MD *digest = EVP_get_digestbyname("sha256");
if (digest == nullptr) { if (digest == nullptr) {

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,7 +32,7 @@
#include "common/net/Client.h" #include "common/net/Client.h"
class Client::Tls class xmrig::Client::Tls
{ {
public: public:
Tls(Client *client); Tls(Client *client);

View file

@ -29,7 +29,7 @@
#include "common/Platform.h" #include "common/Platform.h"
FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : xmrig::FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_quiet(quiet), m_quiet(quiet),
m_retries(retries), m_retries(retries),
m_retryPause(retryPause), m_retryPause(retryPause),
@ -43,7 +43,7 @@ FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause
} }
FailoverStrategy::~FailoverStrategy() xmrig::FailoverStrategy::~FailoverStrategy()
{ {
for (Client *client : m_pools) { for (Client *client : m_pools) {
client->deleteLater(); 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) { if (m_active == -1) {
return -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(); m_pools[m_index]->connect();
} }
void FailoverStrategy::resume() void xmrig::FailoverStrategy::resume()
{ {
if (!isActive()) { if (!isActive()) {
return; 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) { for (Client *client : m_pools) {
client->setAlgo(algo); 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) { for (size_t i = 0; i < m_pools.size(); ++i) {
m_pools[i]->disconnect(); 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) { for (Client *client : m_pools) {
client->tick(now); 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) { if (failures == -1) {
return; 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()) { if (m_active == client->id()) {
m_listener->onJob(this, client, job); 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; 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); 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 *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
client->setPool(pool); client->setPool(pool);

View file

@ -34,9 +34,11 @@
#include "common/interfaces/IStrategy.h" #include "common/interfaces/IStrategy.h"
namespace xmrig {
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Url;
class FailoverStrategy : public IStrategy, public IClientListener class FailoverStrategy : public IStrategy, public IClientListener
@ -51,7 +53,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const xmrig::Algorithm &algo) override; void setAlgo(const Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -73,4 +75,7 @@ private:
std::vector<Client*> m_pools; std::vector<Client*> m_pools;
}; };
} /* namespace xmrig */
#endif /* XMRIG_FAILOVERSTRATEGY_H */ #endif /* XMRIG_FAILOVERSTRATEGY_H */

View file

@ -29,7 +29,7 @@
#include "common/Platform.h" #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_active(false),
m_listener(listener) m_listener(listener)
{ {
@ -41,25 +41,25 @@ SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int ret
} }
SinglePoolStrategy::~SinglePoolStrategy() xmrig::SinglePoolStrategy::~SinglePoolStrategy()
{ {
m_client->deleteLater(); m_client->deleteLater();
} }
int64_t SinglePoolStrategy::submit(const JobResult &result) int64_t xmrig::SinglePoolStrategy::submit(const JobResult &result)
{ {
return m_client->submit(result); return m_client->submit(result);
} }
void SinglePoolStrategy::connect() void xmrig::SinglePoolStrategy::connect()
{ {
m_client->connect(); m_client->connect();
} }
void SinglePoolStrategy::resume() void xmrig::SinglePoolStrategy::resume()
{ {
if (!isActive()) { if (!isActive()) {
return; 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); m_client->setAlgo(algo);
} }
void SinglePoolStrategy::stop() void xmrig::SinglePoolStrategy::stop()
{ {
m_client->disconnect(); m_client->disconnect();
} }
void SinglePoolStrategy::tick(uint64_t now) void xmrig::SinglePoolStrategy::tick(uint64_t now)
{ {
m_client->tick(now); m_client->tick(now);
} }
void SinglePoolStrategy::onClose(Client *client, int failures) void xmrig::SinglePoolStrategy::onClose(Client *client, int failures)
{ {
if (!isActive()) { if (!isActive()) {
return; 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); m_listener->onJob(this, client, job);
} }
void SinglePoolStrategy::onLoginSuccess(Client *client) void xmrig::SinglePoolStrategy::onLoginSuccess(Client *client)
{ {
m_active = true; m_active = true;
m_listener->onActive(this, client); 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); m_listener->onResultAccepted(this, client, result, error);
} }

View file

@ -30,6 +30,9 @@
#include "common/interfaces/IStrategy.h" #include "common/interfaces/IStrategy.h"
namespace xmrig {
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Pool; class Pool;
@ -47,7 +50,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const xmrig::Algorithm &algo) override; void setAlgo(const Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -63,4 +66,8 @@ private:
IStrategyListener *m_listener; IStrategyListener *m_listener;
}; };
} /* namespace xmrig */
#endif /* XMRIG_SINGLEPOOLSTRATEGY_H */ #endif /* XMRIG_SINGLEPOOLSTRATEGY_H */

View file

@ -292,6 +292,8 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
void xmrig::Config::parseJSON(const rapidjson::Document &doc) void xmrig::Config::parseJSON(const rapidjson::Document &doc)
{ {
CommonConfig::parseJSON(doc);
const rapidjson::Value &threads = doc["threads"]; const rapidjson::Value &threads = doc["threads"];
if (threads.IsArray()) { if (threads.IsArray()) {

View file

@ -62,8 +62,8 @@ public:
Network *network; Network *network;
Process *process; Process *process;
std::vector<xmrig::IControllerListener *> listeners; std::vector<IControllerListener *> listeners;
xmrig::Config *config; 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); assert(d_ptr->network != nullptr);

View file

@ -29,7 +29,6 @@
#include "base/kernel/interfaces/IConfigListener.h" #include "base/kernel/interfaces/IConfigListener.h"
class Network;
class StatsData; class StatsData;
@ -39,6 +38,7 @@ namespace xmrig {
class Config; class Config;
class ControllerPrivate; class ControllerPrivate;
class IControllerListener; class IControllerListener;
class Network;
class Process; class Process;
@ -62,6 +62,8 @@ private:
ControllerPrivate *d_ptr; ControllerPrivate *d_ptr;
}; };
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* XMRIG_CONTROLLER_H */ #endif /* XMRIG_CONTROLLER_H */

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __IJOBRESULTLISTENER_H__ #ifndef XMRIG_IJOBRESULTLISTENER_H
#define __IJOBRESULTLISTENER_H__ #define XMRIG_IJOBRESULTLISTENER_H
namespace xmrig {
class Client; class Client;
@ -32,10 +36,13 @@ class JobResult;
class IJobResultListener class IJobResultListener
{ {
public: public:
virtual ~IJobResultListener() {} virtual ~IJobResultListener() = default;
virtual void onJobResult(const JobResult &result) = 0; virtual void onJobResult(const JobResult &result) = 0;
}; };
#endif // __IJOBRESULTLISTENER_H__ } /* namespace xmrig */
#endif // XMRIG_IJOBRESULTLISTENER_H

View file

@ -5,7 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -32,17 +34,20 @@
#include "common/net/Job.h" #include "common/net/Job.h"
namespace xmrig {
class JobResult class JobResult
{ {
public: public:
inline JobResult() : poolId(0), diff(0), nonce(0) {} 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) : inline JobResult(int poolId, const Id &jobId, const Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) :
poolId(poolId),
diff(diff),
nonce(nonce),
algorithm(algorithm), algorithm(algorithm),
clientId(clientId), clientId(clientId),
jobId(jobId) jobId(jobId),
poolId(poolId),
diff(diff),
nonce(nonce)
{ {
memcpy(this->result, result, sizeof(this->result)); memcpy(this->result, result, sizeof(this->result));
} }
@ -65,13 +70,17 @@ public:
} }
Algorithm algorithm;
Id clientId;
Id jobId;
int poolId; int poolId;
uint32_t diff; uint32_t diff;
uint32_t nonce; uint32_t nonce;
uint8_t result[32]; uint8_t result[32];
xmrig::Algorithm algorithm;
xmrig::Id clientId;
xmrig::Id jobId;
}; };
} /* namespace xmrig */
#endif /* XMRIG_JOBRESULT_H */ #endif /* XMRIG_JOBRESULT_H */

View file

@ -44,12 +44,10 @@
#include "workers/Workers.h" #include "workers/Workers.h"
Network::Network(xmrig::Controller *controller) : xmrig::Network::Network(Controller *controller) :
m_donate(nullptr), m_controller(controller),
m_controller(controller) m_donate(nullptr)
{ {
srand(time(0) ^ (uintptr_t) this);
Workers::setListener(this); Workers::setListener(this);
const std::vector<Pool> &pools = controller->config()->pools(); const std::vector<Pool> &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(); m_strategy->connect();
} }
void Network::stop() void xmrig::Network::stop()
{ {
if (m_donate) { if (m_donate) {
m_donate->stop(); 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) { if (m_donate && m_donate == strategy) {
LOG_NOTICE("dev donate started"); 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) { if (m_donate && m_donate->isActive() && m_donate != strategy) {
return; 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) { if (result.poolId == -1 && m_donate) {
m_donate->submit(result); 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) { if (m_donate && m_donate == strategy) {
LOG_NOTICE("dev donate finished"); 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); 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(); 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()) { 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) 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()); 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<Network*>(handle->data)->tick(); static_cast<Network*>(handle->data)->tick();
} }

View file

@ -35,19 +35,17 @@
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
class IStrategy;
class Url;
namespace xmrig { namespace xmrig {
class Controller;
}
class Controller;
class IStrategy;
class Network : public IJobResultListener, public IStrategyListener class Network : public IJobResultListener, public IStrategyListener
{ {
public: public:
Network(xmrig::Controller *controller); Network(Controller *controller);
~Network() override; ~Network() override;
void connect(); void connect();
@ -69,12 +67,15 @@ private:
static void onTick(uv_timer_t *handle); static void onTick(uv_timer_t *handle);
Controller *m_controller;
IStrategy *m_donate; IStrategy *m_donate;
IStrategy *m_strategy; IStrategy *m_strategy;
NetworkState m_state; NetworkState m_state;
uv_timer_t m_timer; uv_timer_t m_timer;
xmrig::Controller *m_controller;
}; };
} /* namespace xmrig */
#endif /* XMRIG_NETWORK_H */ #endif /* XMRIG_NETWORK_H */

View file

@ -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_active(false),
m_donateTime(level * 60 * 1000), m_donateTime(level * 60 * 1000),
m_idleTime((100 - 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]; uint8_t hash[200];
char userId[65] = { 0 }; char userId[65] = { 0 };
xmrig::keccak(reinterpret_cast<const uint8_t *>(user), strlen(user), hash); keccak(reinterpret_cast<const uint8_t *>(user), strlen(user), hash);
Job::toHex(hash, 32, userId); Job::toHex(hash, 32, userId);
# ifndef XMRIG_NO_TLS # 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)); m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true));
for (Pool &pool : m_pools) { for (Pool &pool : m_pools) {
pool.adjust(xmrig::Algorithm(algo, xmrig::VARIANT_AUTO)); pool.adjust(Algorithm(algo, VARIANT_AUTO));
} }
if (m_pools.size() > 1) { 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; delete m_strategy;
} }
int64_t DonateStrategy::submit(const JobResult &result) int64_t xmrig::DonateStrategy::submit(const JobResult &result)
{ {
return m_strategy->submit(result); return m_strategy->submit(result);
} }
void DonateStrategy::connect() void xmrig::DonateStrategy::connect()
{ {
m_strategy->connect(); m_strategy->connect();
} }
void DonateStrategy::setAlgo(const xmrig::Algorithm &algo) void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo)
{ {
m_strategy->setAlgo(algo); m_strategy->setAlgo(algo);
} }
void DonateStrategy::stop() void xmrig::DonateStrategy::stop()
{ {
uv_timer_stop(&m_timer); uv_timer_stop(&m_timer);
m_strategy->stop(); m_strategy->stop();
} }
void DonateStrategy::tick(uint64_t now) void xmrig::DonateStrategy::tick(uint64_t now)
{ {
m_now = 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()) { if (!isActive()) {
uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); 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()) { if (isActive()) {
m_listener->onJob(this, client, job); 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); 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); 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) # if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT)
m_stop = m_now + 5000; 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<DonateStrategy*>(handle->data); auto strategy = static_cast<DonateStrategy*>(handle->data);

View file

@ -36,15 +36,17 @@
#include "common/interfaces/IStrategyListener.h" #include "common/interfaces/IStrategyListener.h"
namespace xmrig {
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Url;
class DonateStrategy : public IStrategy, public IStrategyListener class DonateStrategy : public IStrategy, public IStrategyListener
{ {
public: public:
DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener);
~DonateStrategy() override; ~DonateStrategy() override;
public: public:
@ -53,7 +55,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void setAlgo(const xmrig::Algorithm &algo) override; void setAlgo(const Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -80,4 +82,8 @@ private:
uv_timer_t m_timer; uv_timer_t m_timer;
}; };
} /* namespace xmrig */
#endif /* XMRIG_DONATESTRATEGY_H */ #endif /* XMRIG_DONATESTRATEGY_H */

View file

@ -6,7 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -132,7 +132,7 @@ void MultiWorker<N>::start()
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) { if (*reinterpret_cast<uint64_t*>(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; *nonce(i) += 1;
@ -149,7 +149,7 @@ void MultiWorker<N>::start()
template<size_t N> template<size_t N>
bool MultiWorker<N>::resume(const Job &job) bool MultiWorker<N>::resume(const xmrig::Job &job)
{ {
if (m_state.job.poolId() == -1 && job.poolId() >= 0 && job.id() == m_pausedState.job.id()) { if (m_state.job.poolId() == -1 && job.poolId() >= 0 && job.id() == m_pausedState.job.id()) {
m_state = m_pausedState; m_state = m_pausedState;
@ -237,7 +237,7 @@ bool MultiWorker<N>::verify2(xmrig::Variant variant, const char *test_data)
template<size_t N> template<size_t N>
void MultiWorker<N>::consumeJob() void MultiWorker<N>::consumeJob()
{ {
Job job = Workers::job(); xmrig::Job job = Workers::job();
m_sequence = Workers::sequence(); m_sequence = Workers::sequence();
if (m_state.job == job) { if (m_state.job == job) {
return; return;
@ -272,7 +272,7 @@ void MultiWorker<N>::consumeJob()
template<size_t N> template<size_t N>
void MultiWorker<N>::save(const Job &job) void MultiWorker<N>::save(const xmrig::Job &job)
{ {
if (job.poolId() == -1 && m_state.job.poolId() >= 0) { if (job.poolId() == -1 && m_state.job.poolId() >= 0) {
m_pausedState = m_state; m_pausedState = m_state;

View file

@ -48,11 +48,11 @@ protected:
void start() override; void start() override;
private: private:
bool resume(const Job &job); bool resume(const xmrig::Job &job);
bool verify(xmrig::Variant variant, const uint8_t *referenceValue); bool verify(xmrig::Variant variant, const uint8_t *referenceValue);
bool verify2(xmrig::Variant variant, const char *test_data); bool verify2(xmrig::Variant variant, const char *test_data);
void consumeJob(); void consumeJob();
void save(const Job &job); void save(const xmrig::Job &job);
inline uint32_t *nonce(size_t index) inline uint32_t *nonce(size_t index)
{ {
@ -61,8 +61,8 @@ private:
struct State struct State
{ {
alignas(16) uint8_t blob[Job::kMaxBlobSize * N]; alignas(16) uint8_t blob[xmrig::Job::kMaxBlobSize * N];
Job job; xmrig::Job job;
}; };

View file

@ -45,12 +45,12 @@
bool Workers::m_active = false; bool Workers::m_active = false;
bool Workers::m_enabled = true; bool Workers::m_enabled = true;
Hashrate *Workers::m_hashrate = nullptr; Hashrate *Workers::m_hashrate = nullptr;
IJobResultListener *Workers::m_listener = nullptr; xmrig::IJobResultListener *Workers::m_listener = nullptr;
Job Workers::m_job; xmrig::Job Workers::m_job;
Workers::LaunchStatus Workers::m_status; Workers::LaunchStatus Workers::m_status;
std::atomic<int> Workers::m_paused; std::atomic<int> Workers::m_paused;
std::atomic<uint64_t> Workers::m_sequence; std::atomic<uint64_t> Workers::m_sequence;
std::list<JobResult> Workers::m_queue; std::list<xmrig::JobResult> Workers::m_queue;
std::vector<Handle*> Workers::m_workers; std::vector<Handle*> Workers::m_workers;
uint64_t Workers::m_ticks = 0; uint64_t Workers::m_ticks = 0;
uv_async_t Workers::m_async; uv_async_t Workers::m_async;
@ -60,10 +60,10 @@ uv_timer_t Workers::m_timer;
xmrig::Controller *Workers::m_controller = nullptr; xmrig::Controller *Workers::m_controller = nullptr;
Job Workers::job() xmrig::Job Workers::job()
{ {
uv_rwlock_rdlock(&m_rwlock); uv_rwlock_rdlock(&m_rwlock);
Job job = m_job; xmrig::Job job = m_job;
uv_rwlock_rdunlock(&m_rwlock); uv_rwlock_rdunlock(&m_rwlock);
return job; 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); uv_rwlock_wrlock(&m_rwlock);
m_job = job; 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); uv_mutex_lock(&m_mutex);
m_queue.push_back(result); m_queue.push_back(result);
@ -300,7 +300,7 @@ void Workers::onReady(void *arg)
void Workers::onResult(uv_async_t *handle) void Workers::onResult(uv_async_t *handle)
{ {
std::list<JobResult> results; std::list<xmrig::JobResult> results;
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
while (!m_queue.empty()) { while (!m_queue.empty()) {

View file

@ -38,35 +38,35 @@
class Handle; class Handle;
class Hashrate; class Hashrate;
class IJobResultListener;
class IWorker; class IWorker;
namespace xmrig { namespace xmrig {
class Controller; class Controller;
class IJobResultListener;
} }
class Workers class Workers
{ {
public: public:
static Job job(); static xmrig::Job job();
static size_t hugePages(); static size_t hugePages();
static size_t threads(); static size_t threads();
static void printHashrate(bool detail); static void printHashrate(bool detail);
static void setEnabled(bool enabled); 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 start(xmrig::Controller *controller);
static void stop(); 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 isEnabled() { return m_enabled; }
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; } 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 bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
static inline Hashrate *hashrate() { return m_hashrate; } static inline Hashrate *hashrate() { return m_hashrate; }
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); } 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 pause() { m_active = false; m_paused = 1; m_sequence++; }
static inline void setListener(IJobResultListener *listener) { m_listener = listener; } static inline void setListener(xmrig::IJobResultListener *listener) { m_listener = listener; }
# ifndef XMRIG_NO_API # ifndef XMRIG_NO_API
static void threadsSummary(rapidjson::Document &doc); static void threadsSummary(rapidjson::Document &doc);
@ -103,12 +103,12 @@ private:
static bool m_active; static bool m_active;
static bool m_enabled; static bool m_enabled;
static Hashrate *m_hashrate; static Hashrate *m_hashrate;
static IJobResultListener *m_listener; static xmrig::IJobResultListener *m_listener;
static Job m_job; static xmrig::Job m_job;
static LaunchStatus m_status; static LaunchStatus m_status;
static std::atomic<int> m_paused; static std::atomic<int> m_paused;
static std::atomic<uint64_t> m_sequence; static std::atomic<uint64_t> m_sequence;
static std::list<JobResult> m_queue; static std::list<xmrig::JobResult> m_queue;
static std::vector<Handle*> m_workers; static std::vector<Handle*> m_workers;
static uint64_t m_ticks; static uint64_t m_ticks;
static uv_async_t m_async; static uv_async_t m_async;