Integrated embedded config parsing #245
This commit is contained in:
parent
727dc786b8
commit
a5af2e895f
4 changed files with 97 additions and 11 deletions
68
src/Embedded_config.h
Normal file
68
src/Embedded_config.h
Normal 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
|
|
@ -45,6 +45,7 @@
|
||||||
#include "net/Url.h"
|
#include "net/Url.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
#include "embedded_config.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/error/en.h"
|
#include "rapidjson/error/en.h"
|
||||||
#include "rapidjson/filereadstream.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)) {
|
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
|
#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;
|
uv_fs_t req;
|
||||||
const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr);
|
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;
|
return false;
|
||||||
|
|
||||||
case 'c': /* --config */
|
case 'c': /* --config */
|
||||||
parseConfig(arg);
|
parseConfigFile(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1020: { /* --cpu-affinity */
|
case 1020: { /* --cpu-affinity */
|
||||||
|
@ -978,16 +983,27 @@ Url *Options::parseUrl(const char *arg) const
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Options::parseConfigFile(const char *fileName) {
|
||||||
void Options::parseConfig(const char *fileName)
|
|
||||||
{
|
|
||||||
m_fileName = fileName;
|
m_fileName = fileName;
|
||||||
|
|
||||||
rapidjson::Document doc;
|
rapidjson::Document doc;
|
||||||
if (!getJSON(fileName, doc)) {
|
if (!readJSONFile(fileName, doc)) {
|
||||||
return;
|
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) {
|
for (auto option : config_options) {
|
||||||
parseJSON(&option, doc);
|
parseJSON(&option, doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,13 +141,15 @@ private:
|
||||||
|
|
||||||
static Options *m_self;
|
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, const char *arg);
|
||||||
bool parseArg(int key, uint64_t arg);
|
bool parseArg(int key, uint64_t arg);
|
||||||
bool parseBoolean(int key, bool enable);
|
bool parseBoolean(int key, bool enable);
|
||||||
bool parseCCUrl(const char *arg);
|
bool parseCCUrl(const char *arg);
|
||||||
Url *parseUrl(const char *arg) const;
|
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 parseJSON(const struct option *option, const rapidjson::Value &object);
|
||||||
void showUsage(int status) const;
|
void showUsage(int status) const;
|
||||||
void showDeprecateWarning(const char* deprecated, const char* newParam) const;
|
void showDeprecateWarning(const char* deprecated, const char* newParam) const;
|
||||||
|
|
|
@ -36,14 +36,14 @@
|
||||||
#define APP_DESC "XMRigCC CPU miner"
|
#define APP_DESC "XMRigCC CPU miner"
|
||||||
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
|
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
|
||||||
#endif
|
#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_DOMAIN ""
|
||||||
#define APP_SITE "https://github.com/Bendr0id/xmrigCC"
|
#define APP_SITE "https://github.com/Bendr0id/xmrigCC"
|
||||||
#define APP_KIND "cpu"
|
#define APP_KIND "cpu"
|
||||||
|
|
||||||
#define APP_VER_MAJOR 1
|
#define APP_VER_MAJOR 1
|
||||||
#define APP_VER_MINOR 9
|
#define APP_VER_MINOR 9
|
||||||
#define APP_VER_BUILD 3
|
#define APP_VER_BUILD 4
|
||||||
#define APP_VER_REV 0
|
#define APP_VER_REV 0
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue