This commit is contained in:
MoneroOcean 2020-01-20 18:24:56 +07:00
commit b4c93b7ff6
97 changed files with 6697 additions and 6013 deletions

View file

@ -26,17 +26,13 @@
#include <uv.h>
#ifndef _WIN32
# include <unistd.h>
#endif
#include "base/api/Api.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/api/requests/HttpApiRequest.h"
#include "base/io/json/Json.h"
#include "base/kernel/Base.h"
#include "base/kernel/Env.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
#include "core/config/Config.h"
@ -158,7 +154,7 @@ void xmrig::Api::exec(IApiRequest &request)
auto &reply = request.reply();
reply.AddMember("id", StringRef(m_id), allocator);
reply.AddMember("worker_id", StringRef(m_workerId), allocator);
reply.AddMember("worker_id", m_workerId.toJSON(), allocator);
reply.AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
reply.AddMember("restricted", request.isRestricted(), allocator);
reply.AddMember("resources", getResources(request.doc()), allocator);
@ -245,12 +241,8 @@ void xmrig::Api::genId(const String &id)
void xmrig::Api::genWorkerId(const String &id)
{
memset(m_workerId, 0, sizeof(m_workerId));
if (id.size() > 0) {
strncpy(m_workerId, id.data(), sizeof(m_workerId) - 1);
}
else {
gethostname(m_workerId, sizeof(m_workerId) - 1);
m_workerId = Env::expand(id);
if (m_workerId.isEmpty()) {
m_workerId = Env::hostname();
}
}

View file

@ -32,6 +32,7 @@
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/tools/Object.h"
#include "base/tools/String.h"
namespace xmrig {
@ -71,7 +72,7 @@ private:
Base *m_base;
char m_id[32]{};
char m_workerId[128]{};
String m_workerId;
const uint64_t m_timestamp;
Httpd *m_httpd = nullptr;
std::vector<IApiListener *> m_listeners;

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -69,21 +69,23 @@ public:
virtual ~IApiRequest() = default;
virtual bool accept() = 0;
virtual bool hasParseError() const = 0;
virtual bool isDone() const = 0;
virtual bool isNew() const = 0;
virtual bool isRestricted() const = 0;
virtual const rapidjson::Value &json() const = 0;
virtual const String &rpcMethod() const = 0;
virtual const String &url() const = 0;
virtual int version() const = 0;
virtual Method method() const = 0;
virtual rapidjson::Document &doc() = 0;
virtual rapidjson::Value &reply() = 0;
virtual RequestType type() const = 0;
virtual Source source() const = 0;
virtual void done(int status) = 0;
virtual bool accept() = 0;
virtual bool hasParseError() const = 0;
virtual bool isDone() const = 0;
virtual bool isNew() const = 0;
virtual bool isRestricted() const = 0;
virtual const rapidjson::Value &json() const = 0;
virtual const String &rpcMethod() const = 0;
virtual const String &url() const = 0;
virtual int version() const = 0;
virtual Method method() const = 0;
virtual rapidjson::Document &doc() = 0;
virtual rapidjson::Value &reply() = 0;
virtual RequestType type() const = 0;
virtual Source source() const = 0;
virtual void done(int status) = 0;
virtual void setRpcError(int code, const char *message = nullptr) = 0;
virtual void setRpcResult(rapidjson::Value &result) = 0;
};

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,6 +53,10 @@ static inline const char *rpcError(int code) {
return "Invalid params";
}
if (code >= HTTP_STATUS_BAD_REQUEST && code <= HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED) {
return http_status_str(static_cast<http_status>(code));
}
return "Internal error";
}
@ -82,7 +86,7 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) :
return;
}
m_rpcMethod = Json::getString(json(), "method");
m_rpcMethod = Json::getString(m_body, "method");
if (m_rpcMethod.isEmpty()) {
done(RPC_INVALID_REQUEST);
@ -129,6 +133,10 @@ bool xmrig::HttpApiRequest::accept()
const rapidjson::Value &xmrig::HttpApiRequest::json() const
{
if (type() == REQ_JSON_RPC) {
return Json::getValue(m_body, "params");
}
return m_body;
}
@ -150,25 +158,14 @@ void xmrig::HttpApiRequest::done(int status)
m_res.setStatus(HTTP_STATUS_OK);
if (status != HTTP_STATUS_OK) {
if (status == HTTP_STATUS_NOT_FOUND) {
status = RPC_METHOD_NOT_FOUND;
}
Value error(kObjectType);
error.AddMember("code", status, allocator);
error.AddMember("message", StringRef(rpcError(status)), allocator);
reply().AddMember(StringRef(kError), error, allocator);
setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
}
else if (!reply().HasMember(kResult)) {
Value result(kObjectType);
result.AddMember("status", "OK", allocator);
reply().AddMember(StringRef(kResult), result, allocator);
setRpcResult(result);
}
reply().AddMember("jsonrpc", "2.0", allocator);
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(json(), kId), allocator), allocator);
}
else {
m_res.setStatus(status);
@ -176,3 +173,38 @@ void xmrig::HttpApiRequest::done(int status)
m_res.end();
}
void xmrig::HttpApiRequest::setRpcError(int code, const char *message)
{
using namespace rapidjson;
auto &allocator = doc().GetAllocator();
Value error(kObjectType);
error.AddMember("code", code, allocator);
error.AddMember("message", message ? StringRef(message) : StringRef(rpcError(code)), allocator);
rpcDone(kError, error);
}
void xmrig::HttpApiRequest::setRpcResult(rapidjson::Value &result)
{
rpcDone(kResult, result);
}
void xmrig::HttpApiRequest::rpcDone(const char *key, rapidjson::Value &value)
{
ApiRequest::done(0);
using namespace rapidjson;
auto &allocator = doc().GetAllocator();
reply().AddMember(StringRef(key), value, allocator);
reply().AddMember("jsonrpc", "2.0", allocator);
reply().AddMember(StringRef(kId), Value().CopyFrom(Json::getValue(m_body, kId), allocator), allocator);
m_res.setStatus(HTTP_STATUS_OK);
m_res.end();
}

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,8 +53,12 @@ protected:
const rapidjson::Value &json() const override;
Method method() const override;
void done(int status) override;
void setRpcError(int code, const char *message = nullptr) override;
void setRpcResult(rapidjson::Value &result) override;
private:
void rpcDone(const char *key, rapidjson::Value &value);
const HttpData &m_req;
HttpApiResponse m_res;
int m_parsed = 0;

View file

@ -12,6 +12,7 @@ set(HEADERS_BASE
src/base/kernel/config/BaseConfig.h
src/base/kernel/config/BaseTransform.h
src/base/kernel/Entry.h
src/base/kernel/Env.h
src/base/kernel/interfaces/IBaseListener.h
src/base/kernel/interfaces/IClient.h
src/base/kernel/interfaces/IClientListener.h
@ -66,6 +67,7 @@ set(SOURCES_BASE
src/base/kernel/config/BaseConfig.cpp
src/base/kernel/config/BaseTransform.cpp
src/base/kernel/Entry.cpp
src/base/kernel/Env.cpp
src/base/kernel/Platform.cpp
src/base/kernel/Process.cpp
src/base/kernel/Signals.cpp
@ -167,3 +169,15 @@ else()
remove_definitions(/DXMRIG_FEATURE_HTTP)
remove_definitions(/DXMRIG_FEATURE_API)
endif()
if (WITH_ENV_VARS AND CMAKE_CXX_COMPILER_ID MATCHES GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
set(WITH_ENV_VARS OFF)
endif()
if (WITH_ENV_VARS)
add_definitions(/DXMRIG_FEATURE_ENV)
else()
remove_definitions(/DXMRIG_FEATURE_ENV)
endif()

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,7 +40,9 @@ static const rapidjson::Value kNullValue;
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsBool()) {
@ -51,9 +53,17 @@ bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool def
}
bool xmrig::Json::isEmpty(const rapidjson::Value &obj)
{
return !obj.IsObject() || obj.ObjectEmpty();
}
const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsString()) {
@ -66,7 +76,9 @@ const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key,
const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsArray()) {
@ -79,7 +91,9 @@ const rapidjson::Value &xmrig::Json::getArray(const rapidjson::Value &obj, const
const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsObject()) {
@ -92,7 +106,9 @@ const rapidjson::Value &xmrig::Json::getObject(const rapidjson::Value &obj, cons
const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const char *key)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return kNullValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd()) {
@ -105,7 +121,9 @@ const rapidjson::Value &xmrig::Json::getValue(const rapidjson::Value &obj, const
int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt()) {
@ -118,7 +136,9 @@ int xmrig::Json::getInt(const rapidjson::Value &obj, const char *key, int defaul
int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int64_t defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt64()) {
@ -131,7 +151,9 @@ int64_t xmrig::Json::getInt64(const rapidjson::Value &obj, const char *key, int6
uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, uint64_t defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint64()) {
@ -144,7 +166,9 @@ uint64_t xmrig::Json::getUint64(const rapidjson::Value &obj, const char *key, ui
unsigned xmrig::Json::getUint(const rapidjson::Value &obj, const char *key, unsigned defaultValue)
{
assert(obj.IsObject());
if (isEmpty(obj)) {
return defaultValue;
}
auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint()) {
@ -169,5 +193,5 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero)
bool xmrig::JsonReader::isEmpty() const
{
return !m_obj.IsObject() || m_obj.ObjectEmpty();
return Json::isEmpty(m_obj);
}

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,6 +37,7 @@ class Json
{
public:
static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false);
static bool isEmpty(const rapidjson::Value &obj);
static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr);
static const rapidjson::Value &getArray(const rapidjson::Value &obj, const char *key);
static const rapidjson::Value &getObject(const rapidjson::Value &obj, const char *key);

View file

@ -27,9 +27,10 @@
#include <cstdio>
#include "base/tools/Handle.h"
#include "base/io/log/backends/ConsoleLog.h"
#include "base/tools/Handle.h"
#include "base/io/log/Log.h"
#include "version.h"
xmrig::ConsoleLog::ConsoleLog()
@ -48,7 +49,7 @@ xmrig::ConsoleLog::ConsoleLog()
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
# ifdef WIN32
# ifdef XMRIG_OS_WIN
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
@ -59,6 +60,8 @@ xmrig::ConsoleLog::ConsoleLog()
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
}
}
SetConsoleTitleA(APP_NAME " " APP_VERSION);
# endif
}
@ -75,7 +78,7 @@ void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool c
return;
}
# ifdef _WIN32
# ifdef XMRIG_OS_WIN
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), static_cast<unsigned int>(size));
if (!isWritable()) {
@ -99,7 +102,7 @@ bool xmrig::ConsoleLog::isSupported() const
}
#ifdef WIN32
#ifdef XMRIG_OS_WIN
bool xmrig::ConsoleLog::isWritable() const
{
if (!m_stream || uv_is_writable(m_stream) != 1) {

View file

@ -54,7 +54,7 @@ private:
uv_tty_t *m_tty = nullptr;
# ifdef _WIN32
# ifdef XMRIG_OS_WIN
bool isWritable() const;
uv_stream_t *m_stream = nullptr;

View file

@ -25,6 +25,7 @@
#include "base/io/log/backends/FileLog.h"
#include "base/kernel/Env.h"
#include <cassert>
@ -35,7 +36,7 @@
xmrig::FileLog::FileLog(const char *fileName)
{
uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
m_file = uv_fs_open(uv_default_loop(), &req, Env::expand(fileName), O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
uv_fs_req_cleanup(&req);
}

View file

@ -127,7 +127,7 @@ private:
return config.release();
}
chain.addFile(process->location(Process::ExeLocation, "config.json"));
chain.addFile(Process::location(Process::ExeLocation, "config.json"));
if (read(chain, config)) {
return config.release();

View file

@ -101,9 +101,9 @@ static int showVersion()
#ifdef XMRIG_FEATURE_HWLOC
static int exportTopology(const Process &process)
static int exportTopology(const Process &)
{
const String path = process.location(Process::ExeLocation, "topology.xml");
const String path = Process::location(Process::ExeLocation, "topology.xml");
hwloc_topology_t topology;
hwloc_topology_init(&topology);

147
src/base/kernel/Env.cpp Normal file
View file

@ -0,0 +1,147 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Env.h"
#include "base/kernel/Process.h"
#include "version.h"
#include <regex>
#include <uv.h>
#include <map>
#ifndef _WIN32
# include <unistd.h>
#endif
#ifndef UV_MAXHOSTNAMESIZE
# ifdef MAXHOSTNAMELEN
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
# else
# define UV_MAXHOSTNAMESIZE 256
# endif
#endif
namespace xmrig {
#ifdef XMRIG_FEATURE_ENV
static std::map<String, String> variables;
static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
}
#endif
} // namespace xmrig
xmrig::String xmrig::Env::expand(const char *in)
{
# ifdef XMRIG_FEATURE_ENV
if (in == nullptr) {
return {};
}
std::string text(in);
if (text.size() < 4) {
return text.c_str();
}
static const std::regex env_re{R"--(\$\{([^}]+)\})--"};
std::map<std::string, String> vars;
for (std::sregex_iterator i = std::sregex_iterator(text.begin(), text.end(), env_re); i != std::sregex_iterator(); ++i) {
std::smatch m = *i;
const auto var = m.str();
if (vars.count(var)) {
continue;
}
vars.insert({ var, get(m[1].str().c_str()) });
}
for (const auto &kv : vars) {
if (kv.second.isNull()) {
continue;
}
size_t pos = 0;
while ((pos = text.find(kv.first, pos)) != std::string::npos) {
text.replace(pos, kv.first.size(), kv.second);
pos += kv.second.size();
}
}
return text.c_str();
# else
return in;
# endif
}
xmrig::String xmrig::Env::get(const String &name)
{
# ifdef XMRIG_FEATURE_ENV
if (variables.empty()) {
createVariables();
}
if (variables.count(name)) {
return variables.at(name);
}
# endif
return static_cast<const char *>(getenv(name));
}
xmrig::String xmrig::Env::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
size_t size = sizeof(buf);
# if UV_VERSION_HEX >= 0x010c00
if (uv_os_gethostname(buf, &size) == 0) {
return static_cast<const char *>(buf);
}
# else
if (gethostname(buf, size) == 0) {
return static_cast<const char *>(buf);
}
# endif
return {};
}

47
src/base/kernel/Env.h Normal file
View file

@ -0,0 +1,47 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ENV_H
#define XMRIG_ENV_H
#include "base/tools/String.h"
namespace xmrig {
class Env
{
public:
static String expand(const char *in);
static String get(const String &name);
static String hostname();
};
} /* namespace xmrig */
#endif /* XMRIG_ENV_H */

View file

@ -51,6 +51,7 @@ public:
static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent);
static void restoreTimerResolution();
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);
static inline const char *userAgent() { return m_userAgent; }

