Prepare for daemon support.

This commit is contained in:
XMRig 2019-04-11 00:18:33 +07:00
parent 9a6944d694
commit 0d496aaf2f
8 changed files with 97 additions and 47 deletions

View file

@ -57,6 +57,7 @@ public:
virtual bool hasExtension(Extension extension) const noexcept = 0; virtual bool hasExtension(Extension extension) const noexcept = 0;
virtual bool isEnabled() const = 0; virtual bool isEnabled() const = 0;
virtual bool isTLS() const = 0; virtual bool isTLS() const = 0;
virtual const char *mode() const = 0;
virtual const char *tlsFingerprint() const = 0; virtual const char *tlsFingerprint() const = 0;
virtual const char *tlsVersion() const = 0; virtual const char *tlsVersion() const = 0;
virtual const Job &job() const = 0; virtual const Job &job() const = 0;

View file

@ -79,6 +79,7 @@ public:
void tick(uint64_t now) override; void tick(uint64_t now) override;
inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); } inline bool hasExtension(Extension extension) const noexcept override { return m_extensions.test(extension); }
inline const char *mode() const override { return "pool"; }
protected: protected:
inline void onLine(char *line, size_t size) override { parse(line, size); } inline void onLine(char *line, size_t size) override { parse(line, size); }

View file

@ -7,6 +7,7 @@
* 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 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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
@ -180,9 +181,10 @@ void xmrig::Job::setAlgorithm(const char *algo)
} }
void xmrig::Job::setHeight(uint64_t height) void xmrig::Job::setDiff(uint64_t diff)
{ {
m_height = height; m_diff = diff;
m_target = toDiff(diff);
} }

View file

@ -7,6 +7,7 @@
* 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 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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
@ -53,7 +54,7 @@ public:
bool setBlob(const char *blob); bool setBlob(const char *blob);
bool setTarget(const char *target); bool setTarget(const char *target);
void setAlgorithm(const char *algo); void setAlgorithm(const char *algo);
void setHeight(uint64_t height); void setDiff(uint64_t diff);
inline bool isNicehash() const { return m_nicehash; } inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline bool isValid() const { return m_size > 0 && m_diff > 0; }
@ -73,6 +74,7 @@ public:
inline uint8_t fixedByte() const { return *(m_blob + 42); } inline uint8_t fixedByte() const { return *(m_blob + 42); }
inline void reset() { m_size = 0; m_diff = 0; } inline void reset() { m_size = 0; m_diff = 0; }
inline void setClientId(const String &id) { m_clientId = id; } inline void setClientId(const String &id) { m_clientId = id; }
inline void setHeight(uint64_t height) { m_height = height; }
inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setThreadId(int threadId) { m_threadId = threadId; }
inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); }

View file

@ -6,6 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2019 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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
@ -41,25 +42,34 @@
#ifdef _MSC_VER #ifdef _MSC_VER
# define strncasecmp _strnicmp # define strncasecmp _strnicmp
# define strcasecmp _stricmp
#endif #endif
namespace xmrig { namespace xmrig {
static const char *kEnabled = "enabled"; static const char *kDaemon = "daemon";
static const char *kFingerprint = "tls-fingerprint"; static const char *kDaemonPollInterval = "daemon-poll-interval";
static const char *kKeepalive = "keepalive"; static const char *kEnabled = "enabled";
static const char *kNicehash = "nicehash"; static const char *kFingerprint = "tls-fingerprint";
static const char *kPass = "pass"; static const char *kKeepalive = "keepalive";
static const char *kRigId = "rig-id"; static const char *kNicehash = "nicehash";
static const char *kTls = "tls"; static const char *kPass = "pass";
static const char *kUrl = "url"; static const char *kRigId = "rig-id";
static const char *kUser = "user"; static const char *kTls = "tls";
static const char *kVariant = "variant"; static const char *kUrl = "url";
static const char *kUser = "user";
static const char *kVariant = "variant";
const String Pool::kDefaultPassword = "x"; const String Pool::kDefaultPassword = "x";
const String Pool::kDefaultUser = "x"; const String Pool::kDefaultUser = "x";
static const char kStratumTcp[] = "stratum+tcp://";
static const char kStratumSsl[] = "stratum+ssl://";
#ifdef XMRIG_FEATURE_HTTP
static const char kDaemonHttp[] = "daemon+http://";
static const char kDaemonHttps[] = "daemon+https://";
#endif
} }
@ -67,7 +77,8 @@ const String Pool::kDefaultUser = "x";
xmrig::Pool::Pool() : xmrig::Pool::Pool() :
m_keepAlive(0), m_keepAlive(0),
m_flags(0), m_flags(0),
m_port(kDefaultPort) m_port(kDefaultPort),
m_pollInterval(kDefaultPollInterval)
{ {
} }
@ -86,7 +97,8 @@ xmrig::Pool::Pool() :
xmrig::Pool::Pool(const char *url) : xmrig::Pool::Pool(const char *url) :
m_keepAlive(0), m_keepAlive(0),
m_flags(1), m_flags(1),
m_port(kDefaultPort) m_port(kDefaultPort),
m_pollInterval(kDefaultPollInterval)
{ {
parse(url); parse(url);
} }
@ -95,20 +107,23 @@ xmrig::Pool::Pool(const char *url) :
xmrig::Pool::Pool(const rapidjson::Value &object) : xmrig::Pool::Pool(const rapidjson::Value &object) :
m_keepAlive(0), m_keepAlive(0),
m_flags(1), m_flags(1),
m_port(kDefaultPort) m_port(kDefaultPort),
m_pollInterval(kDefaultPollInterval)
{ {
if (!parse(Json::getString(object, kUrl))) { if (!parse(Json::getString(object, kUrl))) {
return; return;
} }
m_user = Json::getString(object, kUser); m_user = Json::getString(object, kUser);
m_password = Json::getString(object, kPass); m_password = Json::getString(object, kPass);
m_rigId = Json::getString(object, kRigId); m_rigId = Json::getString(object, kRigId);
m_fingerprint = Json::getString(object, kFingerprint); m_fingerprint = Json::getString(object, kFingerprint);
m_pollInterval = Json::getUint64(object, kDaemonPollInterval, kDefaultPollInterval);
m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true)); m_flags.set(FLAG_ENABLED, Json::getBool(object, kEnabled, true));
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash)); m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash));
m_flags.set(FLAG_TLS, Json::getBool(object, kTls, m_flags.test(FLAG_TLS))); m_flags.set(FLAG_TLS, Json::getBool(object, kTls, m_flags.test(FLAG_TLS)));
m_flags.set(FLAG_DAEMON, Json::getBool(object, kDaemon, m_flags.test(FLAG_DAEMON)));
const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive); const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive);
if (keepalive.IsInt()) { if (keepalive.IsInt()) {
@ -135,7 +150,8 @@ xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char
m_host(host), m_host(host),
m_password(password), m_password(password),
m_user(user), m_user(user),
m_port(port) m_port(port),
m_pollInterval(kDefaultPollInterval)
{ {
const size_t size = m_host.size() + 8; const size_t size = m_host.size() + 8;
assert(size > 8); assert(size > 8);
@ -180,22 +196,29 @@ bool xmrig::Pool::isEnabled() const
} }
# endif # endif
# ifndef XMRIG_FEATURE_HTTP
if (isDaemon()) {
return false;
}
# endif
return m_flags.test(FLAG_ENABLED) && isValid() && algorithm().isValid(); return m_flags.test(FLAG_ENABLED) && isValid() && algorithm().isValid();
} }
bool xmrig::Pool::isEqual(const Pool &other) const bool xmrig::Pool::isEqual(const Pool &other) const
{ {
return (m_flags == other.m_flags return (m_flags == other.m_flags
&& m_keepAlive == other.m_keepAlive && m_keepAlive == other.m_keepAlive
&& m_port == other.m_port && m_port == other.m_port
&& m_algorithm == other.m_algorithm && m_algorithm == other.m_algorithm
&& m_fingerprint == other.m_fingerprint && m_fingerprint == other.m_fingerprint
&& m_host == other.m_host && m_host == other.m_host
&& m_password == other.m_password && m_password == other.m_password
&& m_rigId == other.m_rigId && m_rigId == other.m_rigId
&& m_url == other.m_url && m_url == other.m_url
&& m_user == other.m_user); && m_user == other.m_user
&& m_pollInterval == other.m_pollInterval);
} }
@ -203,21 +226,33 @@ bool xmrig::Pool::parse(const char *url)
{ {
assert(url != nullptr); assert(url != nullptr);
const char *p = strstr(url, "://"); const char *p = strstr(url, "://");
const char *base = url; const char *base = url;
if (p) { if (p) {
if (strncasecmp(url, "stratum+tcp://", 14) == 0) { if (strncasecmp(url, kStratumTcp, sizeof(kStratumTcp) - 1) == 0) {
m_flags.set(FLAG_TLS, false); m_flags.set(FLAG_DAEMON, false);
m_flags.set(FLAG_TLS, false);
} }
else if (strncasecmp(url, "stratum+ssl://", 14) == 0) { else if (strncasecmp(url, kStratumSsl, sizeof(kStratumSsl) - 1) == 0) {
m_flags.set(FLAG_TLS, true); m_flags.set(FLAG_DAEMON, false);
m_flags.set(FLAG_TLS, true);
} }
# ifdef XMRIG_FEATURE_HTTP
else if (strncasecmp(url, kDaemonHttps, sizeof(kDaemonHttps) - 1) == 0) {
m_flags.set(FLAG_DAEMON, true);
m_flags.set(FLAG_TLS, true);
}
else if (strncasecmp(url, kDaemonHttp, sizeof(kDaemonHttp) - 1) == 0) {
m_flags.set(FLAG_DAEMON, true);
m_flags.set(FLAG_TLS, false);
}
# endif
else { else {
return false; return false;
} }
base = url + 14; base = p + 3;
} }
if (!strlen(base) || *base == '/') { if (!strlen(base) || *base == '/') {
@ -286,9 +321,11 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const
break; break;
} }
obj.AddMember(StringRef(kEnabled), m_flags.test(FLAG_ENABLED), allocator); obj.AddMember(StringRef(kEnabled), m_flags.test(FLAG_ENABLED), allocator);
obj.AddMember(StringRef(kTls), isTLS(), allocator); obj.AddMember(StringRef(kTls), isTLS(), allocator);
obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator); obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator);
obj.AddMember(StringRef(kDaemon), m_flags.test(FLAG_DAEMON), allocator);
obj.AddMember(StringRef(kDaemonPollInterval), m_pollInterval, allocator);
return obj; return obj;
} }

View file

@ -6,6 +6,7 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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
@ -45,14 +46,16 @@ public:
FLAG_ENABLED, FLAG_ENABLED,
FLAG_NICEHASH, FLAG_NICEHASH,
FLAG_TLS, FLAG_TLS,
FLAG_DAEMON,
FLAG_MAX FLAG_MAX
}; };
static const String kDefaultPassword; static const String kDefaultPassword;
static const String kDefaultUser; static const String kDefaultUser;
constexpr static uint16_t kDefaultPort = 3333; constexpr static int kKeepAliveTimeout = 60;
constexpr static int kKeepAliveTimeout = 60; constexpr static uint16_t kDefaultPort = 3333;
constexpr static uint64_t kDefaultPollInterval = 1000;
Pool(); Pool();
Pool(const char *url); Pool(const char *url);
@ -67,6 +70,7 @@ public:
); );
inline Algorithm &algorithm() { return m_algorithm; } inline Algorithm &algorithm() { return m_algorithm; }
inline bool isDaemon() const { return m_flags.test(FLAG_DAEMON); }
inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); } inline bool isNicehash() const { return m_flags.test(FLAG_NICEHASH); }
inline bool isTLS() const { return m_flags.test(FLAG_TLS); } inline bool isTLS() const { return m_flags.test(FLAG_TLS); }
inline bool isValid() const { return !m_host.isNull() && m_port > 0; } inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
@ -116,6 +120,7 @@ private:
String m_url; String m_url;
String m_user; String m_user;
uint16_t m_port; uint16_t m_port;
uint64_t m_pollInterval;
}; };

View file

@ -6,6 +6,7 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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
@ -101,8 +102,8 @@ void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
m_state.setPool(client->pool().host(), client->pool().port(), client->ip()); m_state.setPool(client->pool().host(), client->pool().port(), client->ip());
const char *tlsVersion = client->tlsVersion(); const char *tlsVersion = client->tlsVersion();
LOG_INFO(WHITE_BOLD("use pool ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"), LOG_INFO(WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data()); client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
const char *fingerprint = client->tlsFingerprint(); const char *fingerprint = client->tlsFingerprint();
if (fingerprint != nullptr) { if (fingerprint != nullptr) {

View file

@ -6,6 +6,7 @@
* 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 2018-2019 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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