From c0dcfc2a9737ec9df88102ed583a2042aa7c4136 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 27 Jun 2017 06:32:17 +0300 Subject: [PATCH] Initial multiple pools support [2/2]. --- src/App.cpp | 2 +- src/Options.cpp | 49 +++++++++------------------------------------ src/Options.h | 8 -------- src/Summary.cpp | 4 ++-- src/net/Network.cpp | 6 +++--- src/net/Url.cpp | 18 +++++++++++++++++ src/net/Url.h | 2 +- 7 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 58f6c3500..4d3305ff2 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -105,7 +105,7 @@ int App::exec() Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash()); Summary::print(); - Workers::start(m_options->affinity(), m_options->nicehash()); + Workers::start(m_options->affinity(), false); m_network->connect(); diff --git a/src/Options.cpp b/src/Options.cpp index 3c636cece..6230f03cf 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -143,13 +143,10 @@ Options::Options(int argc, char **argv) : m_background(false), m_colors(true), m_doubleHash(false), - m_keepAlive(false), - m_nicehash(false), m_ready(false), m_safe(false), m_syslog(false), m_logFile(nullptr), - m_pass(nullptr), m_algo(0), m_algoVariant(0), m_donateLevel(kDonateLevel), @@ -185,18 +182,6 @@ Options::Options(int argc, char **argv) : return; } -// if (!m_nicehash && m_url->isNicehash()) { -// m_nicehash = true; -// } - -// if (!m_user) { -// m_user = strdup("x"); -// } - - if (!m_pass) { - m_pass = strdup("x"); - } - m_algoVariant = getAlgoVariant(); if (m_algoVariant == AV2_AESNI_DOUBLE || m_algoVariant == AV4_SOFT_AES_DOUBLE) { m_doubleHash = true; @@ -218,7 +203,6 @@ Options::Options(int argc, char **argv) : Options::~Options() { - free(m_pass); } @@ -236,13 +220,14 @@ bool Options::parseArg(int key, char *arg) break; case 'O': /* --userpass */ - if (!setUserpass(arg)) { + if (!m_pools.back()->setUserpass(arg)) { return false; } + break; case 'o': /* --url */ - if (m_pools[0]->isValid()) { + if (m_pools.size() > 1 || m_pools[0]->isValid()) { Url *url = new Url(arg); if (url->isValid()) { m_pools.push_back(url); @@ -254,6 +239,11 @@ bool Options::parseArg(int key, char *arg) else { m_pools[0]->parse(arg); } + + if (!m_pools.back()->isValid()) { + return false; + } + break; case 'u': /* --user */ @@ -315,7 +305,7 @@ bool Options::parseArg(int key, char *arg) break; case 'k': /* --keepalive */ - m_keepAlive = true; + m_pools.back()->setKeepAlive(true); break; case 'V': /* --version */ @@ -371,7 +361,7 @@ bool Options::parseArg(int key, char *arg) break; case 1006: /* --nicehash */ - m_nicehash = true; + m_pools.back()->setNicehash(true); break; case 1007: /* --print-time */ @@ -474,25 +464,6 @@ bool Options::setAlgo(const char *algo) } -bool Options::setUserpass(const char *userpass) -{ -// const char *p = strchr(userpass, ':'); -// if (!p) { -// showUsage(1); -// return false; -// } - -//// free(m_user); -// free(m_pass); - -//// m_user = static_cast(calloc(p - userpass + 1, 1)); -// strncpy(m_user, userpass, p - userpass); -// m_pass = strdup(p + 1); - - return true; -} - - int Options::getAlgoVariant() const { # ifndef XMRIG_NO_AEON diff --git a/src/Options.h b/src/Options.h index e2e6c9f9b..cefca538f 100644 --- a/src/Options.h +++ b/src/Options.h @@ -56,11 +56,8 @@ public: inline bool colors() const { return m_colors; } inline bool doubleHash() const { return m_doubleHash; } inline bool isReady() const { return m_ready; } - inline bool keepAlive() const { return m_keepAlive; } - inline bool nicehash() const { return m_nicehash; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } - inline const char *pass() const { return m_pass; } inline const std::vector &pools() const { return m_pools; } inline int algo() const { return m_algo; } inline int algoVariant() const { return m_algoVariant; } @@ -85,7 +82,6 @@ private: void showVersion(void); bool setAlgo(const char *algo); - bool setUserpass(const char *userpass); int getAlgoVariant() const; # ifndef XMRIG_NO_AEON @@ -95,14 +91,10 @@ private: bool m_background; bool m_colors; bool m_doubleHash; - bool m_keepAlive; - bool m_nicehash; bool m_ready; bool m_safe; bool m_syslog; char *m_logFile; - char *m_pass; -// char *m_user; int m_algo; int m_algoVariant; int m_donateLevel; diff --git a/src/Summary.cpp b/src/Summary.cpp index 54630e8c4..9eb195d3b 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -100,12 +100,12 @@ static void print_threads() buf[0] = '\0'; } - Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, donate=%d%%%s%s" : " * THREADS: %d, %s, av=%d, donate=%d%%%s%s", + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, donate=%d%%%s" : " * THREADS: %d, %s, av=%d, donate=%d%%%s", Options::i()->threads(), Options::i()->algoName(), Options::i()->algoVariant(), Options::i()->donateLevel(), - Options::i()->nicehash() ? ", nicehash" : "", buf); + buf); } diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 903ed8268..eddfc3bed 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -45,7 +45,7 @@ Network::Network(const Options *options) : m_agent = userAgent(); addPool(std::make_unique().get()); -// addPool(m_options->url()); + addPool(m_options->pools().front()); // addPool(m_options->backupUrl()); m_timer.data = this; @@ -120,7 +120,7 @@ void Network::onJobResult(const JobResult &result) void Network::onLoginCredentialsRequired(Client *client) { -// client->login(m_options->user(), m_options->pass(), m_agent); + client->login(m_options->pools().front()->password(), m_options->pools().front()->password(), m_agent); } @@ -154,7 +154,7 @@ void Network::addPool(const Url *url) Client *client = new Client(m_pools.size(), this); client->setUrl(url); client->setRetryPause(m_options->retryPause() * 1000); - client->setKeepAlive(m_options->keepAlive()); +// client->setKeepAlive(m_options->keepAlive()); m_pools.push_back(client); } diff --git a/src/net/Url.cpp b/src/net/Url.cpp index 96376d051..3f8ca54e3 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -126,6 +126,24 @@ bool Url::parse(const char *url) } +bool Url::setUserpass(const char *userpass) +{ + const char *p = strchr(userpass, ':'); + if (!p) { + return false; + } + + free(m_user); + free(m_password); + + m_user = static_cast(calloc(p - userpass + 1, 1)); + strncpy(m_user, userpass, p - userpass); + m_password = strdup(p + 1); + + return true; +} + + void Url::setPassword(const char *password, bool force) { if (m_password != nullptr && !force) { diff --git a/src/net/Url.h b/src/net/Url.h index bac2a564c..639df7cd5 100644 --- a/src/net/Url.h +++ b/src/net/Url.h @@ -51,9 +51,9 @@ public: bool isNicehash() const; bool parse(const char *url); + bool setUserpass(const char *userpass); void setPassword(const char *password, bool force = true); void setUser(const char *user, bool force = true); - private: bool m_keepAlive; bool m_nicehash;