Code cleanup.

This commit is contained in:
XMRig 2020-01-07 10:13:01 +07:00
parent 706f588b36
commit c6530e352f
No known key found for this signature in database
GPG key ID: 446A53638BE94409
18 changed files with 341 additions and 212 deletions

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -69,21 +69,23 @@ public:
virtual ~IApiRequest() = default; virtual ~IApiRequest() = default;
virtual bool accept() = 0; virtual bool accept() = 0;
virtual bool hasParseError() const = 0; virtual bool hasParseError() const = 0;
virtual bool isDone() const = 0; virtual bool isDone() const = 0;
virtual bool isNew() const = 0; virtual bool isNew() const = 0;
virtual bool isRestricted() const = 0; virtual bool isRestricted() const = 0;
virtual const rapidjson::Value &json() const = 0; virtual const rapidjson::Value &json() const = 0;
virtual const String &rpcMethod() const = 0; virtual const String &rpcMethod() const = 0;
virtual const String &url() const = 0; virtual const String &url() const = 0;
virtual int version() const = 0; virtual int version() const = 0;
virtual Method method() const = 0; virtual Method method() const = 0;
virtual rapidjson::Document &doc() = 0; virtual rapidjson::Document &doc() = 0;
virtual rapidjson::Value &reply() = 0; virtual rapidjson::Value &reply() = 0;
virtual RequestType type() const = 0; virtual RequestType type() const = 0;
virtual Source source() const = 0; virtual Source source() const = 0;
virtual void done(int status) = 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 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 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -53,6 +53,10 @@ static inline const char *rpcError(int code) {
return "Invalid params"; 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"; return "Internal error";
} }
@ -82,7 +86,7 @@ xmrig::HttpApiRequest::HttpApiRequest(const HttpData &req, bool restricted) :
return; return;
} }
m_rpcMethod = Json::getString(json(), "method"); m_rpcMethod = Json::getString(m_body, "method");
if (m_rpcMethod.isEmpty()) { if (m_rpcMethod.isEmpty()) {
done(RPC_INVALID_REQUEST); done(RPC_INVALID_REQUEST);
@ -129,6 +133,10 @@ bool xmrig::HttpApiRequest::accept()
const rapidjson::Value &xmrig::HttpApiRequest::json() const const rapidjson::Value &xmrig::HttpApiRequest::json() const
{ {
if (type() == REQ_JSON_RPC) {
return Json::getValue(m_body, "params");
}
return m_body; return m_body;
} }
@ -150,25 +158,14 @@ void xmrig::HttpApiRequest::done(int status)
m_res.setStatus(HTTP_STATUS_OK); m_res.setStatus(HTTP_STATUS_OK);
if (status != HTTP_STATUS_OK) { if (status != HTTP_STATUS_OK) {
if (status == HTTP_STATUS_NOT_FOUND) { setRpcError(status == HTTP_STATUS_NOT_FOUND ? RPC_METHOD_NOT_FOUND : status);
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);
} }
else if (!reply().HasMember(kResult)) { else if (!reply().HasMember(kResult)) {
Value result(kObjectType); Value result(kObjectType);
result.AddMember("status", "OK", allocator); 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 { else {
m_res.setStatus(status); m_res.setStatus(status);
@ -176,3 +173,38 @@ void xmrig::HttpApiRequest::done(int status)
m_res.end(); 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 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 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -53,8 +53,12 @@ protected:
const rapidjson::Value &json() const override; const rapidjson::Value &json() const override;
Method method() const override; Method method() const override;
void done(int status) override; void done(int status) override;
void setRpcError(int code, const char *message = nullptr) override;
void setRpcResult(rapidjson::Value &result) override;
private: private:
void rpcDone(const char *key, rapidjson::Value &value);
const HttpData &m_req; const HttpData &m_req;
HttpApiResponse m_res; HttpApiResponse m_res;
int m_parsed = 0; int m_parsed = 0;

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -40,7 +40,9 @@ static const rapidjson::Value kNullValue;
bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsBool()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsString()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsArray()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsObject()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsInt64()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint64()) { 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) 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); auto i = obj.FindMember(key);
if (i != obj.MemberEnd() && i->value.IsUint()) { 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 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 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 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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,6 +37,7 @@ class Json
{ {
public: public:
static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false); 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 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 &getArray(const rapidjson::Value &obj, const char *key);
static const rapidjson::Value &getObject(const rapidjson::Value &obj, const char *key); static const rapidjson::Value &getObject(const rapidjson::Value &obj, const char *key);

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -47,6 +47,28 @@
#endif #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) bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
{ {
m_fileName = fileName; m_fileName = fileName;
@ -55,26 +77,25 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
return false; return false;
} }
m_autoSave = reader.getBool("autosave", m_autoSave); m_autoSave = reader.getBool(kAutosave, m_autoSave);
m_background = reader.getBool("background", m_background); m_background = reader.getBool(kBackground, m_background);
m_dryRun = reader.getBool("dry-run", m_dryRun); m_dryRun = reader.getBool(kDryRun, m_dryRun);
m_syslog = reader.getBool("syslog", m_syslog); m_syslog = reader.getBool(kSyslog, m_syslog);
m_watch = reader.getBool("watch", m_watch); m_watch = reader.getBool(kWatch, m_watch);
m_logFile = reader.getString("log-file"); m_logFile = reader.getString(kLogFile);
m_userAgent = reader.getString("user-agent"); m_userAgent = reader.getString(kUserAgent);
m_version = reader.getUint("version");
Log::setColors(reader.getBool("colors", Log::isColors())); Log::setColors(reader.getBool(kColors, Log::isColors()));
setPrintTime(reader.getUint("print-time", 60)); setPrintTime(reader.getUint(kPrintTime, 60));
setVerbose(reader.getValue("verbose")); setVerbose(reader.getValue(kVerbose));
const rapidjson::Value &api = reader.getObject("api"); const rapidjson::Value &api = reader.getObject(kApi);
if (api.IsObject()) { if (api.IsObject()) {
m_apiId = Json::getString(api, "id"); m_apiId = Json::getString(api, kApiId);
m_apiWorkerId = Json::getString(api, "worker-id"); m_apiWorkerId = Json::getString(api, kApiWorkerId);
} }
m_http.load(reader.getObject("http")); m_http.load(reader.getObject(kHttp));
m_pools.load(reader); m_pools.load(reader);
return m_pools.active() > 0; return m_pools.active() > 0;

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -40,6 +40,21 @@ class IJsonReader;
class BaseConfig : public IConfig class BaseConfig : public IConfig
{ {
public: 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; BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; } inline bool isAutoSave() const { return m_autoSave; }
@ -78,7 +93,6 @@ protected:
String m_logFile; String m_logFile;
String m_userAgent; String m_userAgent;
uint32_t m_printTime = 60; uint32_t m_printTime = 60;
uint32_t m_version = 0;
private: private:
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -33,27 +33,17 @@
#endif #endif
#include "base/kernel/config/BaseTransform.h"
#include "base/io/json/JsonChain.h" #include "base/io/json/JsonChain.h"
#include "base/io/log/Log.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/interfaces/IConfig.h"
#include "base/kernel/Process.h" #include "base/kernel/Process.h"
#include "base/net/stratum/Pool.h" #include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/Config_platform.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) void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
{ {
using namespace rapidjson; using namespace rapidjson;
@ -95,26 +85,26 @@ void xmrig::BaseTransform::finalize(rapidjson::Document &doc)
using namespace rapidjson; using namespace rapidjson;
auto &allocator = doc.GetAllocator(); auto &allocator = doc.GetAllocator();
if (m_algorithm.isValid() && doc.HasMember(kPools)) { if (m_algorithm.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[kPools]; auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) { for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kAlgo)) { if (!pool.HasMember(Pool::kAlgo)) {
pool.AddMember(StringRef(kAlgo), m_algorithm.toJSON(), allocator); pool.AddMember(StringRef(Pool::kAlgo), m_algorithm.toJSON(), allocator);
} }
} }
} }
if (m_coin.isValid() && doc.HasMember(kPools)) { if (m_coin.isValid() && doc.HasMember(Pools::kPools)) {
auto &pools = doc[kPools]; auto &pools = doc[Pools::kPools];
for (Value &pool : pools.GetArray()) { for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kCoin)) { if (!pool.HasMember(Pool::kCoin)) {
pool.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator); pool.AddMember(StringRef(Pool::kCoin), m_coin.toJSON(), allocator);
} }
} }
} }
if (m_http) { 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) { switch (key) {
case IConfig::AlgorithmKey: /* --algo */ case IConfig::AlgorithmKey: /* --algo */
if (!doc.HasMember(kPools)) { if (!doc.HasMember(Pools::kPools)) {
m_algorithm = arg; m_algorithm = arg;
} }
else { else {
return add(doc, kPools, kAlgo, arg); return add(doc, Pools::kPools, Pool::kAlgo, arg);
} }
break; break;
case IConfig::CoinKey: /* --coin */ case IConfig::CoinKey: /* --coin */
if (!doc.HasMember(kPools)) { if (!doc.HasMember(Pools::kPools)) {
m_coin = arg; m_coin = arg;
} }
else { else {
return add(doc, kPools, kCoin, arg); return add(doc, Pools::kPools, Pool::kCoin, arg);
} }
break; break;
@ -150,61 +140,61 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
char *user = new char[p - arg + 1](); char *user = new char[p - arg + 1]();
strncpy(user, arg, static_cast<size_t>(p - arg)); strncpy(user, arg, static_cast<size_t>(p - arg));
add<const char *>(doc, kPools, "user", user); add<const char *>(doc, Pools::kPools, Pool::kUser, user);
add(doc, kPools, "pass", p + 1); add(doc, Pools::kPools, Pool::kPass, p + 1);
delete [] user; delete [] user;
} }
break; break;
case IConfig::UrlKey: /* --url */ case IConfig::UrlKey: /* --url */
{ {
if (!doc.HasMember(kPools)) { if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(kPools), rapidjson::kArrayType, doc.GetAllocator()); 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()) { if (array.Size() == 0 || Pool(array[array.Size() - 1]).isValid()) {
array.PushBack(rapidjson::kObjectType, doc.GetAllocator()); array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
} }
set(doc, array[array.Size() - 1], "url", arg); set(doc, array[array.Size() - 1], Pool::kUrl, arg);
break; break;
} }
case IConfig::UserKey: /* --user */ case IConfig::UserKey: /* --user */
return add(doc, kPools, "user", arg); return add(doc, Pools::kPools, Pool::kUser, arg);
case IConfig::PasswordKey: /* --pass */ case IConfig::PasswordKey: /* --pass */
return add(doc, kPools, "pass", arg); return add(doc, Pools::kPools, Pool::kPass, arg);
case IConfig::RigIdKey: /* --rig-id */ 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 */ 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 */ 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 */ case IConfig::LogFileKey: /* --log-file */
return set(doc, "log-file", arg); return set(doc, BaseConfig::kLogFile, arg);
case IConfig::HttpAccessTokenKey: /* --http-access-token */ case IConfig::HttpAccessTokenKey: /* --http-access-token */
m_http = true; m_http = true;
return set(doc, kHttp, "access-token", arg); return set(doc, BaseConfig::kHttp, Http::kToken, arg);
case IConfig::HttpHostKey: /* --http-host */ case IConfig::HttpHostKey: /* --http-host */
m_http = true; m_http = true;
return set(doc, kHttp, "host", arg); return set(doc, BaseConfig::kHttp, Http::kHost, arg);
case IConfig::ApiWorkerIdKey: /* --api-worker-id */ 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 */ case IConfig::ApiIdKey: /* --api-id */
return set(doc, kApi, "id", arg); return set(doc, BaseConfig::kApi, BaseConfig::kApiId, arg);
case IConfig::UserAgentKey: /* --user-agent */ case IConfig::UserAgentKey: /* --user-agent */
return set(doc, "user-agent", arg); return set(doc, BaseConfig::kUserAgent, arg);
case IConfig::RetriesKey: /* --retries */ case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */ case IConfig::RetryPauseKey: /* --retry-pause */
@ -239,43 +229,43 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
{ {
switch (key) { switch (key) {
case IConfig::BackgroundKey: /* --background */ case IConfig::BackgroundKey: /* --background */
return set(doc, "background", enable); return set(doc, BaseConfig::kBackground, enable);
case IConfig::SyslogKey: /* --syslog */ case IConfig::SyslogKey: /* --syslog */
return set(doc, "syslog", enable); return set(doc, BaseConfig::kSyslog, enable);
case IConfig::KeepAliveKey: /* --keepalive */ case IConfig::KeepAliveKey: /* --keepalive */
return add(doc, kPools, "keepalive", enable); return add(doc, Pools::kPools, Pool::kKeepalive, enable);
case IConfig::TlsKey: /* --tls */ case IConfig::TlsKey: /* --tls */
return add(doc, kPools, "tls", enable); return add(doc, Pools::kPools, Pool::kTls, enable);
# ifdef XMRIG_FEATURE_HTTP # ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */ case IConfig::DaemonKey: /* --daemon */
return add(doc, kPools, "daemon", enable); return add(doc, Pools::kPools, Pool::kDaemon, enable);
# endif # endif
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */ case IConfig::NicehashKey: /* --nicehash */
return add<bool>(doc, kPools, "nicehash", enable); return add<bool>(doc, Pools::kPools, Pool::kNicehash, enable);
# endif # endif
case IConfig::ColorKey: /* --no-color */ case IConfig::ColorKey: /* --no-color */
return set(doc, "colors", enable); return set(doc, BaseConfig::kColors, enable);
case IConfig::HttpRestrictedKey: /* --http-no-restricted */ case IConfig::HttpRestrictedKey: /* --http-no-restricted */
m_http = true; m_http = true;
return set(doc, kHttp, "restricted", enable); return set(doc, BaseConfig::kHttp, Http::kRestricted, enable);
case IConfig::HttpEnabledKey: /* --http-enabled */ case IConfig::HttpEnabledKey: /* --http-enabled */
m_http = true; m_http = true;
break; break;
case IConfig::DryRunKey: /* --dry-run */ case IConfig::DryRunKey: /* --dry-run */
return set(doc, "dry-run", enable); return set(doc, BaseConfig::kDryRun, enable);
case IConfig::VerboseKey: /* --verbose */ case IConfig::VerboseKey: /* --verbose */
return set(doc, "verbose", enable); return set(doc, BaseConfig::kVerbose, enable);
default: default:
break; break;
@ -287,27 +277,27 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
{ {
switch (key) { switch (key) {
case IConfig::RetriesKey: /* --retries */ case IConfig::RetriesKey: /* --retries */
return set(doc, "retries", arg); return set(doc, Pools::kRetries, arg);
case IConfig::RetryPauseKey: /* --retry-pause */ case IConfig::RetryPauseKey: /* --retry-pause */
return set(doc, "retry-pause", arg); return set(doc, Pools::kRetryPause, arg);
case IConfig::DonateLevelKey: /* --donate-level */ case IConfig::DonateLevelKey: /* --donate-level */
return set(doc, "donate-level", arg); return set(doc, Pools::kDonateLevel, arg);
case IConfig::ProxyDonateKey: /* --donate-over-proxy */ case IConfig::ProxyDonateKey: /* --donate-over-proxy */
return set(doc, "donate-over-proxy", arg); return set(doc, Pools::kDonateOverProxy, arg);
case IConfig::HttpPort: /* --http-port */ case IConfig::HttpPort: /* --http-port */
m_http = true; m_http = true;
return set(doc, kHttp, "port", arg); return set(doc, BaseConfig::kHttp, Http::kPort, arg);
case IConfig::PrintTimeKey: /* --print-time */ case IConfig::PrintTimeKey: /* --print-time */
return set(doc, "print-time", arg); return set(doc, BaseConfig::kPrintTime, arg);
# ifdef XMRIG_FEATURE_HTTP # ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */ case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, kPools, "daemon-poll-interval", arg); return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);
# endif # endif
default: default:

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -30,12 +30,14 @@
namespace xmrig { namespace xmrig {
static const char *kEnabled = "enabled";
static const char *kHost = "host"; const char *Http::kEnabled = "enabled";
static const char *kLocalhost = "127.0.0.1"; const char *Http::kHost = "host";
static const char *kPort = "port"; const char *Http::kLocalhost = "127.0.0.1";
static const char *kRestricted = "restricted"; const char *Http::kPort = "port";
static const char *kToken = "access-token"; 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 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 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -36,6 +36,13 @@ namespace xmrig {
class Http class Http
{ {
public: 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(); Http();
inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); } inline bool isAuthRequired() const { return !m_restricted || !m_token.isNull(); }

View file

@ -5,9 +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-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * 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 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 * 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
@ -47,23 +47,26 @@
namespace xmrig { 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::kDefaultPassword = "x";
const String Pool::kDefaultUser = "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 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 2019 Howard Chu <https://github.com/hyc> * 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 * 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
@ -55,6 +55,21 @@ public:
static const String kDefaultPassword; static const String kDefaultPassword;
static const String kDefaultUser; 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 int kKeepAliveTimeout = 60;
constexpr static uint16_t kDefaultPort = 3333; constexpr static uint16_t kDefaultPort = 3333;
constexpr static uint64_t kDefaultPollInterval = 1000; constexpr static uint64_t kDefaultPollInterval = 1000;

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -23,20 +23,30 @@
*/ */
#include "base/net/stratum/Pools.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/interfaces/IJsonReader.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/FailoverStrategy.h"
#include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h"
#include "donate.h" #include "donate.h"
#include "rapidjson/document.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() : xmrig::Pools::Pools() :
m_donateLevel(kDefaultDonateLevel), m_donateLevel(kDefaultDonateLevel)
m_retries(5),
m_retryPause(5),
m_proxyDonate(PROXY_DONATE_AUTO)
{ {
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
m_retries = 2; m_retries = 2;
@ -108,7 +118,7 @@ void xmrig::Pools::load(const IJsonReader &reader)
{ {
m_data.clear(); m_data.clear();
const rapidjson::Value &pools = reader.getArray("pools"); const rapidjson::Value &pools = reader.getArray(kPools);
if (!pools.IsArray()) { if (!pools.IsArray()) {
return; return;
} }
@ -124,10 +134,10 @@ void xmrig::Pools::load(const IJsonReader &reader)
} }
} }
setDonateLevel(reader.getInt("donate-level", kDefaultDonateLevel)); setDonateLevel(reader.getInt(kDonateLevel, kDefaultDonateLevel));
setProxyDonate(reader.getInt("donate-over-proxy", PROXY_DONATE_AUTO)); setProxyDonate(reader.getInt(kDonateOverProxy, PROXY_DONATE_AUTO));
setRetries(reader.getInt("retries")); setRetries(reader.getInt(kRetries));
setRetryPause(reader.getInt("retry-pause")); setRetryPause(reader.getInt(kRetryPause));
} }

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -43,6 +43,12 @@ class IStrategyListener;
class Pools class Pools
{ {
public: public:
static const char *kDonateLevel;
static const char *kDonateOverProxy;
static const char *kPools;
static const char *kRetries;
static const char *kRetryPause;
enum ProxyDonate { enum ProxyDonate {
PROXY_DONATE_NONE, PROXY_DONATE_NONE,
PROXY_DONATE_AUTO, PROXY_DONATE_AUTO,
@ -74,9 +80,9 @@ private:
void setRetryPause(int retryPause); void setRetryPause(int retryPause);
int m_donateLevel; int m_donateLevel;
int m_retries; int m_retries = 5;
int m_retryPause; int m_retryPause = 5;
ProxyDonate m_proxyDonate; ProxyDonate m_proxyDonate = PROXY_DONATE_AUTO;
std::vector<Pool> m_data; std::vector<Pool> m_data;
}; };

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -211,41 +211,41 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
auto &allocator = doc.GetAllocator(); auto &allocator = doc.GetAllocator();
Value api(kObjectType); Value api(kObjectType);
api.AddMember("id", m_apiId.toJSON(), allocator); api.AddMember(StringRef(kApiId), m_apiId.toJSON(), allocator);
api.AddMember("worker-id", m_apiWorkerId.toJSON(), allocator); api.AddMember(StringRef(kApiWorkerId), m_apiWorkerId.toJSON(), allocator);
doc.AddMember("api", api, allocator); doc.AddMember(StringRef(kApi), api, allocator);
doc.AddMember("http", m_http.toJSON(doc), allocator); doc.AddMember(StringRef(kHttp), m_http.toJSON(doc), allocator);
doc.AddMember("autosave", isAutoSave(), allocator); doc.AddMember(StringRef(kAutosave), isAutoSave(), allocator);
doc.AddMember("background", isBackground(), allocator); doc.AddMember(StringRef(kBackground), isBackground(), allocator);
doc.AddMember("colors", Log::isColors(), allocator); doc.AddMember(StringRef(kColors), Log::isColors(), allocator);
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator); doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);
# endif # endif
doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator); doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator);
# ifdef XMRIG_FEATURE_OPENCL # ifdef XMRIG_FEATURE_OPENCL
doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator); doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator);
# endif # endif
# ifdef XMRIG_FEATURE_CUDA # ifdef XMRIG_FEATURE_CUDA
doc.AddMember(StringRef(kCuda), cuda().toJSON(doc), allocator); doc.AddMember(StringRef(kCuda), cuda().toJSON(doc), allocator);
# endif # endif
doc.AddMember("donate-level", m_pools.donateLevel(), allocator); doc.AddMember(StringRef(Pools::kDonateLevel), m_pools.donateLevel(), allocator);
doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator); doc.AddMember(StringRef(Pools::kDonateOverProxy), m_pools.proxyDonate(), allocator);
doc.AddMember("log-file", m_logFile.toJSON(), allocator); doc.AddMember(StringRef(kLogFile), m_logFile.toJSON(), allocator);
doc.AddMember("pools", m_pools.toJSON(doc), allocator); doc.AddMember(StringRef(Pools::kPools), m_pools.toJSON(doc), allocator);
doc.AddMember("print-time", printTime(), allocator); doc.AddMember(StringRef(kPrintTime), printTime(), allocator);
# if defined(XMRIG_FEATURE_NVML) # if defined(XMRIG_FEATURE_NVML)
doc.AddMember(StringRef(kHealthPrintTime), healthPrintTime(), allocator); doc.AddMember(StringRef(kHealthPrintTime), healthPrintTime(), allocator);
# endif # endif
doc.AddMember("retries", m_pools.retries(), allocator); doc.AddMember(StringRef(Pools::kRetries), m_pools.retries(), allocator);
doc.AddMember("retry-pause", m_pools.retryPause(), allocator); doc.AddMember(StringRef(Pools::kRetryPause), m_pools.retryPause(), allocator);
doc.AddMember("syslog", isSyslog(), allocator); doc.AddMember(StringRef(kSyslog), isSyslog(), allocator);
doc.AddMember("user-agent", m_userAgent.toJSON(), allocator); doc.AddMember(StringRef(kUserAgent), m_userAgent.toJSON(), allocator);
doc.AddMember("verbose", Log::verbose(), allocator); doc.AddMember(StringRef(kVerbose), Log::verbose(), allocator);
doc.AddMember("watch", m_watch, allocator); doc.AddMember(StringRef(kWatch), m_watch, allocator);
} }

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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
@ -110,9 +110,7 @@ void xmrig::DonateStrategy::connect()
if (m_proxy) { if (m_proxy) {
m_proxy->connect(); m_proxy->connect();
} }
else if (m_controller->config()->pools().proxyDonate() == Pools::PROXY_DONATE_ALWAYS) {
setState(STATE_IDLE);
}
else { else {
m_strategy->connect(); m_strategy->connect();
} }

View file

@ -5,8 +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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2020 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