mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-05 16:07:42 +00:00
* [WIP] More unification in Pools class.
This commit is contained in:
parent
f6699b5929
commit
ee4f6e28f0
10 changed files with 118 additions and 66 deletions
|
@ -24,10 +24,18 @@
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/Pools.h"
|
#include "base/net/Pools.h"
|
||||||
|
#include "common/log/Log.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
xmrig::Pools::Pools()
|
xmrig::Pools::Pools() :
|
||||||
|
m_retries(5),
|
||||||
|
m_retryPause(5)
|
||||||
{
|
{
|
||||||
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
|
m_retries = 2;
|
||||||
|
m_retryPause = 1;
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +68,21 @@ bool xmrig::Pools::setUrl(const char *url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::Pools::toJSON(rapidjson::Document &doc) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value pools(kArrayType);
|
||||||
|
|
||||||
|
for (const Pool &pool : m_data) {
|
||||||
|
pools.PushBack(pool.toJSON(doc), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pools;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t xmrig::Pools::active() const
|
size_t xmrig::Pools::active() const
|
||||||
{
|
{
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
@ -79,3 +102,56 @@ void xmrig::Pools::adjust(const Algorithm &algorithm)
|
||||||
pool.adjust(algorithm);
|
pool.adjust(algorithm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pools::print()
|
||||||
|
{
|
||||||
|
size_t i = 1;
|
||||||
|
for (const Pool &pool : m_data) {
|
||||||
|
if (Log::colors) {
|
||||||
|
const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31;
|
||||||
|
|
||||||
|
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"),
|
||||||
|
i,
|
||||||
|
color,
|
||||||
|
pool.url(),
|
||||||
|
pool.algorithm().shortName()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log::i()->text(" * POOL #%-7zu%s%s algo=%s %s",
|
||||||
|
i,
|
||||||
|
pool.isEnabled() ? "" : "-",
|
||||||
|
pool.url(),
|
||||||
|
pool.algorithm().shortName(),
|
||||||
|
pool.isTLS() ? "TLS" : ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef APP_DEBUG
|
||||||
|
LOG_NOTICE("POOLS --------------------------------------------------------------------");
|
||||||
|
for (const Pool &pool : m_data) {
|
||||||
|
pool.print();
|
||||||
|
}
|
||||||
|
LOG_NOTICE("--------------------------------------------------------------------------");
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pools::setRetries(int retries)
|
||||||
|
{
|
||||||
|
if (retries > 0 && retries <= 1000) {
|
||||||
|
m_retries = retries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pools::setRetryPause(int retryPause)
|
||||||
|
{
|
||||||
|
if (retryPause > 0 && retryPause <= 3600) {
|
||||||
|
m_retryPause = retryPause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,8 @@ public:
|
||||||
|
|
||||||
inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); }
|
inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); }
|
||||||
inline const std::vector<Pool> &data() const { return m_data; }
|
inline const std::vector<Pool> &data() const { return m_data; }
|
||||||
|
inline int retries() const { return m_retries; }
|
||||||
|
inline int retryPause() const { return m_retryPause; }
|
||||||
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
|
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
|
||||||
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); }
|
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); }
|
||||||
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
|
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
|
||||||
|
@ -54,12 +56,18 @@ public:
|
||||||
inline void setVariant(int variant) { current().algorithm().parseVariant(variant); }
|
inline void setVariant(int variant) { current().algorithm().parseVariant(variant); }
|
||||||
|
|
||||||
bool setUrl(const char *url);
|
bool setUrl(const char *url);
|
||||||
|
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||||
size_t active() const;
|
size_t active() const;
|
||||||
void adjust(const Algorithm &algorithm);
|
void adjust(const Algorithm &algorithm);
|
||||||
|
void print();
|
||||||
|
void setRetries(int retries);
|
||||||
|
void setRetryPause(int retryPause);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pool ¤t();
|
Pool ¤t();
|
||||||
|
|
||||||
|
int m_retries;
|
||||||
|
int m_retryPause;
|
||||||
std::vector<Pool> m_data;
|
std::vector<Pool> m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,21 +71,20 @@ xmrig::CommonConfig::CommonConfig() :
|
||||||
m_apiRestricted(true),
|
m_apiRestricted(true),
|
||||||
m_autoSave(true),
|
m_autoSave(true),
|
||||||
m_background(false),
|
m_background(false),
|
||||||
m_colors(true),
|
|
||||||
m_dryRun(false),
|
m_dryRun(false),
|
||||||
m_syslog(false),
|
m_syslog(false),
|
||||||
m_watch(true),
|
m_watch(true),
|
||||||
m_apiPort(0),
|
m_apiPort(0),
|
||||||
m_donateLevel(kDefaultDonateLevel),
|
m_donateLevel(kDefaultDonateLevel),
|
||||||
m_printTime(60),
|
m_printTime(60),
|
||||||
m_retries(5),
|
|
||||||
m_retryPause(5),
|
|
||||||
m_state(NoneState)
|
m_state(NoneState)
|
||||||
{
|
{
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
}
|
||||||
m_retries = 2;
|
|
||||||
m_retryPause = 1;
|
|
||||||
# endif
|
bool xmrig::CommonConfig::isColors() const
|
||||||
|
{
|
||||||
|
return Log::colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,32 +104,7 @@ void xmrig::CommonConfig::printAPI()
|
||||||
|
|
||||||
void xmrig::CommonConfig::printPools()
|
void xmrig::CommonConfig::printPools()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_pools.data().size(); ++i) {
|
m_pools.print();
|
||||||
if (!isColors()) {
|
|
||||||
Log::i()->text(" * POOL #%-7zu%s algo=%s, TLS=%d",
|
|
||||||
i + 1,
|
|
||||||
m_pools.data()[i].url(),
|
|
||||||
m_pools.data()[i].algorithm().shortName(),
|
|
||||||
static_cast<int>(m_pools.data()[i].isTLS())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"),
|
|
||||||
i + 1,
|
|
||||||
m_pools.data()[i].isTLS() ? 32 : 36,
|
|
||||||
m_pools.data()[i].url(),
|
|
||||||
m_pools.data()[i].algorithm().shortName()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef APP_DEBUG
|
|
||||||
LOG_NOTICE("POOLS --------------------------------------------------------------------");
|
|
||||||
for (const Pool &pool : m_activePools) {
|
|
||||||
pool.print();
|
|
||||||
}
|
|
||||||
LOG_NOTICE("--------------------------------------------------------------------------");
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,7 +235,7 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
case ColorKey: /* --no-color */
|
case ColorKey: /* --no-color */
|
||||||
m_colors = enable;
|
Log::colors = enable;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WatchKey: /* watch */
|
case WatchKey: /* watch */
|
||||||
|
@ -404,15 +378,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
|
||||||
{
|
{
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case RetriesKey: /* --retries */
|
case RetriesKey: /* --retries */
|
||||||
if (arg > 0 && arg <= 1000) {
|
m_pools.setRetries(arg);
|
||||||
m_retries = arg;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RetryPauseKey: /* --retry-pause */
|
case RetryPauseKey: /* --retry-pause */
|
||||||
if (arg > 0 && arg <= 3600) {
|
m_pools.setRetryPause(arg);
|
||||||
m_retryPause = arg;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeepAliveKey: /* --keepalive */
|
case KeepAliveKey: /* --keepalive */
|
||||||
|
|
|
@ -44,7 +44,6 @@ public:
|
||||||
inline bool isApiRestricted() const { return m_apiRestricted; }
|
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||||
inline bool isAutoSave() const { return m_autoSave; }
|
inline bool isAutoSave() const { return m_autoSave; }
|
||||||
inline bool isBackground() const { return m_background; }
|
inline bool isBackground() const { return m_background; }
|
||||||
inline bool isColors() const { return m_colors; }
|
|
||||||
inline bool isDryRun() const { return m_dryRun; }
|
inline bool isDryRun() const { return m_dryRun; }
|
||||||
inline bool isSyslog() const { return m_syslog; }
|
inline bool isSyslog() const { return m_syslog; }
|
||||||
inline const char *apiId() const { return m_apiId.data(); }
|
inline const char *apiId() const { return m_apiId.data(); }
|
||||||
|
@ -56,9 +55,8 @@ public:
|
||||||
inline int apiPort() const { return m_apiPort; }
|
inline int apiPort() const { return m_apiPort; }
|
||||||
inline int donateLevel() const { return m_donateLevel; }
|
inline int donateLevel() const { return m_donateLevel; }
|
||||||
inline int printTime() const { return m_printTime; }
|
inline int printTime() const { return m_printTime; }
|
||||||
inline int retries() const { return m_retries; }
|
inline int retries() const { return m_pools.retries(); }
|
||||||
inline int retryPause() const { return m_retryPause; }
|
inline int retryPause() const { return m_pools.retryPause(); }
|
||||||
inline void setColors(bool colors) { m_colors = colors; }
|
|
||||||
|
|
||||||
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
||||||
inline const Algorithm &algorithm() const override { return m_algorithm; }
|
inline const Algorithm &algorithm() const override { return m_algorithm; }
|
||||||
|
@ -66,6 +64,7 @@ public:
|
||||||
|
|
||||||
bool save() override;
|
bool save() override;
|
||||||
|
|
||||||
|
bool isColors() const;
|
||||||
void printAPI();
|
void printAPI();
|
||||||
void printPools();
|
void printPools();
|
||||||
void printVersions();
|
void printVersions();
|
||||||
|
@ -90,15 +89,12 @@ protected:
|
||||||
bool m_apiRestricted;
|
bool m_apiRestricted;
|
||||||
bool m_autoSave;
|
bool m_autoSave;
|
||||||
bool m_background;
|
bool m_background;
|
||||||
bool m_colors;
|
|
||||||
bool m_dryRun;
|
bool m_dryRun;
|
||||||
bool m_syslog;
|
bool m_syslog;
|
||||||
bool m_watch;
|
bool m_watch;
|
||||||
int m_apiPort;
|
int m_apiPort;
|
||||||
int m_donateLevel;
|
int m_donateLevel;
|
||||||
int m_printTime;
|
int m_printTime;
|
||||||
int m_retries;
|
|
||||||
int m_retryPause;
|
|
||||||
Pools m_pools;
|
Pools m_pools;
|
||||||
State m_state;
|
State m_state;
|
||||||
String m_apiId;
|
String m_apiId;
|
||||||
|
|
|
@ -29,14 +29,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
class Job;
|
|
||||||
class SubmitResult;
|
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class Job;
|
||||||
|
class SubmitResult;
|
||||||
|
|
||||||
|
|
||||||
class IClientListener
|
class IClientListener
|
||||||
|
|
|
@ -45,7 +45,7 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) :
|
||||||
m_controller(controller)
|
m_controller(controller)
|
||||||
{
|
{
|
||||||
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
|
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
|
||||||
controller->config()->setColors(false);
|
Log::colors = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* 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>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -35,9 +36,10 @@
|
||||||
|
|
||||||
|
|
||||||
Log *Log::m_self = nullptr;
|
Log *Log::m_self = nullptr;
|
||||||
|
bool Log::colors = true;
|
||||||
|
|
||||||
|
|
||||||
static const char *colors[5] = {
|
static const char *color[5] = {
|
||||||
"\x1B[0;31m", /* ERR */
|
"\x1B[0;31m", /* ERR */
|
||||||
"\x1B[0;33m", /* WARNING */
|
"\x1B[0;33m", /* WARNING */
|
||||||
"\x1B[1;37m", /* NOTICE */
|
"\x1B[1;37m", /* NOTICE */
|
||||||
|
@ -96,7 +98,7 @@ const char *Log::colorByLevel(ILogBackend::Level level, bool isColors)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return colors[level];
|
return color[level];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* 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>
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -48,6 +49,8 @@ public:
|
||||||
static const char *endl(bool isColors = true);
|
static const char *endl(bool isColors = true);
|
||||||
static void defaultInit();
|
static void defaultInit();
|
||||||
|
|
||||||
|
static bool colors;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline Log() {
|
inline Log() {
|
||||||
assert(m_self == nullptr);
|
assert(m_self == nullptr);
|
||||||
|
|
|
@ -32,7 +32,10 @@
|
||||||
#include "common/net/Client.h"
|
#include "common/net/Client.h"
|
||||||
|
|
||||||
|
|
||||||
class xmrig::Client::Tls
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class Client::Tls
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tls(Client *client);
|
Tls(Client *client);
|
||||||
|
@ -60,4 +63,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
#endif /* XMRIG_CLIENT_TLS_H */
|
#endif /* XMRIG_CLIENT_TLS_H */
|
||||||
|
|
|
@ -103,14 +103,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
||||||
doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator);
|
doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator);
|
||||||
doc.AddMember("log-file", logFile() ? Value(StringRef(logFile())).Move() : Value(kNullType).Move(), allocator);
|
doc.AddMember("log-file", logFile() ? Value(StringRef(logFile())).Move() : Value(kNullType).Move(), allocator);
|
||||||
doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator);
|
doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator);
|
||||||
|
doc.AddMember("pools", m_pools.toJSON(doc), allocator);
|
||||||
Value pools(kArrayType);
|
|
||||||
|
|
||||||
for (const Pool &pool : m_pools.data()) {
|
|
||||||
pools.PushBack(pool.toJSON(doc), allocator);
|
|
||||||
}
|
|
||||||
|
|
||||||
doc.AddMember("pools", pools, allocator);
|
|
||||||
doc.AddMember("print-time", printTime(), allocator);
|
doc.AddMember("print-time", printTime(), allocator);
|
||||||
doc.AddMember("retries", retries(), allocator);
|
doc.AddMember("retries", retries(), allocator);
|
||||||
doc.AddMember("retry-pause", retryPause(), allocator);
|
doc.AddMember("retry-pause", retryPause(), allocator);
|
||||||
|
|
Loading…
Reference in a new issue