Integrated embedded config parsing #245

This commit is contained in:
Ben Gräf 2019-05-31 17:18:16 +02:00
parent 727dc786b8
commit a5af2e895f
4 changed files with 97 additions and 11 deletions

68
src/Embedded_config.h Normal file
View file

@ -0,0 +1,68 @@
/* XMRigCC
* Copyright 2019 BenDroid <ben@graef.in>
*
*
* 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_EMBEDDED_CONFIG_H
#define XMRIG_EMBEDDED_CONFIG_H
constexpr static const char* m_embeddedConfig =
R"===(
{
"algo": "cryptonight",
"aesni": 0,
"threads": 0,
"multihash-factor": 0,
"multihash-thread-mask" : null,
"pow-variant" : "auto",
"asm-optimization" : "auto",
"background": false,
"colors": true,
"cpu-affinity": null,
"cpu-priority": null,
"donate-level": 5,
"log-file": null,
"max-cpu-usage": 100,
"print-time": 60,
"retries": 5,
"retry-pause": 5,
"safe": false,
"syslog": false,
"reboot-cmd" : "",
"force-pow-variant" : false,
"skip-self-check" : false,
"pools": [
{
"url": "donate2.graef.in:80",
"user": "YOUR_WALLET_ID",
"pass": "x",
"use-tls" : false,
"keepalive": true,
"nicehash": false
}
],
"cc-client": {
"url": "localhost:3344",
"use-tls" : false,
"access-token": "mySecret",
"worker-id": null,
"update-interval-s": 10,
"use-remote-logging" : true,
"upload-config-on-startup" : true
}
}
)===";
#endif //XMRIG_EMBEDDED_CONFIG_H

View file

@ -45,6 +45,7 @@
#include "net/Url.h"
#include "Options.h"
#include "Platform.h"
#include "embedded_config.h"
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"
#include "rapidjson/filereadstream.h"
@ -451,7 +452,11 @@ Options::Options(int argc, char **argv) :
}
if (!m_pools[0]->isValid() && (!m_ccHost || m_ccPort == 0)) {
parseConfig(Platform::defaultConfigName());
parseConfigFile(Platform::defaultConfigName());
}
if (!m_pools[0]->isValid() && (!m_ccHost || m_ccPort == 0)) {
parseEmbeddedConfig();
}
#ifdef XMRIG_CC_SERVER
@ -492,7 +497,7 @@ Options::~Options()
}
bool Options::getJSON(const char *fileName, rapidjson::Document &doc)
bool Options::readJSONFile(const char *fileName, rapidjson::Document &doc)
{
uv_fs_t req;
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
@ -726,7 +731,7 @@ bool Options::parseArg(int key, const char *arg)
return false;
case 'c': /* --config */
parseConfig(arg);
parseConfigFile(arg);
break;
case 1020: { /* --cpu-affinity */
@ -978,16 +983,27 @@ Url *Options::parseUrl(const char *arg) const
return url;
}
void Options::parseConfig(const char *fileName)
{
void Options::parseConfigFile(const char *fileName) {
m_fileName = fileName;
rapidjson::Document doc;
if (!getJSON(fileName, doc)) {
if (!readJSONFile(fileName, doc)) {
return;
}
parseConfig(doc);
}
void Options::parseEmbeddedConfig() {
rapidjson::Document doc;
doc.Parse(m_embeddedConfig);
parseConfig(doc);
}
void Options::parseConfig(rapidjson::Document& doc)
{
for (auto option : config_options) {
parseJSON(&option, doc);
}

View file

@ -141,13 +141,15 @@ private:
static Options *m_self;
bool getJSON(const char *fileName, rapidjson::Document &doc);
bool readJSONFile(const char *fileName, rapidjson::Document &doc);
bool parseArg(int key, const char *arg);
bool parseArg(int key, uint64_t arg);
bool parseBoolean(int key, bool enable);
bool parseCCUrl(const char *arg);
Url *parseUrl(const char *arg) const;
void parseConfig(const char *fileName);
void parseConfig(rapidjson::Document &doc);
void parseConfigFile(const char *fileName);
void parseEmbeddedConfig();
void parseJSON(const struct option *option, const rapidjson::Value &object);
void showUsage(int status) const;
void showDeprecateWarning(const char* deprecated, const char* newParam) const;

View file

@ -36,14 +36,14 @@
#define APP_DESC "XMRigCC CPU miner"
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
#endif
#define APP_VERSION "1.9.3 (based on XMRig)"
#define APP_VERSION "1.9.4-dev (based on XMRig)"
#define APP_DOMAIN ""
#define APP_SITE "https://github.com/Bendr0id/xmrigCC"
#define APP_KIND "cpu"
#define APP_VER_MAJOR 1
#define APP_VER_MINOR 9
#define APP_VER_BUILD 3
#define APP_VER_BUILD 4
#define APP_VER_REV 0
#ifndef NDEBUG