diff --git a/src/net/Job.h b/src/net/Job.h index d981ed378..0fe51aeed 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -61,6 +61,7 @@ public: inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } + inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } static bool fromHex(const char* in, unsigned int len, unsigned char* out); diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 978bbf278..ede3f8b46 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -94,7 +94,7 @@ void Network::stop() void Network::onActive(IStrategy *strategy, Client *client) { - if (client->id() == -1) { + if (m_donate && m_donate == strategy) { LOG_NOTICE("dev donate started"); return; } @@ -107,11 +107,11 @@ void Network::onActive(IStrategy *strategy, Client *client) void Network::onJob(IStrategy *strategy, Client *client, const Job &job) { - if (m_donate && m_donate->isActive() && client->id() != -1) { + if (m_donate && m_donate->isActive() && m_donate != strategy) { return; } - setJob(client, job); + setJob(client, job, m_donate == strategy); } @@ -158,7 +158,7 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit } -void Network::setJob(Client *client, const Job &job) +void Network::setJob(Client *client, const Job &job, bool donate) { if (m_options->colors()) { LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff()); @@ -168,7 +168,7 @@ void Network::setJob(Client *client, const Job &job) } m_state.diff = job.diff(); - Workers::setJob(job); + Workers::setJob(job, donate); } diff --git a/src/net/Network.h b/src/net/Network.h index f7eb3ff2b..fae5c5638 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -58,7 +58,7 @@ protected: private: constexpr static int kTickInterval = 1 * 1000; - void setJob(Client *client, const Job &job); + void setJob(Client *client, const Job &job, bool donate); void tick(); static void onTick(uv_timer_t *handle); diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 55de9bdb2..cb28e122e 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -26,6 +26,7 @@ #include "net/Client.h" #include "net/Job.h" #include "net/strategies/DonateStrategy.h" +#include "net/strategies/FailoverStrategy.h" #include "Platform.h" #include "xmrig.h" @@ -36,10 +37,14 @@ extern "C" } +const static char *kDonatePool = "thanks.xmrig.com"; + + DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener) : m_active(false), m_donateTime(level * 60 * 1000), m_idleTime((100 - level) * 60 * 1000), + m_strategy(nullptr), m_listener(listener) { uint8_t hash[200]; @@ -48,14 +53,17 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL keccak(reinterpret_cast(user), static_cast(strlen(user)), hash, sizeof(hash)); Job::toHex(hash, 32, userId); - Url *url = new Url("thanks.xmrig.com", algo == xmrig::ALGO_CRYPTONIGHT_LITE ? 5555 : 80, userId, nullptr, false, true); + if (algo == xmrig::ALGO_CRYPTONIGHT) { + m_pools.push_back(new Url(kDonatePool, 80, userId, nullptr, false, true)); + m_pools.push_back(new Url(kDonatePool, 443, userId, nullptr, false, true)); + m_pools.push_back(new Url("emergency.xmrig.com", 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false)); + } + else { + m_pools.push_back(new Url(kDonatePool, 3333, userId, nullptr, false, true)); + m_pools.push_back(new Url(kDonatePool, 5555, userId, nullptr, false, true)); + } - m_client = new Client(-1, Platform::userAgent(), this); - m_client->setUrl(url); - m_client->setRetryPause(1000); - m_client->setQuiet(true); - - delete url; + m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true); m_timer.data = this; uv_timer_init(uv_default_loop(), &m_timer); @@ -64,15 +72,20 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL } +DonateStrategy::~DonateStrategy() +{ +} + + int64_t DonateStrategy::submit(const JobResult &result) { - return m_client->submit(result); + return m_strategy->submit(result); } void DonateStrategy::connect() { - m_client->connect(); + m_strategy->connect(); } @@ -84,28 +97,17 @@ void DonateStrategy::release() void DonateStrategy::stop() { uv_timer_stop(&m_timer); - m_client->disconnect(); + m_strategy->stop(); } void DonateStrategy::tick(uint64_t now) { - m_client->tick(now); + m_strategy->tick(now); } -void DonateStrategy::onClose(Client *client, int failures) -{ -} - - -void DonateStrategy::onJobReceived(Client *client, const Job &job) -{ - m_listener->onJob(this, client, job); -} - - -void DonateStrategy::onLoginSuccess(Client *client) +void DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); @@ -116,7 +118,18 @@ void DonateStrategy::onLoginSuccess(Client *client) } -void DonateStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) +void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) +{ + m_listener->onJob(this, client, job); +} + + +void DonateStrategy::onPause(IStrategy *strategy) +{ +} + + +void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } @@ -130,7 +143,7 @@ void DonateStrategy::idle() void DonateStrategy::suspend() { - m_client->disconnect(); + m_strategy->stop(); m_active = false; m_listener->onPause(this); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index f805bc782..bb3b63b79 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -26,10 +26,12 @@ #include +#include #include "interfaces/IClientListener.h" #include "interfaces/IStrategy.h" +#include "interfaces/IStrategyListener.h" class Client; @@ -37,10 +39,11 @@ class IStrategyListener; class Url; -class DonateStrategy : public IStrategy, public IClientListener +class DonateStrategy : public IStrategy, public IStrategyListener { public: DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener); + ~DonateStrategy(); public: inline bool isActive() const override { return m_active; } @@ -53,10 +56,10 @@ public: void tick(uint64_t now) override; protected: - void onClose(Client *client, int failures) override; - void onJobReceived(Client *client, const Job &job) override; - void onLoginSuccess(Client *client) override; - void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; + void onActive(IStrategy *strategy, Client *client) override; + void onJob(IStrategy *strategy, Client *client, const Job &job) override; + void onPause(IStrategy *strategy) override; + void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; private: void idle(); @@ -65,10 +68,11 @@ private: static void onTimer(uv_timer_t *handle); bool m_active; - Client *m_client; const int m_donateTime; const int m_idleTime; + IStrategy *m_strategy; IStrategyListener *m_listener; + std::vector m_pools; uv_timer_t m_timer; }; diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 5ead16c19..52bd2fbf5 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -28,8 +28,9 @@ #include "Platform.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener) : +FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_release(false), + m_quiet(quiet), m_retries(retries), m_retryPause(retryPause), m_active(-1), @@ -175,6 +176,7 @@ void FailoverStrategy::add(const Url *url) Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); client->setUrl(url); client->setRetryPause(m_retryPause * 1000); + client->setQuiet(m_quiet); m_pools.push_back(client); } diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h index 7b7adf722..c8e24fb14 100644 --- a/src/net/strategies/FailoverStrategy.h +++ b/src/net/strategies/FailoverStrategy.h @@ -40,7 +40,7 @@ class Url; class FailoverStrategy : public IStrategy, public IClientListener { public: - FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener); + FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); ~FailoverStrategy(); public: @@ -63,6 +63,7 @@ private: void add(const Url *url); bool m_release; + const bool m_quiet; const int m_retries; const int m_retryPause; int m_active; diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp index fe37288be..b0d985197 100644 --- a/src/net/strategies/SinglePoolStrategy.cpp +++ b/src/net/strategies/SinglePoolStrategy.cpp @@ -28,7 +28,7 @@ #include "Platform.h" -SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener) : +SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet) : m_active(false), m_release(false), m_listener(listener) @@ -36,6 +36,7 @@ SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategy m_client = new Client(0, Platform::userAgent(), this); m_client->setUrl(url); m_client->setRetryPause(retryPause * 1000); + m_client->setQuiet(quiet); } diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h index a918768c5..18d2192b1 100644 --- a/src/net/strategies/SinglePoolStrategy.h +++ b/src/net/strategies/SinglePoolStrategy.h @@ -37,7 +37,7 @@ class Url; class SinglePoolStrategy : public IStrategy, public IClientListener { public: - SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener); + SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false); ~SinglePoolStrategy(); public: diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 02646cedf..7a7ff9865 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.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 diff --git a/src/workers/Worker.h b/src/workers/Worker.h index 11c4a198f..08a0551f1 100644 --- a/src/workers/Worker.h +++ b/src/workers/Worker.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 diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 039a1793c..f0aef448d 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -83,10 +83,14 @@ void Workers::setEnabled(bool enabled) } -void Workers::setJob(const Job &job) +void Workers::setJob(const Job &job, bool donate) { uv_rwlock_wrlock(&m_rwlock); m_job = job; + + if (donate) { + m_job.setPoolId(-1); + } uv_rwlock_wrunlock(&m_rwlock); m_active = true; diff --git a/src/workers/Workers.h b/src/workers/Workers.h index e76d0a620..1c85089a1 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -45,7 +45,7 @@ public: static Job job(); static void printHashrate(bool detail); static void setEnabled(bool enabled); - static void setJob(const Job &job); + static void setJob(const Job &job, bool donate); static void start(int64_t affinity, int priority); static void stop(); static void submit(const JobResult &result);