This commit is contained in:
MoneroOcean 2020-03-22 16:26:51 -07:00
commit ca0f93bb22
109 changed files with 4895 additions and 461 deletions

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -27,16 +27,17 @@
#include <memory>
#include "base/kernel/Base.h"
#include "base/io/json/Json.h"
#include "base/io/json/JsonChain.h"
#include "base/io/log/backends/ConsoleLog.h"
#include "base/io/log/backends/FileLog.h"
#include "base/io/log/Log.h"
#include "base/io/Watcher.h"
#include "base/kernel/Base.h"
#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/Platform.h"
#include "base/kernel/Process.h"
#include "base/net/tools/NetBuffer.h"
#include "core/config/Config.h"
#include "core/config/ConfigTransform.h"
@ -84,6 +85,8 @@ public:
delete config;
delete watcher;
NetBuffer::destroy();
}
@ -127,7 +130,7 @@ private:
return config.release();
}
chain.addFile(Process::location(Process::ExeLocation, "config.json"));
chain.addFile(Process::location(Process::DataLocation, "config.json"));
if (read(chain, config)) {
return config.release();

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -56,9 +56,13 @@ static std::map<String, String> variables;
static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_EXE", Process::exepath() });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
}
#endif

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -24,6 +24,7 @@
#include <ctime>
#include <string>
#include <uv.h>
@ -34,20 +35,75 @@
namespace xmrig {
static size_t getLocation(Process::Location location, char *buf, size_t max)
{
using namespace xmrig;
static char pathBuf[520];
static std::string dataDir;
static std::string getPath(Process::Location location)
{
size_t size = sizeof(pathBuf);
if (location == Process::DataLocation) {
if (!dataDir.empty()) {
return dataDir;
}
location = Process::ExeLocation;
}
if (location == Process::HomeLocation) {
# if UV_VERSION_HEX >= 0x010600
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
if (location == Process::TempLocation) {
# if UV_VERSION_HEX >= 0x010900
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
# else
location = Process::ExeLocation;
# endif
}
size_t size = max;
if (location == Process::ExeLocation) {
return uv_exepath(buf, &size) < 0 ? 0 : size;
if (uv_exepath(pathBuf, &size) < 0) {
return {};
}
const auto path = std::string(pathBuf, size);
const auto pos = path.rfind(Process::kDirSeparator);
if (pos != std::string::npos) {
return path.substr(0, pos);
}
return path;
}
if (location == Process::CwdLocation) {
return uv_cwd(buf, &size) < 0 ? 0 : size;
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
}
return 0;
return {};
}
static void setDataDir(const char *path)
{
if (path == nullptr) {
return;
}
std::string dir = path;
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
dir.pop_back();
}
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
dataDir = dir;
}
}
@ -58,46 +114,25 @@ xmrig::Process::Process(int argc, char **argv) :
m_arguments(argc, argv)
{
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
setDataDir(m_arguments.value("--data-dir"));
}
xmrig::String xmrig::Process::exepath()
{
size_t size = sizeof(pathBuf);
return uv_exepath(pathBuf, &size) < 0 ? "" : String(pathBuf, size);
}
xmrig::String xmrig::Process::location(Location location, const char *fileName)
{
constexpr const size_t max = 520;
char *buf = new char[max]();
size_t size = getLocation(location, buf, max);
if (size == 0) {
delete [] buf;
return String();
auto path = getPath(location);
if (path.empty() || fileName == nullptr) {
return path.c_str();
}
if (fileName == nullptr) {
return buf;
}
if (location == ExeLocation) {
char *p = strrchr(buf, kDirSeparator);
if (p == nullptr) {
delete [] buf;
return String();
}
size = static_cast<size_t>(p - buf);
}
if ((size + strlen(fileName) + 2) >= max) {
delete [] buf;
return String();
}
buf[size] = kDirSeparator;
strcpy(buf + size + 1, fileName);
return buf;
return (path + kDirSeparator + fileName).c_str();
}

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -37,7 +37,10 @@ class Process
public:
enum Location {
ExeLocation,
CwdLocation
CwdLocation,
DataLocation,
HomeLocation,
TempLocation
};
# ifdef WIN32
@ -48,6 +51,7 @@ public:
Process(int argc, char **argv);
static String exepath();
static String location(Location location, const char *fileName = nullptr);
inline const Arguments &arguments() const { return m_arguments; }

View file

@ -66,6 +66,11 @@ const char *BaseConfig::kVerbose = "verbose";
const char *BaseConfig::kWatch = "watch";
#ifdef XMRIG_FEATURE_TLS
const char *BaseConfig::kTls = "tls";
#endif
} // namespace xmrig
@ -87,11 +92,16 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
m_rebenchAlgo = reader.getBool("rebench-algo", m_rebenchAlgo);
m_benchAlgoTime = reader.getInt("bench-algo-time", m_benchAlgoTime);
# ifdef XMRIG_FEATURE_TLS
m_tls = reader.getValue(kTls);
# endif
Log::setColors(reader.getBool(kColors, Log::isColors()));
setPrintTime(reader.getUint(kPrintTime, 60));
setVerbose(reader.getValue(kVerbose));
const rapidjson::Value &api = reader.getObject(kApi);
const auto &api = reader.getObject(kApi);
if (api.IsObject()) {
m_apiId = Json::getString(api, kApiId);
m_apiWorkerId = Json::getString(api, kApiWorkerId);

View file

@ -31,6 +31,11 @@
#include "base/net/stratum/Pools.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
namespace xmrig {
@ -55,26 +60,34 @@ public:
static const char *kVerbose;
static const char *kWatch;
# ifdef XMRIG_FEATURE_TLS
static const char *kTls;
# endif
BaseConfig() = default;
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const Http &http() const { return m_http; }
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline uint32_t printTime() const { return m_printTime; }
inline bool isAutoSave() const { return m_autoSave; }
inline bool isBackground() const { return m_background; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); }
inline const Http &http() const { return m_http; }
inline const Pools &pools() const { return m_pools; }
inline const String &apiId() const { return m_apiId; }
inline const String &apiWorkerId() const { return m_apiWorkerId; }
inline uint32_t printTime() const { return m_printTime; }
inline bool isRebenchAlgo() const { return m_rebenchAlgo; }
inline int benchAlgoTime() const { return m_benchAlgoTime; }
inline bool isRebenchAlgo() const { return m_rebenchAlgo; }
inline int benchAlgoTime() const { return m_benchAlgoTime; }
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const String &fileName() const override { return m_fileName; }
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
# ifdef XMRIG_FEATURE_TLS
inline const TlsConfig &tls() const { return m_tls; }
# endif
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const String &fileName() const override { return m_fileName; }
inline void setFileName(const char *fileName) override { m_fileName = fileName; }
bool read(const IJsonReader &reader, const char *fileName) override;
bool save() override;
@ -100,6 +113,10 @@ protected:
bool m_rebenchAlgo = false;
int m_benchAlgoTime = 10;
# ifdef XMRIG_FEATURE_TLS
TlsConfig m_tls;
# endif
private:
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }

View file

@ -44,6 +44,11 @@
#include "core/config/Config_platform.h"
#ifdef XMRIG_FEATURE_TLS
# include "base/net/tls/TlsConfig.h"
#endif
void xmrig::BaseTransform::load(JsonChain &chain, Process *process, IConfigTransform &transform)
{
using namespace rapidjson;
@ -199,6 +204,29 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::UserAgentKey: /* --user-agent */
return set(doc, BaseConfig::kUserAgent, arg);
# ifdef XMRIG_FEATURE_TLS
case IConfig::TlsCertKey: /* --tls-cert */
return set(doc, BaseConfig::kTls, TlsConfig::kCert, arg);
case IConfig::TlsCertKeyKey: /* --tls-cert-key */
return set(doc, BaseConfig::kTls, TlsConfig::kCertKey, arg);
case IConfig::TlsDHparamKey: /* --tls-dhparam */
return set(doc, BaseConfig::kTls, TlsConfig::kDhparam, arg);
case IConfig::TlsCiphersKey: /* --tls-ciphers */
return set(doc, BaseConfig::kTls, TlsConfig::kCiphers, arg);
case IConfig::TlsCipherSuitesKey: /* --tls-ciphersuites */
return set(doc, BaseConfig::kTls, TlsConfig::kCipherSuites, arg);
case IConfig::TlsProtocolsKey: /* --tls-protocols */
return set(doc, BaseConfig::kTls, TlsConfig::kProtocols, arg);
case IConfig::TlsGenKey: /* --tls-gen */
return set(doc, BaseConfig::kTls, TlsConfig::kGen, arg);
# endif
case IConfig::RetriesKey: /* --retries */
case IConfig::RetryPauseKey: /* --retry-pause */
case IConfig::PrintTimeKey: /* --print-time */

View file

@ -73,6 +73,7 @@ public:
DaemonKey = 1018,
DaemonPollKey = 1019,
SelfSelectKey = 1028,
DataDirKey = 1035,
// xmrig common
CPUPriorityKey = 1021,
@ -100,6 +101,7 @@ public:
MemoryPoolKey = 1027,
YieldKey = 1030,
AstroBWTMaxSizeKey = 1034,
AstroBWTAVX2Key = 1036,
// xmrig amd
OclPlatformKey = 1400,
@ -133,6 +135,7 @@ public:
TlsCiphersKey = 1112,
TlsCipherSuitesKey = 1113,
TlsProtocolsKey = 1114,
TlsGenKey = 1117,
AlgoExtKey = 1115,
ProxyPasswordKey = 1116,
LoginFileKey = 'L',

View file

@ -5,8 +5,8 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 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
@ -26,15 +26,12 @@
#define XMRIG_ILINELISTENER_H
#include <stdint.h>
#include <cstdint>
namespace xmrig {
class String;
class ILineListener
{
public: