Added initial next gen config support from proxy.
This commit is contained in:
@ -15,9 +15,17 @@ set(HEADERS
|
||||
src/api/NetworkState.h
|
||||
src/App.h
|
||||
src/Console.h
|
||||
src/core/CommonConfig.h
|
||||
src/core/Config.cpp
|
||||
src/core/ConfigLoader.cpp
|
||||
src/core/ConfigLoader.h
|
||||
src/core/ConfigLoader_platform.h
|
||||
src/core/ConfigWatcher.cpp
|
||||
src/core/Controller.h
|
||||
src/Cpu.h
|
||||
src/interfaces/IClientListener.h
|
||||
src/interfaces/IConfig.h
|
||||
src/interfaces/IConfigCreator.h
|
||||
src/interfaces/IConsoleListener.h
|
||||
src/interfaces/IControllerListener.h
|
||||
src/interfaces/IJobResultListener.h
|
||||
@ -79,6 +87,10 @@ set(SOURCES
|
||||
src/api/NetworkState.cpp
|
||||
src/App.cpp
|
||||
src/Console.cpp
|
||||
src/core/CommonConfig.cpp
|
||||
src/core/Config.cpp
|
||||
src/core/ConfigLoader.cpp
|
||||
src/core/ConfigWatcher.cpp
|
||||
src/core/Controller.cpp
|
||||
src/log/ConsoleLog.cpp
|
||||
src/log/FileLog.cpp
|
||||
|
380
src/core/CommonConfig.cpp
Normal file
380
src/core/CommonConfig.cpp
Normal file
File diff suppressed because it is too large
Load Diff
106
src/core/CommonConfig.h
Normal file
106
src/core/CommonConfig.h
Normal file
@ -0,0 +1,106 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 __COMMONCONFIG_H__
|
||||
#define __COMMONCONFIG_H__
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "interfaces/IConfig.h"
|
||||
|
||||
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CommonConfig : public IConfig
|
||||
{
|
||||
public:
|
||||
CommonConfig();
|
||||
~CommonConfig();
|
||||
|
||||
const char *algoName() const;
|
||||
|
||||
inline bool isApiIPv6() const { return m_apiIPv6; }
|
||||
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isColors() const { return m_colors; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *apiToken() const { return m_apiToken; }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline const char *logFile() const { return m_logFile; }
|
||||
inline const char *userAgent() const { return m_userAgent; }
|
||||
inline const std::vector<Url*> &pools() const { return m_pools; }
|
||||
inline int algorithm() const { return m_algorithm; }
|
||||
inline int apiPort() const { return m_apiPort; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
inline void setColors(bool colors) { m_colors = colors; }
|
||||
|
||||
inline bool isWatch() const override { return m_watch && m_fileName; }
|
||||
inline const char *fileName() const override { return m_fileName; }
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool isValid() const override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
bool save() override;
|
||||
void setFileName(const char *fileName) override;
|
||||
|
||||
bool m_adjusted;
|
||||
bool m_apiIPv6;
|
||||
bool m_apiRestricted;
|
||||
bool m_background;
|
||||
bool m_colors;
|
||||
bool m_syslog;
|
||||
bool m_watch;
|
||||
char *m_apiToken;
|
||||
char *m_apiWorkerId;
|
||||
char *m_fileName;
|
||||
char *m_logFile;
|
||||
char *m_userAgent;
|
||||
int m_algorithm;
|
||||
int m_apiPort;
|
||||
int m_donateLevel;
|
||||
int m_printTime;
|
||||
int m_retries;
|
||||
int m_retryPause;
|
||||
std::vector<Url*> m_pools;
|
||||
|
||||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
void setAlgo(const char *algo);
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __COMMONCONFIG_H__ */
|
329
src/core/Config.cpp
Normal file
329
src/core/Config.cpp
Normal file
File diff suppressed because it is too large
Load Diff
122
src/core/Config.h
Normal file
122
src/core/Config.h
Normal file
@ -0,0 +1,122 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "core/CommonConfig.h"
|
||||
|
||||
|
||||
class Addr;
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ConfigLoader;
|
||||
class IWatcherListener;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Config class
|
||||
*
|
||||
* Options with dynamic reload:
|
||||
* colors
|
||||
* debug
|
||||
* verbose
|
||||
* custom-diff (only for new connections)
|
||||
* api/worker-id
|
||||
* pools/
|
||||
*/
|
||||
class Config : public CommonConfig
|
||||
{
|
||||
friend class ConfigLoader;
|
||||
|
||||
public:
|
||||
enum AlgoVariant {
|
||||
AV0_AUTO,
|
||||
AV1_AESNI,
|
||||
AV2_AESNI_DOUBLE,
|
||||
AV3_SOFT_AES,
|
||||
AV4_SOFT_AES_DOUBLE,
|
||||
AV_MAX
|
||||
};
|
||||
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
bool reload(const char *json);
|
||||
|
||||
void getJSON(rapidjson::Document &doc) const override;
|
||||
|
||||
inline bool isDoubleHash() const { return m_doubleHash; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isHugePages() const { return m_hugePages; }
|
||||
inline int algo() const { return m_algo; }
|
||||
inline int algoVariant() const { return m_algoVariant; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
|
||||
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
||||
|
||||
protected:
|
||||
bool adjust() override;
|
||||
bool parseBoolean(int key, bool enable) override;
|
||||
bool parseString(int key, const char *arg) override;
|
||||
bool parseUint64(int key, uint64_t arg) override;
|
||||
void parseJSON(const rapidjson::Document &doc) override;
|
||||
|
||||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
|
||||
int getAlgoVariant() const;
|
||||
# ifndef XMRIG_NO_AEON
|
||||
int getAlgoVariantLite() const;
|
||||
# endif
|
||||
|
||||
bool m_doubleHash;
|
||||
bool m_dryRun;
|
||||
bool m_hugePages;
|
||||
bool m_safe;
|
||||
int m_algo;
|
||||
int m_algoVariant;
|
||||
int m_maxCpuUsage;
|
||||
int m_printTime;
|
||||
int m_priority;
|
||||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIG_H__ */
|
50
src/core/ConfigCreator.h
Normal file
50
src/core/ConfigCreator.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* 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 __CONFIGCREATOR_H__
|
||||
#define __CONFIGCREATOR_H__
|
||||
|
||||
|
||||
#include "core/Config.h"
|
||||
#include "interfaces/IConfigCreator.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig;
|
||||
|
||||
|
||||
class ConfigCreator : public IConfigCreator
|
||||
{
|
||||
public:
|
||||
inline IConfig *create() const override
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __CONFIGCREATOR_H__
|
311
src/core/ConfigLoader.cpp
Normal file
311
src/core/ConfigLoader.cpp
Normal file
File diff suppressed because it is too large
Load Diff
71
src/core/ConfigLoader.h
Normal file
71
src/core/ConfigLoader.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 __CONFIGLOADER_H__
|
||||
#define __CONFIGLOADER_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
struct option;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class ConfigWatcher;
|
||||
class IConfigCreator;
|
||||
class IWatcherListener;
|
||||
class IConfig;
|
||||
|
||||
|
||||
class ConfigLoader
|
||||
{
|
||||
public:
|
||||
static bool loadFromFile(IConfig *config, const char *fileName);
|
||||
static bool loadFromJSON(IConfig *config, const char *json);
|
||||
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
|
||||
static bool reload(IConfig *oldConfig, const char *json);
|
||||
static IConfig *load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener);
|
||||
static void release();
|
||||
|
||||
private:
|
||||
static bool getJSON(const char *fileName, rapidjson::Document &doc);
|
||||
static bool parseArg(IConfig *config, int key, const char *arg);
|
||||
static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object);
|
||||
static void showUsage();
|
||||
static void showVersion();
|
||||
|
||||
static ConfigWatcher *m_watcher;
|
||||
static IConfigCreator *m_creator;
|
||||
static IWatcherListener *m_listener;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGLOADER_H__ */
|
171
src/core/ConfigLoader_platform.h
Normal file
171
src/core/ConfigLoader_platform.h
Normal file
@ -0,0 +1,171 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
*
|
||||
* 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 __CONFIGLOADER_PLATFORM_H__
|
||||
#define __CONFIGLOADER_PLATFORM_H__
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include "getopt/getopt.h"
|
||||
#else
|
||||
# include <getopt.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "version.h"
|
||||
#include "interfaces/IConfig.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static char const usage[] = "\
|
||||
Usage: " APP_ID " [OPTIONS]\n\
|
||||
Options:\n\
|
||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
|
||||
-o, --url=URL URL of mining server\n\
|
||||
-O, --userpass=U:P username:password pair for mining server\n\
|
||||
-u, --user=USERNAME username for mining server\n\
|
||||
-p, --pass=PASSWORD password for mining server\n\
|
||||
-t, --threads=N number of miner threads\n\
|
||||
-v, --av=N algorithm variation, 0 auto select\n\
|
||||
-k, --keepalive send keepalived for prevent timeout (need pool support)\n\
|
||||
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
|
||||
-R, --retry-pause=N time to pause between retries (default: 5)\n\
|
||||
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
|
||||
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
|
||||
--no-huge-pages disable huge pages support\n\
|
||||
--no-color disable colored output\n\
|
||||
--variant algorithm PoW variant\n\
|
||||
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
|
||||
--user-agent set custom user-agent string for pool\n\
|
||||
-B, --background run the miner in the background\n\
|
||||
-c, --config=FILE load a JSON-format configuration file\n\
|
||||
-l, --log-file=FILE log all output to a file\n"
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
"\
|
||||
-S, --syslog use system log for output messages\n"
|
||||
# endif
|
||||
"\
|
||||
--max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\
|
||||
--safe safe adjust threads and av settings for current CPU\n\
|
||||
--nicehash enable nicehash/xmrig-proxy support\n\
|
||||
--print-time=N print hashrate report every N seconds\n\
|
||||
--api-port=N port for the miner API\n\
|
||||
--api-access-token=T access token for API\n\
|
||||
--api-worker-id=ID custom worker-id for API\n\
|
||||
-h, --help display this help and exit\n\
|
||||
-V, --version output version information and exit\n\
|
||||
";
|
||||
|
||||
|
||||
static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S";
|
||||
|
||||
|
||||
static struct option const options[] = {
|
||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
||||
{ "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
||||
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
|
||||
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "api-no-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
||||
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
||||
{ "config", 1, nullptr, xmrig::IConfig::ConfigKey },
|
||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
||||
{ "help", 0, nullptr, xmrig::IConfig::HelpKey },
|
||||
{ "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "no-color", 0, nullptr, xmrig::IConfig::ColorKey },
|
||||
{ "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
||||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "version", 0, nullptr, xmrig::IConfig::VersionKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const config_options[] = {
|
||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
||||
{ "colors", 0, nullptr, xmrig::IConfig::ColorKey },
|
||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
||||
{ "huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
||||
{ "threads", 1, nullptr, xmrig::IConfig::SafeKey },
|
||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const pool_options[] = {
|
||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
||||
{ "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey },
|
||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct option const api_options[] = {
|
||||
{ "port", 1, nullptr, xmrig::IConfig::ApiPort },
|
||||
{ "access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
||||
{ "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
||||
{ "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
||||
{ "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGLOADER_PLATFORM_H__ */
|
107
src/core/ConfigWatcher.cpp
Normal file
107
src/core/ConfigWatcher.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "core/ConfigCreator.h"
|
||||
#include "core/ConfigLoader.h"
|
||||
#include "core/ConfigWatcher.h"
|
||||
#include "interfaces/IWatcherListener.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) :
|
||||
m_path(strdup(path)),
|
||||
m_creator(creator),
|
||||
m_listener(listener)
|
||||
{
|
||||
uv_fs_event_init(uv_default_loop(), &m_fsEvent);
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
|
||||
m_fsEvent.data = m_timer.data = this;
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
xmrig::ConfigWatcher::~ConfigWatcher()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
uv_fs_event_stop(&m_fsEvent);
|
||||
|
||||
free(m_path);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::onTimer(uv_timer_t* handle)
|
||||
{
|
||||
static_cast<xmrig::ConfigWatcher *>(handle->data)->reload();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status)
|
||||
{
|
||||
if (!filename) {
|
||||
return;
|
||||
}
|
||||
|
||||
static_cast<xmrig::ConfigWatcher *>(handle->data)->queueUpdate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::queueUpdate()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
uv_timer_start(&m_timer, xmrig::ConfigWatcher::onTimer, kDelay, 0);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::reload()
|
||||
{
|
||||
LOG_WARN("\"%s\" was changed, reloading configuration", m_path);
|
||||
|
||||
IConfig *config = m_creator->create();
|
||||
ConfigLoader::loadFromFile(config, m_path);
|
||||
|
||||
if (!config->isValid()) {
|
||||
LOG_ERR("reloading failed");
|
||||
|
||||
delete config;
|
||||
return;
|
||||
}
|
||||
|
||||
m_listener->onNewConfig(config);
|
||||
|
||||
# ifndef _WIN32
|
||||
uv_fs_event_stop(&m_fsEvent);
|
||||
start();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::ConfigWatcher::start()
|
||||
{
|
||||
uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path, 0);
|
||||
}
|
69
src/core/ConfigWatcher.h
Normal file
69
src/core/ConfigWatcher.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 __CONFIGWATCHER_H__
|
||||
#define __CONFIGWATCHER_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
struct option;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfigCreator;
|
||||
class IWatcherListener;
|
||||
|
||||
|
||||
class ConfigWatcher
|
||||
{
|
||||
public:
|
||||
ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener);
|
||||
~ConfigWatcher();
|
||||
|
||||
private:
|
||||
constexpr static int kDelay = 500;
|
||||
|
||||
static void onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status);
|
||||
static void onTimer(uv_timer_t* handle);
|
||||
void queueUpdate();
|
||||
void reload();
|
||||
void start();
|
||||
|
||||
char *m_path;
|
||||
IConfigCreator *m_creator;
|
||||
IWatcherListener *m_listener;
|
||||
uv_fs_event_t m_fsEvent;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
#endif /* __CONFIGWATCHER_H__ */
|
@ -112,7 +112,7 @@ void xmrig::Controller::addListener(IControllerListener *listener)
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Controller::onNewConfig(Config *config)
|
||||
void xmrig::Controller::onNewConfig(IConfig *config)
|
||||
{
|
||||
// xmrig::Config *previousConfig = d_ptr->config;
|
||||
// d_ptr->config = config;
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
void addListener(IControllerListener *listener);
|
||||
|
||||
protected:
|
||||
void onNewConfig(Config *config) override;
|
||||
void onNewConfig(IConfig *config) override;
|
||||
|
||||
private:
|
||||
ControllerPrivate *d_ptr;
|
||||
|
@ -38,7 +38,8 @@
|
||||
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
|
||||
* BTC: 1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT
|
||||
*/
|
||||
constexpr const int kDonateLevel = 5;
|
||||
constexpr const int kDefaultDonateLevel = 5;
|
||||
constexpr const int kMinDonateLevel = 1;
|
||||
|
||||
|
||||
#endif /* __DONATE_H__ */
|
||||
|
109
src/interfaces/IConfig.h
Normal file
109
src/interfaces/IConfig.h
Normal file
@ -0,0 +1,109 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* 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 __ICONFIG_H__
|
||||
#define __ICONFIG_H__
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig
|
||||
{
|
||||
public:
|
||||
enum Keys {
|
||||
// common
|
||||
AlgorithmKey = 'a',
|
||||
ApiPort = 4000,
|
||||
ApiAccessTokenKey = 4001,
|
||||
ApiWorkerIdKey = 4002,
|
||||
ApiIPv6Key = 4003,
|
||||
ApiRestrictedKey = 4004,
|
||||
BackgroundKey = 'B',
|
||||
ConfigKey = 'c',
|
||||
DonateLevelKey = 1003,
|
||||
HelpKey = 'h',
|
||||
KeepAliveKey = 'k',
|
||||
LogFileKey = 'l',
|
||||
ColorKey = 1002,
|
||||
WatchKey = 1105,
|
||||
PasswordKey = 'p',
|
||||
RetriesKey = 'r',
|
||||
RetryPauseKey = 'R',
|
||||
SyslogKey = 'S',
|
||||
UrlKey = 'o',
|
||||
UserKey = 'u',
|
||||
UserAgentKey = 1008,
|
||||
UserpassKey = 'O',
|
||||
VerboseKey = 1100,
|
||||
VersionKey = 'V',
|
||||
VariantKey = 1010,
|
||||
|
||||
// xmrig common
|
||||
CPUPriorityKey = 1021,
|
||||
NicehashKey = 1006,
|
||||
PrintTimeKey = 1007,
|
||||
|
||||
// xmrig cpu
|
||||
AVKey = 'v',
|
||||
CPUAffinityKey = 1020,
|
||||
DryRunKey = 5000,
|
||||
HugePagesKey = 1009,
|
||||
MaxCPUUsageKey = 1004,
|
||||
SafeKey = 1005,
|
||||
ThreadsKey = 't',
|
||||
|
||||
// xmrig-proxy
|
||||
AccessLogFileKey = 'A',
|
||||
BindKey = 'b',
|
||||
CoinKey = 1104,
|
||||
CustomDiffKey = 1102,
|
||||
DebugKey = 1101,
|
||||
ModeKey = 'm',
|
||||
PoolCoinKey = 'C',
|
||||
ReuseTimeoutKey = 1106,
|
||||
WorkersKey = 1103,
|
||||
};
|
||||
|
||||
virtual ~IConfig() {}
|
||||
|
||||
virtual bool adjust() = 0;
|
||||
virtual bool isValid() const = 0;
|
||||
virtual bool isWatch() const = 0;
|
||||
virtual bool parseBoolean(int key, bool enable) = 0;
|
||||
virtual bool parseString(int key, const char *arg) = 0;
|
||||
virtual bool parseUint64(int key, uint64_t arg) = 0;
|
||||
virtual bool save() = 0;
|
||||
virtual const char *fileName() const = 0;
|
||||
virtual void getJSON(rapidjson::Document &doc) const = 0;
|
||||
virtual void parseJSON(const rapidjson::Document &doc) = 0;
|
||||
virtual void setFileName(const char *fileName) = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONFIG_H__
|
45
src/interfaces/IConfigCreator.h
Normal file
45
src/interfaces/IConfigCreator.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* 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 __ICONFIGCREATOR_H__
|
||||
#define __ICONFIGCREATOR_H__
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IConfig;
|
||||
|
||||
|
||||
class IConfigCreator
|
||||
{
|
||||
public:
|
||||
virtual ~IConfigCreator() {}
|
||||
|
||||
virtual IConfig *create() const = 0;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ICONFIGCREATOR_H__
|
@ -28,7 +28,7 @@
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Config;
|
||||
class IConfig;
|
||||
|
||||
|
||||
class IWatcherListener
|
||||
@ -36,7 +36,7 @@ class IWatcherListener
|
||||
public:
|
||||
virtual ~IWatcherListener() {}
|
||||
|
||||
virtual void onNewConfig(Config *config) = 0;
|
||||
virtual void onNewConfig(IConfig *config) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -37,12 +37,12 @@
|
||||
|
||||
|
||||
Url::Url() :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
@ -62,12 +62,12 @@ Url::Url() :
|
||||
* @param url
|
||||
*/
|
||||
Url::Url(const char *url) :
|
||||
m_keepAlive(false),
|
||||
m_nicehash(false),
|
||||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
m_port(kDefaultPort)
|
||||
@ -76,12 +76,12 @@ Url::Url(const char *url) :
|
||||
}
|
||||
|
||||
|
||||
Url::Url(const char *host, uint16_t port, const char *user, const char *password, bool keepAlive, bool nicehash, int variant) :
|
||||
m_keepAlive(keepAlive),
|
||||
Url::Url(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, int variant) :
|
||||
m_nicehash(nicehash),
|
||||
m_password(password ? strdup(password) : nullptr),
|
||||
m_user(user ? strdup(user) : nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_keepAlive(keepAlive),
|
||||
m_variant(variant),
|
||||
m_url(nullptr),
|
||||
m_port(port)
|
||||
|
@ -34,22 +34,24 @@ public:
|
||||
constexpr static const char *kDefaultPassword = "x";
|
||||
constexpr static const char *kDefaultUser = "x";
|
||||
constexpr static uint16_t kDefaultPort = 3333;
|
||||
constexpr static int kKeepAliveTimeout = 60;
|
||||
|
||||
Url();
|
||||
Url(const char *url);
|
||||
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = -1);
|
||||
Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, int keepAlive = 0, bool nicehash = false, int variant = -1);
|
||||
~Url();
|
||||
|
||||
inline bool isKeepAlive() const { return m_keepAlive; }
|
||||
inline bool isKeepAlive() const { return m_keepAlive > 0; } // FIXME: replace isKeepAlive to keepAlive
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_host && m_port > 0; }
|
||||
inline const char *host() const { return m_host; }
|
||||
inline const char *password() const { return m_password ? m_password : kDefaultPassword; }
|
||||
inline const char *user() const { return m_user ? m_user : kDefaultUser; }
|
||||
inline int algo() const { return m_algo; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline int variant() const { return m_variant; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setKeepAlive(bool keepAlive) { m_keepAlive = keepAlive; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setVariant(bool monero) { m_variant = monero; }
|
||||
|
||||
@ -67,12 +69,12 @@ public:
|
||||
private:
|
||||
bool parseIPv6(const char *addr);
|
||||
|
||||
bool m_keepAlive;
|
||||
bool m_nicehash;
|
||||
char *m_host;
|
||||
char *m_password;
|
||||
char *m_user;
|
||||
int m_algo;
|
||||
int m_keepAlive;
|
||||
int m_variant;
|
||||
mutable char *m_url;
|
||||
uint16_t m_port;
|
||||
|
@ -30,8 +30,9 @@ namespace xmrig
|
||||
|
||||
|
||||
enum Algo {
|
||||
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
ALGO_CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user