mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 18:11:05 +00:00
Added "donate-over-proxy" option.
This commit is contained in:
parent
55686c7d57
commit
0907d1eb0c
15 changed files with 229 additions and 141 deletions
|
@ -114,8 +114,8 @@ static void print_threads(xmrig::Config *config)
|
||||||
config->threadsCount(),
|
config->threadsCount(),
|
||||||
config->algorithm().name(),
|
config->algorithm().name(),
|
||||||
config->algoVariant(),
|
config->algoVariant(),
|
||||||
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
|
config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "",
|
||||||
config->donateLevel(),
|
config->pools().donateLevel(),
|
||||||
buf);
|
buf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -124,8 +124,8 @@ static void print_threads(xmrig::Config *config)
|
||||||
"THREADS",
|
"THREADS",
|
||||||
config->threadsCount(),
|
config->threadsCount(),
|
||||||
config->algorithm().name(),
|
config->algorithm().name(),
|
||||||
config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
|
config->isColors() && config->pools().donateLevel() == 0 ? "\x1B[1;31m" : "",
|
||||||
config->donateLevel());
|
config->pools().donateLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifndef XMRIG_NO_ASM
|
# ifndef XMRIG_NO_ASM
|
||||||
|
|
|
@ -254,7 +254,7 @@ void ApiRouter::getMiner(rapidjson::Document &doc) const
|
||||||
doc.AddMember("cpu", cpu, allocator);
|
doc.AddMember("cpu", cpu, allocator);
|
||||||
doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator);
|
doc.AddMember("algo", rapidjson::StringRef(m_controller->config()->algorithm().name()), allocator);
|
||||||
doc.AddMember("hugepages", Workers::hugePages() > 0, allocator);
|
doc.AddMember("hugepages", Workers::hugePages() > 0, allocator);
|
||||||
doc.AddMember("donate_level", m_controller->config()->donateLevel(), allocator);
|
doc.AddMember("donate_level", m_controller->config()->pools().donateLevel(), allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -741,6 +741,11 @@ void xmrig::Client::parseExtensions(const rapidjson::Value &result)
|
||||||
else if (strcmp(name, "keepalive") == 0) {
|
else if (strcmp(name, "keepalive") == 0) {
|
||||||
setExtension(EXT_KEEPALIVE, true);
|
setExtension(EXT_KEEPALIVE, true);
|
||||||
}
|
}
|
||||||
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
|
else if (strcmp(name, "tls") == 0) {
|
||||||
|
setExtension(EXT_TLS, true);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
EXT_ALGO,
|
EXT_ALGO,
|
||||||
EXT_NICEHASH,
|
EXT_NICEHASH,
|
||||||
EXT_CONNECT,
|
EXT_CONNECT,
|
||||||
|
EXT_TLS,
|
||||||
EXT_KEEPALIVE,
|
EXT_KEEPALIVE,
|
||||||
EXT_MAX
|
EXT_MAX
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,12 +27,15 @@
|
||||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||||
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
#include "base/net/stratum/strategies/SinglePoolStrategy.h"
|
||||||
#include "common/log/Log.h"
|
#include "common/log/Log.h"
|
||||||
|
#include "donate.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
xmrig::Pools::Pools() :
|
xmrig::Pools::Pools() :
|
||||||
|
m_donateLevel(kDefaultDonateLevel),
|
||||||
m_retries(5),
|
m_retries(5),
|
||||||
m_retryPause(5)
|
m_retryPause(5),
|
||||||
|
m_proxyDonate(PROXY_DONATE_AUTO)
|
||||||
{
|
{
|
||||||
# ifdef XMRIG_PROXY_PROJECT
|
# ifdef XMRIG_PROXY_PROJECT
|
||||||
m_retries = 2;
|
m_retries = 2;
|
||||||
|
@ -191,6 +194,25 @@ void xmrig::Pools::print() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pools::setDonateLevel(int level)
|
||||||
|
{
|
||||||
|
if (level >= kMinimumDonateLevel && level <= 99) {
|
||||||
|
m_donateLevel = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Pools::setProxyDonate(int value)
|
||||||
|
{
|
||||||
|
switch (value) {
|
||||||
|
case PROXY_DONATE_NONE:
|
||||||
|
case PROXY_DONATE_AUTO:
|
||||||
|
case PROXY_DONATE_ALWAYS:
|
||||||
|
m_proxyDonate = static_cast<ProxyDonate>(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Pools::setRetries(int retries)
|
void xmrig::Pools::setRetries(int retries)
|
||||||
{
|
{
|
||||||
if (retries > 0 && retries <= 1000) {
|
if (retries > 0 && retries <= 1000) {
|
||||||
|
|
|
@ -42,12 +42,20 @@ class IStrategyListener;
|
||||||
class Pools
|
class Pools
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ProxyDonate {
|
||||||
|
PROXY_DONATE_NONE,
|
||||||
|
PROXY_DONATE_AUTO,
|
||||||
|
PROXY_DONATE_ALWAYS
|
||||||
|
};
|
||||||
|
|
||||||
Pools();
|
Pools();
|
||||||
|
|
||||||
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 donateLevel() const { return m_donateLevel; }
|
||||||
inline int retries() const { return m_retries; }
|
inline int retries() const { return m_retries; }
|
||||||
inline int retryPause() const { return m_retryPause; }
|
inline int retryPause() const { return m_retryPause; }
|
||||||
|
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
|
||||||
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
|
inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); }
|
||||||
inline void setKeepAlive(bool enable) { current().setKeepAlive(enable); }
|
inline void setKeepAlive(bool enable) { current().setKeepAlive(enable); }
|
||||||
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
|
inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); }
|
||||||
|
@ -70,14 +78,18 @@ public:
|
||||||
void adjust(const Algorithm &algorithm);
|
void adjust(const Algorithm &algorithm);
|
||||||
void load(const rapidjson::Value &pools);
|
void load(const rapidjson::Value &pools);
|
||||||
void print() const;
|
void print() const;
|
||||||
|
void setDonateLevel(int level);
|
||||||
|
void setProxyDonate(int value);
|
||||||
void setRetries(int retries);
|
void setRetries(int retries);
|
||||||
void setRetryPause(int retryPause);
|
void setRetryPause(int retryPause);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pool ¤t();
|
Pool ¤t();
|
||||||
|
|
||||||
|
int m_donateLevel;
|
||||||
int m_retries;
|
int m_retries;
|
||||||
int m_retryPause;
|
int m_retryPause;
|
||||||
|
ProxyDonate m_proxyDonate;
|
||||||
std::vector<Pool> m_data;
|
std::vector<Pool> m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@
|
||||||
#include "base/io/Json.h"
|
#include "base/io/Json.h"
|
||||||
#include "common/config/CommonConfig.h"
|
#include "common/config/CommonConfig.h"
|
||||||
#include "common/log/Log.h"
|
#include "common/log/Log.h"
|
||||||
#include "donate.h"
|
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/filewritestream.h"
|
#include "rapidjson/filewritestream.h"
|
||||||
#include "rapidjson/prettywriter.h"
|
#include "rapidjson/prettywriter.h"
|
||||||
|
@ -75,7 +74,6 @@ xmrig::CommonConfig::CommonConfig() :
|
||||||
m_syslog(false),
|
m_syslog(false),
|
||||||
m_watch(true),
|
m_watch(true),
|
||||||
m_apiPort(0),
|
m_apiPort(0),
|
||||||
m_donateLevel(kDefaultDonateLevel),
|
|
||||||
m_printTime(60),
|
m_printTime(60),
|
||||||
m_state(NoneState)
|
m_state(NoneState)
|
||||||
{
|
{
|
||||||
|
@ -397,9 +395,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DonateLevelKey: /* --donate-level */
|
case DonateLevelKey: /* --donate-level */
|
||||||
if (arg >= kMinimumDonateLevel && arg <= 99) {
|
m_pools.setDonateLevel(arg);
|
||||||
m_donateLevel = arg;
|
break;
|
||||||
}
|
|
||||||
|
case ProxyDonateKey: /* --donate-over-proxy */
|
||||||
|
m_pools.setProxyDonate(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ApiPort: /* --api-port */
|
case ApiPort: /* --api-port */
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
inline const char *userAgent() const { return m_userAgent.data(); }
|
inline const char *userAgent() const { return m_userAgent.data(); }
|
||||||
inline const Pools &pools() const { return m_pools; }
|
inline const Pools &pools() const { return m_pools; }
|
||||||
inline int apiPort() const { return m_apiPort; }
|
inline int apiPort() const { return m_apiPort; }
|
||||||
inline int donateLevel() const { return m_donateLevel; }
|
|
||||||
inline int printTime() const { return m_printTime; }
|
inline int printTime() const { return m_printTime; }
|
||||||
|
|
||||||
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
|
||||||
|
@ -91,7 +90,6 @@ protected:
|
||||||
bool m_syslog;
|
bool m_syslog;
|
||||||
bool m_watch;
|
bool m_watch;
|
||||||
int m_apiPort;
|
int m_apiPort;
|
||||||
int m_donateLevel;
|
|
||||||
int m_printTime;
|
int m_printTime;
|
||||||
Pools m_pools;
|
Pools m_pools;
|
||||||
State m_state;
|
State m_state;
|
||||||
|
|
|
@ -69,6 +69,7 @@ public:
|
||||||
TlsKey = 1013,
|
TlsKey = 1013,
|
||||||
FingerprintKey = 1014,
|
FingerprintKey = 1014,
|
||||||
AutoSaveKey = 1016,
|
AutoSaveKey = 1016,
|
||||||
|
ProxyDonateKey = 1017,
|
||||||
|
|
||||||
// xmrig common
|
// xmrig common
|
||||||
CPUPriorityKey = 1021,
|
CPUPriorityKey = 1021,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"cpu-affinity": null,
|
"cpu-affinity": null,
|
||||||
"cpu-priority": null,
|
"cpu-priority": null,
|
||||||
"donate-level": 5,
|
"donate-level": 5,
|
||||||
|
"donate-over-proxy": 1,
|
||||||
"huge-pages": true,
|
"huge-pages": true,
|
||||||
"hw-aes": null,
|
"hw-aes": null,
|
||||||
"log-file": null,
|
"log-file": null,
|
||||||
|
|
|
@ -98,10 +98,11 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator);
|
doc.AddMember("cpu-priority", priority() != -1 ? Value(priority()) : Value(kNullType), allocator);
|
||||||
doc.AddMember("donate-level", donateLevel(), allocator);
|
doc.AddMember("donate-level", m_pools.donateLevel(), allocator);
|
||||||
|
doc.AddMember("donate-over-proxy", m_pools.proxyDonate(), allocator);
|
||||||
doc.AddMember("huge-pages", isHugePages(), allocator);
|
doc.AddMember("huge-pages", isHugePages(), allocator);
|
||||||
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", m_logFile.toJSON(), 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);
|
doc.AddMember("pools", m_pools.toJSON(doc), allocator);
|
||||||
doc.AddMember("print-time", printTime(), allocator);
|
doc.AddMember("print-time", printTime(), allocator);
|
||||||
|
|
|
@ -44,81 +44,83 @@ static char const short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S";
|
||||||
|
|
||||||
|
|
||||||
static struct option const options[] = {
|
static struct option const options[] = {
|
||||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
{ "algo", 1, nullptr, IConfig::AlgorithmKey },
|
||||||
{ "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
{ "api-access-token", 1, nullptr, IConfig::ApiAccessTokenKey },
|
||||||
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
|
{ "api-port", 1, nullptr, IConfig::ApiPort },
|
||||||
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
{ "api-worker-id", 1, nullptr, IConfig::ApiWorkerIdKey },
|
||||||
{ "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey },
|
{ "api-id", 1, nullptr, IConfig::ApiIdKey },
|
||||||
{ "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
{ "api-ipv6", 0, nullptr, IConfig::ApiIPv6Key },
|
||||||
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
{ "api-no-restricted", 0, nullptr, IConfig::ApiRestrictedKey },
|
||||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
{ "av", 1, nullptr, IConfig::AVKey },
|
||||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
{ "background", 0, nullptr, IConfig::BackgroundKey },
|
||||||
{ "config", 1, nullptr, xmrig::IConfig::ConfigKey },
|
{ "config", 1, nullptr, IConfig::ConfigKey },
|
||||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
{ "cpu-affinity", 1, nullptr, IConfig::CPUAffinityKey },
|
||||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
{ "cpu-priority", 1, nullptr, IConfig::CPUPriorityKey },
|
||||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
{ "donate-level", 1, nullptr, IConfig::DonateLevelKey },
|
||||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
{ "donate-over-proxy", 1, nullptr, IConfig::ProxyDonateKey },
|
||||||
{ "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey },
|
{ "dry-run", 0, nullptr, IConfig::DryRunKey },
|
||||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
{ "keepalive", 0, nullptr, IConfig::KeepAliveKey },
|
||||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
{ "log-file", 1, nullptr, IConfig::LogFileKey },
|
||||||
{ "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey },
|
{ "max-cpu-usage", 1, nullptr, IConfig::MaxCPUUsageKey },
|
||||||
{ "no-color", 0, nullptr, xmrig::IConfig::ColorKey },
|
{ "nicehash", 0, nullptr, IConfig::NicehashKey },
|
||||||
{ "no-watch", 0, nullptr, xmrig::IConfig::WatchKey },
|
{ "no-color", 0, nullptr, IConfig::ColorKey },
|
||||||
{ "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
{ "no-watch", 0, nullptr, IConfig::WatchKey },
|
||||||
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey },
|
{ "no-huge-pages", 0, nullptr, IConfig::HugePagesKey },
|
||||||
{ "pass", 1, nullptr, xmrig::IConfig::PasswordKey },
|
{ "variant", 1, nullptr, IConfig::VariantKey },
|
||||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
{ "pass", 1, nullptr, IConfig::PasswordKey },
|
||||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
{ "print-time", 1, nullptr, IConfig::PrintTimeKey },
|
||||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
{ "retries", 1, nullptr, IConfig::RetriesKey },
|
||||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
{ "retry-pause", 1, nullptr, IConfig::RetryPauseKey },
|
||||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
{ "safe", 0, nullptr, IConfig::SafeKey },
|
||||||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
{ "syslog", 0, nullptr, IConfig::SyslogKey },
|
||||||
{ "url", 1, nullptr, xmrig::IConfig::UrlKey },
|
{ "threads", 1, nullptr, IConfig::ThreadsKey },
|
||||||
{ "user", 1, nullptr, xmrig::IConfig::UserKey },
|
{ "url", 1, nullptr, IConfig::UrlKey },
|
||||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
{ "user", 1, nullptr, IConfig::UserKey },
|
||||||
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
|
{ "user-agent", 1, nullptr, IConfig::UserAgentKey },
|
||||||
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
|
{ "userpass", 1, nullptr, IConfig::UserpassKey },
|
||||||
{ "tls", 0, nullptr, xmrig::IConfig::TlsKey },
|
{ "rig-id", 1, nullptr, IConfig::RigIdKey },
|
||||||
{ "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey },
|
{ "tls", 0, nullptr, IConfig::TlsKey },
|
||||||
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
|
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },
|
||||||
|
{ "asm", 1, nullptr, IConfig::AssemblyKey },
|
||||||
{ nullptr, 0, nullptr, 0 }
|
{ nullptr, 0, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct option const config_options[] = {
|
static struct option const config_options[] = {
|
||||||
{ "algo", 1, nullptr, xmrig::IConfig::AlgorithmKey },
|
{ "algo", 1, nullptr, IConfig::AlgorithmKey },
|
||||||
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
|
{ "av", 1, nullptr, IConfig::AVKey },
|
||||||
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },
|
{ "background", 0, nullptr, IConfig::BackgroundKey },
|
||||||
{ "colors", 0, nullptr, xmrig::IConfig::ColorKey },
|
{ "colors", 0, nullptr, IConfig::ColorKey },
|
||||||
{ "cpu-affinity", 1, nullptr, xmrig::IConfig::CPUAffinityKey },
|
{ "cpu-affinity", 1, nullptr, IConfig::CPUAffinityKey },
|
||||||
{ "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey },
|
{ "cpu-priority", 1, nullptr, IConfig::CPUPriorityKey },
|
||||||
{ "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey },
|
{ "donate-level", 1, nullptr, IConfig::DonateLevelKey },
|
||||||
{ "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey },
|
{ "donate-over-proxy", 1, nullptr, IConfig::ProxyDonateKey },
|
||||||
{ "huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey },
|
{ "dry-run", 0, nullptr, IConfig::DryRunKey },
|
||||||
{ "log-file", 1, nullptr, xmrig::IConfig::LogFileKey },
|
{ "huge-pages", 0, nullptr, IConfig::HugePagesKey },
|
||||||
{ "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey },
|
{ "log-file", 1, nullptr, IConfig::LogFileKey },
|
||||||
{ "print-time", 1, nullptr, xmrig::IConfig::PrintTimeKey },
|
{ "max-cpu-usage", 1, nullptr, IConfig::MaxCPUUsageKey },
|
||||||
{ "retries", 1, nullptr, xmrig::IConfig::RetriesKey },
|
{ "print-time", 1, nullptr, IConfig::PrintTimeKey },
|
||||||
{ "retry-pause", 1, nullptr, xmrig::IConfig::RetryPauseKey },
|
{ "retries", 1, nullptr, IConfig::RetriesKey },
|
||||||
{ "safe", 0, nullptr, xmrig::IConfig::SafeKey },
|
{ "retry-pause", 1, nullptr, IConfig::RetryPauseKey },
|
||||||
{ "syslog", 0, nullptr, xmrig::IConfig::SyslogKey },
|
{ "safe", 0, nullptr, IConfig::SafeKey },
|
||||||
{ "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
|
{ "syslog", 0, nullptr, IConfig::SyslogKey },
|
||||||
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
|
{ "threads", 1, nullptr, IConfig::ThreadsKey },
|
||||||
{ "watch", 0, nullptr, xmrig::IConfig::WatchKey },
|
{ "user-agent", 1, nullptr, IConfig::UserAgentKey },
|
||||||
{ "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey },
|
{ "watch", 0, nullptr, IConfig::WatchKey },
|
||||||
{ "asm", 1, nullptr, xmrig::IConfig::AssemblyKey },
|
{ "hw-aes", 0, nullptr, IConfig::HardwareAESKey },
|
||||||
{ "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey },
|
{ "asm", 1, nullptr, IConfig::AssemblyKey },
|
||||||
|
{ "autosave", 0, nullptr, IConfig::AutoSaveKey },
|
||||||
{ nullptr, 0, nullptr, 0 }
|
{ nullptr, 0, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct option const api_options[] = {
|
static struct option const api_options[] = {
|
||||||
{ "port", 1, nullptr, xmrig::IConfig::ApiPort },
|
{ "port", 1, nullptr, IConfig::ApiPort },
|
||||||
{ "access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
|
{ "access-token", 1, nullptr, IConfig::ApiAccessTokenKey },
|
||||||
{ "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
|
{ "worker-id", 1, nullptr, IConfig::ApiWorkerIdKey },
|
||||||
{ "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
|
{ "ipv6", 0, nullptr, IConfig::ApiIPv6Key },
|
||||||
{ "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
|
{ "restricted", 0, nullptr, IConfig::ApiRestrictedKey },
|
||||||
{ "id", 1, nullptr, xmrig::IConfig::ApiIdKey },
|
{ "id", 1, nullptr, IConfig::ApiIdKey },
|
||||||
{ nullptr, 0, nullptr, 0 }
|
{ nullptr, 0, nullptr, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,8 @@ xmrig::Network::Network(Controller *controller) :
|
||||||
const Pools &pools = controller->config()->pools();
|
const Pools &pools = controller->config()->pools();
|
||||||
m_strategy = pools.createStrategy(this);
|
m_strategy = pools.createStrategy(this);
|
||||||
|
|
||||||
if (controller->config()->donateLevel() > 0) {
|
if (pools.donateLevel() > 0) {
|
||||||
m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this);
|
m_donate = new DonateStrategy(controller, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_timer = new Timer(this, kTickInterval, kTickInterval);
|
m_timer = new Timer(this, kTickInterval, kTickInterval);
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/stratum/Client.h"
|
#include "base/net/stratum/Client.h"
|
||||||
#include "base/net/stratum/Job.h"
|
#include "base/net/stratum/Job.h"
|
||||||
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
#include "base/net/stratum/strategies/FailoverStrategy.h"
|
||||||
|
@ -32,6 +35,9 @@
|
||||||
#include "common/crypto/keccak.h"
|
#include "common/crypto/keccak.h"
|
||||||
#include "common/Platform.h"
|
#include "common/Platform.h"
|
||||||
#include "common/xmrig.h"
|
#include "common/xmrig.h"
|
||||||
|
#include "core/Config.h"
|
||||||
|
#include "core/Controller.h"
|
||||||
|
#include "net/Network.h"
|
||||||
#include "net/strategies/DonateStrategy.h"
|
#include "net/strategies/DonateStrategy.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,32 +46,39 @@ namespace xmrig {
|
||||||
static inline double randomf(double min, double max) { return (max - min) * (((static_cast<double>(rand())) / static_cast<double>(RAND_MAX))) + min; }
|
static inline double randomf(double min, double max) { return (max - min) * (((static_cast<double>(rand())) / static_cast<double>(RAND_MAX))) + min; }
|
||||||
static inline uint64_t random(uint64_t base, double min, double max) { return static_cast<uint64_t>(base * randomf(min, max)); }
|
static inline uint64_t random(uint64_t base, double min, double max) { return static_cast<uint64_t>(base * randomf(min, max)); }
|
||||||
|
|
||||||
|
static const char *kDonateHost = "donate.v2.xmrig.com";
|
||||||
|
#ifdef XMRIG_FEATURE_TLS
|
||||||
|
static const char *kDonateHostTls = "donate.ssl.xmrig.com";
|
||||||
|
#endif
|
||||||
|
|
||||||
} /* namespace xmrig */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener) :
|
xmrig::DonateStrategy::DonateStrategy(Controller *controller, IStrategyListener *listener) :
|
||||||
m_active(false),
|
m_proxy(nullptr),
|
||||||
m_donateTime(static_cast<uint64_t>(level) * 60 * 1000),
|
m_donateTime(static_cast<uint64_t>(controller->config()->pools().donateLevel()) * 60 * 1000),
|
||||||
m_idleTime((100 - static_cast<uint64_t>(level)) * 60 * 1000),
|
m_idleTime((100 - static_cast<uint64_t>(controller->config()->pools().donateLevel())) * 60 * 1000),
|
||||||
|
m_controller(controller),
|
||||||
m_strategy(nullptr),
|
m_strategy(nullptr),
|
||||||
m_listener(listener),
|
m_listener(listener),
|
||||||
|
m_state(STATE_NEW),
|
||||||
m_now(0),
|
m_now(0),
|
||||||
m_stop(0)
|
m_stop(0)
|
||||||
{
|
{
|
||||||
uint8_t hash[200];
|
uint8_t hash[200];
|
||||||
char userId[65] = { 0 };
|
char userId[65] = { 0 };
|
||||||
|
|
||||||
keccak(reinterpret_cast<const uint8_t *>(user), strlen(user), hash);
|
const String &user = controller->config()->pools().data().front().user();
|
||||||
|
keccak(reinterpret_cast<const uint8_t *>(user.data()), user.size(), hash);
|
||||||
Buffer::toHex(hash, 32, userId);
|
Buffer::toHex(hash, 32, userId);
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_TLS
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
m_pools.push_back(Pool("donate.ssl.xmrig.com", 443, userId, nullptr, false, true, true));
|
m_pools.push_back(Pool(kDonateHostTls, 443, userId, nullptr, false, true, true));
|
||||||
# endif
|
# endif
|
||||||
|
m_pools.push_back(Pool(kDonateHost, 3333, userId, nullptr, false, true));
|
||||||
m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true));
|
|
||||||
|
|
||||||
for (Pool &pool : m_pools) {
|
for (Pool &pool : m_pools) {
|
||||||
pool.adjust(Algorithm(algo, VARIANT_AUTO));
|
pool.adjust(Algorithm(controller->config()->algorithm().algo(), VARIANT_AUTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pools.size() > 1) {
|
if (m_pools.size() > 1) {
|
||||||
|
@ -77,7 +90,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS
|
||||||
|
|
||||||
m_timer = new Timer(this);
|
m_timer = new Timer(this);
|
||||||
|
|
||||||
idle(random(m_idleTime, 0.5, 1.5));
|
setState(STATE_IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,20 +132,19 @@ void xmrig::DonateStrategy::tick(uint64_t now)
|
||||||
|
|
||||||
m_strategy->tick(now);
|
m_strategy->tick(now);
|
||||||
|
|
||||||
if (m_stop && now > m_stop) {
|
if (state() == STATE_WAIT && now > m_stop) {
|
||||||
m_strategy->stop();
|
setState(STATE_IDLE);
|
||||||
m_stop = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client)
|
void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client)
|
||||||
{
|
{
|
||||||
if (!isActive()) {
|
if (isActive()) {
|
||||||
m_timer->start(m_donateTime, 0);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_active = true;
|
setState(STATE_ACTIVE);
|
||||||
m_listener->onActive(this, client);
|
m_listener->onActive(this, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,30 +170,53 @@ void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client
|
||||||
|
|
||||||
void xmrig::DonateStrategy::onTimer(const Timer *)
|
void xmrig::DonateStrategy::onTimer(const Timer *)
|
||||||
{
|
{
|
||||||
if (!isActive()) {
|
setState(isActive() ? STATE_WAIT : STATE_CONNECT);
|
||||||
return connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::DonateStrategy::idle(uint64_t timeout)
|
void xmrig::DonateStrategy::idle(double min, double max)
|
||||||
{
|
{
|
||||||
m_timer->start(timeout, 0);
|
m_timer->start(random(m_idleTime, min, max), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::DonateStrategy::suspend()
|
void xmrig::DonateStrategy::setState(State state)
|
||||||
{
|
{
|
||||||
# if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT)
|
constexpr const uint64_t waitTime = 3000;
|
||||||
m_stop = m_now + 5000;
|
|
||||||
# else
|
|
||||||
m_stop = m_now + 500;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
m_active = false;
|
assert(m_state != state && state != STATE_NEW);
|
||||||
|
if (m_state == state) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const State prev = m_state;
|
||||||
|
m_state = state;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case STATE_NEW:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_IDLE:
|
||||||
|
if (prev == STATE_NEW) {
|
||||||
|
idle(0.5, 1.5);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_strategy->stop();
|
||||||
|
idle(0.8, 1.2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_CONNECT:
|
||||||
|
connect();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_ACTIVE:
|
||||||
|
m_timer->start(m_donateTime, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_WAIT:
|
||||||
|
m_stop = m_now + waitTime;
|
||||||
m_listener->onPause(this);
|
m_listener->onPause(this);
|
||||||
|
break;
|
||||||
idle(random(m_idleTime, 0.8, 1.2));
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#define XMRIG_DONATESTRATEGY_H
|
#define XMRIG_DONATESTRATEGY_H
|
||||||
|
|
||||||
|
|
||||||
#include <uv.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,17 +40,18 @@ namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class Controller;
|
||||||
class IStrategyListener;
|
class IStrategyListener;
|
||||||
|
|
||||||
|
|
||||||
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener
|
class DonateStrategy : public IStrategy, public IStrategyListener, public ITimerListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener);
|
DonateStrategy(Controller *controller, IStrategyListener *listener);
|
||||||
~DonateStrategy() override;
|
~DonateStrategy() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline bool isActive() const override { return m_active; }
|
inline bool isActive() const override { return state() == STATE_ACTIVE; }
|
||||||
inline void resume() override {}
|
inline void resume() override {}
|
||||||
|
|
||||||
int64_t submit(const JobResult &result) override;
|
int64_t submit(const JobResult &result) override;
|
||||||
|
@ -68,20 +68,30 @@ protected:
|
||||||
void onTimer(const Timer *timer) override;
|
void onTimer(const Timer *timer) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void idle(uint64_t timeout);
|
enum State {
|
||||||
void suspend();
|
STATE_NEW,
|
||||||
|
STATE_IDLE,
|
||||||
|
STATE_CONNECT,
|
||||||
|
STATE_ACTIVE,
|
||||||
|
STATE_WAIT
|
||||||
|
};
|
||||||
|
|
||||||
static void onTimer(uv_timer_t *handle);
|
inline State state() const { return m_state; }
|
||||||
|
|
||||||
bool m_active;
|
void idle(double min, double max);
|
||||||
|
void setState(State state);
|
||||||
|
|
||||||
|
Client *m_proxy;
|
||||||
const uint64_t m_donateTime;
|
const uint64_t m_donateTime;
|
||||||
const uint64_t m_idleTime;
|
const uint64_t m_idleTime;
|
||||||
|
Controller *m_controller;
|
||||||
IStrategy *m_strategy;
|
IStrategy *m_strategy;
|
||||||
IStrategyListener *m_listener;
|
IStrategyListener *m_listener;
|
||||||
|
State m_state;
|
||||||
std::vector<Pool> m_pools;
|
std::vector<Pool> m_pools;
|
||||||
|
Timer *m_timer;
|
||||||
uint64_t m_now;
|
uint64_t m_now;
|
||||||
uint64_t m_stop;
|
uint64_t m_stop;
|
||||||
Timer *m_timer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue