diff --git a/CMakeLists.txt b/CMakeLists.txt index 550de480..2bc90d43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,10 @@ set(HEADERS src/common/Platform.h src/common/utils/mm_malloc.h src/common/xmrig.h - src/core/config/Config.h - src/core/config/ConfigTransform.h src/core/config/Config_default.h src/core/config/Config_platform.h + src/core/config/Config.h + src/core/config/ConfigTransform.h src/core/config/usage.h src/core/Controller.h src/interfaces/IJobResultListener.h diff --git a/src/base/io/JsonChain.cpp b/src/base/io/JsonChain.cpp index d65427cc..4dd75f0b 100644 --- a/src/base/io/JsonChain.cpp +++ b/src/base/io/JsonChain.cpp @@ -84,6 +84,18 @@ bool xmrig::JsonChain::addRaw(const char *json) } +void xmrig::JsonChain::dump(const char *fileName) +{ + rapidjson::Document doc(rapidjson::kArrayType); + + for (rapidjson::Document &value : m_chain) { + doc.PushBack(value, doc.GetAllocator()); + } + + Json::save(fileName, doc); +} + + bool xmrig::JsonChain::getBool(const char *key, bool defaultValue) const { for (auto it = m_chain.rbegin(); it != m_chain.rend(); ++it) { diff --git a/src/base/io/JsonChain.h b/src/base/io/JsonChain.h index dab01218..275f789e 100644 --- a/src/base/io/JsonChain.h +++ b/src/base/io/JsonChain.h @@ -46,6 +46,8 @@ public: bool addFile(const char *fileName); bool addRaw(const char *json); + void dump(const char *fileName); + inline const String &fileName() const { return m_fileName; } inline size_t size() const { return m_chain.size(); } diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 84152441..157363f0 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -37,7 +37,6 @@ #include "base/kernel/interfaces/IBaseListener.h" #include "base/kernel/Process.h" #include "common/Platform.h" -#include "core/config/Config_default.h" #include "core/config/Config.h" #include "core/config/ConfigTransform.h" @@ -52,6 +51,11 @@ #endif +#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG +# include "core/config/Config_default.h" +#endif + + class xmrig::BasePrivate { public: @@ -166,7 +170,10 @@ int xmrig::Base::init() # endif Platform::init(config()->userAgent()); + +# ifndef XMRIG_PROXY_PROJECT Platform::setProcessPriority(config()->priority()); +# endif if (!config()->isBackground()) { Log::add(new ConsoleLog()); diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index c676330e..c794d071 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -92,53 +92,53 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch { switch (key) { case IConfig::AlgorithmKey: /* --algo */ - return set(doc, "algo", arg); + return set(doc, "algo", arg); case IConfig::UserpassKey: /* --userpass */ - return add(doc, kPools, "userpass", arg); + return add(doc, kPools, "userpass", arg); case IConfig::UrlKey: /* --url */ - return add(doc, kPools, "url", arg, true); + return add(doc, kPools, "url", arg, true); case IConfig::UserKey: /* --user */ - return add(doc, kPools, "user", arg); + return add(doc, kPools, "user", arg); case IConfig::PasswordKey: /* --pass */ - return add(doc, kPools, "pass", arg); + return add(doc, kPools, "pass", arg); case IConfig::RigIdKey: /* --rig-id */ - return add(doc, kPools, "rig-id", arg); + return add(doc, kPools, "rig-id", arg); case IConfig::FingerprintKey: /* --tls-fingerprint */ - return add(doc, kPools, "tls-fingerprint", arg); + return add(doc, kPools, "tls-fingerprint", arg); case IConfig::VariantKey: /* --variant */ - return add(doc, kPools, "variant", arg); + return add(doc, kPools, "variant", arg); case IConfig::LogFileKey: /* --log-file */ - return set(doc, "log-file", arg); + return set(doc, "log-file", arg); # ifdef XMRIG_DEPRECATED case IConfig::ApiAccessTokenKey: /* --api-access-token */ fputs("option \"--api-access-token\" deprecated, use \"--http-access-token\" instead.\n", stderr); fflush(stdout); - return set(doc, kHttp, "access-token", arg); + return set(doc, kHttp, "access-token", arg); # endif case IConfig::HttpAccessTokenKey: /* --http-access-token */ - return set(doc, kHttp, "access-token", arg); + return set(doc, kHttp, "access-token", arg); case IConfig::HttpHostKey: /* --http-host */ - return set(doc, kHttp, "host", arg); + return set(doc, kHttp, "host", arg); case IConfig::ApiWorkerIdKey: /* --api-worker-id */ - return set(doc, kApi, "worker-id", arg); + return set(doc, kApi, "worker-id", arg); case IConfig::ApiIdKey: /* --api-id */ - return set(doc, kApi, "id", arg); + return set(doc, kApi, "id", arg); case IConfig::UserAgentKey: /* --user-agent */ - return set(doc, "user-agent", arg); + return set(doc, "user-agent", arg); case IConfig::RetriesKey: /* --retries */ case IConfig::RetryPauseKey: /* --retry-pause */ @@ -177,16 +177,16 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b { switch (key) { case IConfig::BackgroundKey: /* --background */ - return set(doc, "background", enable); + return set(doc, "background", enable); case IConfig::SyslogKey: /* --syslog */ - return set(doc, "syslog", enable); + return set(doc, "syslog", enable); case IConfig::KeepAliveKey: /* --keepalive */ - return add(doc, kPools, "keepalive", enable); + return add(doc, kPools, "keepalive", enable); case IConfig::TlsKey: /* --tls */ - return add(doc, kPools, "tls", enable); + return add(doc, kPools, "tls", enable); # ifndef XMRIG_PROXY_PROJECT case IConfig::NicehashKey: /* --nicehash */ @@ -194,7 +194,7 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b # endif case IConfig::ColorKey: /* --no-color */ - return set(doc, "colors", enable); + return set(doc, "colors", enable); # ifdef XMRIG_DEPRECATED case IConfig::ApiIPv6Key: /* --api-ipv6 */ @@ -203,17 +203,17 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b case IConfig::ApiRestrictedKey: /* --api-no-restricted */ fputs("option \"--api-no-restricted\" deprecated, use \"--http-no-restricted\" instead.\n", stderr); fflush(stdout); - return set(doc, kHttp, "restricted", enable); + return set(doc, kHttp, "restricted", enable); # endif case IConfig::HttpRestrictedKey: /* --http-no-restricted */ - return set(doc, kHttp, "restricted", enable); + return set(doc, kHttp, "restricted", enable); case IConfig::HttpEnabledKey: /* --http-enabled */ - return set(doc, kHttp, "enabled", enable); + return set(doc, kHttp, "enabled", enable); case IConfig::DryRunKey: /* --dry-run */ - return set(doc, "dry-run", enable); + return set(doc, "dry-run", enable); default: break; @@ -225,29 +225,29 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui { switch (key) { case IConfig::RetriesKey: /* --retries */ - return set(doc, "retries", arg); + return set(doc, "retries", arg); case IConfig::RetryPauseKey: /* --retry-pause */ - return set(doc, "retry-pause", arg); + return set(doc, "retry-pause", arg); case IConfig::DonateLevelKey: /* --donate-level */ - return set(doc, "donate-level", arg); + return set(doc, "donate-level", arg); case IConfig::ProxyDonateKey: /* --donate-over-proxy */ - return set(doc, "donate-over-proxy", arg); + return set(doc, "donate-over-proxy", arg); # ifdef XMRIG_DEPRECATED case IConfig::ApiPort: /* --api-port */ fputs("option \"--api-port\" deprecated, use \"--http-port\" instead.\n", stderr); fflush(stdout); - return set(doc, kHttp, "port", arg); + return set(doc, kHttp, "port", arg); # endif case IConfig::HttpPort: /* --http-port */ - return set(doc, kHttp, "port", arg); + return set(doc, kHttp, "port", arg); case IConfig::PrintTimeKey: /* --print-time */ - return set(doc, "print-time", arg); + return set(doc, "print-time", arg); default: break; diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 44628129..d592c4cb 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -110,7 +110,6 @@ public: // xmrig-proxy AccessLogFileKey = 'A', BindKey = 'b', - CoinKey = 1104, CustomDiffKey = 1102, DebugKey = 1101, ModeKey = 'm', diff --git a/src/core/Controller.h b/src/core/Controller.h index 10e12147..02f9ca92 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -33,7 +33,6 @@ namespace xmrig { class Network; -class Process; class Controller : public Base diff --git a/src/core/config/ConfigTransform.cpp b/src/core/config/ConfigTransform.cpp index 7c9afc17..7d313726 100644 --- a/src/core/config/ConfigTransform.cpp +++ b/src/core/config/ConfigTransform.cpp @@ -36,71 +36,14 @@ xmrig::ConfigTransform::ConfigTransform() void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const char *arg) { BaseTransform::transform(doc, key, arg); - - switch (key) { - case IConfig::AVKey: /* --av */ - case IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ - case IConfig::CPUPriorityKey: /* --cpu-priority */ - case IConfig::ThreadsKey: /* --threads */ - return transformUint64(doc, key, static_cast(strtol(arg, nullptr, 10))); - - case IConfig::SafeKey: /* --safe */ - return transformBoolean(doc, key, true); - - case IConfig::HugePagesKey: /* --no-huge-pages */ - return transformBoolean(doc, key, false); - - case IConfig::CPUAffinityKey: /* --cpu-affinity */ - { - const char *p = strstr(arg, "0x"); - return transformUint64(doc, key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); - } - -# ifndef XMRIG_NO_ASM - case IConfig::AssemblyKey: /* --asm */ - return set(doc, "asm", arg); -# endif - - default: - break; - } } void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key, bool enable) { - switch (key) { - case IConfig::SafeKey: /* --safe */ - return set(doc, "safe", enable); - - case IConfig::HugePagesKey: /* --no-huge-pages */ - return set(doc, "huge-pages", enable); - - default: - break; - } } void xmrig::ConfigTransform::transformUint64(rapidjson::Document &doc, int key, uint64_t arg) { - switch (key) { - case IConfig::CPUAffinityKey: /* --cpu-affinity */ - return set(doc, "cpu-affinity", static_cast(arg)); - - case IConfig::ThreadsKey: /* --threads */ - return set(doc, "threads", arg); - - case IConfig::AVKey: /* --av */ - return set(doc, "av", arg); - - case IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ - return set(doc, "max-cpu-usage", arg); - - case IConfig::CPUPriorityKey: /* --cpu-priority */ - return set(doc, "cpu-priority", arg); - - default: - break; - } }