Skip to content

Commit

Permalink
Integrated embedded config parsing #245
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendr0id committed May 31, 2019
1 parent 727dc78 commit a5af2e8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
68 changes: 68 additions & 0 deletions src/Embedded_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* XMRigCC
* Copyright 2019 BenDroid <[email protected]>
*
*
* 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
30 changes: 23 additions & 7 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ class Options

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;
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5af2e8

Please sign in to comment.