This commit is contained in:
commit
eb58aea9c7
48 changed files with 970 additions and 454 deletions
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
if (Log::background && m_backends.empty()) {
|
||||
if (Log::isBackground() && m_backends.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -195,9 +195,10 @@ private:
|
|||
};
|
||||
|
||||
|
||||
bool Log::background = false;
|
||||
bool Log::colors = true;
|
||||
LogPrivate *Log::d = new LogPrivate();
|
||||
bool Log::m_background = false;
|
||||
bool Log::m_colors = true;
|
||||
LogPrivate *Log::d = new LogPrivate();
|
||||
uint32_t Log::m_verbose = 0;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#define XMRIG_LOG_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
@ -54,10 +57,19 @@ public:
|
|||
static void print(const char *fmt, ...);
|
||||
static void print(Level level, const char *fmt, ...);
|
||||
|
||||
static bool background;
|
||||
static bool colors;
|
||||
static inline bool isBackground() { return m_background; }
|
||||
static inline bool isColors() { return m_colors; }
|
||||
static inline bool isVerbose() { return m_verbose > 0; }
|
||||
static inline uint32_t verbose() { return m_verbose; }
|
||||
static inline void setBackground(bool background) { m_background = background; }
|
||||
static inline void setColors(bool colors) { m_colors = colors; }
|
||||
static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; }
|
||||
|
||||
private:
|
||||
static bool m_background;
|
||||
static bool m_colors;
|
||||
static uint32_t m_verbose;
|
||||
|
||||
static LogPrivate *d;
|
||||
};
|
||||
|
||||
|
@ -119,13 +131,14 @@ private:
|
|||
#define CYAN_BG_BOLD(x) CYAN_BG_BOLD_S x CLEAR
|
||||
|
||||
|
||||
#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__)
|
||||
#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__)
|
||||
#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__)
|
||||
#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__)
|
||||
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
|
||||
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
|
||||
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
|
||||
#define LOG_EMERG(x, ...) xmrig::Log::print(xmrig::Log::EMERG, x, ##__VA_ARGS__)
|
||||
#define LOG_ALERT(x, ...) xmrig::Log::print(xmrig::Log::ALERT, x, ##__VA_ARGS__)
|
||||
#define LOG_CRIT(x, ...) xmrig::Log::print(xmrig::Log::CRIT, x, ##__VA_ARGS__)
|
||||
#define LOG_ERR(x, ...) xmrig::Log::print(xmrig::Log::ERR, x, ##__VA_ARGS__)
|
||||
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
|
||||
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
|
||||
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
|
||||
#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)
|
||||
|
|
|
@ -35,14 +35,14 @@
|
|||
xmrig::ConsoleLog::ConsoleLog()
|
||||
{
|
||||
if (!isSupported()) {
|
||||
Log::colors = false;
|
||||
Log::setColors(false);
|
||||
return;
|
||||
}
|
||||
|
||||
m_tty = new uv_tty_t;
|
||||
|
||||
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
|
||||
Log::colors = false;
|
||||
Log::setColors(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ xmrig::ConsoleLog::~ConsoleLog()
|
|||
|
||||
void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors)
|
||||
{
|
||||
if (!m_tty || Log::colors != colors) {
|
||||
if (!m_tty || Log::isColors() != colors) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ int xmrig::Base::init()
|
|||
Platform::init(config()->userAgent());
|
||||
|
||||
if (isBackground()) {
|
||||
Log::background = true;
|
||||
Log::setBackground(true);
|
||||
}
|
||||
else {
|
||||
Log::add(new ConsoleLog());
|
||||
|
|
|
@ -23,10 +23,18 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "base/kernel/config/BaseConfig.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/interfaces/IJsonReader.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
@ -38,80 +46,6 @@
|
|||
# include "backend/cpu/Cpu.h"
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_AMD_PROJECT
|
||||
# if defined(__APPLE__)
|
||||
# include <OpenCL/cl.h>
|
||||
# else
|
||||
# include "3rdparty/CL/cl.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_NVIDIA_PROJECT
|
||||
# include "nvidia/cryptonight.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/config/BaseConfig.h"
|
||||
#include "base/kernel/interfaces/IJsonReader.h"
|
||||
#include "donate.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
void xmrig::BaseConfig::printVersions()
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
# if defined(__clang__)
|
||||
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf);
|
||||
|
||||
# if defined(XMRIG_AMD_PROJECT)
|
||||
# if CL_VERSION_2_0
|
||||
const char *ocl = "2.0";
|
||||
# elif CL_VERSION_1_2
|
||||
const char *ocl = "1.2";
|
||||
# elif CL_VERSION_1_1
|
||||
const char *ocl = "1.1";
|
||||
# elif CL_VERSION_1_0
|
||||
const char *ocl = "1.0";
|
||||
# else
|
||||
const char *ocl = "0.0";
|
||||
# endif
|
||||
int length = snprintf(buf, sizeof buf, "OpenCL/%s ", ocl);
|
||||
# elif defined(XMRIG_NVIDIA_PROJECT)
|
||||
const int cudaVersion = cuda_get_runtime_version();
|
||||
int length = snprintf(buf, sizeof buf, "CUDA/%d.%d ", cudaVersion / 1000, cudaVersion % 100);
|
||||
# endif
|
||||
|
||||
std::string libs;
|
||||
|
||||
# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT)
|
||||
{
|
||||
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
|
||||
snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
libs += buf;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(XMRIG_FEATURE_HWLOC)
|
||||
libs += Cpu::info()->backend();
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
|
||||
{
|
||||
|
@ -126,15 +60,16 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
|
|||
m_dryRun = reader.getBool("dry-run", m_dryRun);
|
||||
m_syslog = reader.getBool("syslog", m_syslog);
|
||||
m_watch = reader.getBool("watch", m_watch);
|
||||
Log::colors = reader.getBool("colors", Log::colors);
|
||||
m_logFile = reader.getString("log-file");
|
||||
m_userAgent = reader.getString("user-agent");
|
||||
m_version = reader.getUint("version");
|
||||
|
||||
m_rebenchAlgo = reader.getBool("rebench-algo", m_rebenchAlgo);
|
||||
m_benchAlgoTime = reader.getInt("bench-algo-time", m_benchAlgoTime);
|
||||
Log::setColors(reader.getBool("colors", Log::isColors()));
|
||||
|
||||
setPrintTime(reader.getUint("print-time", 60));
|
||||
setVerbose(reader.getValue("verbose"));
|
||||
|
||||
const rapidjson::Value &api = reader.getObject("api");
|
||||
if (api.IsObject()) {
|
||||
|
@ -165,3 +100,46 @@ bool xmrig::BaseConfig::save()
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BaseConfig::printVersions()
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
# if defined(__clang__)
|
||||
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf);
|
||||
|
||||
std::string libs;
|
||||
|
||||
# if defined(XMRIG_FEATURE_TLS) && defined(OPENSSL_VERSION_TEXT)
|
||||
{
|
||||
constexpr const char *v = OPENSSL_VERSION_TEXT + 8;
|
||||
snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
libs += buf;
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(XMRIG_FEATURE_HWLOC)
|
||||
libs += Cpu::info()->backend();
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BaseConfig::setVerbose(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsBool()) {
|
||||
Log::setVerbose(value.GetBool() ? 1 : 0);
|
||||
}
|
||||
else if (value.IsUint()) {
|
||||
Log::setVerbose(value.GetUint());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ protected:
|
|||
|
||||
private:
|
||||
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }
|
||||
|
||||
void setVerbose(const rapidjson::Value &value);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -224,6 +224,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
|
|||
case IConfig::HttpEnabledKey: /* --http-enabled */
|
||||
case IConfig::DaemonKey: /* --daemon */
|
||||
case IConfig::RebenchAlgoKey: /* --rebench-algo */
|
||||
case IConfig::VerboseKey: /* --verbose */
|
||||
return transformBoolean(doc, key, true);
|
||||
|
||||
case IConfig::ColorKey: /* --no-color */
|
||||
|
@ -278,6 +279,9 @@ void xmrig::BaseTransform::transformBoolean(rapidjson::Document &doc, int key, b
|
|||
case IConfig::RebenchAlgoKey: /* --rebench-algo */
|
||||
return set(doc, "rebench-algo", enable);
|
||||
|
||||
case IConfig::VerboseKey: /* --verbose */
|
||||
return set(doc, "verbose", enable);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,8 @@ static const char *states[] = {
|
|||
|
||||
xmrig::Client::Client(int id, const char *agent, IClientListener *listener) :
|
||||
BaseClient(id, listener),
|
||||
m_agent(agent)
|
||||
m_agent(agent),
|
||||
m_sendBuf(1024)
|
||||
{
|
||||
m_key = m_storage.add(this);
|
||||
m_dns = new Dns(this);
|
||||
|
@ -158,13 +159,18 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj)
|
|||
obj.Accept(writer);
|
||||
|
||||
const size_t size = buffer.GetSize();
|
||||
if (size > (sizeof(m_sendBuf) - 2)) {
|
||||
LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2));
|
||||
if (size > kMaxSendBufferSize) {
|
||||
LOG_ERR("[%s] send failed: \"max send buffer size exceeded: %zu\"", url(), size);
|
||||
close();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(m_sendBuf, buffer.GetString(), size);
|
||||
if (size > (m_sendBuf.size() - 2)) {
|
||||
m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024);
|
||||
}
|
||||
|
||||
memcpy(m_sendBuf.data(), buffer.GetString(), size);
|
||||
m_sendBuf[size] = '\n';
|
||||
m_sendBuf[size + 1] = '\0';
|
||||
|
||||
|
@ -186,8 +192,8 @@ int64_t xmrig::Client::submit(const JobResult &result)
|
|||
const char *nonce = result.nonce;
|
||||
const char *data = result.result;
|
||||
# else
|
||||
char *nonce = m_sendBuf;
|
||||
char *data = m_sendBuf + 16;
|
||||
char *nonce = m_sendBuf.data();
|
||||
char *data = m_sendBuf.data() + 16;
|
||||
|
||||
Buffer::toHex(reinterpret_cast<const char*>(&result.nonce), 4, nonce);
|
||||
nonce[8] = '\0';
|
||||
|
@ -460,11 +466,7 @@ bool xmrig::Client::send(BIO *bio)
|
|||
|
||||
bool result = false;
|
||||
if (state() == ConnectedState && uv_is_writable(m_stream)) {
|
||||
result = uv_try_write(m_stream, &buf, 1) > 0;
|
||||
|
||||
if (!result) {
|
||||
close();
|
||||
}
|
||||
result = write(buf);
|
||||
}
|
||||
else {
|
||||
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
|
||||
|
@ -505,6 +507,23 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo
|
|||
}
|
||||
|
||||
|
||||
bool xmrig::Client::write(const uv_buf_t &buf)
|
||||
{
|
||||
const int rc = uv_try_write(m_stream, &buf, 1);
|
||||
if (static_cast<size_t>(rc) == buf.len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isQuiet()) {
|
||||
LOG_ERR("[%s] write error: \"%s\"", url(), uv_strerror(rc));
|
||||
}
|
||||
|
||||
close();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Client::resolve(const String &host)
|
||||
{
|
||||
setState(HostLookupState);
|
||||
|
@ -529,11 +548,11 @@ int xmrig::Client::resolve(const String &host)
|
|||
|
||||
int64_t xmrig::Client::send(size_t size)
|
||||
{
|
||||
LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast<int>(size) - 1, m_sendBuf);
|
||||
LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast<int>(size) - 1, m_sendBuf.data());
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
if (isTLS()) {
|
||||
if (!m_tls->send(m_sendBuf, size)) {
|
||||
if (!m_tls->send(m_sendBuf.data(), size)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -545,10 +564,9 @@ int64_t xmrig::Client::send(size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size);
|
||||
uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size);
|
||||
|
||||
if (uv_try_write(m_stream, &buf, 1) < 0) {
|
||||
close();
|
||||
if (!write(buf)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -795,7 +813,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
|
|||
|
||||
void xmrig::Client::ping()
|
||||
{
|
||||
send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
|
||||
send(snprintf(m_sendBuf.data(), m_sendBuf.size(), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data()));
|
||||
|
||||
m_keepAlive = 0;
|
||||
}
|
||||
|
|
|
@ -60,14 +60,10 @@ class Client : public BaseClient, public IDnsListener, public ILineListener
|
|||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client)
|
||||
|
||||
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
constexpr static size_t kInputBufferSize = 1024 * 16;
|
||||
# else
|
||||
constexpr static size_t kInputBufferSize = 1024 * 2;
|
||||
# endif
|
||||
constexpr static uint64_t kConnectTimeout = 20 * 1000;
|
||||
constexpr static uint64_t kResponseTimeout = 20 * 1000;
|
||||
constexpr static size_t kInputBufferSize = 1024 * 16;
|
||||
constexpr static size_t kMaxSendBufferSize = 1024 * 16;
|
||||
|
||||
Client(int id, const char *agent, IClientListener *listener);
|
||||
~Client() override;
|
||||
|
@ -100,6 +96,7 @@ private:
|
|||
bool parseLogin(const rapidjson::Value &result, int *code);
|
||||
bool send(BIO *bio);
|
||||
bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const;
|
||||
bool write(const uv_buf_t &buf);
|
||||
int resolve(const String &host);
|
||||
int64_t send(size_t size);
|
||||
void connect(sockaddr *addr);
|
||||
|
@ -128,11 +125,11 @@ private:
|
|||
|
||||
static inline Client *getClient(void *data) { return m_storage.get(data); }
|
||||
|
||||
char m_sendBuf[4096] = { 0 };
|
||||
const char *m_agent;
|
||||
Dns *m_dns;
|
||||
RecvBuf<kInputBufferSize> m_recvBuf;
|
||||
std::bitset<EXT_MAX> m_extensions;
|
||||
std::vector<char> m_sendBuf;
|
||||
String m_rpcId;
|
||||
Tls *m_tls = nullptr;
|
||||
uint64_t m_expire = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue