Rename class Url to Pool.

This commit is contained in:
XMRig 2018-04-11 06:09:34 +07:00
parent ad7545d149
commit 36ef254c73
18 changed files with 136 additions and 126 deletions

View file

@ -45,12 +45,12 @@ set(HEADERS
src/net/Job.h src/net/Job.h
src/net/JobResult.h src/net/JobResult.h
src/net/Network.h src/net/Network.h
src/net/Pool.h
src/net/Storage.h src/net/Storage.h
src/net/strategies/DonateStrategy.h src/net/strategies/DonateStrategy.h
src/net/strategies/FailoverStrategy.h src/net/strategies/FailoverStrategy.h
src/net/strategies/SinglePoolStrategy.h src/net/strategies/SinglePoolStrategy.h
src/net/SubmitResult.h src/net/SubmitResult.h
src/net/Url.h
src/Platform.h src/Platform.h
src/Summary.h src/Summary.h
src/version.h src/version.h
@ -102,11 +102,11 @@ set(SOURCES
src/net/Client.cpp src/net/Client.cpp
src/net/Job.cpp src/net/Job.cpp
src/net/Network.cpp src/net/Network.cpp
src/net/Pool.cpp
src/net/strategies/DonateStrategy.cpp src/net/strategies/DonateStrategy.cpp
src/net/strategies/FailoverStrategy.cpp src/net/strategies/FailoverStrategy.cpp
src/net/strategies/SinglePoolStrategy.cpp src/net/strategies/SinglePoolStrategy.cpp
src/net/SubmitResult.cpp src/net/SubmitResult.cpp
src/net/Url.cpp
src/Platform.cpp src/Platform.cpp
src/Summary.cpp src/Summary.cpp
src/workers/CpuThread.cpp src/workers/CpuThread.cpp

View file

@ -32,7 +32,7 @@
#include "Cpu.h" #include "Cpu.h"
#include "log/Log.h" #include "log/Log.h"
#include "Mem.h" #include "Mem.h"
#include "net/Url.h" #include "net/Pool.h"
#include "Summary.h" #include "Summary.h"
#include "version.h" #include "version.h"
@ -112,13 +112,13 @@ static void print_threads(xmrig::Config *config)
static void print_pools(xmrig::Config *config) static void print_pools(xmrig::Config *config)
{ {
const std::vector<Url*> &pools = config->pools(); const std::vector<Pool> &pools = config->pools();
for (size_t i = 0; i < pools.size(); ++i) { for (size_t i = 0; i < pools.size(); ++i) {
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s:%d" : " * POOL #%d: %s:%d", Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s",
i + 1, i + 1,
pools[i]->host(), pools[i].url()
pools[i]->port()); );
} }
# ifdef APP_DEBUG # ifdef APP_DEBUG

View file

@ -32,7 +32,7 @@
#include "core/CommonConfig.h" #include "core/CommonConfig.h"
#include "donate.h" #include "donate.h"
#include "log/Log.h" #include "log/Log.h"
#include "net/Url.h" #include "net/Pool.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"
@ -79,7 +79,7 @@ xmrig::CommonConfig::CommonConfig() :
m_retries(5), m_retries(5),
m_retryPause(5) m_retryPause(5)
{ {
m_pools.push_back(new Url()); m_pools.push_back(Pool());
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
m_retries = 2; m_retries = 2;
@ -90,11 +90,6 @@ xmrig::CommonConfig::CommonConfig() :
xmrig::CommonConfig::~CommonConfig() xmrig::CommonConfig::~CommonConfig()
{ {
for (Url *url : m_pools) {
delete url;
}
m_pools.clear();
} }
@ -112,8 +107,8 @@ bool xmrig::CommonConfig::adjust()
m_adjusted = true; m_adjusted = true;
for (Url *url : m_pools) { for (Pool &pool : m_pools) {
url->adjust(algorithm()); pool.adjust(algorithm());
} }
return true; return true;
@ -122,7 +117,7 @@ bool xmrig::CommonConfig::adjust()
bool xmrig::CommonConfig::isValid() const bool xmrig::CommonConfig::isValid() const
{ {
return m_pools[0]->isValid(); return m_pools[0].isValid();
} }
@ -138,12 +133,12 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
break; break;
case KeepAliveKey: /* --keepalive */ case KeepAliveKey: /* --keepalive */
m_pools.back()->setKeepAlive(enable ? Url::kKeepAliveTimeout : 0); m_pools.back().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0);
break; break;
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
case NicehashKey: /* --nicehash */ case NicehashKey: /* --nicehash */
m_pools.back()->setNicehash(enable); m_pools.back().setNicehash(enable);
break; break;
# endif # endif
@ -177,38 +172,36 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
break; break;
case UserpassKey: /* --userpass */ case UserpassKey: /* --userpass */
if (!m_pools.back()->setUserpass(arg)) { if (!m_pools.back().setUserpass(arg)) {
return false; return false;
} }
break; break;
case UrlKey: /* --url */ case UrlKey: /* --url */
if (m_pools.size() > 1 || m_pools[0]->isValid()) { if (m_pools.size() > 1 || m_pools[0].isValid()) {
Url *url = new Url(arg); Pool pool(arg);
if (url->isValid()) {
m_pools.push_back(url); if (pool.isValid()) {
} m_pools.push_back(std::move(pool));
else {
delete url;
} }
} }
else { else {
m_pools[0]->parse(arg); m_pools[0].parse(arg);
} }
if (!m_pools.back()->isValid()) { if (!m_pools.back().isValid()) {
return false; return false;
} }
break; break;
case UserKey: /* --user */ case UserKey: /* --user */
m_pools.back()->setUser(arg); m_pools.back().setUser(arg);
break; break;
case PasswordKey: /* --pass */ case PasswordKey: /* --pass */
m_pools.back()->setPassword(arg); m_pools.back().setPassword(arg);
break; break;
case LogFileKey: /* --log-file */ case LogFileKey: /* --log-file */
@ -325,11 +318,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
break; break;
case KeepAliveKey: /* --keepalive */ case KeepAliveKey: /* --keepalive */
m_pools.back()->setKeepAlive(arg); m_pools.back().setKeepAlive(arg);
break; break;
case VariantKey: /* --variant */ case VariantKey: /* --variant */
m_pools.back()->setVariant(arg); m_pools.back().setVariant(arg);
break; break;
case DonateLevelKey: /* --donate-level */ case DonateLevelKey: /* --donate-level */

View file

@ -31,9 +31,7 @@
#include "core/utils/c_str.h" #include "core/utils/c_str.h"
#include "interfaces/IConfig.h" #include "interfaces/IConfig.h"
#include "xmrig.h" #include "xmrig.h"
#include "net/Pool.h"
class Url;
namespace xmrig { namespace xmrig {
@ -58,7 +56,7 @@ public:
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
inline const char *logFile() const { return m_logFile.data(); } inline const char *logFile() const { return m_logFile.data(); }
inline const char *userAgent() const { return m_userAgent.data(); } inline const char *userAgent() const { return m_userAgent.data(); }
inline const std::vector<Url*> &pools() const { return m_pools; } inline const std::vector<Pool> &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 donateLevel() const { return m_donateLevel; }
inline int printTime() const { return m_printTime; } inline int printTime() const { return m_printTime; }
@ -91,7 +89,7 @@ protected:
int m_printTime; int m_printTime;
int m_retries; int m_retries;
int m_retryPause; int m_retryPause;
std::vector<Url*> m_pools; std::vector<Pool> m_pools;
xmrig::c_str m_apiToken; xmrig::c_str m_apiToken;
xmrig::c_str m_apiWorkerId; xmrig::c_str m_apiWorkerId;
xmrig::c_str m_fileName; xmrig::c_str m_fileName;

View file

@ -30,7 +30,7 @@
#include "core/ConfigCreator.h" #include "core/ConfigCreator.h"
#include "core/ConfigLoader.h" #include "core/ConfigLoader.h"
#include "Cpu.h" #include "Cpu.h"
#include "net/Url.h" #include "net/Pool.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"
@ -110,22 +110,22 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
rapidjson::Value pools(rapidjson::kArrayType); rapidjson::Value pools(rapidjson::kArrayType);
for (const Url *url : m_pools) { for (const Pool &pool : m_pools) {
rapidjson::Value obj(rapidjson::kObjectType); rapidjson::Value obj(rapidjson::kObjectType);
obj.AddMember("url", rapidjson::StringRef(url->url()), allocator); obj.AddMember("url", rapidjson::StringRef(pool.url()), allocator);
obj.AddMember("user", rapidjson::StringRef(url->user()), allocator); obj.AddMember("user", rapidjson::StringRef(pool.user()), allocator);
obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator); obj.AddMember("pass", rapidjson::StringRef(pool.password()), allocator);
if (url->keepAlive() == 0 || url->keepAlive() == Url::kKeepAliveTimeout) { if (pool.keepAlive() == 0 || pool.keepAlive() == Pool::kKeepAliveTimeout) {
obj.AddMember("keepalive", url->keepAlive() > 0, allocator); obj.AddMember("keepalive", pool.keepAlive() > 0, allocator);
} }
else { else {
obj.AddMember("keepalive", url->keepAlive(), allocator); obj.AddMember("keepalive", pool.keepAlive(), allocator);
} }
obj.AddMember("nicehash", url->isNicehash(), allocator); obj.AddMember("nicehash", pool.isNicehash(), allocator);
obj.AddMember("variant", url->variant(), allocator); obj.AddMember("variant", pool.variant(), allocator);
pools.PushBack(obj, allocator); pools.PushBack(obj, allocator);
} }

View file

@ -38,7 +38,7 @@
#include "core/ConfigWatcher.h" #include "core/ConfigWatcher.h"
#include "interfaces/IConfig.h" #include "interfaces/IConfig.h"
#include "interfaces/IWatcherListener.h" #include "interfaces/IWatcherListener.h"
#include "net/Url.h" #include "net/Pool.h"
#include "Platform.h" #include "Platform.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"

View file

@ -43,9 +43,11 @@ namespace xmrig {
class c_str class c_str
{ {
public: public:
inline c_str() : m_data(nullptr) {} inline c_str() : m_data(nullptr) {}
inline c_str(const char *str) : m_data(nullptr) { set(str); } inline c_str(c_str &&other) { m_data = other.m_data; other.m_data = nullptr; }
inline ~c_str() { free(m_data); } inline c_str(const c_str &other) : m_data(nullptr) { set(other.data()); }
inline c_str(const char *str) : m_data(nullptr) { set(str); }
inline ~c_str() { free(m_data); }
inline void set(const char *str) inline void set(const char *str)

View file

@ -32,7 +32,6 @@
#include "interfaces/IClientListener.h" #include "interfaces/IClientListener.h"
#include "log/Log.h" #include "log/Log.h"
#include "net/Client.h" #include "net/Client.h"
#include "net/Url.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
#include "rapidjson/stringbuffer.h" #include "rapidjson/stringbuffer.h"
@ -97,7 +96,7 @@ Client::~Client()
void Client::connect() void Client::connect()
{ {
resolve(m_url.host()); resolve(m_pool.host());
} }
@ -106,10 +105,10 @@ void Client::connect()
* *
* @param url * @param url
*/ */
void Client::connect(const Url *url) void Client::connect(const Pool &url)
{ {
setUrl(url); setUrl(url);
resolve(m_url.host()); connect();
} }
@ -132,13 +131,13 @@ void Client::deleteLater()
} }
void Client::setUrl(const Url *url) void Client::setUrl(const Pool &pool)
{ {
if (!url || !url->isValid()) { if (!pool.isValid()) {
return; return;
} }
m_url = *url; m_pool = pool;
} }
@ -146,7 +145,7 @@ void Client::tick(uint64_t now)
{ {
if (m_state == ConnectedState) { if (m_state == ConnectedState) {
if (m_expire && now > m_expire) { if (m_expire && now > m_expire) {
LOG_DEBUG_ERR("[%s:%u] timeout", m_url.host(), m_url.port()); LOG_DEBUG_ERR("[%s] timeout", m_pool.url());
close(); close();
} }
else if (m_keepAlive && now > m_keepAlive) { else if (m_keepAlive && now > m_keepAlive) {
@ -266,11 +265,10 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
} }
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
Job job(m_id, m_url.variant()); Job job(m_id, m_pool.variant());
job.setClientId(m_rpcId); job.setClientId(m_rpcId);
job.setCoin(m_url.coin());
# else # else
Job job(m_id, m_nicehash, m_url.algo(), m_url.variant()); Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant());
# endif # endif
if (!job.setId(params["job_id"].GetString())) { if (!job.setId(params["job_id"].GetString())) {
@ -307,7 +305,7 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
} }
if (!m_quiet) { if (!m_quiet) {
LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port()); LOG_WARN("[%s] duplicate job received, reconnect", m_pool.url());
} }
close(); close();
@ -323,7 +321,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code)
} }
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
m_nicehash = m_url.isNicehash(); m_nicehash = m_pool.isNicehash();
# endif # endif
if (result.HasMember("extensions")) { if (result.HasMember("extensions")) {
@ -351,7 +349,7 @@ int Client::resolve(const char *host)
const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints); const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints);
if (r) { if (r) {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r)); LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_pool.port(), uv_strerror(r));
} }
return 1; return 1;
} }
@ -402,7 +400,7 @@ void Client::connect(sockaddr *addr)
{ {
setState(ConnectingState); setState(ConnectingState);
reinterpret_cast<struct sockaddr_in*>(addr)->sin_port = htons(m_url.port()); reinterpret_cast<sockaddr_in*>(addr)->sin_port = htons(m_pool.port());
delete m_socket; delete m_socket;
uv_connect_t *req = new uv_connect_t; uv_connect_t *req = new uv_connect_t;
@ -436,9 +434,9 @@ void Client::login()
doc.AddMember("method", "login", allocator); doc.AddMember("method", "login", allocator);
rapidjson::Value params(rapidjson::kObjectType); rapidjson::Value params(rapidjson::kObjectType);
params.AddMember("login", rapidjson::StringRef(m_url.user()), allocator); params.AddMember("login", rapidjson::StringRef(m_pool.user()), allocator);
params.AddMember("pass", rapidjson::StringRef(m_url.password()), allocator); params.AddMember("pass", rapidjson::StringRef(m_pool.password()), allocator);
params.AddMember("agent", rapidjson::StringRef(m_agent), allocator); params.AddMember("agent", rapidjson::StringRef(m_agent), allocator);
doc.AddMember("params", params, allocator); doc.AddMember("params", params, allocator);
@ -481,7 +479,7 @@ void Client::parse(char *line, size_t len)
if (len < 32 || line[0] != '{') { if (len < 32 || line[0] != '{') {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port()); LOG_ERR("[%s] JSON decode failed", m_pool.url());
} }
return; return;
@ -490,7 +488,7 @@ void Client::parse(char *line, size_t len)
rapidjson::Document doc; rapidjson::Document doc;
if (doc.ParseInsitu(line).HasParseError()) { if (doc.ParseInsitu(line).HasParseError()) {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] JSON decode failed: \"%s\"", m_url.host(), m_url.port(), rapidjson::GetParseError_En(doc.GetParseError())); LOG_ERR("[%s] JSON decode failed: \"%s\"", m_pool.url(), rapidjson::GetParseError_En(doc.GetParseError()));
} }
return; return;
@ -532,7 +530,7 @@ void Client::parseNotification(const char *method, const rapidjson::Value &param
{ {
if (error.IsObject()) { if (error.IsObject()) {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), error["message"].GetString(), error["code"].GetInt()); LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), error["message"].GetString(), error["code"].GetInt());
} }
return; return;
} }
@ -550,7 +548,7 @@ void Client::parseNotification(const char *method, const rapidjson::Value &param
return; return;
} }
LOG_WARN("[%s:%u] unsupported method: \"%s\"", m_url.host(), m_url.port(), method); LOG_WARN("[%s] unsupported method: \"%s\"", m_pool.url(), method);
} }
@ -566,7 +564,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
m_results.erase(it); m_results.erase(it);
} }
else if (!m_quiet) { else if (!m_quiet) {
LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), message, error["code"].GetInt()); LOG_ERR("[%s] error: \"%s\", code: %d", m_pool.url(), message, error["code"].GetInt());
} }
if (isCriticalError(message)) { if (isCriticalError(message)) {
@ -584,7 +582,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rap
int code = -1; int code = -1;
if (!parseLogin(result, &code)) { if (!parseLogin(result, &code)) {
if (!m_quiet) { if (!m_quiet) {
LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code); LOG_ERR("[%s] login error code: %d", m_pool.url(), code);
} }
close(); close();
@ -650,8 +648,8 @@ void Client::startTimeout()
{ {
m_expire = 0; m_expire = 0;
if (m_url.keepAlive()) { if (m_pool.keepAlive()) {
m_keepAlive = uv_now(uv_default_loop()) + (m_url.keepAlive() * 1000); m_keepAlive = uv_now(uv_default_loop()) + (m_pool.keepAlive() * 1000);
} }
} }
@ -689,7 +687,7 @@ void Client::onConnect(uv_connect_t *req, int status)
if (status < 0) { if (status < 0) {
if (!client->m_quiet) { if (!client->m_quiet) {
LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); LOG_ERR("[%s] connect error: \"%s\"", client->m_pool.url(), uv_strerror(status));
} }
delete req; delete req;
@ -717,7 +715,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
if (nread < 0) { if (nread < 0) {
if (nread != UV_EOF && !client->m_quiet) { if (nread != UV_EOF && !client->m_quiet) {
LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); LOG_ERR("[%s] read error: \"%s\"", client->m_pool.url(), uv_strerror((int) nread));
} }
client->close(); client->close();
@ -777,7 +775,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
if (status < 0) { if (status < 0) {
if (!client->m_quiet) { if (!client->m_quiet) {
LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status)); LOG_ERR("[%s] DNS error: \"%s\"", client->m_pool.url(), uv_strerror(status));
} }
return client->reconnect(); return client->reconnect();
@ -801,7 +799,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
if (ipv4.empty() && ipv6.empty()) { if (ipv4.empty() && ipv6.empty()) {
if (!client->m_quiet) { if (!client->m_quiet) {
LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port()); LOG_ERR("[%s] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_pool.url());
} }
uv_freeaddrinfo(res); uv_freeaddrinfo(res);

View file

@ -30,12 +30,11 @@
#include <vector> #include <vector>
#include "core/utils/c_str.h"
#include "net/Id.h" #include "net/Id.h"
#include "net/Job.h" #include "net/Job.h"
#include "net/Storage.h" #include "net/Storage.h"
#include "net/SubmitResult.h" #include "net/SubmitResult.h"
#include "net/Url.h" #include "net/Pool.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
@ -62,18 +61,18 @@ public:
bool disconnect(); bool disconnect();
int64_t submit(const JobResult &result); int64_t submit(const JobResult &result);
void connect(); void connect();
void connect(const Url *url); void connect(const Pool &pool);
void deleteLater(); void deleteLater();
void setUrl(const Url *url); void setUrl(const Pool &pool);
void tick(uint64_t now); void tick(uint64_t now);
inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
inline const char *host() const { return m_url.host(); } inline const char *host() const { return m_pool.host(); }
inline const char *ip() const { return m_ip; } inline const char *ip() const { return m_ip; }
inline const Job &job() const { return m_job; } inline const Job &job() const { return m_job; }
inline int id() const { return m_id; } inline int id() const { return m_id; }
inline SocketState state() const { return m_state; } inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_url.port(); } inline uint16_t port() const { return m_pool.port(); }
inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setQuiet(bool quiet) { m_quiet = quiet; }
inline void setRetryPause(int ms) { m_retryPause = ms; } inline void setRetryPause(int ms) { m_retryPause = ms; }
@ -118,6 +117,7 @@ private:
int m_retryPause; int m_retryPause;
int64_t m_failures; int64_t m_failures;
Job m_job; Job m_job;
Pool m_pool;
size_t m_recvBufPos; size_t m_recvBufPos;
SocketState m_state; SocketState m_state;
std::map<int64_t, SubmitResult> m_results; std::map<int64_t, SubmitResult> m_results;
@ -125,7 +125,6 @@ private:
uint64_t m_jobs; uint64_t m_jobs;
uint64_t m_keepAlive; uint64_t m_keepAlive;
uintptr_t m_key; uintptr_t m_key;
Url m_url;
uv_buf_t m_recvBuf; uv_buf_t m_recvBuf;
uv_getaddrinfo_t m_resolver; uv_getaddrinfo_t m_resolver;
uv_stream_t *m_stream; uv_stream_t *m_stream;

View file

@ -38,7 +38,6 @@
#include "net/strategies/FailoverStrategy.h" #include "net/strategies/FailoverStrategy.h"
#include "net/strategies/SinglePoolStrategy.h" #include "net/strategies/SinglePoolStrategy.h"
#include "net/SubmitResult.h" #include "net/SubmitResult.h"
#include "net/Url.h"
#include "workers/Workers.h" #include "workers/Workers.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "core/Config.h" #include "core/Config.h"
@ -52,7 +51,7 @@ Network::Network(xmrig::Controller *controller) :
Workers::setListener(this); Workers::setListener(this);
const std::vector<Url*> &pools = controller->config()->pools(); const std::vector<Pool> &pools = controller->config()->pools();
if (pools.size() > 1) { if (pools.size() > 1) {
m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this); m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this);
@ -62,7 +61,7 @@ Network::Network(xmrig::Controller *controller) :
} }
if (controller->config()->donateLevel() > 0) { if (controller->config()->donateLevel() > 0) {
m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front()->user(), controller->config()->algorithm(), this); m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front().user(), controller->config()->algorithm(), this);
} }
m_timer.data = this; m_timer.data = this;

View file

@ -28,7 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include "net/Url.h" #include "net/Pool.h"
#ifdef _MSC_VER #ifdef _MSC_VER
@ -36,7 +36,7 @@
#endif #endif
Url::Url() : Pool::Pool() :
m_nicehash(false), m_nicehash(false),
m_keepAlive(0), m_keepAlive(0),
m_port(kDefaultPort), m_port(kDefaultPort),
@ -57,7 +57,7 @@ Url::Url() :
* *
* @param url * @param url
*/ */
Url::Url(const char *url) : Pool::Pool(const char *url) :
m_nicehash(false), m_nicehash(false),
m_keepAlive(0), m_keepAlive(0),
m_port(kDefaultPort), m_port(kDefaultPort),
@ -69,7 +69,7 @@ Url::Url(const char *url) :
} }
Url::Url(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, xmrig::Variant variant) : Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, xmrig::Variant variant) :
m_nicehash(nicehash), m_nicehash(nicehash),
m_keepAlive(keepAlive), m_keepAlive(keepAlive),
m_port(port), m_port(port),
@ -89,7 +89,7 @@ Url::Url(const char *host, uint16_t port, const char *user, const char *password
} }
bool Url::parse(const char *url) bool Pool::parse(const char *url)
{ {
assert(url != nullptr); assert(url != nullptr);
@ -114,7 +114,7 @@ bool Url::parse(const char *url)
const char *port = strchr(base, ':'); const char *port = strchr(base, ':');
if (!port) { if (!port) {
m_host = strdup(base); m_host = base;
return false; return false;
} }
@ -129,7 +129,7 @@ bool Url::parse(const char *url)
} }
bool Url::setUserpass(const char *userpass) bool Pool::setUserpass(const char *userpass)
{ {
const char *p = strchr(userpass, ':'); const char *p = strchr(userpass, ':');
if (!p) { if (!p) {
@ -146,7 +146,7 @@ bool Url::setUserpass(const char *userpass)
} }
void Url::adjust(xmrig::Algo algo) void Pool::adjust(xmrig::Algo algo)
{ {
if (!isValid()) { if (!isValid()) {
return; return;
@ -165,7 +165,7 @@ void Url::adjust(xmrig::Algo algo)
} }
void Url::setVariant(int variant) void Pool::setVariant(int variant)
{ {
switch (variant) { switch (variant) {
case xmrig::VARIANT_AUTO: case xmrig::VARIANT_AUTO:
@ -181,7 +181,21 @@ void Url::setVariant(int variant)
} }
bool Url::parseIPv6(const char *addr) bool Pool::isEqual(const Pool &other) const
{
return (m_nicehash == other.m_nicehash
&& m_keepAlive == other.m_keepAlive
&& m_port == other.m_port
&& m_algo == other.m_algo
&& m_host == other.m_host
&& m_password == other.m_password
&& m_url == other.m_url
&& m_user == other.m_user
&& m_variant == other.m_variant);
}
bool Pool::parseIPv6(const char *addr)
{ {
const char *end = strchr(addr, ']'); const char *end = strchr(addr, ']');
if (!end) { if (!end) {

View file

@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __URL_H__ #ifndef __POOL_H__
#define __URL_H__ #define __POOL_H__
#include <stdint.h> #include <stdint.h>
@ -32,7 +32,7 @@
#include "xmrig.h" #include "xmrig.h"
class Url class Pool
{ {
public: public:
constexpr static const char *kDefaultPassword = "x"; constexpr static const char *kDefaultPassword = "x";
@ -40,9 +40,9 @@ public:
constexpr static uint16_t kDefaultPort = 3333; constexpr static uint16_t kDefaultPort = 3333;
constexpr static int kKeepAliveTimeout = 60; constexpr static int kKeepAliveTimeout = 60;
Url(); Pool();
Url(const char *url); Pool(const char *url);
Url(const char *host, Pool(const char *host,
uint16_t port, uint16_t port,
const char *user = nullptr, const char *user = nullptr,
const char *password = nullptr, const char *password = nullptr,
@ -66,11 +66,16 @@ public:
inline xmrig::Algo algo() const { return m_algo; } inline xmrig::Algo algo() const { return m_algo; }
inline xmrig::Variant variant() const { return m_variant; } inline xmrig::Variant variant() const { return m_variant; }
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
inline bool operator==(const Pool &other) const { return isEqual(other); }
bool parse(const char *url); bool parse(const char *url);
bool setUserpass(const char *userpass); bool setUserpass(const char *userpass);
void adjust(xmrig::Algo algo); void adjust(xmrig::Algo algo);
void setVariant(int variant); void setVariant(int variant);
bool isEqual(const Pool &other) const;
private: private:
bool parseIPv6(const char *addr); bool parseIPv6(const char *addr);
@ -85,4 +90,4 @@ private:
xmrig::Variant m_variant; xmrig::Variant m_variant;
}; };
#endif /* __URL_H__ */ #endif /* __POOL_H__ */

View file

@ -60,17 +60,17 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL
Job::toHex(hash, 32, userId); Job::toHex(hash, 32, userId);
if (algo == xmrig::CRYPTONIGHT) { if (algo == xmrig::CRYPTONIGHT) {
m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 6666, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 80, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false)); m_pools.push_back(Pool(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
} }
else if (algo == xmrig::CRYPTONIGHT_HEAVY) { else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
m_pools.push_back(new Url(kDonatePool1, 8888, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 8888, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool1, 8889, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 8889, userId, nullptr, false, true));
} }
else { else {
m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 5555, userId, nullptr, false, true));
m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true)); m_pools.push_back(Pool(kDonatePool1, 7777, userId, nullptr, false, true));
} }
m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true); m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true);

View file

@ -32,6 +32,7 @@
#include "interfaces/IClientListener.h" #include "interfaces/IClientListener.h"
#include "interfaces/IStrategy.h" #include "interfaces/IStrategy.h"
#include "interfaces/IStrategyListener.h" #include "interfaces/IStrategyListener.h"
#include "net/Pool.h"
class Client; class Client;
@ -71,7 +72,7 @@ private:
const int m_idleTime; const int m_idleTime;
IStrategy *m_strategy; IStrategy *m_strategy;
IStrategyListener *m_listener; IStrategyListener *m_listener;
std::vector<Url*> m_pools; std::vector<Pool> m_pools;
uv_timer_t m_timer; uv_timer_t m_timer;
}; };

View file

@ -28,7 +28,7 @@
#include "Platform.h" #include "Platform.h"
FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
m_quiet(quiet), m_quiet(quiet),
m_retries(retries), m_retries(retries),
m_retryPause(retryPause), m_retryPause(retryPause),
@ -36,7 +36,7 @@ FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, int retryPause
m_index(0), m_index(0),
m_listener(listener) m_listener(listener)
{ {
for (const Url *url : urls) { for (const Pool &url : urls) {
add(url); add(url);
} }
} }
@ -153,10 +153,10 @@ void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &resu
} }
void FailoverStrategy::add(const Url *url) void FailoverStrategy::add(const Pool &pool)
{ {
Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
client->setUrl(url); client->setUrl(pool);
client->setRetryPause(m_retryPause * 1000); client->setRetryPause(m_retryPause * 1000);
client->setQuiet(m_quiet); client->setQuiet(m_quiet);

View file

@ -30,6 +30,7 @@
#include "interfaces/IClientListener.h" #include "interfaces/IClientListener.h"
#include "interfaces/IStrategy.h" #include "interfaces/IStrategy.h"
#include "net/Pool.h"
class Client; class Client;
@ -40,7 +41,7 @@ class Url;
class FailoverStrategy : public IStrategy, public IClientListener class FailoverStrategy : public IStrategy, public IClientListener
{ {
public: public:
FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~FailoverStrategy(); ~FailoverStrategy();
public: public:
@ -59,7 +60,7 @@ protected:
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
private: private:
void add(const Url *url); void add(const Pool &pool);
const bool m_quiet; const bool m_quiet;
const int m_retries; const int m_retries;

View file

@ -28,12 +28,12 @@
#include "Platform.h" #include "Platform.h"
SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet) : SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet) :
m_active(false), m_active(false),
m_listener(listener) m_listener(listener)
{ {
m_client = new Client(0, Platform::userAgent(), this); m_client = new Client(0, Platform::userAgent(), this);
m_client->setUrl(url); m_client->setUrl(pool);
m_client->setRetryPause(retryPause * 1000); m_client->setRetryPause(retryPause * 1000);
m_client->setQuiet(quiet); m_client->setQuiet(quiet);
} }

View file

@ -37,7 +37,7 @@ class Url;
class SinglePoolStrategy : public IStrategy, public IClientListener class SinglePoolStrategy : public IStrategy, public IClientListener
{ {
public: public:
SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false); SinglePoolStrategy(const Pool &pool, int retryPause, IStrategyListener *listener, bool quiet = false);
~SinglePoolStrategy(); ~SinglePoolStrategy();
public: public: