Embedded config (#256)

* Integrated embedded config parsing #245

* cleanup

* Cleanup in remotelog

* Fixed MS Visual Studio 2019 compatibility

* Embedded config parsing only for miner not server
This commit is contained in:
Ben Gräf 2019-07-24 13:54:22 -07:00 committed by GitHub
parent 31cf575b5d
commit 5b0fed8be9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 19 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,7 @@ Options::Options(int argc, char **argv) :
}
if (!m_pools[0]->isValid() && (!m_ccHost || m_ccPort == 0)) {
parseConfig(Platform::defaultConfigName());
parseConfigFile(Platform::defaultConfigName());
}
#ifdef XMRIG_CC_SERVER
@ -467,6 +468,11 @@ Options::Options(int argc, char **argv) :
}
#endif
if (!m_pools[0]->isValid() && (!m_ccHost || m_ccPort == 0)) {
fprintf(stderr, "No valid pool/cc configuration found, using embedded config.\n");
parseEmbeddedConfig();
}
if (!m_pools[0]->isValid() && (!m_ccHost || m_ccPort == 0)) {
fprintf(stderr, "Neither pool nor CCServer URL supplied. Exiting.\n");
return;
@ -491,8 +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

@ -300,10 +300,10 @@ void CCClient::publishConfig()
m_self->m_config->ccPort(), requestUrl.c_str());
}
} else {
LOG_ERR("Not able to send config. Client config %s is broken!", m_self->m_config->fileName());
LOG_ERR("[CC-Client] Not able to send config. Client config %s is broken!", m_self->m_config->fileName());
}
} else {
LOG_ERR("Not able to load client config %s. Please make sure it exists!", m_self->m_config->fileName());
LOG_ERR("[CC-Client] Not able to load client config %s. Please make sure it exists! Using embedded config.", m_self->m_config->fileName());
}
}

View file

@ -21,6 +21,7 @@
#include "log/RemoteLog.h"
RemoteLog* RemoteLog::m_self = nullptr;
static const std::regex COLOR_PATTERN("\x1B\\[[0-9;]*[a-zA-Z]");
RemoteLog::RemoteLog(size_t maxRows)
: m_maxRows(maxRows)
@ -57,18 +58,19 @@ void RemoteLog::message(int level, const char* fmt, va_list args)
stime.tm_min,
stime.tm_sec);
size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size;
size = vsnprintf(buf + size, static_cast<size_t>(512 - size - 1), fmt, args) + size;
buf[size] = '\n';
std::string coloredLogLine(buf, static_cast<unsigned long>(size + 1));
std::string logLine = std::regex_replace(coloredLogLine, COLOR_PATTERN, "");
uv_mutex_lock(&m_mutex);
if (m_rows.size() == m_maxRows) {
m_rows.pop_front();
}
std::string row = std::regex_replace(std::string(buf, size+1), std::regex("\x1B\\[[0-9;]*[a-zA-Z]"), "");
m_rows.push_back(row);
m_rows.push_back(logLine);
uv_mutex_unlock(&m_mutex);

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
@ -61,7 +61,9 @@
#endif
#ifdef _MSC_VER
# if (_MSC_VER >= 1910)
# if (_MSC_VER >= 1920)
# define MSVC_VERSION 2019
# elif (_MSC_VER >= 1910 && _MSC_VER < 1920)
# define MSVC_VERSION 2017
# elif _MSC_VER == 1900
# define MSVC_VERSION 2015