From a2f747fb0c4b8282115302832d62b7bba5532652 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 17 Mar 2018 04:16:08 +0700 Subject: [PATCH] Pass all options to network strategies in constructor. --- src/net/Network.cpp | 6 +++--- src/net/strategies/DonateStrategy.cpp | 12 +++++------- src/net/strategies/DonateStrategy.h | 2 +- src/net/strategies/FailoverStrategy.cpp | 13 +++++++------ src/net/strategies/FailoverStrategy.h | 8 +++++--- src/net/strategies/SinglePoolStrategy.cpp | 9 ++++----- src/net/strategies/SinglePoolStrategy.h | 6 +++--- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/net/Network.cpp b/src/net/Network.cpp index e0f654977..d2cf8b1a7 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -55,14 +55,14 @@ Network::Network(const Options *options) : const std::vector &pools = options->pools(); if (pools.size() > 1) { - m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this); + m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), Platform::userAgent(), this); } else { - m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this); + m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), Platform::userAgent(), this); } if (m_options->donateLevel() > 0) { - m_donate = new DonateStrategy(Platform::userAgent(), this); + m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), Platform::userAgent(), this); } m_timer.data = this; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 84d1e4da5..aaab222b8 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -26,7 +26,6 @@ #include "net/Client.h" #include "net/Job.h" #include "net/strategies/DonateStrategy.h" -#include "Options.h" #include "xmrig.h" @@ -36,24 +35,23 @@ extern "C" } -DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : +DonateStrategy::DonateStrategy(int level, const char *user, int algo, const char *agent, IStrategyListener *listener) : m_active(false), - m_donateTime(Options::i()->donateLevel() * 60 * 1000), - m_idleTime((100 - Options::i()->donateLevel()) * 60 * 1000), + m_donateTime(level * 60 * 1000), + m_idleTime((100 - level) * 60 * 1000), m_listener(listener) { uint8_t hash[200]; char userId[65] = { 0 }; - const char *user = Options::i()->pools().front()->user(); keccak(reinterpret_cast(user), static_cast(strlen(user)), hash, sizeof(hash)); Job::toHex(hash, 32, userId); - Url *url = new Url("thanks.xmrig.com", Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT_LITE ? 5555 : 80, userId, nullptr, false, true); + Url *url = new Url("thanks.xmrig.com", algo == xmrig::ALGO_CRYPTONIGHT_LITE ? 5555 : 80, userId, nullptr, false, true); m_client = new Client(-1, agent, this); m_client->setUrl(url); - m_client->setRetryPause(Options::i()->retryPause() * 1000); + m_client->setRetryPause(1000); m_client->setQuiet(true); delete url; diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 070110533..52e3a38db 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -40,7 +40,7 @@ class Url; class DonateStrategy : public IStrategy, public IClientListener { public: - DonateStrategy(const char *agent, IStrategyListener *listener); + DonateStrategy(int level, const char *user, int algo, const char *agent, IStrategyListener *listener); public: inline bool isActive() const override { return m_active; } diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 47d390b06..db449cccc 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -25,10 +25,11 @@ #include "interfaces/IStrategyListener.h" #include "net/Client.h" #include "net/strategies/FailoverStrategy.h" -#include "Options.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, const char *agent, IStrategyListener *listener) : +FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, const char *agent, IStrategyListener *listener) : + m_retries(retries), + m_retryPause(retryPause), m_active(-1), m_index(0), m_listener(listener) @@ -93,7 +94,7 @@ void FailoverStrategy::onClose(Client *client, int failures) m_listener->onPause(this); } - if (m_index == 0 && failures < Options::i()->retries()) { + if (m_index == 0 && failures < m_retries) { return; } @@ -142,7 +143,7 @@ void FailoverStrategy::add(const Url *url, const char *agent) { Client *client = new Client((int) m_pools.size(), agent, this); client->setUrl(url); - client->setRetryPause(Options::i()->retryPause() * 1000); + client->setRetryPause(m_retryPause * 1000); m_pools.push_back(client); } diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h index 963d31575..e29c7d62e 100644 --- a/src/net/strategies/FailoverStrategy.h +++ b/src/net/strategies/FailoverStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -40,7 +40,7 @@ class Url; class FailoverStrategy : public IStrategy, public IClientListener { public: - FailoverStrategy(const std::vector &urls, const char *agent, IStrategyListener *listener); + FailoverStrategy(const std::vector &urls, int retryPause, int retries, const char *agent, IStrategyListener *listener); public: inline bool isActive() const override { return m_active >= 0; } @@ -60,6 +60,8 @@ protected: private: void add(const Url *url, const char *agent); + const int m_retries; + const int m_retryPause; int m_active; int m_index; IStrategyListener *m_listener; diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp index 997dc00b9..2671ba727 100644 --- a/src/net/strategies/SinglePoolStrategy.cpp +++ b/src/net/strategies/SinglePoolStrategy.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -25,16 +25,15 @@ #include "interfaces/IStrategyListener.h" #include "net/Client.h" #include "net/strategies/SinglePoolStrategy.h" -#include "Options.h" -SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener) : +SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, const char *agent, IStrategyListener *listener) : m_active(false), m_listener(listener) { m_client = new Client(0, agent, this); m_client->setUrl(url); - m_client->setRetryPause(Options::i()->retryPause() * 1000); + m_client->setRetryPause(retryPause * 1000); } diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h index 95e21547c..d444772e6 100644 --- a/src/net/strategies/SinglePoolStrategy.h +++ b/src/net/strategies/SinglePoolStrategy.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * 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 @@ -37,7 +37,7 @@ class Url; class SinglePoolStrategy : public IStrategy, public IClientListener { public: - SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener); + SinglePoolStrategy(const Url *url, int retryPause, const char *agent, IStrategyListener *listener); public: inline bool isActive() const override { return m_active; }