From 143da8380ed8052d2a41fc35264b0deadc1777e0 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 27 Sep 2018 19:07:04 +0300 Subject: [PATCH] Add "autosave" config option. --- src/common/config/CommonConfig.cpp | 9 +++++++-- src/common/config/CommonConfig.h | 2 ++ src/common/interfaces/IConfig.h | 1 + src/config.json | 13 +++++++++---- src/core/Config.cpp | 17 ++++++++++------- src/core/Config.h | 2 ++ src/core/ConfigLoader_platform.h | 1 + src/workers/Workers.cpp | 4 ++++ 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index b70d5e3d..beb2d0c9 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -67,6 +67,7 @@ xmrig::CommonConfig::CommonConfig() : m_adjusted(false), m_apiIPv6(false), m_apiRestricted(true), + m_autoSave(true), m_background(false), m_colors(true), m_dryRun(false), @@ -217,7 +218,7 @@ bool xmrig::CommonConfig::save() rapidjson::PrettyWriter writer(os); doc.Accept(writer); - fclose(fp); + fflush(fp); uv_fs_close(uv_default_loop(), &req, fd, nullptr); uv_fs_req_cleanup(&req); @@ -308,10 +309,14 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) m_apiRestricted = enable; break; - case IConfig::DryRunKey: /* --dry-run */ + case DryRunKey: /* --dry-run */ m_dryRun = enable; break; + case AutoSaveKey: + m_autoSave = enable; + break; + default: break; } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 7643a1a5..422a6bb2 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -44,6 +44,7 @@ public: inline bool isApiIPv6() const { return m_apiIPv6; } inline bool isApiRestricted() const { return m_apiRestricted; } + inline bool isAutoSave() const { return m_autoSave; } inline bool isBackground() const { return m_background; } inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } @@ -88,6 +89,7 @@ protected: bool m_adjusted; bool m_apiIPv6; bool m_apiRestricted; + bool m_autoSave; bool m_background; bool m_colors; bool m_dryRun; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 0fcac2d1..69f2ffab 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -65,6 +65,7 @@ public: WatchKey = 1105, TlsKey = 1013, FingerprintKey = 1014, + AutoSaveKey = 1016, // xmrig common CPUPriorityKey = 1021, diff --git a/src/config.json b/src/config.json index b2dad4c9..d4fb42f3 100644 --- a/src/config.json +++ b/src/config.json @@ -3,10 +3,13 @@ "api": { "port": 0, "access-token": null, + "id": null, "worker-id": null, "ipv6": false, - "restricted": true + "restricted": false }, + "asm": true, + "autosave": true, "av": 0, "background": false, "colors": true, @@ -19,13 +22,15 @@ "max-cpu-usage": 75, "pools": [ { - "url": "proxy.fee.xmrig.com:9999", - "user": "YOUR_WALLET", + "url": "donate.v2.xmrig.com:3333", + "user": "YOUR_WALLET_ADDRESS", "pass": "x", "rig-id": null, "nicehash": false, "keepalive": false, - "variant": 1 + "variant": 1, + "tls": false, + "tls-fingerprint": null } ], "print-time": 60, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 79b19265..c8891c77 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -47,6 +47,7 @@ xmrig::Config::Config() : xmrig::CommonConfig(), m_assembly(ASM_AUTO), m_hugePages(true), m_safe(false), + m_shouldSave(false), m_maxCpuUsage(75), m_priority(-1) { @@ -69,10 +70,6 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("algo", StringRef(algorithm().name()), allocator); -# ifndef XMRIG_NO_ASM - doc.AddMember("asm", Asm::toJSON(m_assembly), allocator); -# endif - Value api(kObjectType); api.AddMember("port", apiPort(), allocator); api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); @@ -82,6 +79,11 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const api.AddMember("restricted", isApiRestricted(), allocator); doc.AddMember("api", api, allocator); +# ifndef XMRIG_NO_ASM + doc.AddMember("asm", Asm::toJSON(m_assembly), allocator); +# endif + + doc.AddMember("autosave", isAutoSave(), allocator); doc.AddMember("av", algoVariant(), allocator); doc.AddMember("background", isBackground(), allocator); doc.AddMember("colors", isColors(), allocator); @@ -113,7 +115,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("retry-pause", retryPause(), allocator); doc.AddMember("safe", m_safe, allocator); - if (threadsMode() == Advanced) { + if (threadsMode() != Simple) { Value threads(kArrayType); for (const IThread *thread : m_threads.list) { @@ -123,7 +125,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("threads", threads, allocator); } else { - doc.AddMember("threads", threadsMode() == Automatic ? Value(kNullType) : Value(threadsCount()), allocator); + doc.AddMember("threads", threadsCount(), allocator); } doc.AddMember("user-agent", userAgent() ? Value(StringRef(userAgent())).Move() : Value(kNullType).Move(), allocator); @@ -163,7 +165,7 @@ bool xmrig::Config::finalize() return true; } - const AlgoVariant av = getAlgoVariant(); + const AlgoVariant av = getAlgoVariant(); m_threads.mode = m_threads.count ? Simple : Automatic; const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024; @@ -182,6 +184,7 @@ bool xmrig::Config::finalize() m_threads.list.push_back(CpuThread::createFromAV(i, m_algorithm.algo(), av, m_threads.mask, m_priority, m_assembly)); } + m_shouldSave = m_threads.mode == Automatic; return true; } diff --git a/src/core/Config.h b/src/core/Config.h index 95afc34c..eb33ee14 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -78,6 +78,7 @@ public: inline AlgoVariant algoVariant() const { return m_algoVariant; } inline Assembly assembly() const { return m_assembly; } inline bool isHugePages() const { return m_hugePages; } + inline bool isShouldSave() const { return m_shouldSave && isAutoSave(); } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } inline int threadsCount() const { return m_threads.list.size(); } @@ -119,6 +120,7 @@ private: Assembly m_assembly; bool m_hugePages; bool m_safe; + bool m_shouldSave; int m_maxCpuUsage; int m_priority; Threads m_threads; diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 3b95a90f..a932b235 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -161,6 +161,7 @@ static struct option const config_options[] = { { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, + { "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey }, { nullptr, 0, nullptr, 0 } }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 5deb14f7..a5109e9b 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -200,6 +200,10 @@ void Workers::start(xmrig::Controller *controller) m_workers.push_back(handle); handle->start(Workers::onReady); } + + if (controller->config()->isShouldSave()) { + controller->config()->save(); + } }