diff --git a/src/common/interfaces/IStrategy.h b/src/common/interfaces/IStrategy.h index 9f2795f9..b3ac7f9c 100644 --- a/src/common/interfaces/IStrategy.h +++ b/src/common/interfaces/IStrategy.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __ISTRATEGY_H__ -#define __ISTRATEGY_H__ +#ifndef XMRIG_ISTRATEGY_H +#define XMRIG_ISTRATEGY_H #include @@ -31,18 +32,24 @@ class JobResult; +namespace xmrig { + class Algorithm; +} + + class IStrategy { public: virtual ~IStrategy() {} - virtual bool isActive() const = 0; - virtual int64_t submit(const JobResult &result) = 0; - virtual void connect() = 0; - virtual void resume() = 0; - virtual void stop() = 0; - virtual void tick(uint64_t now) = 0; + virtual bool isActive() const = 0; + virtual int64_t submit(const JobResult &result) = 0; + virtual void connect() = 0; + virtual void resume() = 0; + virtual void setAlgo(const xmrig::Algorithm &algo) = 0; + virtual void stop() = 0; + virtual void tick(uint64_t now) = 0; }; -#endif // __ISTRATEGY_H__ +#endif // XMRIG_ISTRATEGY_H diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 2010aade..ad1ac663 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -203,10 +203,10 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const Value obj(kObjectType); - obj.AddMember("url", StringRef(url()), allocator); - obj.AddMember("user", StringRef(user()), allocator); - obj.AddMember("pass", StringRef(password()), allocator); - obj.AddMember("rig-id", rigId() ? Value(StringRef(rigId())).Move() : Value(kNullType).Move(), allocator); + obj.AddMember("url", m_url.toJSON(), allocator); + obj.AddMember("user", m_user.toJSON(), allocator); + obj.AddMember("pass", m_password.toJSON(), allocator); + obj.AddMember("rig-id", m_rigId.toJSON(), allocator); # ifndef XMRIG_PROXY_PROJECT obj.AddMember("nicehash", isNicehash(), allocator); @@ -223,17 +223,20 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const case xmrig::VARIANT_AUTO: case xmrig::VARIANT_0: case xmrig::VARIANT_1: - case xmrig::VARIANT_2: obj.AddMember("variant", m_algorithm.variant(), allocator); break; + case xmrig::VARIANT_2: + obj.AddMember("variant", 2, allocator); + break; + default: obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator); break; } obj.AddMember("tls", isTLS(), allocator); - obj.AddMember("tls-fingerprint", fingerprint() ? Value(StringRef(fingerprint())).Move() : Value(kNullType).Move(), allocator); + obj.AddMember("tls-fingerprint", m_fingerprint.toJSON(), allocator); return obj; } diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index fab78590..3be3687d 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -76,6 +77,14 @@ void FailoverStrategy::resume() } +void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) +{ + for (Client *client : m_pools) { + client->setAlgo(algo); + } +} + + void FailoverStrategy::stop() { for (size_t i = 0; i < m_pools.size(); ++i) { diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index 07095b3b..9fe9f9d8 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __FAILOVERSTRATEGY_H__ -#define __FAILOVERSTRATEGY_H__ +#ifndef XMRIG_FAILOVERSTRATEGY_H +#define XMRIG_FAILOVERSTRATEGY_H #include @@ -42,7 +43,7 @@ class FailoverStrategy : public IStrategy, public IClientListener { public: FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); - ~FailoverStrategy(); + ~FailoverStrategy() override; public: inline bool isActive() const override { return m_active >= 0; } @@ -50,6 +51,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; + void setAlgo(const xmrig::Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -71,4 +73,4 @@ private: std::vector m_pools; }; -#endif /* __FAILOVERSTRATEGY_H__ */ +#endif /* XMRIG_FAILOVERSTRATEGY_H */ diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index 2cfc0976..354bf6d6 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -68,6 +69,12 @@ void SinglePoolStrategy::resume() } +void SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo) +{ + m_client->setAlgo(algo); +} + + void SinglePoolStrategy::stop() { m_client->disconnect(); diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index 1a48d678..f258d9cd 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __SINGLEPOOLSTRATEGY_H__ -#define __SINGLEPOOLSTRATEGY_H__ +#ifndef XMRIG_SINGLEPOOLSTRATEGY_H +#define XMRIG_SINGLEPOOLSTRATEGY_H #include "common/interfaces/IClientListener.h" @@ -31,14 +32,14 @@ class Client; class IStrategyListener; -class Url; +class Pool; class SinglePoolStrategy : public IStrategy, public IClientListener { public: SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); - ~SinglePoolStrategy(); + ~SinglePoolStrategy() override; public: inline bool isActive() const override { return m_active; } @@ -46,6 +47,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; + void setAlgo(const xmrig::Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -61,4 +63,4 @@ private: IStrategyListener *m_listener; }; -#endif /* __SINGLEPOOLSTRATEGY_H__ */ +#endif /* XMRIG_SINGLEPOOLSTRATEGY_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 828203a1..b17242d6 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -154,12 +155,12 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit m_state.add(result, error); if (error) { - LOG_INFO(isColors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" + LOG_INFO(isColors() ? "\x1B[1;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[1;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[1;30m(%" PRIu64 " ms)" : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)", m_state.accepted, m_state.rejected, result.diff, error, result.elapsed); } else { - LOG_INFO(isColors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" + LOG_INFO(isColors() ? "\x1B[1;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[1;37m%u\x1B[0m \x1B[1;30m(%" PRIu64 " ms)" : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)", m_state.accepted, m_state.rejected, result.diff, result.elapsed); } @@ -178,6 +179,10 @@ void Network::setJob(Client *client, const Job &job, bool donate) : "new job from %s:%d diff %d algo %s", client->host(), client->port(), job.diff(), job.algorithm().shortName()); + if (!donate && m_donate) { + m_donate->setAlgo(job.algorithm()); + } + m_state.diff = job.diff(); Workers::setJob(job, donate); } diff --git a/src/net/Network.h b/src/net/Network.h index 51e95d6d..aac4010b 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __NETWORK_H__ -#define __NETWORK_H__ +#ifndef XMRIG_NETWORK_H +#define XMRIG_NETWORK_H #include @@ -47,7 +48,7 @@ class Network : public IJobResultListener, public IStrategyListener { public: Network(xmrig::Controller *controller); - ~Network(); + ~Network() override; void connect(); void stop(); @@ -76,4 +77,4 @@ private: }; -#endif /* __NETWORK_H__ */ +#endif /* XMRIG_NETWORK_H */ diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 6fc90842..417a31fb 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -43,7 +44,9 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS m_donateTime(level * 60 * 1000), m_idleTime((100 - level) * 60 * 1000), m_strategy(nullptr), - m_listener(listener) + m_listener(listener), + m_now(0), + m_stop(0) { uint8_t hash[200]; char userId[65] = { 0 }; @@ -93,6 +96,12 @@ void DonateStrategy::connect() } +void DonateStrategy::setAlgo(const xmrig::Algorithm &algo) +{ + m_strategy->setAlgo(algo); +} + + void DonateStrategy::stop() { uv_timer_stop(&m_timer); @@ -102,7 +111,14 @@ void DonateStrategy::stop() void DonateStrategy::tick(uint64_t now) { + m_now = now; + m_strategy->tick(now); + + if (m_stop && now > m_stop) { + m_strategy->stop(); + m_stop = 0; + } } @@ -119,7 +135,9 @@ void DonateStrategy::onActive(IStrategy *strategy, Client *client) void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) { - m_listener->onJob(this, client, job); + if (isActive()) { + m_listener->onJob(this, client, job); + } } @@ -142,7 +160,11 @@ void DonateStrategy::idle(uint64_t timeout) void DonateStrategy::suspend() { - m_strategy->stop(); +# if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT) + m_stop = m_now + 5000; +# else + m_stop = m_now + 500; +# endif m_active = false; m_listener->onPause(this); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index e75e41a4..d012c1b9 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -44,7 +45,7 @@ class DonateStrategy : public IStrategy, public IStrategyListener { public: DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); - ~DonateStrategy(); + ~DonateStrategy() override; public: inline bool isActive() const override { return m_active; } @@ -52,6 +53,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; + void setAlgo(const xmrig::Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -68,11 +70,13 @@ private: static void onTimer(uv_timer_t *handle); bool m_active; - const int m_donateTime; - const int m_idleTime; + const uint64_t m_donateTime; + const uint64_t m_idleTime; IStrategy *m_strategy; IStrategyListener *m_listener; std::vector m_pools; + uint64_t m_now; + uint64_t m_stop; uv_timer_t m_timer; };