View file

@ -83,6 +83,11 @@ void xmrig::Platform::restoreTimerResolution()
}
void xmrig::Platform::setProcessPriority(int)
{
}
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {

View file

@ -111,6 +111,11 @@ void xmrig::Platform::restoreTimerResolution()
}
void xmrig::Platform::setProcessPriority(int)
{
}
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {

View file

@ -131,6 +131,43 @@ void xmrig::Platform::restoreTimerResolution()
}
void xmrig::Platform::setProcessPriority(int priority)
{
if (priority == -1) {
return;
}
DWORD prio = IDLE_PRIORITY_CLASS;
switch (priority)
{
case 1:
prio = BELOW_NORMAL_PRIORITY_CLASS;
break;
case 2:
prio = NORMAL_PRIORITY_CLASS;
break;
case 3:
prio = ABOVE_NORMAL_PRIORITY_CLASS;
break;
case 4:
prio = HIGH_PRIORITY_CLASS;
break;
case 5:
prio = REALTIME_PRIORITY_CLASS;
break;
default:
break;
}
SetPriorityClass(GetCurrentProcess(), prio);
}
void xmrig::Platform::setThreadPriority(int priority)
{
if (priority == -1) {

View file

@ -31,7 +31,10 @@
#include "base/tools/Chrono.h"
static size_t location(xmrig::Process::Location location, char *buf, size_t max)
namespace xmrig {
static size_t getLocation(Process::Location location, char *buf, size_t max)
{
using namespace xmrig;
@ -48,6 +51,9 @@ static size_t location(xmrig::Process::Location location, char *buf, size_t max)
}
} // namespace xmrig
xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
@ -55,12 +61,12 @@ xmrig::Process::Process(int argc, char **argv) :
}
xmrig::String xmrig::Process::location(Location location, const char *fileName) const
xmrig::String xmrig::Process::location(Location location, const char *fileName)
{
constexpr const size_t max = 520;
char *buf = new char[max]();
size_t size = ::location(location, buf, max);
size_t size = getLocation(location, buf, max);
if (size == 0) {
delete [] buf;

View file

@ -48,7 +48,7 @@ public:
Process(int argc, char **argv);
String location(Location location, const char *fileName = nullptr) const;
static String location(Location location, const char *fileName = nullptr);
inline const Arguments &arguments() const { return m_arguments; }

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,6 +47,28 @@
#endif
namespace xmrig {
const char *BaseConfig::kApi = "api";
const char *BaseConfig::kApiId = "id";
const char *BaseConfig::kApiWorkerId = "worker-id";
const char *BaseConfig::kAutosave = "autosave";
const char *BaseConfig::kBackground = "background";
const char *BaseConfig::kColors = "colors";
const char *BaseConfig::kDryRun = "dry-run";
const char *BaseConfig::kHttp = "http";
const char *BaseConfig::kLogFile = "log-file";
const char *BaseConfig::kPrintTime = "print-time";
const char *BaseConfig::kSyslog = "syslog";
const char *BaseConfig::kUserAgent = "user-agent";
const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
} // namespace xmrig
bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
{
m_fileName = fileName;
@ -55,29 +77,27 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
return false;
}
m_autoSave = reader.getBool("autosave", m_autoSave);
m_background = reader.getBool("background", m_background);
m_dryRun = reader.getBool("dry-run", m_dryRun);
m_syslog = reader.getBool("syslog", m_syslog);
m_watch = reader.getBool("watch", m_watch);
m_logFile = reader.getString("log-file");
m_userAgent = reader.getString("user-agent");
m_version = reader.getUint("version");
m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool(kWatch, m_watch);
m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString(kUserAgent);
m_rebenchAlgo = reader.getBool("rebench-algo", m_rebenchAlgo);
m_benchAlgoTime = reader.getInt("bench-algo-time", m_benchAlgoTime);
Log::setColors(reader.getBool("colors", Log::isColors()));
Log::setColors(reader.getBool(kColors, Log::isColors()));
setPrintTime(reader.getUint(kPrintTime, 60));
setVerbose(reader.getValue(kVerbose));
setPrintTime(reader.getUint("print-time", 60));
setVerbose(reader.getValue("verbose"));
const rapidjson::Value &api = reader.getObject("api");
const rapidjson::Value &api = reader.getObject(kApi);
if (api.IsObject()) {
m_apiId = Json::getString(api, "id");
m_apiWorkerId = Json::getString(api, "worker-id");
m_apiId = Json::getString(api, kApiId);
m_apiWorkerId = Json::getString(api, kApiWorkerId);
}
m_http.load(reader.getObject("http"));
m_http.load(reader.getObject(kHttp));
m_pools.load(reader);
return m_pools.active() > 0;

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,6 +40,21 @@ class IJsonReader;
class BaseConfig : public IConfig
{
public:
static const char *kApi;
static const char *kApiId;
static const char *kApiWorkerId;
static const char *kAutosave;
static const char *kBackground;
static const char *kColors;
static const char *kDryRun;
static const char *kHttp;
static const char *kLogFile;
static const char *kPrintTime;
static const char *kSyslog;
static const char *kUserAgent;
static const char *kVerbose;
static const char *kWatch;
BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; }
@ -81,7 +96,6 @@ protected:
String m_logFile;
String m_userAgent;
uint32_t m_printTime = 60;
uint32_t m_version = 0;
bool m_rebenchAlgo = false;
int m_benchAlgoTime = 10;

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,27 +33,17 @@
#endif
#include "base/kernel/config/BaseTransform.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/Log.h"
#include "base/kernel/config/BaseTransform.h"
#include "base/kernel/config/BaseConfig.h"
#include "base/kernel/interfaces/IConfig.h"
#include "base/kernel/Process.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/Config_platform.h"
namespace xmrig
{
static const char *kAlgo = "algo";
static const char *kApi = "api";
static const char *kCoin = "coin";
static const char *kHttp = "http";
static const char *kPools = "pools";
} // namespace xmrig
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
{
using namespace rapidjson;
@ -95,26 +85,26 @@ void xmrig::BaseTransform::finalize(rapidjson::Document &doc)
using namespace rapidjson;
auto &allocator = doc.GetAllocator();
if (m_algorithm.isValid() && doc.HasMember(kPools)) {
auto &pools = doc[kPools];
if (m_algorithm.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kAlgo)) {
pool.AddMember(StringRef(kAlgo), m_algorithm.toJSON(), allocator);
if (!pool.HasMember(Pool::kAlgo)) {
pool.AddMember(StringRef(Pool::kAlgo), m_algorithm.toJSON(), allocator);
}
}
}
if (m_coin.isValid() && doc.HasMember(kPools)) {
auto &pools = doc[kPools];
if (m_coin.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kCoin)) {
pool.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator);
if (!pool.HasMember(Pool::kCoin)) {
pool.AddMember(StringRef(Pool::kCoin), m_coin.toJSON(), allocator);
}
}
}
if (m_http) {
set(doc, kHttp, "enabled", true);
set(doc, BaseConfig::kHttp, Http::kEnabled, true);
}
}
@ -123,20 +113,20 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
{
switch (key) {
case IConfig::AlgorithmKey: /* --algo */
if (!doc.HasMember(kPools)) {
if (!doc.HasMember(Pools::kPools)) {
m_algorithm = arg;
}
else {
return add(doc, kPools, kAlgo, arg);
return add(doc, Pools::kPools, Pool::kAlgo, arg);
}
break;
case IConfig::CoinKey: /* --coin */
if (!doc.HasMember(kPools)) {
if (!doc.HasMember(Pools::kPools)) {
m_coin = arg;
}
else {
return add(doc, kPools, kCoin, arg);
return add(doc, Pools::kPools, Pool::kCoin, arg);
}
break;
@ -150,61 +140,61 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
char *user = new char[p - arg + 1]();
strncpy(user, arg, static_cast<size_t>(p - arg));
add<const char *>(doc, kPools, "user", user);
add(doc, kPools, "pass", p + 1);
add<const char *>(doc, Pools::kPools, Pool::kUser, user);
add(doc, Pools::kPools, Pool::kPass, p + 1);
delete [] user;
}
break;
case IConfig::UrlKey: /* --url */
{
if (!doc.HasMember(kPools)) {
doc.AddMember(rapidjson::StringRef(kPools), rapidjson::kArrayType, doc.GetAllocator());
if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
}
rapidjson::Value &array = doc[kPools];
rapidjson::Value &array = doc[Pools::kPools];
if (array.Size() == 0 || Pool(array[array.Size() - 1]).isValid()) {
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
}
set(doc, array[array.Size() - 1], "url", arg);
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
break;
}
case IConfig::UserKey: /* --user */
return add(doc, kPools, "user", arg);
return add(doc, Pools::kPools, Pool::kUser, arg);
case IConfig::PasswordKey: /* --pass */
return add(doc, kPools, "pass", arg);
return add(doc, Pools::kPools, Pool::kPass, arg);
case IConfig::RigIdKey: /* --rig-id */
return add(doc, kPools, "rig-id", arg);
return add(doc, Pools::kPools, Pool::kRigId, arg);
case IConfig::FingerprintKey: /* --tls-fingerprint */
return add(doc, kPools, "tls-fingerprint", arg);
return add(doc, Pools::kPools, Pool::kFingerprint, arg);
case IConfig::SelfSelectKey: /* --self-select */
return add(doc, kPools, "self-select", arg);
return add(doc, Pools::kPools, Pool::kSelfSelect, arg);
case IConfig::LogFileKey: /* --log-file */
return set(doc, "log-file", arg);
return set(doc, BaseConfig::kLogFile, arg);
case IConfig::HttpAccessTokenKey: /* --http-access-token */
m_http = true;
return set(doc, kHttp, "access-token", arg);
return set(doc, BaseConfig::kHttp, Http::kToken, arg);
case IConfig::HttpHostKey: /* --http-host */
m_http = true;
return set(doc, kHttp, "host", arg);
return set(doc, BaseConfig::kHttp, Http::kHost, arg);
case IConfig::ApiWorkerIdKey: /* --api-worker-id */
return set(doc, kApi, "worker-id", arg);
return set(doc, BaseConfig::kApi, BaseConfig::kApiWorkerId, arg);
case IConfig::ApiIdKey: /* --api-id */
return set(doc, kApi, "id", arg);
return set(doc, BaseConfig::kApi, BaseConfig::kApiId, arg);
case IConfig::UserAgentKey: /* --user-agent */
return set(doc, "user-agent", arg);
return set(doc, BaseConfig::kUserAgent, arg);
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
@ -241,46 +231,46 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
{
switch (key) {
case IConfig::BackgroundKey: /* --background */
return set(doc, "background", enable);
return set(doc, BaseConfig::kBackground, enable);
case IConfig::SyslogKey: /* --syslog */
return set(doc, "syslog", enable);
return set(doc, BaseConfig::kSyslog, enable);
case IConfig::KeepAliveKey: /* --keepalive */
return add(doc, kPools, "keepalive", enable);
return add(doc, Pools::kPools, Pool::kKeepalive, enable);
case IConfig::TlsKey: /* --tls */
return add(doc, kPools, "tls", enable);
return add(doc, Pools::kPools, Pool::kTls, enable);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */
return add(doc, kPools, "daemon", enable);
return add(doc, Pools::kPools, Pool::kDaemon, enable);
# endif
# ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */
return add<bool>(doc, kPools, "nicehash", enable);
return add<bool>(doc, Pools::kPools, Pool::kNicehash, enable);
# endif
case IConfig::ColorKey: /* --no-color */
return set(doc, "colors", enable);
return set(doc, BaseConfig::kColors, enable);
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
m_http = true;
return set(doc, kHttp, "restricted", enable);
return set(doc, BaseConfig::kHttp, Http::kRestricted, enable);
case IConfig::HttpEnabledKey: /* --http-enabled */
m_http = true;
break;
case IConfig::DryRunKey: /* --dry-run */
return set(doc, "dry-run", enable);
return set(doc, BaseConfig::kDryRun, enable);
case IConfig::RebenchAlgoKey: /* --rebench-algo */
return set(doc, "rebench-algo", enable);
case IConfig::VerboseKey: /* --verbose */
return set(doc, "verbose", enable);
return set(doc, BaseConfig::kVerbose, enable);
default:
break;
@ -292,27 +282,27 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
{
switch (key) {
case IConfig::RetriesKey: /* --retries */
return set(doc, "retries", arg);
return set(doc, Pools::kRetries, arg);
case IConfig::RetryPauseKey: /* --retry-pause */
return set(doc, "retry-pause", arg);
return set(doc, Pools::kRetryPause, arg);
case IConfig::DonateLevelKey: /* --donate-level */
return set(doc, "donate-level", arg);
return set(doc, Pools::kDonateLevel, arg);
case IConfig::ProxyDonateKey: /* --donate-over-proxy */
return set(doc, "donate-over-proxy", arg);
return set(doc, Pools::kDonateOverProxy, arg);
case IConfig::HttpPort: /* --http-port */
m_http = true;
return set(doc, kHttp, "port", arg);
return set(doc, BaseConfig::kHttp, Http::kPort, arg);
case IConfig::PrintTimeKey: /* --print-time */
return set(doc, "print-time", arg);
return set(doc, BaseConfig::kPrintTime, arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, kPools, "daemon-poll-interval", arg);
return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);
# endif
case IConfig::BenchAlgoTimeKey: /* --bench-algo-time */

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -95,6 +95,7 @@ public:
RandomXModeKey = 1029,
RandomX1GbPagesKey = 1031,
RandomXWrmsrKey = 1032,
RandomXRdmsrKey = 1033,
CPUMaxThreadsKey = 1026,
MemoryPoolKey = 1027,
YieldKey = 1030,
@ -117,6 +118,7 @@ public:
AccessLogFileKey = 'A',
BindKey = 'b',
CustomDiffKey = 1102,
CustomDiffStatsKey = 1104,
DebugKey = 1101,
ModeKey = 'm',
PoolCoinKey = 'C',

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,12 +30,14 @@
namespace xmrig {
static const char *kEnabled = "enabled";
static const char *kHost = "host";
static const char *kLocalhost = "127.0.0.1";
static const char *kPort = "port";
static const char *kRestricted = "restricted";
static const char *kToken = "access-token";
const char *Http::kEnabled = "enabled";
const char *Http::kHost = "host";
const char *Http::kLocalhost = "127.0.0.1";
const char *Http::kPort = "port";
const char *Http::kRestricted = "restricted";
const char *Http::kToken = "access-token";
}

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,6 +36,13 @@ namespace xmrig {
class Http
{
public:
static const char *kEnabled;
static const char *kHost;
static const char *kLocalhost;
static const char *kPort;
static const char *kRestricted;
static const char *kToken;
Http();
inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); }

View file

@ -23,16 +23,19 @@
*/
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/stratum/BaseClient.h"
#include "base/kernel/Env.h"
#include "base/kernel/interfaces/IClientListener.h"
#include "base/net/stratum/SubmitResult.h"
#include "rapidjson/document.h"
namespace xmrig {
int64_t BaseClient::m_sequence = 1;
} /* namespace xmrig */
@ -43,6 +46,19 @@ xmrig::BaseClient::BaseClient(int id, IClientListener *listener) :
}
void xmrig::BaseClient::setPool(const Pool &pool)
{
if (!pool.isValid()) {
return;
}
m_pool = pool;
m_user = Env::expand(pool.user());
m_password = Env::expand(pool.password());
m_rigId = Env::expand(pool.rigId());
}
bool xmrig::BaseClient::handleResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
if (id == 1) {

View file

@ -56,11 +56,12 @@ protected:
inline int64_t sequence() const override { return m_sequence; }
inline void setAlgo(const Algorithm &algo) override { m_pool.setAlgo(algo); }
inline void setEnabled(bool enabled) override { m_enabled = enabled; }
inline void setPool(const Pool &pool) override { if (pool.isValid()) { m_pool = pool; } }
inline void setQuiet(bool quiet) override { m_quiet = quiet; }
inline void setRetries(int retries) override { m_retries = retries; }
inline void setRetryPause(uint64_t ms) override { m_retryPause = ms; }
void setPool(const Pool &pool) override;
protected:
enum SocketState {
UnconnectedState,
@ -95,6 +96,9 @@ protected:
std::map<int64_t, SendResult> m_callbacks;
std::map<int64_t, SubmitResult> m_results;
String m_ip;
String m_password;
String m_rigId;
String m_user;
uint64_t m_retryPause = 5000;
static int64_t m_sequence;

View file

@ -624,12 +624,12 @@ void xmrig::Client::login()
auto &allocator = doc.GetAllocator();
Value params(kObjectType);
params.AddMember("login", m_pool.user().toJSON(), allocator);
params.AddMember("pass", m_pool.password().toJSON(), allocator);
params.AddMember("login", m_user.toJSON(), allocator);
params.AddMember("pass", m_password.toJSON(), allocator);
params.AddMember("agent", StringRef(m_agent), allocator);
if (!m_pool.rigId().isNull()) {
params.AddMember("rigid", m_pool.rigId().toJSON(), allocator);
if (!m_rigId.isNull()) {
params.AddMember("rigid", m_rigId.toJSON(), allocator);
}
m_listener->onLogin(this, doc, params);

View file

@ -284,8 +284,8 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
auto &allocator = doc.GetAllocator();
Value params(kObjectType);
params.AddMember("wallet_address", m_pool.user().toJSON(), allocator);
params.AddMember("reserve_size", 8, allocator);
params.AddMember("wallet_address", m_user.toJSON(), allocator);
params.AddMember("reserve_size", 8, allocator);
JsonRequest::create(doc, m_sequence, "getblocktemplate", params);

View file

@ -5,9 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,23 +47,26 @@
namespace xmrig {
static const char *kAlgo = "algo";
static const char *kCoin = "coin";
static const char *kDaemon = "daemon";
static const char *kDaemonPollInterval = "daemon-poll-interval";
static const char *kEnabled = "enabled";
static const char *kFingerprint = "tls-fingerprint";
static const char *kKeepalive = "keepalive";
static const char *kNicehash = "nicehash";
static const char *kPass = "pass";
static const char *kRigId = "rig-id";
static const char *kSelfSelect = "self-select";
static const char *kTls = "tls";
static const char *kUrl = "url";
static const char *kUser = "user";
const String Pool::kDefaultPassword = "x";
const String Pool::kDefaultUser = "x";
const String Pool::kDefaultPassword = "x";
const String Pool::kDefaultUser = "x";
const char *Pool::kAlgo = "algo";
const char *Pool::kCoin = "coin";
const char *Pool::kDaemon = "daemon";
const char *Pool::kDaemonPollInterval = "daemon-poll-interval";
const char *Pool::kEnabled = "enabled";
const char *Pool::kFingerprint = "tls-fingerprint";
const char *Pool::kKeepalive = "keepalive";
const char *Pool::kNicehash = "nicehash";
const char *Pool::kPass = "pass";
const char *Pool::kRigId = "rig-id";
const char *Pool::kSelfSelect = "self-select";
const char *Pool::kTls = "tls";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
}

View file

@ -5,9 +5,9 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -55,6 +55,21 @@ public:
static const String kDefaultPassword;
static const String kDefaultUser;
static const char *kAlgo;
static const char *kCoin;
static const char *kDaemon;
static const char *kDaemonPollInterval;
static const char *kEnabled;
static const char *kFingerprint;
static const char *kKeepalive;
static const char *kNicehash;
static const char *kPass;
static const char *kRigId;
static const char *kSelfSelect;
static const char *kTls;
static const char *kUrl;
static const char *kUser;
constexpr static int kKeepAliveTimeout = 60;
constexpr static uint16_t kDefaultPort = 3333;
constexpr static uint64_t kDefaultPollInterval = 1000;

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,20 +23,30 @@
*/
#include "base/net/stratum/Pools.h"
#include "base/io/log/Log.h"
#include "base/kernel/interfaces/IJsonReader.h"
#include "base/net/stratum/Pools.h"
#include "base/net/stratum/strategies/FailoverStrategy.h"
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
#include "donate.h"
#include "rapidjson/document.h"
namespace xmrig {
const char *Pools::kDonateLevel = "donate-level";
const char *Pools::kDonateOverProxy = "donate-over-proxy";
const char *Pools::kPools = "pools";
const char *Pools::kRetries = "retries";
const char *Pools::kRetryPause = "retry-pause";
} // namespace xmrig
xmrig::Pools::Pools() :
m_donateLevel(kDefaultDonateLevel),
m_retries(5),
m_retryPause(5),
m_proxyDonate(PROXY_DONATE_AUTO)
m_donateLevel(kDefaultDonateLevel)
{
# ifdef XMRIG_PROXY_PROJECT
m_retries = 2;
@ -108,7 +118,7 @@ void xmrig::Pools::load(const IJsonReader &reader)
{
m_data.clear();
const rapidjson::Value &pools = reader.getArray("pools");
const rapidjson::Value &pools = reader.getArray(kPools);
if (!pools.IsArray()) {
return;
}
@ -127,10 +137,10 @@ void xmrig::Pools::load(const IJsonReader &reader)
}
if (mo) m_donateLevel = 0; else
setDonateLevel(reader.getInt("donate-level", kDefaultDonateLevel));
setProxyDonate(reader.getInt("donate-over-proxy", PROXY_DONATE_AUTO));
setRetries(reader.getInt("retries"));
setRetryPause(reader.getInt("retry-pause"));
setDonateLevel(reader.getInt(kDonateLevel, kDefaultDonateLevel));
setProxyDonate(reader.getInt(kDonateOverProxy, PROXY_DONATE_AUTO));
setRetries(reader.getInt(kRetries));
setRetryPause(reader.getInt(kRetryPause));
}

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -43,6 +43,12 @@ class IStrategyListener;
class Pools
{
public:
static const char *kDonateLevel;
static const char *kDonateOverProxy;
static const char *kPools;
static const char *kRetries;
static const char *kRetryPause;
enum ProxyDonate {
PROXY_DONATE_NONE,
PROXY_DONATE_AUTO,
@ -74,9 +80,9 @@ private:
void setRetryPause(int retryPause);
int m_donateLevel;
int m_retries;
int m_retryPause;
ProxyDonate m_proxyDonate;
int m_retries = 5;
int m_retryPause = 5;
ProxyDonate m_proxyDonate = PROXY_DONATE_AUTO;
std::vector<Pool> m_data;
};