Resolved conflicts

This commit is contained in:
MoneroOcean 2019-09-28 20:26:20 -07:00
commit d03fb91b0a
82 changed files with 3489 additions and 439 deletions

View file

@ -23,7 +23,7 @@
*/
#include <assert.h>
#include <cassert>
#include <memory>
@ -64,15 +64,16 @@ static const char *kConfigPathV2 = "/2/config";
#endif
class xmrig::BasePrivate
namespace xmrig {
class BasePrivate
{
public:
inline BasePrivate(Process *process) :
api(nullptr),
config(nullptr),
process(process),
watcher(nullptr)
{}
XMRIG_DISABLE_COPY_MOVE_DEFAULT(BasePrivate)
inline BasePrivate(Process *process) : config(load(process)) {}
inline ~BasePrivate()
@ -94,13 +95,33 @@ public:
}
inline Config *load()
inline void replace(Config *newConfig)
{
Config *previousConfig = config;
config = newConfig;
for (IBaseListener *listener : listeners) {
listener->onConfigChanged(config, previousConfig);
}
delete previousConfig;
}
Api *api = nullptr;
Config *config = nullptr;
std::vector<IBaseListener *> listeners;
Watcher *watcher = nullptr;
private:
inline Config *load(Process *process)
{
JsonChain chain;
ConfigTransform transform;
std::unique_ptr<Config> config;
transform.load(chain, process, transform);
ConfigTransform::load(chain, process, transform);
if (read(chain, config)) {
return config.release();
@ -122,29 +143,12 @@ public:
return nullptr;
}
inline void replace(Config *newConfig)
{
Config *previousConfig = config;
config = newConfig;
for (IBaseListener *listener : listeners) {
listener->onConfigChanged(config, previousConfig);
}
delete previousConfig;
}
Api *api;
Config *config;
Process *process;
std::vector<IBaseListener *> listeners;
Watcher *watcher;
};
} // namespace xmrig
xmrig::Base::Base(Process *process)
: d_ptr(new BasePrivate(process))
{
@ -165,14 +169,6 @@ bool xmrig::Base::isReady() const
int xmrig::Base::init()
{
d_ptr->config = d_ptr->load();
if (!d_ptr->config) {
LOG_EMERG("No valid configuration found. Exiting.");
return 1;
}
# ifdef XMRIG_FEATURE_API
d_ptr->api = new Api(this);
d_ptr->api->addListener(this);
@ -184,7 +180,7 @@ int xmrig::Base::init()
Platform::setProcessPriority(config()->cpu().priority());
# endif
if (config()->isBackground()) {
if (isBackground()) {
Log::background = true;
}
else {
@ -240,6 +236,12 @@ xmrig::Api *xmrig::Base::api() const
}
bool xmrig::Base::isBackground() const
{
return d_ptr->config && d_ptr->config->isBackground();
}
bool xmrig::Base::reload(const rapidjson::Value &json)
{
JsonReader reader(json);
@ -247,7 +249,7 @@ bool xmrig::Base::reload(const rapidjson::Value &json)
return false;
}
Config *config = new Config();
auto config = new Config();
if (!config->read(reader, d_ptr->config->fileName())) {
delete config;
@ -289,7 +291,7 @@ void xmrig::Base::onFileChanged(const String &fileName)
JsonChain chain;
chain.addFile(fileName);
Config *config = new Config();
auto config = new Config();
if (!config->read(chain, chain.fileName())) {
LOG_ERR("reloading failed");

View file

@ -29,6 +29,7 @@
#include "base/api/interfaces/IApiListener.h"
#include "base/kernel/interfaces/IConfigListener.h"
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/tools/Object.h"
#include "rapidjson/fwd.h"
@ -45,6 +46,8 @@ class Process;
class Base : public IWatcherListener, public IApiListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Base)
Base(Process *process);
~Base() override;
@ -54,6 +57,7 @@ public:
virtual void stop();
Api *api() const;
bool isBackground() const;
bool reload(const rapidjson::Value &json);
Config *config() const;
void addListener(IBaseListener *listener);

View file

@ -23,7 +23,7 @@
*/
#include <stdio.h>
#include <cstdio>
#include <uv.h>
@ -161,7 +161,7 @@ int xmrig::Entry::exec(const Process &process, Id id)
{
switch (id) {
case Usage:
printf(usage);
printf("%s\n", usage().c_str());
return 0;
case Version:

View file

@ -23,8 +23,8 @@
*/
#include <ctime>
#include <uv.h>
#include <time.h>
#include "base/kernel/Process.h"
@ -55,11 +55,6 @@ xmrig::Process::Process(int argc, char **argv) :
}
xmrig::Process::~Process()
{
}
xmrig::String xmrig::Process::location(Location location, const char *fileName) const
{
constexpr const size_t max = 520;

View file

@ -47,7 +47,6 @@ public:
# endif
Process(int argc, char **argv);
~Process();
String location(Location location, const char *fileName = nullptr) const;

View file

@ -23,7 +23,7 @@
*/
#include <stdio.h>
#include <cstdio>
#ifdef _MSC_VER
@ -47,15 +47,11 @@ namespace xmrig
static const char *kAlgo = "algo";
static const char *kApi = "api";
static const char *kCoin = "coin";
static const char *kHttp = "http";
static const char *kPools = "pools";
}
xmrig::BaseTransform::BaseTransform()
{
}
} // namespace xmrig
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
@ -68,7 +64,7 @@ void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTrans
Document doc(kObjectType);
while (1) {
while (true) {
key = getopt_long(argc, argv, short_options, options, nullptr);
if (key < 0) {
break;
@ -107,6 +103,19 @@ void xmrig::BaseTransform::finalize(rapidjson::Document &doc)
}
}
}
if (m_coin.isValid() && doc.HasMember(kPools)) {
auto &pools = doc[kPools];
for (Value &pool : pools.GetArray()) {
if (!pool.HasMember(kCoin)) {
pool.AddMember(StringRef(kCoin), m_coin.toJSON(), allocator);
}
}
}
if (m_http) {
set(doc, kHttp, "enabled", true);
}
}
@ -122,6 +131,15 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
}
break;
case IConfig::CoinKey: /* --coin */
if (!doc.HasMember(kPools)) {
m_coin = arg;
}
else {
return add(doc, kPools, kCoin, arg);
}
break;
case IConfig::UserpassKey: /* --userpass */
{
const char *p = strrchr(arg, ':');
@ -169,9 +187,11 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
return set(doc, "log-file", arg);
case IConfig::HttpAccessTokenKey: /* --http-access-token */
m_http = true;
return set(doc, kHttp, "access-token", arg);
case IConfig::HttpHostKey: /* --http-host */
m_http = true;
return set(doc, kHttp, "host", arg);
case IConfig::ApiWorkerIdKey: /* --api-worker-id */
@ -228,8 +248,10 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
case IConfig::TlsKey: /* --tls */
return add(doc, kPools, "tls", enable);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonKey: /* --daemon */
return add(doc, kPools, "daemon", enable);
# endif
# ifndef XMRIG_PROXY_PROJECT
case IConfig::NicehashKey: /* --nicehash */
@ -240,10 +262,12 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
return set(doc, "colors", enable);
case IConfig::HttpRestrictedKey: /* --http-no-restricted */
m_http = true;
return set(doc, kHttp, "restricted", enable);
case IConfig::HttpEnabledKey: /* --http-enabled */
return set(doc, kHttp, "enabled", enable);
m_http = true;
break;
case IConfig::DryRunKey: /* --dry-run */
return set(doc, "dry-run", enable);
@ -273,13 +297,16 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
return set(doc, "donate-over-proxy", arg);
case IConfig::HttpPort: /* --http-port */
m_http = true;
return set(doc, kHttp, "port", arg);
case IConfig::PrintTimeKey: /* --print-time */
return set(doc, "print-time", arg);
# ifdef XMRIG_FEATURE_HTTP
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, kPools, "daemon-poll-interval", arg);
# endif
case IConfig::BenchAlgoTimeKey: /* --bench-algo-time */
return set(doc, "bench-algo-time", arg);

View file

@ -27,6 +27,7 @@
#include "base/kernel/interfaces/IConfigTransform.h"
#include "crypto/common/Coin.h"
#include "rapidjson/document.h"
@ -44,8 +45,6 @@ class Process;
class BaseTransform : public IConfigTransform
{
public:
BaseTransform();
static void load(JsonChain &chain, Process *process, IConfigTransform &transform);
protected:
@ -99,11 +98,14 @@ protected:
protected:
Algorithm m_algorithm;
Coin m_coin;
private:
void transformBoolean(rapidjson::Document &doc, int key, bool enable);
void transformUint64(rapidjson::Document &doc, int key, uint64_t arg);
bool m_http = false;
};

View file

@ -43,6 +43,7 @@ public:
enum Keys {
// common
AlgorithmKey = 'a',
CoinKey = 1025,
ApiWorkerIdKey = 4002,
ApiIdKey = 4005,
HttpPort = 4100,
@ -81,6 +82,7 @@ public:
BenchAlgoTimeKey = 10002,
// xmrig cpu
CPUKey = 1024,
AVKey = 'v',
CPUAffinityKey = 1020,
DryRunKey = 5000,
@ -89,6 +91,7 @@ public:
AssemblyKey = 1015,
RandomXInitKey = 1022,
RandomXNumaKey = 1023,
CPUMaxThreadsKey = 1026,
// xmrig amd
OclPlatformKey = 1400,
@ -102,6 +105,7 @@ public:
OclMemChunkKey = 1408,
OclUnrollKey = 1409,
OclCompModeKey = 1410,
OclKey = 1411,
// xmrig-proxy
AccessLogFileKey = 'A',